Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Memory-access and commands for "inferior" process, for GDB. |
990a07ab | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
4c38e0a4 | 5 | 2008, 2009, 2010 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
5af949e3 | 23 | #include "arch-utils.h" |
c906108c SS |
24 | #include <signal.h> |
25 | #include "gdb_string.h" | |
26 | #include "symtab.h" | |
27 | #include "gdbtypes.h" | |
28 | #include "frame.h" | |
29 | #include "inferior.h" | |
30 | #include "environ.h" | |
31 | #include "value.h" | |
32 | #include "gdbcmd.h" | |
1adeb98a | 33 | #include "symfile.h" |
c906108c SS |
34 | #include "gdbcore.h" |
35 | #include "target.h" | |
36 | #include "language.h" | |
37 | #include "symfile.h" | |
38 | #include "objfiles.h" | |
c94fdfd0 | 39 | #include "completer.h" |
8b93c638 | 40 | #include "ui-out.h" |
6426a772 | 41 | #include "event-top.h" |
96baa820 | 42 | #include "parser-defs.h" |
36160dc4 | 43 | #include "regcache.h" |
f9418c0f | 44 | #include "reggroups.h" |
fe898f56 | 45 | #include "block.h" |
a77053c2 | 46 | #include "solib.h" |
f9418c0f | 47 | #include <ctype.h> |
92ad9cd9 | 48 | #include "gdb_assert.h" |
281b533b | 49 | #include "observer.h" |
424163ea | 50 | #include "target-descriptions.h" |
ad842144 | 51 | #include "user-regs.h" |
32c1e744 | 52 | #include "exceptions.h" |
700b53b1 | 53 | #include "cli/cli-decode.h" |
a0ef4274 | 54 | #include "gdbthread.h" |
79a45b7d | 55 | #include "valprint.h" |
edb3359d | 56 | #include "inline-frame.h" |
573cda03 | 57 | #include "tracepoint.h" |
d5551862 | 58 | |
a58dd373 | 59 | /* Functions exported for general use, in inferior.h: */ |
c906108c | 60 | |
a14ed312 | 61 | void all_registers_info (char *, int); |
c906108c | 62 | |
a14ed312 | 63 | void registers_info (char *, int); |
c906108c | 64 | |
a58dd373 EZ |
65 | void nexti_command (char *, int); |
66 | ||
67 | void stepi_command (char *, int); | |
c906108c | 68 | |
a14ed312 | 69 | void continue_command (char *, int); |
c906108c | 70 | |
a58dd373 EZ |
71 | void interrupt_target_command (char *args, int from_tty); |
72 | ||
73 | /* Local functions: */ | |
74 | ||
75 | static void nofp_registers_info (char *, int); | |
76 | ||
c055b101 CV |
77 | static void print_return_value (struct type *func_type, |
78 | struct type *value_type); | |
11cf8741 | 79 | |
a14ed312 | 80 | static void until_next_command (int); |
c906108c | 81 | |
a14ed312 | 82 | static void until_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void path_info (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void path_command (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void unset_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void float_info (char *, int); |
c906108c | 91 | |
6ad8ae5c DJ |
92 | static void disconnect_command (char *, int); |
93 | ||
a14ed312 | 94 | static void unset_environment_command (char *, int); |
c906108c | 95 | |
a14ed312 | 96 | static void set_environment_command (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void environment_info (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void program_info (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void finish_command (char *, int); |
c906108c | 103 | |
a14ed312 | 104 | static void signal_command (char *, int); |
c906108c | 105 | |
a14ed312 | 106 | static void jump_command (char *, int); |
c906108c | 107 | |
a14ed312 | 108 | static void step_1 (int, int, char *); |
611c83ae | 109 | static void step_once (int skip_subroutines, int single_inst, int count, int thread); |
c906108c | 110 | |
a14ed312 | 111 | static void next_command (char *, int); |
c906108c | 112 | |
a14ed312 | 113 | static void step_command (char *, int); |
c906108c | 114 | |
a14ed312 | 115 | static void run_command (char *, int); |
c906108c | 116 | |
a14ed312 | 117 | static void run_no_args_command (char *args, int from_tty); |
392a587b | 118 | |
a14ed312 | 119 | static void go_command (char *line_no, int from_tty); |
392a587b | 120 | |
a14ed312 | 121 | static int strip_bg_char (char **); |
43ff13b4 | 122 | |
a14ed312 | 123 | void _initialize_infcmd (void); |
c906108c | 124 | |
c906108c | 125 | #define ERROR_NO_INFERIOR \ |
8a3fe4f8 | 126 | if (!target_has_execution) error (_("The program is not being run.")); |
c906108c | 127 | |
3f81c18a VP |
128 | /* Scratch area where string containing arguments to give to the program will be |
129 | stored by 'set args'. As soon as anything is stored, notice_args_set will | |
130 | move it into per-inferior storage. Arguments are separated by spaces. Empty | |
131 | string (pointer to '\0') means no args. */ | |
c906108c | 132 | |
3f81c18a | 133 | static char *inferior_args_scratch; |
c906108c | 134 | |
3f81c18a VP |
135 | /* Scratch area where 'set inferior-tty' will store user-provided value. |
136 | We'll immediate copy it into per-inferior storage. */ | |
552c04a7 | 137 | |
3f81c18a | 138 | static char *inferior_io_terminal_scratch; |
c906108c SS |
139 | |
140 | /* Pid of our debugged inferior, or 0 if no inferior now. | |
141 | Since various parts of infrun.c test this to see whether there is a program | |
142 | being debugged it should be nonzero (currently 3 is used) for remote | |
143 | debugging. */ | |
144 | ||
39f77062 | 145 | ptid_t inferior_ptid; |
c906108c | 146 | |
c906108c SS |
147 | /* Address at which inferior stopped. */ |
148 | ||
149 | CORE_ADDR stop_pc; | |
150 | ||
c906108c SS |
151 | /* Flag indicating that a command has proceeded the inferior past the |
152 | current breakpoint. */ | |
153 | ||
154 | int breakpoint_proceeded; | |
155 | ||
c906108c SS |
156 | /* Nonzero if stopped due to completion of a stack dummy routine. */ |
157 | ||
aa7d318d | 158 | enum stop_stack_kind stop_stack_dummy; |
c906108c SS |
159 | |
160 | /* Nonzero if stopped due to a random (unexpected) signal in inferior | |
161 | process. */ | |
162 | ||
163 | int stopped_by_random_signal; | |
164 | ||
c906108c | 165 | \f |
07091751 FN |
166 | /* Accessor routines. */ |
167 | ||
3f81c18a VP |
168 | /* Set the io terminal for the current inferior. Ownership of |
169 | TERMINAL_NAME is not transferred. */ | |
170 | ||
3cb3b8df BR |
171 | void |
172 | set_inferior_io_terminal (const char *terminal_name) | |
173 | { | |
3f81c18a VP |
174 | xfree (current_inferior ()->terminal); |
175 | current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0; | |
3cb3b8df BR |
176 | } |
177 | ||
178 | const char * | |
179 | get_inferior_io_terminal (void) | |
180 | { | |
3f81c18a VP |
181 | return current_inferior ()->terminal; |
182 | } | |
183 | ||
184 | static void | |
185 | set_inferior_tty_command (char *args, int from_tty, | |
186 | struct cmd_list_element *c) | |
187 | { | |
188 | /* CLI has assigned the user-provided value to inferior_io_terminal_scratch. | |
189 | Now route it to current inferior. */ | |
190 | set_inferior_io_terminal (inferior_io_terminal_scratch); | |
191 | } | |
192 | ||
193 | static void | |
194 | show_inferior_tty_command (struct ui_file *file, int from_tty, | |
195 | struct cmd_list_element *c, const char *value) | |
196 | { | |
197 | /* Note that we ignore the passed-in value in favor of computing it | |
198 | directly. */ | |
275f2e57 DJ |
199 | const char *inferior_io_terminal = get_inferior_io_terminal (); |
200 | if (inferior_io_terminal == NULL) | |
201 | inferior_io_terminal = ""; | |
3f81c18a | 202 | fprintf_filtered (gdb_stdout, |
275f2e57 DJ |
203 | _("Terminal for future runs of program being debugged " |
204 | "is \"%s\".\n"), inferior_io_terminal); | |
3cb3b8df BR |
205 | } |
206 | ||
07091751 FN |
207 | char * |
208 | get_inferior_args (void) | |
209 | { | |
3f81c18a | 210 | if (current_inferior ()->argc != 0) |
552c04a7 | 211 | { |
3f81c18a | 212 | char *n; |
552c04a7 | 213 | |
3f81c18a VP |
214 | n = construct_inferior_arguments (current_inferior ()->argc, |
215 | current_inferior ()->argv); | |
216 | set_inferior_args (n); | |
217 | xfree (n); | |
552c04a7 TT |
218 | } |
219 | ||
3f81c18a VP |
220 | if (current_inferior ()->args == NULL) |
221 | current_inferior ()->args = xstrdup (""); | |
552c04a7 | 222 | |
3f81c18a | 223 | return current_inferior ()->args; |
07091751 FN |
224 | } |
225 | ||
3f81c18a VP |
226 | /* Set the arguments for the current inferior. Ownership of |
227 | NEWARGS is not transferred. */ | |
228 | ||
229 | void | |
07091751 FN |
230 | set_inferior_args (char *newargs) |
231 | { | |
3f81c18a VP |
232 | xfree (current_inferior ()->args); |
233 | current_inferior ()->args = newargs ? xstrdup (newargs) : NULL; | |
234 | current_inferior ()->argc = 0; | |
235 | current_inferior ()->argv = 0; | |
07091751 | 236 | } |
c5aa993b | 237 | |
552c04a7 TT |
238 | void |
239 | set_inferior_args_vector (int argc, char **argv) | |
240 | { | |
3f81c18a VP |
241 | current_inferior ()->argc = argc; |
242 | current_inferior ()->argv = argv; | |
552c04a7 TT |
243 | } |
244 | ||
245 | /* Notice when `set args' is run. */ | |
246 | static void | |
3f81c18a | 247 | set_args_command (char *args, int from_tty, struct cmd_list_element *c) |
552c04a7 | 248 | { |
3f81c18a VP |
249 | /* CLI has assigned the user-provided value to inferior_args_scratch. |
250 | Now route it to current inferior. */ | |
251 | set_inferior_args (inferior_args_scratch); | |
552c04a7 TT |
252 | } |
253 | ||
254 | /* Notice when `show args' is run. */ | |
255 | static void | |
3f81c18a VP |
256 | show_args_command (struct ui_file *file, int from_tty, |
257 | struct cmd_list_element *c, const char *value) | |
552c04a7 | 258 | { |
258c00cc TT |
259 | /* Note that we ignore the passed-in value in favor of computing it |
260 | directly. */ | |
261 | deprecated_show_value_hack (file, from_tty, c, get_inferior_args ()); | |
552c04a7 TT |
262 | } |
263 | ||
c2a727fa TT |
264 | \f |
265 | /* Compute command-line string given argument vector. This does the | |
266 | same shell processing as fork_inferior. */ | |
c2a727fa | 267 | char * |
bd57a748 | 268 | construct_inferior_arguments (int argc, char **argv) |
c2a727fa TT |
269 | { |
270 | char *result; | |
271 | ||
272 | if (STARTUP_WITH_SHELL) | |
273 | { | |
274 | /* This holds all the characters considered special to the | |
275 | typical Unix shells. We include `^' because the SunOS | |
276 | /bin/sh treats it as a synonym for `|'. */ | |
277 | char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n"; | |
278 | int i; | |
279 | int length = 0; | |
280 | char *out, *cp; | |
281 | ||
282 | /* We over-compute the size. It shouldn't matter. */ | |
283 | for (i = 0; i < argc; ++i) | |
c2226152 | 284 | length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0'); |
c2a727fa TT |
285 | |
286 | result = (char *) xmalloc (length); | |
287 | out = result; | |
288 | ||
289 | for (i = 0; i < argc; ++i) | |
290 | { | |
291 | if (i > 0) | |
292 | *out++ = ' '; | |
293 | ||
03c6228e AS |
294 | /* Need to handle empty arguments specially. */ |
295 | if (argv[i][0] == '\0') | |
c2a727fa | 296 | { |
03c6228e AS |
297 | *out++ = '\''; |
298 | *out++ = '\''; | |
299 | } | |
300 | else | |
301 | { | |
302 | for (cp = argv[i]; *cp; ++cp) | |
303 | { | |
c2226152 AS |
304 | if (*cp == '\n') |
305 | { | |
306 | /* A newline cannot be quoted with a backslash (it | |
307 | just disappears), only by putting it inside | |
308 | quotes. */ | |
309 | *out++ = '\''; | |
310 | *out++ = '\n'; | |
311 | *out++ = '\''; | |
312 | } | |
313 | else | |
314 | { | |
315 | if (strchr (special, *cp) != NULL) | |
316 | *out++ = '\\'; | |
317 | *out++ = *cp; | |
318 | } | |
03c6228e | 319 | } |
c2a727fa TT |
320 | } |
321 | } | |
322 | *out = '\0'; | |
323 | } | |
324 | else | |
325 | { | |
326 | /* In this case we can't handle arguments that contain spaces, | |
327 | tabs, or newlines -- see breakup_args(). */ | |
328 | int i; | |
329 | int length = 0; | |
330 | ||
331 | for (i = 0; i < argc; ++i) | |
332 | { | |
333 | char *cp = strchr (argv[i], ' '); | |
334 | if (cp == NULL) | |
335 | cp = strchr (argv[i], '\t'); | |
336 | if (cp == NULL) | |
337 | cp = strchr (argv[i], '\n'); | |
338 | if (cp != NULL) | |
8a3fe4f8 | 339 | error (_("can't handle command-line argument containing whitespace")); |
c2a727fa TT |
340 | length += strlen (argv[i]) + 1; |
341 | } | |
342 | ||
343 | result = (char *) xmalloc (length); | |
344 | result[0] = '\0'; | |
345 | for (i = 0; i < argc; ++i) | |
346 | { | |
347 | if (i > 0) | |
348 | strcat (result, " "); | |
349 | strcat (result, argv[i]); | |
350 | } | |
351 | } | |
352 | ||
353 | return result; | |
354 | } | |
552c04a7 TT |
355 | \f |
356 | ||
43ff13b4 JM |
357 | /* This function detects whether or not a '&' character (indicating |
358 | background execution) has been added as *the last* of the arguments ARGS | |
359 | of a command. If it has, it removes it and returns 1. Otherwise it | |
360 | does nothing and returns 0. */ | |
c5aa993b | 361 | static int |
fba45db2 | 362 | strip_bg_char (char **args) |
43ff13b4 JM |
363 | { |
364 | char *p = NULL; | |
c5aa993b | 365 | |
9846de1b | 366 | p = strchr (*args, '&'); |
c5aa993b | 367 | |
9846de1b | 368 | if (p) |
43ff13b4 JM |
369 | { |
370 | if (p == (*args + strlen (*args) - 1)) | |
371 | { | |
c5aa993b | 372 | if (strlen (*args) > 1) |
43ff13b4 JM |
373 | { |
374 | do | |
375 | p--; | |
376 | while (*p == ' ' || *p == '\t'); | |
377 | *(p + 1) = '\0'; | |
378 | } | |
379 | else | |
380 | *args = 0; | |
381 | return 1; | |
382 | } | |
383 | } | |
384 | return 0; | |
385 | } | |
386 | ||
281b533b DJ |
387 | /* Common actions to take after creating any sort of inferior, by any |
388 | means (running, attaching, connecting, et cetera). The target | |
389 | should be stopped. */ | |
390 | ||
391 | void | |
392 | post_create_inferior (struct target_ops *target, int from_tty) | |
393 | { | |
b79599ff DP |
394 | /* Be sure we own the terminal in case write operations are performed. */ |
395 | target_terminal_ours (); | |
396 | ||
424163ea DJ |
397 | /* If the target hasn't taken care of this already, do it now. |
398 | Targets which need to access registers during to_open, | |
399 | to_create_inferior, or to_attach should do it earlier; but many | |
400 | don't need to. */ | |
401 | target_find_description (); | |
402 | ||
f698437e | 403 | /* Now that we know the register layout, retrieve current PC. */ |
fb14de7b | 404 | stop_pc = regcache_read_pc (get_current_regcache ()); |
f698437e | 405 | |
50c71eaf PA |
406 | if (exec_bfd) |
407 | { | |
9353355f DJ |
408 | /* Create the hooks to handle shared library load and unload |
409 | events. */ | |
410 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
37706b70 | 411 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
9353355f | 412 | #else |
268a4a75 JK |
413 | solib_create_inferior_hook (from_tty); |
414 | #endif | |
415 | } | |
416 | ||
417 | /* If the solist is global across processes, there's no need to | |
418 | refetch it here. */ | |
419 | if (exec_bfd && !gdbarch_has_global_solist (target_gdbarch)) | |
420 | { | |
421 | /* Sometimes the platform-specific hook loads initial shared | |
422 | libraries, and sometimes it doesn't. If it doesn't FROM_TTY will be | |
423 | incorrectly 0 but such solib targets should be fixed anyway. If we | |
424 | made all the inferior hook methods consistent, this call could be | |
425 | removed. Call it only after the solib target has been initialized by | |
426 | solib_create_inferior_hook. */ | |
427 | ||
428 | #ifdef SOLIB_ADD | |
429 | SOLIB_ADD (NULL, 0, target, auto_solib_add); | |
430 | #else | |
431 | solib_add (NULL, 0, target, auto_solib_add); | |
9353355f | 432 | #endif |
9353355f DJ |
433 | } |
434 | ||
ea5d7a99 PM |
435 | /* If the user sets watchpoints before execution having started, |
436 | then she gets software watchpoints, because GDB can't know which | |
437 | target will end up being pushed, or if it supports hardware | |
438 | watchpoints or not. breakpoint_re_set takes care of promoting | |
439 | watchpoints to hardware watchpoints if possible, however, if this | |
440 | new inferior doesn't load shared libraries or we don't pull in | |
441 | symbols from any other source on this target/arch, | |
442 | breakpoint_re_set is never called. Call it now so that software | |
443 | watchpoints get a chance to be promoted to hardware watchpoints | |
444 | if the now pushed target supports hardware watchpoints. */ | |
445 | breakpoint_re_set (); | |
446 | ||
281b533b DJ |
447 | observer_notify_inferior_created (target, from_tty); |
448 | } | |
449 | ||
a4d5f2e0 JB |
450 | /* Kill the inferior if already running. This function is designed |
451 | to be called when we are about to start the execution of the program | |
452 | from the beginning. Ask the user to confirm that he wants to restart | |
453 | the program being debugged when FROM_TTY is non-null. */ | |
c906108c | 454 | |
8edfe269 | 455 | static void |
a4d5f2e0 JB |
456 | kill_if_already_running (int from_tty) |
457 | { | |
39f77062 | 458 | if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution) |
c906108c | 459 | { |
8edfe269 DJ |
460 | /* Bail out before killing the program if we will not be able to |
461 | restart it. */ | |
462 | target_require_runnable (); | |
463 | ||
adf40b2e | 464 | if (from_tty |
9e2f0ad4 HZ |
465 | && !query (_("The program being debugged has been started already.\n\ |
466 | Start it from the beginning? "))) | |
8a3fe4f8 | 467 | error (_("Program not restarted.")); |
c906108c | 468 | target_kill (); |
c906108c | 469 | } |
a4d5f2e0 JB |
470 | } |
471 | ||
f67a969f JB |
472 | /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert |
473 | a temporary breakpoint at the begining of the main program before | |
474 | running the program. */ | |
475 | ||
a4d5f2e0 | 476 | static void |
f67a969f | 477 | run_command_1 (char *args, int from_tty, int tbreak_at_main) |
a4d5f2e0 JB |
478 | { |
479 | char *exec_file; | |
29f49a6a PA |
480 | struct cleanup *old_chain; |
481 | ptid_t ptid; | |
c906108c | 482 | |
a4d5f2e0 JB |
483 | dont_repeat (); |
484 | ||
485 | kill_if_already_running (from_tty); | |
3c35e65b UW |
486 | |
487 | init_wait_for_inferior (); | |
c906108c SS |
488 | clear_breakpoint_hit_counts (); |
489 | ||
fd79ecee DJ |
490 | /* Clean up any leftovers from other runs. Some other things from |
491 | this function should probably be moved into target_pre_inferior. */ | |
492 | target_pre_inferior (from_tty); | |
493 | ||
39ad761d JB |
494 | /* The comment here used to read, "The exec file is re-read every |
495 | time we do a generic_mourn_inferior, so we just have to worry | |
496 | about the symbol file." The `generic_mourn_inferior' function | |
497 | gets called whenever the program exits. However, suppose the | |
498 | program exits, and *then* the executable file changes? We need | |
499 | to check again here. Since reopen_exec_file doesn't do anything | |
500 | if the timestamp hasn't changed, I don't see the harm. */ | |
501 | reopen_exec_file (); | |
c906108c SS |
502 | reread_symbols (); |
503 | ||
f67a969f JB |
504 | /* Insert the temporary breakpoint if a location was specified. */ |
505 | if (tbreak_at_main) | |
506 | tbreak_command (main_name (), 0); | |
507 | ||
39ad761d JB |
508 | exec_file = (char *) get_exec_file (0); |
509 | ||
9908b566 VP |
510 | if (non_stop && !target_supports_non_stop ()) |
511 | error (_("The target does not support running in non-stop mode.")); | |
512 | ||
c906108c SS |
513 | /* We keep symbols from add-symbol-file, on the grounds that the |
514 | user might want to add some symbols before running the program | |
515 | (right?). But sometimes (dynamic loading where the user manually | |
516 | introduces the new symbols with add-symbol-file), the code which | |
517 | the symbols describe does not persist between runs. Currently | |
518 | the user has to manually nuke all symbols between runs if they | |
519 | want them to go away (PR 2207). This is probably reasonable. */ | |
520 | ||
43ff13b4 | 521 | if (!args) |
6426a772 | 522 | { |
362646f5 | 523 | if (target_can_async_p ()) |
6426a772 JM |
524 | async_disable_stdin (); |
525 | } | |
43ff13b4 | 526 | else |
c906108c | 527 | { |
43ff13b4 JM |
528 | int async_exec = strip_bg_char (&args); |
529 | ||
530 | /* If we get a request for running in the bg but the target | |
531 | doesn't support it, error out. */ | |
362646f5 | 532 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 533 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 JM |
534 | |
535 | /* If we don't get a request of running in the bg, then we need | |
c5aa993b | 536 | to simulate synchronous (fg) execution. */ |
362646f5 | 537 | if (!async_exec && target_can_async_p ()) |
43ff13b4 JM |
538 | { |
539 | /* Simulate synchronous execution */ | |
6426a772 | 540 | async_disable_stdin (); |
43ff13b4 JM |
541 | } |
542 | ||
543 | /* If there were other args, beside '&', process them. */ | |
544 | if (args) | |
3f81c18a | 545 | set_inferior_args (args); |
c906108c SS |
546 | } |
547 | ||
548 | if (from_tty) | |
549 | { | |
8b93c638 JM |
550 | ui_out_field_string (uiout, NULL, "Starting program"); |
551 | ui_out_text (uiout, ": "); | |
552 | if (exec_file) | |
553 | ui_out_field_string (uiout, "execfile", exec_file); | |
554 | ui_out_spaces (uiout, 1); | |
552c04a7 TT |
555 | /* We call get_inferior_args() because we might need to compute |
556 | the value now. */ | |
557 | ui_out_field_string (uiout, "infargs", get_inferior_args ()); | |
8b93c638 JM |
558 | ui_out_text (uiout, "\n"); |
559 | ui_out_flush (uiout); | |
c906108c SS |
560 | } |
561 | ||
552c04a7 TT |
562 | /* We call get_inferior_args() because we might need to compute |
563 | the value now. */ | |
564 | target_create_inferior (exec_file, get_inferior_args (), | |
3f81c18a | 565 | environ_vector (current_inferior ()->environment), from_tty); |
281b533b | 566 | |
29f49a6a PA |
567 | /* We're starting off a new process. When we get out of here, in |
568 | non-stop mode, finish the state of all threads of that process, | |
569 | but leave other threads alone, as they may be stopped in internal | |
570 | events --- the frontend shouldn't see them as stopped. In | |
571 | all-stop, always finish the state of all threads, as we may be | |
572 | resuming more than just the new process. */ | |
573 | if (non_stop) | |
574 | ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); | |
575 | else | |
576 | ptid = minus_one_ptid; | |
577 | old_chain = make_cleanup (finish_thread_state_cleanup, &ptid); | |
578 | ||
de1b3c3d PA |
579 | /* Pass zero for FROM_TTY, because at this point the "run" command |
580 | has done its thing; now we are setting up the running program. */ | |
581 | post_create_inferior (¤t_target, 0); | |
281b533b | 582 | |
74d1f91e JK |
583 | /* Start the target running. Do not use -1 continuation as it would skip |
584 | breakpoint right at the entry point. */ | |
585 | proceed (regcache_read_pc (get_current_regcache ()), TARGET_SIGNAL_0, 0); | |
c906108c | 586 | |
29f49a6a PA |
587 | /* Since there was no error, there's no need to finish the thread |
588 | states here. */ | |
589 | discard_cleanups (old_chain); | |
590 | } | |
c906108c | 591 | |
f67a969f JB |
592 | static void |
593 | run_command (char *args, int from_tty) | |
594 | { | |
595 | run_command_1 (args, from_tty, 0); | |
596 | } | |
597 | ||
c906108c | 598 | static void |
fba45db2 | 599 | run_no_args_command (char *args, int from_tty) |
c906108c | 600 | { |
3f81c18a | 601 | set_inferior_args (""); |
c906108c | 602 | } |
c906108c | 603 | \f |
c5aa993b | 604 | |
a4d5f2e0 JB |
605 | /* Start the execution of the program up until the beginning of the main |
606 | program. */ | |
607 | ||
608 | static void | |
609 | start_command (char *args, int from_tty) | |
610 | { | |
611 | /* Some languages such as Ada need to search inside the program | |
612 | minimal symbols for the location where to put the temporary | |
613 | breakpoint before starting. */ | |
614 | if (!have_minimal_symbols ()) | |
8a3fe4f8 | 615 | error (_("No symbol table loaded. Use the \"file\" command.")); |
a4d5f2e0 | 616 | |
f67a969f JB |
617 | /* Run the program until reaching the main procedure... */ |
618 | run_command_1 (args, from_tty, 1); | |
a4d5f2e0 JB |
619 | } |
620 | ||
8cae4b3f PA |
621 | static int |
622 | proceed_thread_callback (struct thread_info *thread, void *arg) | |
623 | { | |
74531fed PA |
624 | /* We go through all threads individually instead of compressing |
625 | into a single target `resume_all' request, because some threads | |
626 | may be stopped in internal breakpoints/events, or stopped waiting | |
627 | for its turn in the displaced stepping queue (that is, they are | |
628 | running && !executing). The target side has no idea about why | |
629 | the thread is stopped, so a `resume_all' command would resume too | |
630 | much. If/when GDB gains a way to tell the target `hold this | |
631 | thread stopped until I say otherwise', then we can optimize | |
632 | this. */ | |
4f8d22e3 | 633 | if (!is_stopped (thread->ptid)) |
8cae4b3f PA |
634 | return 0; |
635 | ||
dcf4fbde | 636 | switch_to_thread (thread->ptid); |
8cae4b3f PA |
637 | clear_proceed_status (); |
638 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); | |
639 | return 0; | |
640 | } | |
641 | ||
d729566a PA |
642 | void |
643 | ensure_valid_thread (void) | |
644 | { | |
645 | if (ptid_equal (inferior_ptid, null_ptid) | |
646 | || is_exited (inferior_ptid)) | |
647 | error (_("\ | |
648 | Cannot execute this command without a live selected thread.")); | |
649 | } | |
650 | ||
573cda03 SS |
651 | /* If the user is looking at trace frames, any resumption of execution |
652 | is likely to mix up recorded and live target data. So simply | |
653 | disallow those commands. */ | |
654 | ||
655 | void | |
656 | ensure_not_tfind_mode (void) | |
657 | { | |
658 | if (get_traceframe_number () >= 0) | |
659 | error (_("\ | |
660 | Cannot execute this command while looking at trace frames.")); | |
661 | } | |
662 | ||
77ebaa5a VP |
663 | void |
664 | continue_1 (int all_threads) | |
665 | { | |
3d488bfc | 666 | ERROR_NO_INFERIOR; |
573cda03 | 667 | ensure_not_tfind_mode (); |
3d488bfc | 668 | |
77ebaa5a VP |
669 | if (non_stop && all_threads) |
670 | { | |
671 | /* Don't error out if the current thread is running, because | |
672 | there may be other stopped threads. */ | |
673 | struct cleanup *old_chain; | |
674 | ||
675 | /* Backup current thread and selected frame. */ | |
676 | old_chain = make_cleanup_restore_current_thread (); | |
677 | ||
678 | iterate_over_threads (proceed_thread_callback, NULL); | |
679 | ||
680 | /* Restore selected ptid. */ | |
681 | do_cleanups (old_chain); | |
682 | } | |
683 | else | |
684 | { | |
d729566a | 685 | ensure_valid_thread (); |
77ebaa5a VP |
686 | ensure_not_running (); |
687 | clear_proceed_status (); | |
688 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); | |
689 | } | |
690 | } | |
691 | ||
8cae4b3f | 692 | /* continue [-a] [proceed-count] [&] */ |
c906108c | 693 | void |
8cae4b3f | 694 | continue_command (char *args, int from_tty) |
c906108c | 695 | { |
c5aa993b | 696 | int async_exec = 0; |
8cae4b3f | 697 | int all_threads = 0; |
c906108c SS |
698 | ERROR_NO_INFERIOR; |
699 | ||
43ff13b4 | 700 | /* Find out whether we must run in the background. */ |
8cae4b3f PA |
701 | if (args != NULL) |
702 | async_exec = strip_bg_char (&args); | |
43ff13b4 JM |
703 | |
704 | /* If we must run in the background, but the target can't do it, | |
705 | error out. */ | |
362646f5 | 706 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 707 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 JM |
708 | |
709 | /* If we are not asked to run in the bg, then prepare to run in the | |
710 | foreground, synchronously. */ | |
362646f5 | 711 | if (!async_exec && target_can_async_p ()) |
c5aa993b | 712 | { |
43ff13b4 | 713 | /* Simulate synchronous execution */ |
6426a772 | 714 | async_disable_stdin (); |
43ff13b4 | 715 | } |
c906108c | 716 | |
8cae4b3f PA |
717 | if (args != NULL) |
718 | { | |
719 | if (strncmp (args, "-a", sizeof ("-a") - 1) == 0) | |
720 | { | |
721 | all_threads = 1; | |
722 | args += sizeof ("-a") - 1; | |
723 | if (*args == '\0') | |
724 | args = NULL; | |
725 | } | |
726 | } | |
727 | ||
728 | if (!non_stop && all_threads) | |
729 | error (_("`-a' is meaningless in all-stop mode.")); | |
730 | ||
731 | if (args != NULL && all_threads) | |
732 | error (_("\ | |
733 | Can't resume all threads and specify proceed count simultaneously.")); | |
734 | ||
735 | /* If we have an argument left, set proceed count of breakpoint we | |
736 | stopped at. */ | |
737 | if (args != NULL) | |
c906108c | 738 | { |
347bddb7 | 739 | bpstat bs = NULL; |
8671a17b PA |
740 | int num, stat; |
741 | int stopped = 0; | |
347bddb7 PA |
742 | struct thread_info *tp; |
743 | ||
744 | if (non_stop) | |
e09875d4 | 745 | tp = find_thread_ptid (inferior_ptid); |
347bddb7 PA |
746 | else |
747 | { | |
748 | ptid_t last_ptid; | |
749 | struct target_waitstatus ws; | |
750 | ||
751 | get_last_target_status (&last_ptid, &ws); | |
e09875d4 | 752 | tp = find_thread_ptid (last_ptid); |
347bddb7 PA |
753 | } |
754 | if (tp != NULL) | |
755 | bs = tp->stop_bpstat; | |
8671a17b PA |
756 | |
757 | while ((stat = bpstat_num (&bs, &num)) != 0) | |
758 | if (stat > 0) | |
759 | { | |
760 | set_ignore_count (num, | |
8cae4b3f | 761 | parse_and_eval_long (args) - 1, |
8671a17b PA |
762 | from_tty); |
763 | /* set_ignore_count prints a message ending with a period. | |
764 | So print two spaces before "Continuing.". */ | |
765 | if (from_tty) | |
766 | printf_filtered (" "); | |
767 | stopped = 1; | |
768 | } | |
769 | ||
770 | if (!stopped && from_tty) | |
c906108c SS |
771 | { |
772 | printf_filtered | |
773 | ("Not stopped at any breakpoint; argument ignored.\n"); | |
774 | } | |
c906108c SS |
775 | } |
776 | ||
777 | if (from_tty) | |
a3f17187 | 778 | printf_filtered (_("Continuing.\n")); |
c906108c | 779 | |
77ebaa5a | 780 | continue_1 (all_threads); |
c906108c SS |
781 | } |
782 | \f | |
edb3359d DJ |
783 | /* Record the starting point of a "step" or "next" command. */ |
784 | ||
785 | static void | |
786 | set_step_frame (void) | |
787 | { | |
788 | struct symtab_and_line sal; | |
789 | ||
790 | find_frame_sal (get_current_frame (), &sal); | |
791 | set_step_info (get_current_frame (), sal); | |
792 | } | |
793 | ||
c906108c SS |
794 | /* Step until outside of current statement. */ |
795 | ||
c906108c | 796 | static void |
fba45db2 | 797 | step_command (char *count_string, int from_tty) |
c906108c SS |
798 | { |
799 | step_1 (0, 0, count_string); | |
800 | } | |
801 | ||
802 | /* Likewise, but skip over subroutine calls as if single instructions. */ | |
803 | ||
c906108c | 804 | static void |
fba45db2 | 805 | next_command (char *count_string, int from_tty) |
c906108c SS |
806 | { |
807 | step_1 (1, 0, count_string); | |
808 | } | |
809 | ||
810 | /* Likewise, but step only one instruction. */ | |
811 | ||
c906108c | 812 | void |
fba45db2 | 813 | stepi_command (char *count_string, int from_tty) |
c906108c SS |
814 | { |
815 | step_1 (0, 1, count_string); | |
816 | } | |
817 | ||
c906108c | 818 | void |
fba45db2 | 819 | nexti_command (char *count_string, int from_tty) |
c906108c SS |
820 | { |
821 | step_1 (1, 1, count_string); | |
822 | } | |
823 | ||
74b7792f | 824 | static void |
611c83ae | 825 | delete_longjmp_breakpoint_cleanup (void *arg) |
74b7792f | 826 | { |
611c83ae PA |
827 | int thread = * (int *) arg; |
828 | delete_longjmp_breakpoint (thread); | |
74b7792f AC |
829 | } |
830 | ||
c906108c | 831 | static void |
fba45db2 | 832 | step_1 (int skip_subroutines, int single_inst, char *count_string) |
c906108c | 833 | { |
52f0bd74 | 834 | int count = 1; |
c906108c | 835 | struct frame_info *frame; |
f107f563 | 836 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
43ff13b4 | 837 | int async_exec = 0; |
b3dc826b | 838 | int thread = -1; |
c5aa993b | 839 | |
c906108c | 840 | ERROR_NO_INFERIOR; |
573cda03 | 841 | ensure_not_tfind_mode (); |
d729566a | 842 | ensure_valid_thread (); |
94cc34af | 843 | ensure_not_running (); |
43ff13b4 JM |
844 | |
845 | if (count_string) | |
846 | async_exec = strip_bg_char (&count_string); | |
c5aa993b | 847 | |
43ff13b4 JM |
848 | /* If we get a request for running in the bg but the target |
849 | doesn't support it, error out. */ | |
362646f5 | 850 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 851 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 JM |
852 | |
853 | /* If we don't get a request of running in the bg, then we need | |
854 | to simulate synchronous (fg) execution. */ | |
362646f5 | 855 | if (!async_exec && target_can_async_p ()) |
43ff13b4 JM |
856 | { |
857 | /* Simulate synchronous execution */ | |
6426a772 | 858 | async_disable_stdin (); |
43ff13b4 JM |
859 | } |
860 | ||
bb518678 | 861 | count = count_string ? parse_and_eval_long (count_string) : 1; |
c906108c | 862 | |
c5aa993b | 863 | if (!single_inst || skip_subroutines) /* leave si command alone */ |
c906108c | 864 | { |
611c83ae | 865 | if (in_thread_list (inferior_ptid)) |
b3dc826b | 866 | thread = pid_to_thread_id (inferior_ptid); |
611c83ae | 867 | |
0fd8e87f | 868 | set_longjmp_breakpoint (thread); |
611c83ae | 869 | |
b3dc826b | 870 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c2d11a7d JM |
871 | } |
872 | ||
37d94800 | 873 | /* In synchronous case, all is well; each step_once call will step once. */ |
362646f5 | 874 | if (!target_can_async_p ()) |
c2d11a7d JM |
875 | { |
876 | for (; count > 0; count--) | |
877 | { | |
37d94800 PA |
878 | struct thread_info *tp; |
879 | step_once (skip_subroutines, single_inst, count, thread); | |
c2d11a7d | 880 | |
37d94800 PA |
881 | if (target_has_execution |
882 | && !ptid_equal (inferior_ptid, null_ptid)) | |
883 | tp = inferior_thread (); | |
c2d11a7d | 884 | else |
37d94800 PA |
885 | tp = NULL; |
886 | ||
887 | if (!tp || !tp->stop_step || !tp->step_multi) | |
c2d11a7d | 888 | { |
37d94800 PA |
889 | /* If we stopped for some reason that is not stepping |
890 | there are no further steps to make. */ | |
891 | if (tp) | |
892 | tp->step_multi = 0; | |
893 | break; | |
c2d11a7d | 894 | } |
c2d11a7d JM |
895 | } |
896 | ||
f107f563 | 897 | do_cleanups (cleanups); |
c2d11a7d | 898 | } |
c2d11a7d JM |
899 | else |
900 | { | |
37d94800 PA |
901 | /* In the case of an asynchronous target things get complicated; |
902 | do only one step for now, before returning control to the | |
903 | event loop. Let the continuation figure out how many other | |
904 | steps we need to do, and handle them one at the time, through | |
905 | step_once. */ | |
b3dc826b | 906 | step_once (skip_subroutines, single_inst, count, thread); |
37d94800 | 907 | |
611c83ae | 908 | /* We are running, and the continuation is installed. It will |
f107f563 VP |
909 | disable the longjmp breakpoint as appropriate. */ |
910 | discard_cleanups (cleanups); | |
c906108c | 911 | } |
c2d11a7d | 912 | } |
c906108c | 913 | |
bfec99b2 PA |
914 | struct step_1_continuation_args |
915 | { | |
916 | int count; | |
917 | int skip_subroutines; | |
918 | int single_inst; | |
919 | int thread; | |
920 | }; | |
921 | ||
c2d11a7d JM |
922 | /* Called after we are done with one step operation, to check whether |
923 | we need to step again, before we print the prompt and return control | |
924 | to the user. If count is > 1, we will need to do one more call to | |
925 | proceed(), via step_once(). Basically it is like step_once and | |
926 | step_1_continuation are co-recursive. */ | |
927 | static void | |
604ead4a | 928 | step_1_continuation (void *args) |
c2d11a7d | 929 | { |
bfec99b2 | 930 | struct step_1_continuation_args *a = args; |
f13468d9 | 931 | |
af679fd0 | 932 | if (target_has_execution) |
f13468d9 | 933 | { |
af679fd0 PA |
934 | struct thread_info *tp; |
935 | ||
936 | tp = inferior_thread (); | |
414c69f7 | 937 | if (tp->step_multi && tp->stop_step) |
af679fd0 PA |
938 | { |
939 | /* There are more steps to make, and we did stop due to | |
940 | ending a stepping range. Do another step. */ | |
37d94800 PA |
941 | step_once (a->skip_subroutines, a->single_inst, |
942 | a->count - 1, a->thread); | |
af679fd0 PA |
943 | return; |
944 | } | |
945 | tp->step_multi = 0; | |
f107f563 | 946 | } |
af679fd0 PA |
947 | |
948 | /* We either stopped for some reason that is not stepping, or there | |
949 | are no further steps to make. Cleanup. */ | |
950 | if (!a->single_inst || a->skip_subroutines) | |
951 | delete_longjmp_breakpoint (a->thread); | |
c2d11a7d JM |
952 | } |
953 | ||
37d94800 PA |
954 | /* Do just one step operation. This is useful to implement the 'step |
955 | n' kind of commands. In case of asynchronous targets, we will have | |
956 | to set up a continuation to be done after the target stops (after | |
957 | this one step). For synch targets, the caller handles further | |
958 | stepping. */ | |
959 | ||
960 | static void | |
611c83ae | 961 | step_once (int skip_subroutines, int single_inst, int count, int thread) |
bfec99b2 | 962 | { |
edb3359d | 963 | struct frame_info *frame = get_current_frame (); |
c2d11a7d JM |
964 | |
965 | if (count > 0) | |
c906108c | 966 | { |
4e1c45ea PA |
967 | /* Don't assume THREAD is a valid thread id. It is set to -1 if |
968 | the longjmp breakpoint was not required. Use the | |
969 | INFERIOR_PTID thread instead, which is the same thread when | |
970 | THREAD is set. */ | |
971 | struct thread_info *tp = inferior_thread (); | |
c906108c | 972 | clear_proceed_status (); |
edb3359d | 973 | set_step_frame (); |
c906108c | 974 | |
c5aa993b | 975 | if (!single_inst) |
c906108c | 976 | { |
1641cfcc PA |
977 | CORE_ADDR pc; |
978 | ||
edb3359d DJ |
979 | /* Step at an inlined function behaves like "down". */ |
980 | if (!skip_subroutines && !single_inst | |
981 | && inline_skipped_frames (inferior_ptid)) | |
982 | { | |
983 | step_into_inline_frame (inferior_ptid); | |
984 | if (count > 1) | |
985 | step_once (skip_subroutines, single_inst, count - 1, thread); | |
986 | else | |
987 | /* Pretend that we've stopped. */ | |
988 | normal_stop (); | |
989 | return; | |
990 | } | |
991 | ||
1641cfcc PA |
992 | pc = get_frame_pc (frame); |
993 | find_pc_line_pc_range (pc, | |
4e1c45ea | 994 | &tp->step_range_start, &tp->step_range_end); |
5fbbeb29 CF |
995 | |
996 | /* If we have no line info, switch to stepi mode. */ | |
4e1c45ea | 997 | if (tp->step_range_end == 0 && step_stop_if_no_debug) |
edb3359d | 998 | tp->step_range_start = tp->step_range_end = 1; |
4e1c45ea | 999 | else if (tp->step_range_end == 0) |
c906108c SS |
1000 | { |
1001 | char *name; | |
1641cfcc | 1002 | if (find_pc_partial_function (pc, &name, |
4e1c45ea PA |
1003 | &tp->step_range_start, |
1004 | &tp->step_range_end) == 0) | |
8a3fe4f8 | 1005 | error (_("Cannot find bounds of current function")); |
c906108c SS |
1006 | |
1007 | target_terminal_ours (); | |
a3f17187 | 1008 | printf_filtered (_("\ |
c906108c | 1009 | Single stepping until exit from function %s, \n\ |
a3f17187 | 1010 | which has no line number information.\n"), name); |
c906108c SS |
1011 | } |
1012 | } | |
1013 | else | |
1014 | { | |
1015 | /* Say we are stepping, but stop after one insn whatever it does. */ | |
4e1c45ea | 1016 | tp->step_range_start = tp->step_range_end = 1; |
c906108c SS |
1017 | if (!skip_subroutines) |
1018 | /* It is stepi. | |
1019 | Don't step over function calls, not even to functions lacking | |
1020 | line numbers. */ | |
078130d0 | 1021 | tp->step_over_calls = STEP_OVER_NONE; |
c906108c SS |
1022 | } |
1023 | ||
1024 | if (skip_subroutines) | |
078130d0 | 1025 | tp->step_over_calls = STEP_OVER_ALL; |
c906108c | 1026 | |
95e54da7 | 1027 | tp->step_multi = (count > 1); |
f107f563 | 1028 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); |
bfec99b2 | 1029 | |
37d94800 PA |
1030 | /* For async targets, register a continuation to do any |
1031 | additional steps. For sync targets, the caller will handle | |
1032 | further stepping. */ | |
1033 | if (target_can_async_p ()) | |
1034 | { | |
1035 | struct step_1_continuation_args *args; | |
1036 | ||
1037 | args = xmalloc (sizeof (*args)); | |
1038 | args->skip_subroutines = skip_subroutines; | |
1039 | args->single_inst = single_inst; | |
1040 | args->count = count; | |
1041 | args->thread = thread; | |
1042 | ||
1043 | add_intermediate_continuation (tp, step_1_continuation, args, xfree); | |
1044 | } | |
c906108c | 1045 | } |
c906108c | 1046 | } |
c2d11a7d | 1047 | |
c906108c SS |
1048 | \f |
1049 | /* Continue program at specified address. */ | |
1050 | ||
1051 | static void | |
fba45db2 | 1052 | jump_command (char *arg, int from_tty) |
c906108c | 1053 | { |
5af949e3 | 1054 | struct gdbarch *gdbarch = get_current_arch (); |
52f0bd74 | 1055 | CORE_ADDR addr; |
c906108c SS |
1056 | struct symtabs_and_lines sals; |
1057 | struct symtab_and_line sal; | |
1058 | struct symbol *fn; | |
1059 | struct symbol *sfn; | |
43ff13b4 | 1060 | int async_exec = 0; |
c5aa993b | 1061 | |
c906108c | 1062 | ERROR_NO_INFERIOR; |
573cda03 | 1063 | ensure_not_tfind_mode (); |
d729566a | 1064 | ensure_valid_thread (); |
94cc34af | 1065 | ensure_not_running (); |
c906108c | 1066 | |
43ff13b4 JM |
1067 | /* Find out whether we must run in the background. */ |
1068 | if (arg != NULL) | |
1069 | async_exec = strip_bg_char (&arg); | |
1070 | ||
1071 | /* If we must run in the background, but the target can't do it, | |
1072 | error out. */ | |
362646f5 | 1073 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 1074 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 | 1075 | |
c906108c | 1076 | if (!arg) |
e2e0b3e5 | 1077 | error_no_arg (_("starting address")); |
c906108c SS |
1078 | |
1079 | sals = decode_line_spec_1 (arg, 1); | |
1080 | if (sals.nelts != 1) | |
1081 | { | |
8a3fe4f8 | 1082 | error (_("Unreasonable jump request")); |
c906108c SS |
1083 | } |
1084 | ||
1085 | sal = sals.sals[0]; | |
b8c9b27d | 1086 | xfree (sals.sals); |
c906108c SS |
1087 | |
1088 | if (sal.symtab == 0 && sal.pc == 0) | |
8a3fe4f8 | 1089 | error (_("No source file has been specified.")); |
c906108c | 1090 | |
c5aa993b | 1091 | resolve_sal_pc (&sal); /* May error out */ |
c906108c SS |
1092 | |
1093 | /* See if we are trying to jump to another function. */ | |
1094 | fn = get_frame_function (get_current_frame ()); | |
1095 | sfn = find_pc_function (sal.pc); | |
1096 | if (fn != NULL && sfn != fn) | |
1097 | { | |
9e2f0ad4 | 1098 | if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal.line, |
de5ad195 | 1099 | SYMBOL_PRINT_NAME (fn))) |
c906108c | 1100 | { |
8a3fe4f8 | 1101 | error (_("Not confirmed.")); |
c906108c SS |
1102 | /* NOTREACHED */ |
1103 | } | |
1104 | } | |
1105 | ||
c5aa993b | 1106 | if (sfn != NULL) |
c906108c SS |
1107 | { |
1108 | fixup_symbol_section (sfn, 0); | |
714835d5 UW |
1109 | if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn)) && |
1110 | !section_is_mapped (SYMBOL_OBJ_SECTION (sfn))) | |
c906108c | 1111 | { |
9e2f0ad4 | 1112 | if (!query (_("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))) |
c906108c | 1113 | { |
8a3fe4f8 | 1114 | error (_("Not confirmed.")); |
c906108c SS |
1115 | /* NOTREACHED */ |
1116 | } | |
1117 | } | |
1118 | } | |
1119 | ||
c906108c SS |
1120 | addr = sal.pc; |
1121 | ||
1122 | if (from_tty) | |
1123 | { | |
a3f17187 | 1124 | printf_filtered (_("Continuing at ")); |
5af949e3 | 1125 | fputs_filtered (paddress (gdbarch, addr), gdb_stdout); |
c906108c SS |
1126 | printf_filtered (".\n"); |
1127 | } | |
1128 | ||
89113898 PA |
1129 | /* If we are not asked to run in the bg, then prepare to run in the |
1130 | foreground, synchronously. */ | |
1131 | if (!async_exec && target_can_async_p ()) | |
1132 | { | |
1133 | /* Simulate synchronous execution */ | |
1134 | async_disable_stdin (); | |
1135 | } | |
1136 | ||
c906108c SS |
1137 | clear_proceed_status (); |
1138 | proceed (addr, TARGET_SIGNAL_0, 0); | |
1139 | } | |
c906108c | 1140 | \f |
c5aa993b | 1141 | |
c906108c SS |
1142 | /* Go to line or address in current procedure */ |
1143 | static void | |
fba45db2 | 1144 | go_command (char *line_no, int from_tty) |
c906108c | 1145 | { |
c5aa993b | 1146 | if (line_no == (char *) NULL || !*line_no) |
f42429a6 | 1147 | printf_filtered (_("Usage: go <location>\n")); |
c906108c SS |
1148 | else |
1149 | { | |
b83266a0 SS |
1150 | tbreak_command (line_no, from_tty); |
1151 | jump_command (line_no, from_tty); | |
c906108c SS |
1152 | } |
1153 | } | |
c906108c | 1154 | \f |
c5aa993b | 1155 | |
c906108c SS |
1156 | /* Continue program giving it specified signal. */ |
1157 | ||
1158 | static void | |
fba45db2 | 1159 | signal_command (char *signum_exp, int from_tty) |
c906108c SS |
1160 | { |
1161 | enum target_signal oursig; | |
32c1e744 | 1162 | int async_exec = 0; |
c906108c SS |
1163 | |
1164 | dont_repeat (); /* Too dangerous. */ | |
1165 | ERROR_NO_INFERIOR; | |
573cda03 | 1166 | ensure_not_tfind_mode (); |
d729566a | 1167 | ensure_valid_thread (); |
94cc34af | 1168 | ensure_not_running (); |
c906108c | 1169 | |
32c1e744 VP |
1170 | /* Find out whether we must run in the background. */ |
1171 | if (signum_exp != NULL) | |
1172 | async_exec = strip_bg_char (&signum_exp); | |
1173 | ||
1174 | /* If we must run in the background, but the target can't do it, | |
1175 | error out. */ | |
1176 | if (async_exec && !target_can_async_p ()) | |
1177 | error (_("Asynchronous execution not supported on this target.")); | |
1178 | ||
1179 | /* If we are not asked to run in the bg, then prepare to run in the | |
1180 | foreground, synchronously. */ | |
1181 | if (!async_exec && target_can_async_p ()) | |
1182 | { | |
1183 | /* Simulate synchronous execution. */ | |
1184 | async_disable_stdin (); | |
1185 | } | |
1186 | ||
c906108c | 1187 | if (!signum_exp) |
e2e0b3e5 | 1188 | error_no_arg (_("signal number")); |
c906108c SS |
1189 | |
1190 | /* It would be even slicker to make signal names be valid expressions, | |
1191 | (the type could be "enum $signal" or some such), then the user could | |
1192 | assign them to convenience variables. */ | |
1193 | oursig = target_signal_from_name (signum_exp); | |
1194 | ||
1195 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
1196 | { | |
1197 | /* No, try numeric. */ | |
bb518678 | 1198 | int num = parse_and_eval_long (signum_exp); |
c906108c SS |
1199 | |
1200 | if (num == 0) | |
1201 | oursig = TARGET_SIGNAL_0; | |
1202 | else | |
1203 | oursig = target_signal_from_command (num); | |
1204 | } | |
1205 | ||
1206 | if (from_tty) | |
1207 | { | |
1208 | if (oursig == TARGET_SIGNAL_0) | |
a3f17187 | 1209 | printf_filtered (_("Continuing with no signal.\n")); |
c906108c | 1210 | else |
a3f17187 | 1211 | printf_filtered (_("Continuing with signal %s.\n"), |
c906108c SS |
1212 | target_signal_to_name (oursig)); |
1213 | } | |
1214 | ||
1215 | clear_proceed_status (); | |
a12cc160 | 1216 | proceed ((CORE_ADDR) -1, oursig, 0); |
c906108c SS |
1217 | } |
1218 | ||
c906108c SS |
1219 | /* Proceed until we reach a different source line with pc greater than |
1220 | our current one or exit the function. We skip calls in both cases. | |
1221 | ||
1222 | Note that eventually this command should probably be changed so | |
1223 | that only source lines are printed out when we hit the breakpoint | |
1224 | we set. This may involve changes to wait_for_inferior and the | |
1225 | proceed status code. */ | |
1226 | ||
c906108c | 1227 | static void |
fba45db2 | 1228 | until_next_command (int from_tty) |
c906108c SS |
1229 | { |
1230 | struct frame_info *frame; | |
1231 | CORE_ADDR pc; | |
1232 | struct symbol *func; | |
1233 | struct symtab_and_line sal; | |
4e1c45ea | 1234 | struct thread_info *tp = inferior_thread (); |
c5aa993b | 1235 | |
c906108c | 1236 | clear_proceed_status (); |
edb3359d | 1237 | set_step_frame (); |
c906108c SS |
1238 | |
1239 | frame = get_current_frame (); | |
1240 | ||
1241 | /* Step until either exited from this function or greater | |
1242 | than the current line (if in symbolic section) or pc (if | |
1243 | not). */ | |
1244 | ||
1c7819ef | 1245 | pc = get_frame_pc (frame); |
c906108c | 1246 | func = find_pc_function (pc); |
c5aa993b | 1247 | |
c906108c SS |
1248 | if (!func) |
1249 | { | |
1250 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc); | |
c5aa993b | 1251 | |
c906108c | 1252 | if (msymbol == NULL) |
8a3fe4f8 | 1253 | error (_("Execution is not within a known function.")); |
c5aa993b | 1254 | |
4e1c45ea PA |
1255 | tp->step_range_start = SYMBOL_VALUE_ADDRESS (msymbol); |
1256 | tp->step_range_end = pc; | |
c906108c SS |
1257 | } |
1258 | else | |
1259 | { | |
1260 | sal = find_pc_line (pc, 0); | |
c5aa993b | 1261 | |
4e1c45ea PA |
1262 | tp->step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func)); |
1263 | tp->step_range_end = sal.end; | |
c906108c | 1264 | } |
c5aa993b | 1265 | |
078130d0 | 1266 | tp->step_over_calls = STEP_OVER_ALL; |
c906108c | 1267 | |
af679fd0 | 1268 | tp->step_multi = 0; /* Only one call to proceed */ |
c5aa993b | 1269 | |
2acceee2 | 1270 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); |
c906108c SS |
1271 | } |
1272 | ||
c5aa993b | 1273 | static void |
fba45db2 | 1274 | until_command (char *arg, int from_tty) |
c906108c | 1275 | { |
43ff13b4 JM |
1276 | int async_exec = 0; |
1277 | ||
4247603b | 1278 | ERROR_NO_INFERIOR; |
573cda03 | 1279 | ensure_not_tfind_mode (); |
4247603b PA |
1280 | ensure_valid_thread (); |
1281 | ensure_not_running (); | |
573cda03 | 1282 | |
43ff13b4 JM |
1283 | /* Find out whether we must run in the background. */ |
1284 | if (arg != NULL) | |
1285 | async_exec = strip_bg_char (&arg); | |
1286 | ||
1287 | /* If we must run in the background, but the target can't do it, | |
1288 | error out. */ | |
362646f5 | 1289 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 1290 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 JM |
1291 | |
1292 | /* If we are not asked to run in the bg, then prepare to run in the | |
1293 | foreground, synchronously. */ | |
362646f5 | 1294 | if (!async_exec && target_can_async_p ()) |
c5aa993b | 1295 | { |
43ff13b4 | 1296 | /* Simulate synchronous execution */ |
6426a772 | 1297 | async_disable_stdin (); |
43ff13b4 JM |
1298 | } |
1299 | ||
c906108c | 1300 | if (arg) |
ae66c1fc | 1301 | until_break_command (arg, from_tty, 0); |
c906108c SS |
1302 | else |
1303 | until_next_command (from_tty); | |
1304 | } | |
ae66c1fc EZ |
1305 | |
1306 | static void | |
1307 | advance_command (char *arg, int from_tty) | |
1308 | { | |
1309 | int async_exec = 0; | |
1310 | ||
4247603b | 1311 | ERROR_NO_INFERIOR; |
573cda03 | 1312 | ensure_not_tfind_mode (); |
4247603b PA |
1313 | ensure_valid_thread (); |
1314 | ensure_not_running (); | |
573cda03 | 1315 | |
ae66c1fc | 1316 | if (arg == NULL) |
e2e0b3e5 | 1317 | error_no_arg (_("a location")); |
ae66c1fc EZ |
1318 | |
1319 | /* Find out whether we must run in the background. */ | |
1320 | if (arg != NULL) | |
1321 | async_exec = strip_bg_char (&arg); | |
1322 | ||
1323 | /* If we must run in the background, but the target can't do it, | |
1324 | error out. */ | |
362646f5 | 1325 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 1326 | error (_("Asynchronous execution not supported on this target.")); |
ae66c1fc EZ |
1327 | |
1328 | /* If we are not asked to run in the bg, then prepare to run in the | |
1329 | foreground, synchronously. */ | |
362646f5 | 1330 | if (!async_exec && target_can_async_p ()) |
ae66c1fc EZ |
1331 | { |
1332 | /* Simulate synchronous execution. */ | |
1333 | async_disable_stdin (); | |
1334 | } | |
1335 | ||
1336 | until_break_command (arg, from_tty, 1); | |
1337 | } | |
c906108c | 1338 | \f |
f941662f MK |
1339 | /* Print the result of a function at the end of a 'finish' command. */ |
1340 | ||
11cf8741 | 1341 | static void |
c055b101 | 1342 | print_return_value (struct type *func_type, struct type *value_type) |
11cf8741 | 1343 | { |
d80b854b | 1344 | struct gdbarch *gdbarch = get_regcache_arch (stop_registers); |
bb472c1e MK |
1345 | struct cleanup *old_chain; |
1346 | struct ui_stream *stb; | |
44e5158b AC |
1347 | struct value *value; |
1348 | ||
181fc57c | 1349 | CHECK_TYPEDEF (value_type); |
44e5158b | 1350 | gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID); |
11cf8741 | 1351 | |
92ad9cd9 AC |
1352 | /* FIXME: 2003-09-27: When returning from a nested inferior function |
1353 | call, it's possible (with no help from the architecture vector) | |
1354 | to locate and return/print a "struct return" value. This is just | |
1355 | a more complicated case of what is already being done in in the | |
1356 | inferior function call code. In fact, when inferior function | |
1357 | calls are made async, this will likely be made the norm. */ | |
31db7b6c | 1358 | |
c055b101 CV |
1359 | switch (gdbarch_return_value (gdbarch, func_type, value_type, |
1360 | NULL, NULL, NULL)) | |
44e5158b | 1361 | { |
750eb019 AC |
1362 | case RETURN_VALUE_REGISTER_CONVENTION: |
1363 | case RETURN_VALUE_ABI_RETURNS_ADDRESS: | |
181fc57c | 1364 | case RETURN_VALUE_ABI_PRESERVES_ADDRESS: |
44e5158b | 1365 | value = allocate_value (value_type); |
c055b101 | 1366 | gdbarch_return_value (gdbarch, func_type, value_type, stop_registers, |
990a07ab | 1367 | value_contents_raw (value), NULL); |
750eb019 AC |
1368 | break; |
1369 | case RETURN_VALUE_STRUCT_CONVENTION: | |
1370 | value = NULL; | |
1371 | break; | |
1372 | default: | |
e2e0b3e5 | 1373 | internal_error (__FILE__, __LINE__, _("bad switch")); |
44e5158b | 1374 | } |
bb472c1e | 1375 | |
31db7b6c MK |
1376 | if (value) |
1377 | { | |
79a45b7d TT |
1378 | struct value_print_options opts; |
1379 | ||
31db7b6c | 1380 | /* Print it. */ |
1d751abe PA |
1381 | stb = ui_out_stream_new (uiout); |
1382 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
31db7b6c MK |
1383 | ui_out_text (uiout, "Value returned is "); |
1384 | ui_out_field_fmt (uiout, "gdb-result-var", "$%d", | |
1385 | record_latest_value (value)); | |
1386 | ui_out_text (uiout, " = "); | |
79a45b7d TT |
1387 | get_raw_print_options (&opts); |
1388 | value_print (value, stb->stream, &opts); | |
31db7b6c MK |
1389 | ui_out_field_stream (uiout, "return-value", stb); |
1390 | ui_out_text (uiout, "\n"); | |
1d751abe | 1391 | do_cleanups (old_chain); |
31db7b6c MK |
1392 | } |
1393 | else | |
1394 | { | |
1395 | ui_out_text (uiout, "Value returned has type: "); | |
1d751abe PA |
1396 | ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type)); |
1397 | ui_out_text (uiout, "."); | |
1398 | ui_out_text (uiout, " Cannot determine contents\n"); | |
31db7b6c | 1399 | } |
11cf8741 JM |
1400 | } |
1401 | ||
43ff13b4 | 1402 | /* Stuff that needs to be done by the finish command after the target |
f941662f MK |
1403 | has stopped. In asynchronous mode, we wait for the target to stop |
1404 | in the call to poll or select in the event loop, so it is | |
1405 | impossible to do all the stuff as part of the finish_command | |
1406 | function itself. The only chance we have to complete this command | |
1407 | is in fetch_inferior_event, which is called by the event loop as | |
1408 | soon as it detects that the target has stopped. This function is | |
1409 | called via the cmd_continuation pointer. */ | |
1410 | ||
bfec99b2 | 1411 | struct finish_command_continuation_args |
43ff13b4 | 1412 | { |
43ff13b4 | 1413 | struct breakpoint *breakpoint; |
bfec99b2 PA |
1414 | struct symbol *function; |
1415 | }; | |
c5aa993b | 1416 | |
bfec99b2 | 1417 | static void |
604ead4a | 1418 | finish_command_continuation (void *arg) |
bfec99b2 PA |
1419 | { |
1420 | struct finish_command_continuation_args *a = arg; | |
41d2bdb4 | 1421 | struct thread_info *tp = NULL; |
347bddb7 PA |
1422 | bpstat bs = NULL; |
1423 | ||
1424 | if (!ptid_equal (inferior_ptid, null_ptid) | |
1425 | && target_has_execution | |
1426 | && is_stopped (inferior_ptid)) | |
41d2bdb4 PA |
1427 | { |
1428 | tp = inferior_thread (); | |
1429 | bs = tp->stop_bpstat; | |
1430 | } | |
347bddb7 PA |
1431 | |
1432 | if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL | |
604ead4a | 1433 | && a->function != NULL) |
43ff13b4 | 1434 | { |
604ead4a | 1435 | struct type *value_type; |
bfec99b2 | 1436 | |
604ead4a PA |
1437 | value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function)); |
1438 | if (!value_type) | |
1439 | internal_error (__FILE__, __LINE__, | |
1440 | _("finish_command: function has no target type")); | |
f5871ec0 | 1441 | |
604ead4a | 1442 | if (TYPE_CODE (value_type) != TYPE_CODE_VOID) |
40c549d6 TT |
1443 | { |
1444 | volatile struct gdb_exception ex; | |
1445 | ||
1446 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
1447 | { | |
1448 | /* print_return_value can throw an exception in some | |
1449 | circumstances. We need to catch this so that we still | |
1450 | delete the breakpoint. */ | |
1451 | print_return_value (SYMBOL_TYPE (a->function), value_type); | |
1452 | } | |
1453 | if (ex.reason < 0) | |
1454 | exception_print (gdb_stdout, ex); | |
1455 | } | |
43ff13b4 | 1456 | } |
f941662f | 1457 | |
604ead4a | 1458 | /* We suppress normal call of normal_stop observer and do it here so |
41d2bdb4 PA |
1459 | that the *stopped notification includes the return value. */ |
1460 | if (bs != NULL && tp->proceed_to_finish) | |
1461 | observer_notify_normal_stop (bs, 1 /* print frame */); | |
bfec99b2 | 1462 | delete_breakpoint (a->breakpoint); |
43ff13b4 JM |
1463 | } |
1464 | ||
604ead4a PA |
1465 | static void |
1466 | finish_command_continuation_free_arg (void *arg) | |
1467 | { | |
604ead4a PA |
1468 | xfree (arg); |
1469 | } | |
1470 | ||
b2175913 MS |
1471 | /* finish_backward -- helper function for finish_command. */ |
1472 | ||
1473 | static void | |
1474 | finish_backward (struct symbol *function) | |
1475 | { | |
1476 | struct symtab_and_line sal; | |
1477 | struct thread_info *tp = inferior_thread (); | |
1478 | struct breakpoint *breakpoint; | |
1479 | struct cleanup *old_chain; | |
1c7819ef | 1480 | CORE_ADDR pc; |
b2175913 MS |
1481 | CORE_ADDR func_addr; |
1482 | int back_up; | |
1483 | ||
1c7819ef PA |
1484 | pc = get_frame_pc (get_current_frame ()); |
1485 | ||
1486 | if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0) | |
b2175913 MS |
1487 | internal_error (__FILE__, __LINE__, |
1488 | _("Finish: couldn't find function.")); | |
1489 | ||
1490 | sal = find_pc_line (func_addr, 0); | |
1491 | ||
1492 | /* We don't need a return value. */ | |
1493 | tp->proceed_to_finish = 0; | |
1494 | /* Special case: if we're sitting at the function entry point, | |
1495 | then all we need to do is take a reverse singlestep. We | |
1496 | don't need to set a breakpoint, and indeed it would do us | |
1497 | no good to do so. | |
1498 | ||
1499 | Note that this can only happen at frame #0, since there's | |
1500 | no way that a function up the stack can have a return address | |
1501 | that's equal to its entry point. */ | |
1502 | ||
1c7819ef | 1503 | if (sal.pc != pc) |
b2175913 | 1504 | { |
a6d9a66e UW |
1505 | struct frame_info *frame = get_selected_frame (NULL); |
1506 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
1507 | ||
b2175913 MS |
1508 | /* Set breakpoint and continue. */ |
1509 | breakpoint = | |
a6d9a66e UW |
1510 | set_momentary_breakpoint (gdbarch, sal, |
1511 | get_stack_frame_id (frame), | |
b2175913 MS |
1512 | bp_breakpoint); |
1513 | /* Tell the breakpoint to keep quiet. We won't be done | |
1514 | until we've done another reverse single-step. */ | |
1515 | make_breakpoint_silent (breakpoint); | |
1516 | old_chain = make_cleanup_delete_breakpoint (breakpoint); | |
1517 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); | |
1518 | /* We will be stopped when proceed returns. */ | |
1519 | back_up = bpstat_find_breakpoint (tp->stop_bpstat, breakpoint) != NULL; | |
1520 | do_cleanups (old_chain); | |
1521 | } | |
1522 | else | |
1523 | back_up = 1; | |
1524 | if (back_up) | |
1525 | { | |
1526 | /* If in fact we hit the step-resume breakpoint (and not | |
1527 | some other breakpoint), then we're almost there -- | |
1528 | we just need to back up by one more single-step. */ | |
1529 | tp->step_range_start = tp->step_range_end = 1; | |
1530 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); | |
1531 | } | |
1532 | return; | |
1533 | } | |
1534 | ||
1535 | /* finish_forward -- helper function for finish_command. */ | |
1536 | ||
1537 | static void | |
1538 | finish_forward (struct symbol *function, struct frame_info *frame) | |
1539 | { | |
a6d9a66e | 1540 | struct gdbarch *gdbarch = get_frame_arch (frame); |
b2175913 MS |
1541 | struct symtab_and_line sal; |
1542 | struct thread_info *tp = inferior_thread (); | |
1543 | struct breakpoint *breakpoint; | |
1544 | struct cleanup *old_chain; | |
1545 | struct finish_command_continuation_args *cargs; | |
1546 | ||
1547 | sal = find_pc_line (get_frame_pc (frame), 0); | |
1548 | sal.pc = get_frame_pc (frame); | |
1549 | ||
a6d9a66e UW |
1550 | breakpoint = set_momentary_breakpoint (gdbarch, sal, |
1551 | get_stack_frame_id (frame), | |
b2175913 MS |
1552 | bp_finish); |
1553 | ||
1554 | old_chain = make_cleanup_delete_breakpoint (breakpoint); | |
1555 | ||
1556 | tp->proceed_to_finish = 1; /* We want stop_registers, please... */ | |
b2175913 MS |
1557 | cargs = xmalloc (sizeof (*cargs)); |
1558 | ||
1559 | cargs->breakpoint = breakpoint; | |
1560 | cargs->function = function; | |
1561 | add_continuation (tp, finish_command_continuation, cargs, | |
1562 | finish_command_continuation_free_arg); | |
6c95b8df | 1563 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); |
b2175913 MS |
1564 | |
1565 | discard_cleanups (old_chain); | |
1566 | if (!target_can_async_p ()) | |
1567 | do_all_continuations (); | |
1568 | } | |
1569 | ||
f941662f MK |
1570 | /* "finish": Set a temporary breakpoint at the place the selected |
1571 | frame will return to, then continue. */ | |
c906108c SS |
1572 | |
1573 | static void | |
fba45db2 | 1574 | finish_command (char *arg, int from_tty) |
c906108c | 1575 | { |
52f0bd74 AC |
1576 | struct frame_info *frame; |
1577 | struct symbol *function; | |
43ff13b4 JM |
1578 | |
1579 | int async_exec = 0; | |
1580 | ||
4247603b | 1581 | ERROR_NO_INFERIOR; |
573cda03 | 1582 | ensure_not_tfind_mode (); |
4247603b PA |
1583 | ensure_valid_thread (); |
1584 | ensure_not_running (); | |
573cda03 | 1585 | |
f941662f | 1586 | /* Find out whether we must run in the background. */ |
43ff13b4 JM |
1587 | if (arg != NULL) |
1588 | async_exec = strip_bg_char (&arg); | |
1589 | ||
1590 | /* If we must run in the background, but the target can't do it, | |
f941662f | 1591 | error out. */ |
362646f5 | 1592 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 1593 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 | 1594 | |
b2175913 MS |
1595 | /* Don't try to async in reverse. */ |
1596 | if (async_exec && execution_direction == EXEC_REVERSE) | |
1597 | error (_("Asynchronous 'finish' not supported in reverse.")); | |
1598 | ||
43ff13b4 | 1599 | /* If we are not asked to run in the bg, then prepare to run in the |
f941662f | 1600 | foreground, synchronously. */ |
362646f5 | 1601 | if (!async_exec && target_can_async_p ()) |
c5aa993b | 1602 | { |
f941662f | 1603 | /* Simulate synchronous execution. */ |
6426a772 | 1604 | async_disable_stdin (); |
43ff13b4 | 1605 | } |
c906108c SS |
1606 | |
1607 | if (arg) | |
8a3fe4f8 | 1608 | error (_("The \"finish\" command does not take any arguments.")); |
c906108c | 1609 | |
206415a3 | 1610 | frame = get_prev_frame (get_selected_frame (_("No selected frame."))); |
c906108c | 1611 | if (frame == 0) |
8a3fe4f8 | 1612 | error (_("\"finish\" not meaningful in the outermost frame.")); |
c906108c SS |
1613 | |
1614 | clear_proceed_status (); | |
1615 | ||
edb3359d DJ |
1616 | /* Finishing from an inline frame is completely different. We don't |
1617 | try to show the "return value" - no way to locate it. So we do | |
1618 | not need a completion. */ | |
1619 | if (get_frame_type (get_selected_frame (_("No selected frame."))) | |
1620 | == INLINE_FRAME) | |
1621 | { | |
1622 | /* Claim we are stepping in the calling frame. An empty step | |
1623 | range means that we will stop once we aren't in a function | |
1624 | called by that frame. We don't use the magic "1" value for | |
1625 | step_range_end, because then infrun will think this is nexti, | |
1626 | and not step over the rest of this inlined function call. */ | |
1627 | struct thread_info *tp = inferior_thread (); | |
1628 | struct symtab_and_line empty_sal; | |
1629 | init_sal (&empty_sal); | |
1630 | set_step_info (frame, empty_sal); | |
1631 | tp->step_range_start = tp->step_range_end = get_frame_pc (frame); | |
1632 | tp->step_over_calls = STEP_OVER_ALL; | |
1633 | ||
1634 | /* Print info on the selected frame, including level number but not | |
1635 | source. */ | |
1636 | if (from_tty) | |
1637 | { | |
1638 | printf_filtered (_("Run till exit from ")); | |
1639 | print_stack_frame (get_selected_frame (NULL), 1, LOCATION); | |
1640 | } | |
1641 | ||
1642 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); | |
1643 | return; | |
1644 | } | |
1645 | ||
c906108c SS |
1646 | /* Find the function we will return from. */ |
1647 | ||
206415a3 | 1648 | function = find_pc_function (get_frame_pc (get_selected_frame (NULL))); |
c906108c | 1649 | |
f941662f MK |
1650 | /* Print info on the selected frame, including level number but not |
1651 | source. */ | |
c906108c SS |
1652 | if (from_tty) |
1653 | { | |
b2175913 MS |
1654 | if (execution_direction == EXEC_REVERSE) |
1655 | printf_filtered (_("Run back to call of ")); | |
1656 | else | |
1657 | printf_filtered (_("Run till exit from ")); | |
1658 | ||
b04f3ab4 | 1659 | print_stack_frame (get_selected_frame (NULL), 1, LOCATION); |
c906108c SS |
1660 | } |
1661 | ||
b2175913 MS |
1662 | if (execution_direction == EXEC_REVERSE) |
1663 | finish_backward (function); | |
1664 | else | |
1665 | finish_forward (function, frame); | |
c906108c SS |
1666 | } |
1667 | \f | |
f941662f | 1668 | |
c906108c | 1669 | static void |
fba45db2 | 1670 | program_info (char *args, int from_tty) |
c906108c | 1671 | { |
347bddb7 PA |
1672 | bpstat bs; |
1673 | int num, stat; | |
1674 | struct thread_info *tp; | |
1675 | ptid_t ptid; | |
c5aa993b | 1676 | |
c906108c SS |
1677 | if (!target_has_execution) |
1678 | { | |
a3f17187 | 1679 | printf_filtered (_("The program being debugged is not being run.\n")); |
c906108c SS |
1680 | return; |
1681 | } | |
1682 | ||
347bddb7 PA |
1683 | if (non_stop) |
1684 | ptid = inferior_ptid; | |
1685 | else | |
1686 | { | |
1687 | struct target_waitstatus ws; | |
1688 | get_last_target_status (&ptid, &ws); | |
1689 | } | |
1690 | ||
1691 | if (ptid_equal (ptid, null_ptid) || is_exited (ptid)) | |
1692 | error (_("Invalid selected thread.")); | |
1693 | else if (is_running (ptid)) | |
1694 | error (_("Selected thread is running.")); | |
1695 | ||
e09875d4 | 1696 | tp = find_thread_ptid (ptid); |
347bddb7 PA |
1697 | bs = tp->stop_bpstat; |
1698 | stat = bpstat_num (&bs, &num); | |
1699 | ||
c906108c | 1700 | target_files_info (); |
5af949e3 UW |
1701 | printf_filtered (_("Program stopped at %s.\n"), |
1702 | paddress (target_gdbarch, stop_pc)); | |
414c69f7 | 1703 | if (tp->stop_step) |
a3f17187 | 1704 | printf_filtered (_("It stopped after being stepped.\n")); |
8671a17b | 1705 | else if (stat != 0) |
c906108c SS |
1706 | { |
1707 | /* There may be several breakpoints in the same place, so this | |
c5aa993b | 1708 | isn't as strange as it seems. */ |
8671a17b | 1709 | while (stat != 0) |
c906108c | 1710 | { |
8671a17b | 1711 | if (stat < 0) |
c906108c | 1712 | { |
a3f17187 AC |
1713 | printf_filtered (_("\ |
1714 | It stopped at a breakpoint that has since been deleted.\n")); | |
c906108c SS |
1715 | } |
1716 | else | |
a3f17187 | 1717 | printf_filtered (_("It stopped at breakpoint %d.\n"), num); |
8671a17b | 1718 | stat = bpstat_num (&bs, &num); |
c906108c SS |
1719 | } |
1720 | } | |
2020b7ab | 1721 | else if (tp->stop_signal != TARGET_SIGNAL_0) |
c906108c | 1722 | { |
a3f17187 | 1723 | printf_filtered (_("It stopped with signal %s, %s.\n"), |
2020b7ab PA |
1724 | target_signal_to_name (tp->stop_signal), |
1725 | target_signal_to_string (tp->stop_signal)); | |
c906108c SS |
1726 | } |
1727 | ||
1728 | if (!from_tty) | |
1729 | { | |
a3f17187 AC |
1730 | printf_filtered (_("\ |
1731 | Type \"info stack\" or \"info registers\" for more information.\n")); | |
c906108c SS |
1732 | } |
1733 | } | |
1734 | \f | |
1735 | static void | |
fba45db2 | 1736 | environment_info (char *var, int from_tty) |
c906108c SS |
1737 | { |
1738 | if (var) | |
1739 | { | |
3f81c18a | 1740 | char *val = get_in_environ (current_inferior ()->environment, var); |
c906108c SS |
1741 | if (val) |
1742 | { | |
1743 | puts_filtered (var); | |
1744 | puts_filtered (" = "); | |
1745 | puts_filtered (val); | |
1746 | puts_filtered ("\n"); | |
1747 | } | |
1748 | else | |
1749 | { | |
1750 | puts_filtered ("Environment variable \""); | |
1751 | puts_filtered (var); | |
1752 | puts_filtered ("\" not defined.\n"); | |
1753 | } | |
1754 | } | |
1755 | else | |
1756 | { | |
3f81c18a | 1757 | char **vector = environ_vector (current_inferior ()->environment); |
c906108c SS |
1758 | while (*vector) |
1759 | { | |
1760 | puts_filtered (*vector++); | |
1761 | puts_filtered ("\n"); | |
1762 | } | |
1763 | } | |
1764 | } | |
1765 | ||
1766 | static void | |
fba45db2 | 1767 | set_environment_command (char *arg, int from_tty) |
c906108c | 1768 | { |
52f0bd74 | 1769 | char *p, *val, *var; |
c906108c SS |
1770 | int nullset = 0; |
1771 | ||
1772 | if (arg == 0) | |
e2e0b3e5 | 1773 | error_no_arg (_("environment variable and value")); |
c906108c SS |
1774 | |
1775 | /* Find seperation between variable name and value */ | |
1776 | p = (char *) strchr (arg, '='); | |
1777 | val = (char *) strchr (arg, ' '); | |
1778 | ||
1779 | if (p != 0 && val != 0) | |
1780 | { | |
1781 | /* We have both a space and an equals. If the space is before the | |
c5aa993b JM |
1782 | equals, walk forward over the spaces til we see a nonspace |
1783 | (possibly the equals). */ | |
c906108c SS |
1784 | if (p > val) |
1785 | while (*val == ' ') | |
1786 | val++; | |
1787 | ||
1788 | /* Now if the = is after the char following the spaces, | |
c5aa993b | 1789 | take the char following the spaces. */ |
c906108c SS |
1790 | if (p > val) |
1791 | p = val - 1; | |
1792 | } | |
1793 | else if (val != 0 && p == 0) | |
1794 | p = val; | |
1795 | ||
1796 | if (p == arg) | |
e2e0b3e5 | 1797 | error_no_arg (_("environment variable to set")); |
c906108c SS |
1798 | |
1799 | if (p == 0 || p[1] == 0) | |
1800 | { | |
1801 | nullset = 1; | |
1802 | if (p == 0) | |
1803 | p = arg + strlen (arg); /* So that savestring below will work */ | |
1804 | } | |
1805 | else | |
1806 | { | |
1807 | /* Not setting variable value to null */ | |
1808 | val = p + 1; | |
1809 | while (*val == ' ' || *val == '\t') | |
1810 | val++; | |
1811 | } | |
1812 | ||
c5aa993b JM |
1813 | while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) |
1814 | p--; | |
c906108c SS |
1815 | |
1816 | var = savestring (arg, p - arg); | |
1817 | if (nullset) | |
1818 | { | |
a3f17187 AC |
1819 | printf_filtered (_("\ |
1820 | Setting environment variable \"%s\" to null value.\n"), | |
1821 | var); | |
3f81c18a | 1822 | set_in_environ (current_inferior ()->environment, var, ""); |
c906108c SS |
1823 | } |
1824 | else | |
3f81c18a | 1825 | set_in_environ (current_inferior ()->environment, var, val); |
b8c9b27d | 1826 | xfree (var); |
c906108c SS |
1827 | } |
1828 | ||
1829 | static void | |
fba45db2 | 1830 | unset_environment_command (char *var, int from_tty) |
c906108c SS |
1831 | { |
1832 | if (var == 0) | |
1833 | { | |
1834 | /* If there is no argument, delete all environment variables. | |
c5aa993b | 1835 | Ask for confirmation if reading from the terminal. */ |
e2e0b3e5 | 1836 | if (!from_tty || query (_("Delete all environment variables? "))) |
c906108c | 1837 | { |
3f81c18a VP |
1838 | free_environ (current_inferior ()->environment); |
1839 | current_inferior ()->environment = make_environ (); | |
c906108c SS |
1840 | } |
1841 | } | |
1842 | else | |
3f81c18a | 1843 | unset_in_environ (current_inferior ()->environment, var); |
c906108c SS |
1844 | } |
1845 | ||
1846 | /* Handle the execution path (PATH variable) */ | |
1847 | ||
1848 | static const char path_var_name[] = "PATH"; | |
1849 | ||
c906108c | 1850 | static void |
fba45db2 | 1851 | path_info (char *args, int from_tty) |
c906108c SS |
1852 | { |
1853 | puts_filtered ("Executable and object file path: "); | |
3f81c18a | 1854 | puts_filtered (get_in_environ (current_inferior ()->environment, path_var_name)); |
c906108c SS |
1855 | puts_filtered ("\n"); |
1856 | } | |
1857 | ||
1858 | /* Add zero or more directories to the front of the execution path. */ | |
1859 | ||
1860 | static void | |
fba45db2 | 1861 | path_command (char *dirname, int from_tty) |
c906108c SS |
1862 | { |
1863 | char *exec_path; | |
1864 | char *env; | |
1865 | dont_repeat (); | |
3f81c18a | 1866 | env = get_in_environ (current_inferior ()->environment, path_var_name); |
c906108c SS |
1867 | /* Can be null if path is not set */ |
1868 | if (!env) | |
1869 | env = ""; | |
4fcf66da | 1870 | exec_path = xstrdup (env); |
c906108c | 1871 | mod_path (dirname, &exec_path); |
3f81c18a | 1872 | set_in_environ (current_inferior ()->environment, path_var_name, exec_path); |
b8c9b27d | 1873 | xfree (exec_path); |
c906108c | 1874 | if (from_tty) |
c5aa993b | 1875 | path_info ((char *) NULL, from_tty); |
c906108c | 1876 | } |
c906108c | 1877 | \f |
c5aa993b | 1878 | |
4782dc19 | 1879 | /* Print out the machine register regnum. If regnum is -1, print all |
0ab7a791 AC |
1880 | registers (print_all == 1) or all non-float and non-vector |
1881 | registers (print_all == 0). | |
c906108c SS |
1882 | |
1883 | For most machines, having all_registers_info() print the | |
0ab7a791 AC |
1884 | register(s) one per line is good enough. If a different format is |
1885 | required, (eg, for MIPS or Pyramid 90x, which both have lots of | |
1886 | regs), or there is an existing convention for showing all the | |
1887 | registers, define the architecture method PRINT_REGISTERS_INFO to | |
1888 | provide that format. */ | |
c906108c | 1889 | |
666e11c5 | 1890 | void |
0ab7a791 AC |
1891 | default_print_registers_info (struct gdbarch *gdbarch, |
1892 | struct ui_file *file, | |
1893 | struct frame_info *frame, | |
1894 | int regnum, int print_all) | |
c906108c | 1895 | { |
0ab7a791 | 1896 | int i; |
a4bd449d UW |
1897 | const int numregs = gdbarch_num_regs (gdbarch) |
1898 | + gdbarch_num_pseudo_regs (gdbarch); | |
10c42a71 | 1899 | gdb_byte buffer[MAX_REGISTER_SIZE]; |
0ab7a791 | 1900 | |
c906108c SS |
1901 | for (i = 0; i < numregs; i++) |
1902 | { | |
4782dc19 AC |
1903 | /* Decide between printing all regs, non-float / vector regs, or |
1904 | specific reg. */ | |
c5aa993b JM |
1905 | if (regnum == -1) |
1906 | { | |
f9418c0f | 1907 | if (print_all) |
4782dc19 | 1908 | { |
f9418c0f | 1909 | if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup)) |
4782dc19 | 1910 | continue; |
f9418c0f AC |
1911 | } |
1912 | else | |
1913 | { | |
1914 | if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup)) | |
4782dc19 AC |
1915 | continue; |
1916 | } | |
c5aa993b JM |
1917 | } |
1918 | else | |
1919 | { | |
1920 | if (i != regnum) | |
1921 | continue; | |
1922 | } | |
c906108c SS |
1923 | |
1924 | /* If the register name is empty, it is undefined for this | |
c5aa993b | 1925 | processor, so don't display anything. */ |
a4bd449d UW |
1926 | if (gdbarch_register_name (gdbarch, i) == NULL |
1927 | || *(gdbarch_register_name (gdbarch, i)) == '\0') | |
c906108c SS |
1928 | continue; |
1929 | ||
a4bd449d | 1930 | fputs_filtered (gdbarch_register_name (gdbarch, i), file); |
c9f4d572 | 1931 | print_spaces_filtered (15 - strlen (gdbarch_register_name |
a4bd449d | 1932 | (gdbarch, i)), file); |
c906108c SS |
1933 | |
1934 | /* Get the data in raw format. */ | |
9730f241 | 1935 | if (! frame_register_read (frame, i, buffer)) |
c906108c | 1936 | { |
0ab7a791 | 1937 | fprintf_filtered (file, "*value not available*\n"); |
c906108c SS |
1938 | continue; |
1939 | } | |
1940 | ||
0ab7a791 AC |
1941 | /* If virtual format is floating, print it that way, and in raw |
1942 | hex. */ | |
f949c649 TJB |
1943 | if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT |
1944 | || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT) | |
c906108c | 1945 | { |
0ab7a791 | 1946 | int j; |
79a45b7d | 1947 | struct value_print_options opts; |
c906108c | 1948 | |
79a45b7d TT |
1949 | get_user_print_options (&opts); |
1950 | opts.deref_ref = 1; | |
a4bd449d | 1951 | val_print (register_type (gdbarch, i), buffer, 0, 0, |
79a45b7d | 1952 | file, 0, &opts, current_language); |
c906108c | 1953 | |
0ab7a791 | 1954 | fprintf_filtered (file, "\t(raw 0x"); |
a4bd449d | 1955 | for (j = 0; j < register_size (gdbarch, i); j++) |
c906108c | 1956 | { |
0ab7a791 | 1957 | int idx; |
a4bd449d | 1958 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
0ab7a791 AC |
1959 | idx = j; |
1960 | else | |
a4bd449d | 1961 | idx = register_size (gdbarch, i) - 1 - j; |
9730f241 | 1962 | fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]); |
c906108c | 1963 | } |
0ab7a791 | 1964 | fprintf_filtered (file, ")"); |
c906108c | 1965 | } |
c906108c SS |
1966 | else |
1967 | { | |
79a45b7d TT |
1968 | struct value_print_options opts; |
1969 | ||
ab4327e0 | 1970 | /* Print the register in hex. */ |
79a45b7d TT |
1971 | get_formatted_print_options (&opts, 'x'); |
1972 | opts.deref_ref = 1; | |
a4bd449d | 1973 | val_print (register_type (gdbarch, i), buffer, 0, 0, |
79a45b7d TT |
1974 | file, 0, &opts, |
1975 | current_language); | |
ab4327e0 EZ |
1976 | /* If not a vector register, print it also according to its |
1977 | natural format. */ | |
a4bd449d | 1978 | if (TYPE_VECTOR (register_type (gdbarch, i)) == 0) |
ab4327e0 | 1979 | { |
79a45b7d TT |
1980 | get_user_print_options (&opts); |
1981 | opts.deref_ref = 1; | |
9d84ac84 | 1982 | fprintf_filtered (file, "\t"); |
a4bd449d | 1983 | val_print (register_type (gdbarch, i), buffer, 0, 0, |
79a45b7d | 1984 | file, 0, &opts, current_language); |
ab4327e0 | 1985 | } |
c906108c SS |
1986 | } |
1987 | ||
0ab7a791 | 1988 | fprintf_filtered (file, "\n"); |
c906108c SS |
1989 | } |
1990 | } | |
c906108c | 1991 | |
c906108c | 1992 | void |
fba45db2 | 1993 | registers_info (char *addr_exp, int fpregs) |
c906108c | 1994 | { |
206415a3 | 1995 | struct frame_info *frame; |
a4bd449d | 1996 | struct gdbarch *gdbarch; |
c906108c | 1997 | int regnum, numregs; |
52f0bd74 | 1998 | char *end; |
c906108c SS |
1999 | |
2000 | if (!target_has_registers) | |
8a3fe4f8 | 2001 | error (_("The program has no registers now.")); |
206415a3 | 2002 | frame = get_selected_frame (NULL); |
a4bd449d | 2003 | gdbarch = get_frame_arch (frame); |
c906108c SS |
2004 | |
2005 | if (!addr_exp) | |
2006 | { | |
a4bd449d | 2007 | gdbarch_print_registers_info (gdbarch, gdb_stdout, |
206415a3 | 2008 | frame, -1, fpregs); |
c906108c SS |
2009 | return; |
2010 | } | |
2011 | ||
f9418c0f | 2012 | while (*addr_exp != '\0') |
c5aa993b | 2013 | { |
f9418c0f AC |
2014 | char *start; |
2015 | const char *end; | |
c906108c | 2016 | |
f9418c0f AC |
2017 | /* Keep skipping leading white space. */ |
2018 | if (isspace ((*addr_exp))) | |
2019 | { | |
2020 | addr_exp++; | |
2021 | continue; | |
2022 | } | |
c906108c | 2023 | |
f9418c0f AC |
2024 | /* Discard any leading ``$''. Check that there is something |
2025 | resembling a register following it. */ | |
2026 | if (addr_exp[0] == '$') | |
2027 | addr_exp++; | |
2028 | if (isspace ((*addr_exp)) || (*addr_exp) == '\0') | |
8a3fe4f8 | 2029 | error (_("Missing register name")); |
c906108c | 2030 | |
f9418c0f AC |
2031 | /* Find the start/end of this register name/num/group. */ |
2032 | start = addr_exp; | |
2033 | while ((*addr_exp) != '\0' && !isspace ((*addr_exp))) | |
2034 | addr_exp++; | |
2035 | end = addr_exp; | |
ad842144 | 2036 | |
f9418c0f AC |
2037 | /* Figure out what we've found and display it. */ |
2038 | ||
2039 | /* A register name? */ | |
2040 | { | |
029a67e4 | 2041 | int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start); |
f9418c0f AC |
2042 | if (regnum >= 0) |
2043 | { | |
ad842144 MR |
2044 | /* User registers lie completely outside of the range of |
2045 | normal registers. Catch them early so that the target | |
2046 | never sees them. */ | |
2047 | if (regnum >= gdbarch_num_regs (gdbarch) | |
2048 | + gdbarch_num_pseudo_regs (gdbarch)) | |
2049 | { | |
79a45b7d | 2050 | struct value_print_options opts; |
ad842144 MR |
2051 | struct value *val = value_of_user_reg (regnum, frame); |
2052 | ||
2053 | printf_filtered ("%s: ", start); | |
79a45b7d | 2054 | get_formatted_print_options (&opts, 'x'); |
ad842144 MR |
2055 | print_scalar_formatted (value_contents (val), |
2056 | check_typedef (value_type (val)), | |
79a45b7d | 2057 | &opts, 0, gdb_stdout); |
ad842144 MR |
2058 | printf_filtered ("\n"); |
2059 | } | |
2060 | else | |
2061 | gdbarch_print_registers_info (gdbarch, gdb_stdout, | |
2062 | frame, regnum, fpregs); | |
f9418c0f AC |
2063 | continue; |
2064 | } | |
2065 | } | |
ad842144 | 2066 | |
f9418c0f AC |
2067 | /* A register group? */ |
2068 | { | |
6c7d17ba | 2069 | struct reggroup *group; |
a4bd449d | 2070 | for (group = reggroup_next (gdbarch, NULL); |
6c7d17ba | 2071 | group != NULL; |
a4bd449d | 2072 | group = reggroup_next (gdbarch, group)) |
f9418c0f AC |
2073 | { |
2074 | /* Don't bother with a length check. Should the user | |
2075 | enter a short register group name, go with the first | |
2076 | group that matches. */ | |
6c7d17ba | 2077 | if (strncmp (start, reggroup_name (group), end - start) == 0) |
f9418c0f AC |
2078 | break; |
2079 | } | |
6c7d17ba | 2080 | if (group != NULL) |
f9418c0f AC |
2081 | { |
2082 | int regnum; | |
f57d151a | 2083 | for (regnum = 0; |
a4bd449d UW |
2084 | regnum < gdbarch_num_regs (gdbarch) |
2085 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 2086 | regnum++) |
f9418c0f | 2087 | { |
a4bd449d UW |
2088 | if (gdbarch_register_reggroup_p (gdbarch, regnum, group)) |
2089 | gdbarch_print_registers_info (gdbarch, | |
206415a3 | 2090 | gdb_stdout, frame, |
f9418c0f AC |
2091 | regnum, fpregs); |
2092 | } | |
2093 | continue; | |
2094 | } | |
2095 | } | |
c906108c | 2096 | |
f9418c0f | 2097 | /* Nothing matched. */ |
8a3fe4f8 | 2098 | error (_("Invalid register `%.*s'"), (int) (end - start), start); |
c5aa993b | 2099 | } |
c906108c SS |
2100 | } |
2101 | ||
2102 | void | |
fba45db2 | 2103 | all_registers_info (char *addr_exp, int from_tty) |
c906108c SS |
2104 | { |
2105 | registers_info (addr_exp, 1); | |
2106 | } | |
2107 | ||
a58dd373 | 2108 | static void |
fba45db2 | 2109 | nofp_registers_info (char *addr_exp, int from_tty) |
c906108c SS |
2110 | { |
2111 | registers_info (addr_exp, 0); | |
2112 | } | |
e76f1f2e AC |
2113 | |
2114 | static void | |
d80b854b | 2115 | print_vector_info (struct ui_file *file, |
e76f1f2e AC |
2116 | struct frame_info *frame, const char *args) |
2117 | { | |
d80b854b UW |
2118 | struct gdbarch *gdbarch = get_frame_arch (frame); |
2119 | ||
e76f1f2e AC |
2120 | if (gdbarch_print_vector_info_p (gdbarch)) |
2121 | gdbarch_print_vector_info (gdbarch, file, frame, args); | |
2122 | else | |
2123 | { | |
2124 | int regnum; | |
2125 | int printed_something = 0; | |
ab4327e0 | 2126 | |
f57d151a | 2127 | for (regnum = 0; |
a4bd449d UW |
2128 | regnum < gdbarch_num_regs (gdbarch) |
2129 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 2130 | regnum++) |
e76f1f2e | 2131 | { |
f9418c0f | 2132 | if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup)) |
e76f1f2e AC |
2133 | { |
2134 | printed_something = 1; | |
e76f1f2e | 2135 | gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1); |
e76f1f2e AC |
2136 | } |
2137 | } | |
2138 | if (!printed_something) | |
2139 | fprintf_filtered (file, "No vector information\n"); | |
2140 | } | |
2141 | } | |
2142 | ||
2143 | static void | |
2144 | vector_info (char *args, int from_tty) | |
2145 | { | |
206415a3 DJ |
2146 | if (!target_has_registers) |
2147 | error (_("The program has no registers now.")); | |
2148 | ||
d80b854b | 2149 | print_vector_info (gdb_stdout, get_selected_frame (NULL), args); |
e76f1f2e | 2150 | } |
c906108c | 2151 | \f |
5fd62852 PA |
2152 | /* Kill the inferior process. Make us have no inferior. */ |
2153 | ||
2154 | static void | |
2155 | kill_command (char *arg, int from_tty) | |
2156 | { | |
2157 | /* FIXME: This should not really be inferior_ptid (or target_has_execution). | |
2158 | It should be a distinct flag that indicates that a target is active, cuz | |
2159 | some targets don't have processes! */ | |
2160 | ||
2161 | if (ptid_equal (inferior_ptid, null_ptid)) | |
2162 | error (_("The program is not being run.")); | |
2163 | if (!query (_("Kill the program being debugged? "))) | |
2164 | error (_("Not confirmed.")); | |
2165 | target_kill (); | |
2166 | ||
c35b1492 PA |
2167 | /* If we still have other inferiors to debug, then don't mess with |
2168 | with their threads. */ | |
2169 | if (!have_inferiors ()) | |
5fd62852 PA |
2170 | { |
2171 | init_thread_list (); /* Destroy thread info */ | |
2172 | ||
2173 | /* Killing off the inferior can leave us with a core file. If | |
2174 | so, print the state we are left in. */ | |
2175 | if (target_has_stack) | |
2176 | { | |
2177 | printf_filtered (_("In %s,\n"), target_longname); | |
2178 | print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC); | |
2179 | } | |
2180 | } | |
2181 | bfd_cache_close_all (); | |
2182 | } | |
c5aa993b | 2183 | |
74531fed PA |
2184 | /* Used in `attach&' command. ARG is a point to an integer |
2185 | representing a process id. Proceed threads of this process iff | |
2186 | they stopped due to debugger request, and when they did, they | |
2187 | reported a clean stop (TARGET_SIGNAL_0). Do not proceed threads | |
2188 | that have been explicitly been told to stop. */ | |
2189 | ||
2190 | static int | |
2191 | proceed_after_attach_callback (struct thread_info *thread, | |
2192 | void *arg) | |
2193 | { | |
2194 | int pid = * (int *) arg; | |
2195 | ||
2196 | if (ptid_get_pid (thread->ptid) == pid | |
2197 | && !is_exited (thread->ptid) | |
2198 | && !is_executing (thread->ptid) | |
2199 | && !thread->stop_requested | |
2200 | && thread->stop_signal == TARGET_SIGNAL_0) | |
2201 | { | |
2202 | switch_to_thread (thread->ptid); | |
2203 | clear_proceed_status (); | |
2204 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); | |
2205 | } | |
2206 | ||
2207 | return 0; | |
2208 | } | |
2209 | ||
2210 | static void | |
2211 | proceed_after_attach (int pid) | |
2212 | { | |
2213 | /* Don't error out if the current thread is running, because | |
2214 | there may be other stopped threads. */ | |
2215 | struct cleanup *old_chain; | |
2216 | ||
2217 | /* Backup current thread and selected frame. */ | |
2218 | old_chain = make_cleanup_restore_current_thread (); | |
2219 | ||
2220 | iterate_over_threads (proceed_after_attach_callback, &pid); | |
2221 | ||
2222 | /* Restore selected ptid. */ | |
2223 | do_cleanups (old_chain); | |
2224 | } | |
2225 | ||
c906108c SS |
2226 | /* |
2227 | * TODO: | |
2228 | * Should save/restore the tty state since it might be that the | |
2229 | * program to be debugged was started on this tty and it wants | |
2230 | * the tty in some state other than what we want. If it's running | |
2231 | * on another terminal or without a terminal, then saving and | |
2232 | * restoring the tty state is a harmless no-op. | |
2233 | * This only needs to be done if we are attaching to a process. | |
2234 | */ | |
2235 | ||
2236 | /* | |
2237 | attach_command -- | |
2238 | takes a program started up outside of gdb and ``attaches'' to it. | |
2239 | This stops it cold in its tracks and allows us to start debugging it. | |
2240 | and wait for the trace-trap that results from attaching. */ | |
2241 | ||
9356cf8d PA |
2242 | static void |
2243 | attach_command_post_wait (char *args, int from_tty, int async_exec) | |
2244 | { | |
2245 | char *exec_file; | |
2246 | char *full_exec_path = NULL; | |
d6b48e9c | 2247 | struct inferior *inferior; |
9356cf8d | 2248 | |
d6b48e9c PA |
2249 | inferior = current_inferior (); |
2250 | inferior->stop_soon = NO_STOP_QUIETLY; | |
9356cf8d PA |
2251 | |
2252 | /* If no exec file is yet known, try to determine it from the | |
2253 | process itself. */ | |
2254 | exec_file = (char *) get_exec_file (0); | |
2255 | if (!exec_file) | |
2256 | { | |
2257 | exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid)); | |
2258 | if (exec_file) | |
2259 | { | |
2260 | /* It's possible we don't have a full path, but rather just a | |
2261 | filename. Some targets, such as HP-UX, don't provide the | |
2262 | full path, sigh. | |
2263 | ||
2264 | Attempt to qualify the filename against the source path. | |
2265 | (If that fails, we'll just fall back on the original | |
2266 | filename. Not much more we can do...) | |
2267 | */ | |
2268 | if (!source_full_path_of (exec_file, &full_exec_path)) | |
1b36a34b | 2269 | full_exec_path = xstrdup (exec_file); |
9356cf8d PA |
2270 | |
2271 | exec_file_attach (full_exec_path, from_tty); | |
2272 | symbol_file_add_main (full_exec_path, from_tty); | |
2273 | } | |
2274 | } | |
2275 | else | |
2276 | { | |
2277 | reopen_exec_file (); | |
2278 | reread_symbols (); | |
2279 | } | |
2280 | ||
2281 | /* Take any necessary post-attaching actions for this platform. */ | |
2282 | target_post_attach (PIDGET (inferior_ptid)); | |
2283 | ||
2284 | post_create_inferior (¤t_target, from_tty); | |
2285 | ||
2286 | /* Install inferior's terminal modes. */ | |
2287 | target_terminal_inferior (); | |
2288 | ||
2289 | if (async_exec) | |
74531fed PA |
2290 | { |
2291 | /* The user requested an `attach&', so be sure to leave threads | |
2292 | that didn't get a signal running. */ | |
2293 | ||
2294 | /* Immediatelly resume all suspended threads of this inferior, | |
2295 | and this inferior only. This should have no effect on | |
2296 | already running threads. If a thread has been stopped with a | |
2297 | signal, leave it be. */ | |
2298 | if (non_stop) | |
2299 | proceed_after_attach (inferior->pid); | |
2300 | else | |
2301 | { | |
2302 | if (inferior_thread ()->stop_signal == TARGET_SIGNAL_0) | |
2303 | { | |
2304 | clear_proceed_status (); | |
2305 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); | |
2306 | } | |
2307 | } | |
2308 | } | |
9356cf8d PA |
2309 | else |
2310 | { | |
74531fed PA |
2311 | /* The user requested a plain `attach', so be sure to leave |
2312 | the inferior stopped. */ | |
2313 | ||
9356cf8d PA |
2314 | if (target_can_async_p ()) |
2315 | async_enable_stdin (); | |
74531fed PA |
2316 | |
2317 | /* At least the current thread is already stopped. */ | |
2318 | ||
2319 | /* In all-stop, by definition, all threads have to be already | |
2320 | stopped at this point. In non-stop, however, although the | |
2321 | selected thread is stopped, others may still be executing. | |
2322 | Be sure to explicitly stop all threads of the process. This | |
2323 | should have no effect on already stopped threads. */ | |
2324 | if (non_stop) | |
2325 | target_stop (pid_to_ptid (inferior->pid)); | |
2326 | ||
2327 | /* Tell the user/frontend where we're stopped. */ | |
9356cf8d PA |
2328 | normal_stop (); |
2329 | if (deprecated_attach_hook) | |
2330 | deprecated_attach_hook (); | |
2331 | } | |
2332 | } | |
2333 | ||
bfec99b2 | 2334 | struct attach_command_continuation_args |
9356cf8d PA |
2335 | { |
2336 | char *args; | |
2337 | int from_tty; | |
2338 | int async_exec; | |
bfec99b2 | 2339 | }; |
9356cf8d | 2340 | |
bfec99b2 | 2341 | static void |
604ead4a | 2342 | attach_command_continuation (void *args) |
bfec99b2 PA |
2343 | { |
2344 | struct attach_command_continuation_args *a = args; | |
2345 | attach_command_post_wait (a->args, a->from_tty, a->async_exec); | |
9356cf8d PA |
2346 | } |
2347 | ||
604ead4a PA |
2348 | static void |
2349 | attach_command_continuation_free_args (void *args) | |
2350 | { | |
2351 | struct attach_command_continuation_args *a = args; | |
2352 | xfree (a->args); | |
2353 | xfree (a); | |
2354 | } | |
2355 | ||
c906108c | 2356 | void |
fba45db2 | 2357 | attach_command (char *args, int from_tty) |
c906108c | 2358 | { |
c5aa993b JM |
2359 | char *exec_file; |
2360 | char *full_exec_path = NULL; | |
9356cf8d | 2361 | int async_exec = 0; |
cb0362bb | 2362 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); |
c906108c | 2363 | |
c5aa993b | 2364 | dont_repeat (); /* Not for the faint of heart */ |
c906108c | 2365 | |
2567c7d9 PA |
2366 | if (gdbarch_has_global_solist (target_gdbarch)) |
2367 | /* Don't complain if all processes share the same symbol | |
2368 | space. */ | |
8a305172 PA |
2369 | ; |
2370 | else if (target_has_execution) | |
c906108c | 2371 | { |
9e2f0ad4 | 2372 | if (query (_("A program is being debugged already. Kill it? "))) |
c906108c SS |
2373 | target_kill (); |
2374 | else | |
8a3fe4f8 | 2375 | error (_("Not killed.")); |
c906108c SS |
2376 | } |
2377 | ||
fd79ecee DJ |
2378 | /* Clean up any leftovers from other runs. Some other things from |
2379 | this function should probably be moved into target_pre_inferior. */ | |
2380 | target_pre_inferior (from_tty); | |
2381 | ||
9908b566 VP |
2382 | if (non_stop && !target_supports_non_stop ()) |
2383 | error (_("Cannot attach to this target in non-stop mode")); | |
2384 | ||
9356cf8d PA |
2385 | if (args) |
2386 | { | |
2387 | async_exec = strip_bg_char (&args); | |
2388 | ||
2389 | /* If we get a request for running in the bg but the target | |
2390 | doesn't support it, error out. */ | |
2391 | if (async_exec && !target_can_async_p ()) | |
2392 | error (_("Asynchronous execution not supported on this target.")); | |
2393 | } | |
2394 | ||
2395 | /* If we don't get a request of running in the bg, then we need | |
2396 | to simulate synchronous (fg) execution. */ | |
2397 | if (!async_exec && target_can_async_p ()) | |
2398 | { | |
2399 | /* Simulate synchronous execution */ | |
2400 | async_disable_stdin (); | |
cb0362bb | 2401 | make_cleanup ((make_cleanup_ftype *)async_enable_stdin, NULL); |
9356cf8d PA |
2402 | } |
2403 | ||
c906108c SS |
2404 | target_attach (args, from_tty); |
2405 | ||
2406 | /* Set up the "saved terminal modes" of the inferior | |
2407 | based on what modes we are starting it with. */ | |
2408 | target_terminal_init (); | |
2409 | ||
c906108c SS |
2410 | /* Set up execution context to know that we should return from |
2411 | wait_for_inferior as soon as the target reports a stop. */ | |
2412 | init_wait_for_inferior (); | |
2413 | clear_proceed_status (); | |
c906108c | 2414 | |
74531fed PA |
2415 | if (non_stop) |
2416 | { | |
2417 | /* If we find that the current thread isn't stopped, explicitly | |
2418 | do so now, because we're going to install breakpoints and | |
2419 | poke at memory. */ | |
2420 | ||
2421 | if (async_exec) | |
2422 | /* The user requested an `attach&'; stop just one thread. */ | |
2423 | target_stop (inferior_ptid); | |
2424 | else | |
2425 | /* The user requested an `attach', so stop all threads of this | |
2426 | inferior. */ | |
2427 | target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid))); | |
2428 | } | |
2429 | ||
dc177b7a PA |
2430 | /* Some system don't generate traps when attaching to inferior. |
2431 | E.g. Mach 3 or GNU hurd. */ | |
2432 | if (!target_attach_no_wait) | |
c5aa993b | 2433 | { |
d6b48e9c PA |
2434 | struct inferior *inferior = current_inferior (); |
2435 | ||
dc177b7a PA |
2436 | /* Careful here. See comments in inferior.h. Basically some |
2437 | OSes don't ignore SIGSTOPs on continue requests anymore. We | |
2438 | need a way for handle_inferior_event to reset the stop_signal | |
2439 | variable after an attach, and this is what | |
2440 | STOP_QUIETLY_NO_SIGSTOP is for. */ | |
d6b48e9c | 2441 | inferior->stop_soon = STOP_QUIETLY_NO_SIGSTOP; |
c5aa993b | 2442 | |
dc177b7a PA |
2443 | if (target_can_async_p ()) |
2444 | { | |
2445 | /* sync_execution mode. Wait for stop. */ | |
bfec99b2 PA |
2446 | struct attach_command_continuation_args *a; |
2447 | ||
2448 | a = xmalloc (sizeof (*a)); | |
2449 | a->args = xstrdup (args); | |
2450 | a->from_tty = from_tty; | |
2451 | a->async_exec = async_exec; | |
e0ba6746 PA |
2452 | add_inferior_continuation (attach_command_continuation, a, |
2453 | attach_command_continuation_free_args); | |
cb0362bb | 2454 | discard_cleanups (back_to); |
dc177b7a PA |
2455 | return; |
2456 | } | |
c906108c | 2457 | |
dc177b7a PA |
2458 | wait_for_inferior (0); |
2459 | } | |
6426a772 | 2460 | |
9356cf8d | 2461 | attach_command_post_wait (args, from_tty, async_exec); |
cb0362bb | 2462 | discard_cleanups (back_to); |
c906108c SS |
2463 | } |
2464 | ||
1941c569 PA |
2465 | /* We had just found out that the target was already attached to an |
2466 | inferior. PTID points at a thread of this new inferior, that is | |
2467 | the most likely to be stopped right now, but not necessarily so. | |
2468 | The new inferior is assumed to be already added to the inferior | |
2469 | list at this point. If LEAVE_RUNNING, then leave the threads of | |
2470 | this inferior running, except those we've explicitly seen reported | |
2471 | as stopped. */ | |
2472 | ||
2473 | void | |
2474 | notice_new_inferior (ptid_t ptid, int leave_running, int from_tty) | |
2475 | { | |
2476 | struct cleanup* old_chain; | |
2477 | int async_exec; | |
2478 | ||
2479 | old_chain = make_cleanup (null_cleanup, NULL); | |
2480 | ||
2481 | /* If in non-stop, leave threads as running as they were. If | |
2482 | they're stopped for some reason other than us telling it to, the | |
2483 | target reports a signal != TARGET_SIGNAL_0. We don't try to | |
2484 | resume threads with such a stop signal. */ | |
2485 | async_exec = non_stop; | |
2486 | ||
2487 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2488 | make_cleanup_restore_current_thread (); | |
2489 | ||
2490 | switch_to_thread (ptid); | |
2491 | ||
2492 | /* When we "notice" a new inferior we need to do all the things we | |
2493 | would normally do if we had just attached to it. */ | |
2494 | ||
2495 | if (is_executing (inferior_ptid)) | |
2496 | { | |
2497 | struct inferior *inferior = current_inferior (); | |
2498 | ||
2499 | /* We're going to install breakpoints, and poke at memory, | |
2500 | ensure that the inferior is stopped for a moment while we do | |
2501 | that. */ | |
2502 | target_stop (inferior_ptid); | |
2503 | ||
2504 | inferior->stop_soon = STOP_QUIETLY_REMOTE; | |
2505 | ||
2506 | /* Wait for stop before proceeding. */ | |
2507 | if (target_can_async_p ()) | |
2508 | { | |
2509 | struct attach_command_continuation_args *a; | |
2510 | ||
2511 | a = xmalloc (sizeof (*a)); | |
2512 | a->args = xstrdup (""); | |
2513 | a->from_tty = from_tty; | |
2514 | a->async_exec = async_exec; | |
2515 | add_inferior_continuation (attach_command_continuation, a, | |
2516 | attach_command_continuation_free_args); | |
2517 | ||
2518 | do_cleanups (old_chain); | |
2519 | return; | |
2520 | } | |
2521 | else | |
2522 | wait_for_inferior (0); | |
2523 | } | |
2524 | ||
2525 | async_exec = leave_running; | |
2526 | attach_command_post_wait ("" /* args */, from_tty, async_exec); | |
2527 | ||
2528 | do_cleanups (old_chain); | |
2529 | } | |
2530 | ||
c906108c SS |
2531 | /* |
2532 | * detach_command -- | |
2533 | * takes a program previously attached to and detaches it. | |
2534 | * The program resumes execution and will no longer stop | |
2535 | * on signals, etc. We better not have left any breakpoints | |
2536 | * in the program or it'll die when it hits one. For this | |
2537 | * to work, it may be necessary for the process to have been | |
2538 | * previously attached. It *might* work if the program was | |
2539 | * started via the normal ptrace (PTRACE_TRACEME). | |
2540 | */ | |
2541 | ||
6418d433 | 2542 | void |
fba45db2 | 2543 | detach_command (char *args, int from_tty) |
c906108c | 2544 | { |
1f5d0fc9 | 2545 | dont_repeat (); /* Not for the faint of heart. */ |
d729566a PA |
2546 | |
2547 | if (ptid_equal (inferior_ptid, null_ptid)) | |
2548 | error (_("The program is not being run.")); | |
2549 | ||
33da3f1c | 2550 | disconnect_tracing (from_tty); |
d5551862 | 2551 | |
c906108c | 2552 | target_detach (args, from_tty); |
50c71eaf PA |
2553 | |
2554 | /* If the solist is global across inferiors, don't clear it when we | |
2555 | detach from a single inferior. */ | |
2556 | if (!gdbarch_has_global_solist (target_gdbarch)) | |
2557 | no_shared_libraries (NULL, from_tty); | |
8a305172 | 2558 | |
c35b1492 PA |
2559 | /* If we still have inferiors to debug, then don't mess with their |
2560 | threads. */ | |
2561 | if (!have_inferiors ()) | |
8a305172 PA |
2562 | init_thread_list (); |
2563 | ||
9a4105ab AC |
2564 | if (deprecated_detach_hook) |
2565 | deprecated_detach_hook (); | |
c906108c SS |
2566 | } |
2567 | ||
6ad8ae5c DJ |
2568 | /* Disconnect from the current target without resuming it (leaving it |
2569 | waiting for a debugger). | |
2570 | ||
2571 | We'd better not have left any breakpoints in the program or the | |
2572 | next debugger will get confused. Currently only supported for some | |
2573 | remote targets, since the normal attach mechanisms don't work on | |
2574 | stopped processes on some native platforms (e.g. GNU/Linux). */ | |
2575 | ||
2576 | static void | |
2577 | disconnect_command (char *args, int from_tty) | |
2578 | { | |
2579 | dont_repeat (); /* Not for the faint of heart */ | |
2580 | target_disconnect (args, from_tty); | |
e85a822c | 2581 | no_shared_libraries (NULL, from_tty); |
a0ef4274 | 2582 | init_thread_list (); |
9a4105ab AC |
2583 | if (deprecated_detach_hook) |
2584 | deprecated_detach_hook (); | |
6ad8ae5c DJ |
2585 | } |
2586 | ||
77ebaa5a VP |
2587 | void |
2588 | interrupt_target_1 (int all_threads) | |
2589 | { | |
2590 | ptid_t ptid; | |
2591 | if (all_threads) | |
2592 | ptid = minus_one_ptid; | |
2593 | else | |
2594 | ptid = inferior_ptid; | |
2595 | target_stop (ptid); | |
252fbfc8 PA |
2596 | |
2597 | /* Tag the thread as having been explicitly requested to stop, so | |
2598 | other parts of gdb know not to resume this thread automatically, | |
2599 | if it was stopped due to an internal event. Limit this to | |
2600 | non-stop mode, as when debugging a multi-threaded application in | |
2601 | all-stop mode, we will only get one stop event --- it's undefined | |
2602 | which thread will report the event. */ | |
2603 | if (non_stop) | |
2604 | set_stop_requested (ptid, 1); | |
77ebaa5a VP |
2605 | } |
2606 | ||
43ff13b4 | 2607 | /* Stop the execution of the target while running in async mode, in |
8cae4b3f PA |
2608 | the backgound. In all-stop, stop the whole process. In non-stop |
2609 | mode, stop the current thread only by default, or stop all threads | |
2610 | if the `-a' switch is used. */ | |
2611 | ||
2612 | /* interrupt [-a] */ | |
8b93c638 | 2613 | void |
fba45db2 | 2614 | interrupt_target_command (char *args, int from_tty) |
43ff13b4 | 2615 | { |
362646f5 | 2616 | if (target_can_async_p ()) |
43ff13b4 | 2617 | { |
8cae4b3f PA |
2618 | int all_threads = 0; |
2619 | ||
c5aa993b | 2620 | dont_repeat (); /* Not for the faint of heart */ |
94cc34af | 2621 | |
8cae4b3f PA |
2622 | if (args != NULL |
2623 | && strncmp (args, "-a", sizeof ("-a") - 1) == 0) | |
2624 | all_threads = 1; | |
2625 | ||
2626 | if (!non_stop && all_threads) | |
2627 | error (_("-a is meaningless in all-stop mode.")); | |
2628 | ||
77ebaa5a | 2629 | interrupt_target_1 (all_threads); |
43ff13b4 JM |
2630 | } |
2631 | } | |
2632 | ||
c906108c | 2633 | static void |
d80b854b | 2634 | print_float_info (struct ui_file *file, |
23e3a7ac | 2635 | struct frame_info *frame, const char *args) |
c906108c | 2636 | { |
d80b854b UW |
2637 | struct gdbarch *gdbarch = get_frame_arch (frame); |
2638 | ||
23e3a7ac AC |
2639 | if (gdbarch_print_float_info_p (gdbarch)) |
2640 | gdbarch_print_float_info (gdbarch, file, frame, args); | |
2641 | else | |
2642 | { | |
23e3a7ac AC |
2643 | int regnum; |
2644 | int printed_something = 0; | |
ab4327e0 | 2645 | |
f57d151a | 2646 | for (regnum = 0; |
a4bd449d UW |
2647 | regnum < gdbarch_num_regs (gdbarch) |
2648 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 2649 | regnum++) |
23e3a7ac | 2650 | { |
f9418c0f | 2651 | if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup)) |
23e3a7ac AC |
2652 | { |
2653 | printed_something = 1; | |
23e3a7ac | 2654 | gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1); |
23e3a7ac AC |
2655 | } |
2656 | } | |
2657 | if (!printed_something) | |
2658 | fprintf_filtered (file, "\ | |
2659 | No floating-point info available for this processor.\n"); | |
23e3a7ac AC |
2660 | } |
2661 | } | |
2662 | ||
2663 | static void | |
2664 | float_info (char *args, int from_tty) | |
2665 | { | |
206415a3 DJ |
2666 | if (!target_has_registers) |
2667 | error (_("The program has no registers now.")); | |
2668 | ||
d80b854b | 2669 | print_float_info (gdb_stdout, get_selected_frame (NULL), args); |
c906108c SS |
2670 | } |
2671 | \f | |
c906108c | 2672 | static void |
fba45db2 | 2673 | unset_command (char *args, int from_tty) |
c906108c | 2674 | { |
a3f17187 AC |
2675 | printf_filtered (_("\ |
2676 | \"unset\" must be followed by the name of an unset subcommand.\n")); | |
c906108c SS |
2677 | help_list (unsetlist, "unset ", -1, gdb_stdout); |
2678 | } | |
2679 | ||
2680 | void | |
fba45db2 | 2681 | _initialize_infcmd (void) |
c906108c | 2682 | { |
3cb3b8df BR |
2683 | struct cmd_list_element *c = NULL; |
2684 | ||
2685 | /* add the filename of the terminal connected to inferior I/O */ | |
2686 | add_setshow_filename_cmd ("inferior-tty", class_run, | |
3f81c18a | 2687 | &inferior_io_terminal_scratch, _("\ |
3cb3b8df BR |
2688 | Set terminal for future runs of program being debugged."), _("\ |
2689 | Show terminal for future runs of program being debugged."), _("\ | |
3f81c18a VP |
2690 | Usage: set inferior-tty /dev/pts/1"), |
2691 | set_inferior_tty_command, | |
2692 | show_inferior_tty_command, | |
2693 | &setlist, &showlist); | |
3cb3b8df | 2694 | add_com_alias ("tty", "set inferior-tty", class_alias, 0); |
c906108c | 2695 | |
b4b4ac0b | 2696 | add_setshow_optional_filename_cmd ("args", class_run, |
3f81c18a | 2697 | &inferior_args_scratch, _("\ |
b4b4ac0b AC |
2698 | Set argument list to give program being debugged when it is started."), _("\ |
2699 | Show argument list to give program being debugged when it is started."), _("\ | |
2700 | Follow this command with any number of args, to be passed to the program."), | |
3f81c18a VP |
2701 | set_args_command, |
2702 | show_args_command, | |
b4b4ac0b | 2703 | &setlist, &showlist); |
c906108c | 2704 | |
1a966eab AC |
2705 | c = add_cmd ("environment", no_class, environment_info, _("\ |
2706 | The environment to give the program, or one variable's value.\n\ | |
c906108c SS |
2707 | With an argument VAR, prints the value of environment variable VAR to\n\ |
2708 | give the program being debugged. With no arguments, prints the entire\n\ | |
1a966eab | 2709 | environment to be given to the program."), &showlist); |
5ba2abeb | 2710 | set_cmd_completer (c, noop_completer); |
c906108c SS |
2711 | |
2712 | add_prefix_cmd ("unset", no_class, unset_command, | |
1bedd215 | 2713 | _("Complement to certain \"set\" commands."), |
c906108c | 2714 | &unsetlist, "unset ", 0, &cmdlist); |
c5aa993b | 2715 | |
1a966eab AC |
2716 | c = add_cmd ("environment", class_run, unset_environment_command, _("\ |
2717 | Cancel environment variable VAR for the program.\n\ | |
2718 | This does not affect the program until the next \"run\" command."), | |
c5aa993b | 2719 | &unsetlist); |
5ba2abeb | 2720 | set_cmd_completer (c, noop_completer); |
c906108c | 2721 | |
1a966eab AC |
2722 | c = add_cmd ("environment", class_run, set_environment_command, _("\ |
2723 | Set environment variable value to give the program.\n\ | |
c906108c SS |
2724 | Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\ |
2725 | VALUES of environment variables are uninterpreted strings.\n\ | |
1a966eab | 2726 | This does not affect the program until the next \"run\" command."), |
c5aa993b | 2727 | &setlist); |
5ba2abeb | 2728 | set_cmd_completer (c, noop_completer); |
c5aa993b | 2729 | |
1bedd215 AC |
2730 | c = add_com ("path", class_files, path_command, _("\ |
2731 | Add directory DIR(s) to beginning of search path for object files.\n\ | |
c906108c SS |
2732 | $cwd in the path means the current working directory.\n\ |
2733 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
2734 | directories, separated by colons. These directories are searched to find\n\ | |
1bedd215 | 2735 | fully linked executable files and separately compiled object files as needed.")); |
5ba2abeb | 2736 | set_cmd_completer (c, filename_completer); |
c906108c | 2737 | |
1a966eab AC |
2738 | c = add_cmd ("paths", no_class, path_info, _("\ |
2739 | Current search path for finding object files.\n\ | |
c906108c SS |
2740 | $cwd in the path means the current working directory.\n\ |
2741 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
2742 | directories, separated by colons. These directories are searched to find\n\ | |
1a966eab | 2743 | fully linked executable files and separately compiled object files as needed."), |
c906108c | 2744 | &showlist); |
5ba2abeb | 2745 | set_cmd_completer (c, noop_completer); |
c906108c | 2746 | |
2277426b PA |
2747 | add_prefix_cmd ("kill", class_run, kill_command, |
2748 | _("Kill execution of program being debugged."), | |
2749 | &killlist, "kill ", 0, &cmdlist); | |
5fd62852 | 2750 | |
1bedd215 AC |
2751 | add_com ("attach", class_run, attach_command, _("\ |
2752 | Attach to a process or file outside of GDB.\n\ | |
c906108c SS |
2753 | This command attaches to another target, of the same type as your last\n\ |
2754 | \"target\" command (\"info files\" will show your target stack).\n\ | |
2755 | The command may take as argument a process id or a device file.\n\ | |
2756 | For a process id, you must have permission to send the process a signal,\n\ | |
2757 | and it must have the same effective uid as the debugger.\n\ | |
2758 | When using \"attach\" with a process id, the debugger finds the\n\ | |
2759 | program running in the process, looking first in the current working\n\ | |
2760 | directory, or (if not found there) using the source file search path\n\ | |
2761 | (see the \"directory\" command). You can also use the \"file\" command\n\ | |
1bedd215 | 2762 | to specify the program, and to load its symbol table.")); |
c906108c | 2763 | |
f73adfeb | 2764 | add_prefix_cmd ("detach", class_run, detach_command, _("\ |
1bedd215 | 2765 | Detach a process or file previously attached.\n\ |
c906108c | 2766 | If a process, it is no longer traced, and it continues its execution. If\n\ |
f73adfeb AS |
2767 | you were debugging a file, the file is closed and gdb no longer accesses it."), |
2768 | &detachlist, "detach ", 0, &cmdlist); | |
c906108c | 2769 | |
1bedd215 AC |
2770 | add_com ("disconnect", class_run, disconnect_command, _("\ |
2771 | Disconnect from a target.\n\ | |
6ad8ae5c | 2772 | The target will wait for another debugger to connect. Not available for\n\ |
1bedd215 | 2773 | all targets.")); |
6ad8ae5c | 2774 | |
1bedd215 AC |
2775 | add_com ("signal", class_run, signal_command, _("\ |
2776 | Continue program giving it signal specified by the argument.\n\ | |
2777 | An argument of \"0\" means continue program without giving it a signal.")); | |
c906108c | 2778 | |
1bedd215 AC |
2779 | add_com ("stepi", class_run, stepi_command, _("\ |
2780 | Step one instruction exactly.\n\ | |
2781 | Argument N means do this N times (or till program stops for another reason).")); | |
c906108c SS |
2782 | add_com_alias ("si", "stepi", class_alias, 0); |
2783 | ||
1bedd215 AC |
2784 | add_com ("nexti", class_run, nexti_command, _("\ |
2785 | Step one instruction, but proceed through subroutine calls.\n\ | |
2786 | Argument N means do this N times (or till program stops for another reason).")); | |
c906108c SS |
2787 | add_com_alias ("ni", "nexti", class_alias, 0); |
2788 | ||
1bedd215 AC |
2789 | add_com ("finish", class_run, finish_command, _("\ |
2790 | Execute until selected stack frame returns.\n\ | |
2791 | Upon return, the value returned is printed and put in the value history.")); | |
0e479716 | 2792 | add_com_alias ("fin", "finish", class_run, 1); |
c906108c | 2793 | |
1bedd215 AC |
2794 | add_com ("next", class_run, next_command, _("\ |
2795 | Step program, proceeding through subroutine calls.\n\ | |
c906108c SS |
2796 | Like the \"step\" command as long as subroutine calls do not happen;\n\ |
2797 | when they do, the call is treated as one instruction.\n\ | |
1bedd215 | 2798 | Argument N means do this N times (or till program stops for another reason).")); |
c906108c SS |
2799 | add_com_alias ("n", "next", class_run, 1); |
2800 | if (xdb_commands) | |
c5aa993b | 2801 | add_com_alias ("S", "next", class_run, 1); |
c906108c | 2802 | |
1bedd215 AC |
2803 | add_com ("step", class_run, step_command, _("\ |
2804 | Step program until it reaches a different source line.\n\ | |
2805 | Argument N means do this N times (or till program stops for another reason).")); | |
c906108c SS |
2806 | add_com_alias ("s", "step", class_run, 1); |
2807 | ||
1bedd215 AC |
2808 | c = add_com ("until", class_run, until_command, _("\ |
2809 | Execute until the program reaches a source line greater than the current\n\ | |
2810 | or a specified location (same args as break command) within the current frame.")); | |
5ba2abeb | 2811 | set_cmd_completer (c, location_completer); |
c906108c | 2812 | add_com_alias ("u", "until", class_run, 1); |
c5aa993b | 2813 | |
1bedd215 AC |
2814 | c = add_com ("advance", class_run, advance_command, _("\ |
2815 | Continue the program up to the given location (same form as args for break command).\n\ | |
2816 | Execution will also stop upon exit from the current stack frame.")); | |
ae66c1fc EZ |
2817 | set_cmd_completer (c, location_completer); |
2818 | ||
1bedd215 AC |
2819 | c = add_com ("jump", class_run, jump_command, _("\ |
2820 | Continue program being debugged at specified line or address.\n\ | |
c906108c | 2821 | Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\ |
1bedd215 | 2822 | for an address to start at.")); |
5ba2abeb | 2823 | set_cmd_completer (c, location_completer); |
c906108c | 2824 | |
b83266a0 | 2825 | if (xdb_commands) |
c94fdfd0 | 2826 | { |
1bedd215 AC |
2827 | c = add_com ("go", class_run, go_command, _("\ |
2828 | Usage: go <location>\n\ | |
c906108c SS |
2829 | Continue program being debugged, stopping at specified line or \n\ |
2830 | address.\n\ | |
2831 | Give as argument either LINENUM or *ADDR, where ADDR is an \n\ | |
2832 | expression for an address to start at.\n\ | |
1bedd215 | 2833 | This command is a combination of tbreak and jump.")); |
5ba2abeb | 2834 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 2835 | } |
b83266a0 | 2836 | |
c906108c | 2837 | if (xdb_commands) |
c5aa993b | 2838 | add_com_alias ("g", "go", class_run, 1); |
c906108c | 2839 | |
8cae4b3f | 2840 | c = add_com ("continue", class_run, continue_command, _("\ |
1bedd215 | 2841 | Continue program being debugged, after signal or breakpoint.\n\ |
c906108c SS |
2842 | If proceeding from breakpoint, a number N may be used as an argument,\n\ |
2843 | which means to set the ignore count of that breakpoint to N - 1 (so that\n\ | |
8cae4b3f PA |
2844 | the breakpoint won't break until the Nth time it is reached).\n\ |
2845 | \n\ | |
2846 | If non-stop mode is enabled, continue only the current thread,\n\ | |
2847 | otherwise all the threads in the program are continued. To \n\ | |
2848 | continue all stopped threads in non-stop mode, use the -a option.\n\ | |
2849 | Specifying -a and an ignore count simultaneously is an error.")); | |
c906108c SS |
2850 | add_com_alias ("c", "cont", class_run, 1); |
2851 | add_com_alias ("fg", "cont", class_run, 1); | |
2852 | ||
1bedd215 AC |
2853 | c = add_com ("run", class_run, run_command, _("\ |
2854 | Start debugged program. You may specify arguments to give it.\n\ | |
c906108c SS |
2855 | Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\ |
2856 | Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\ | |
2857 | With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\ | |
2858 | To cancel previous arguments and run with no arguments,\n\ | |
1bedd215 | 2859 | use \"set args\" without arguments.")); |
5ba2abeb | 2860 | set_cmd_completer (c, filename_completer); |
c906108c SS |
2861 | add_com_alias ("r", "run", class_run, 1); |
2862 | if (xdb_commands) | |
2863 | add_com ("R", class_run, run_no_args_command, | |
1bedd215 | 2864 | _("Start debugged program with no arguments.")); |
c906108c | 2865 | |
1bedd215 | 2866 | c = add_com ("start", class_run, start_command, _("\ |
a4d5f2e0 JB |
2867 | Run the debugged program until the beginning of the main procedure.\n\ |
2868 | You may specify arguments to give to your program, just as with the\n\ | |
1bedd215 | 2869 | \"run\" command.")); |
a4d5f2e0 JB |
2870 | set_cmd_completer (c, filename_completer); |
2871 | ||
700b53b1 | 2872 | c = add_com ("interrupt", class_run, interrupt_target_command, |
8cae4b3f PA |
2873 | _("Interrupt the execution of the debugged program.\n\ |
2874 | If non-stop mode is enabled, interrupt only the current thread,\n\ | |
2875 | otherwise all the threads in the program are stopped. To \n\ | |
2876 | interrupt all running threads in non-stop mode, use the -a option.")); | |
43ff13b4 | 2877 | |
1bedd215 AC |
2878 | add_info ("registers", nofp_registers_info, _("\ |
2879 | List of integer registers and their contents, for selected stack frame.\n\ | |
2880 | Register name as argument means describe only that register.")); | |
7194c49b | 2881 | add_info_alias ("r", "registers", 1); |
c906108c SS |
2882 | |
2883 | if (xdb_commands) | |
1bedd215 AC |
2884 | add_com ("lr", class_info, nofp_registers_info, _("\ |
2885 | List of integer registers and their contents, for selected stack frame.\n\ | |
2886 | Register name as argument means describe only that register.")); | |
2887 | add_info ("all-registers", all_registers_info, _("\ | |
2888 | List of all registers and their contents, for selected stack frame.\n\ | |
2889 | Register name as argument means describe only that register.")); | |
c906108c SS |
2890 | |
2891 | add_info ("program", program_info, | |
1bedd215 | 2892 | _("Execution status of the program.")); |
c906108c SS |
2893 | |
2894 | add_info ("float", float_info, | |
1bedd215 | 2895 | _("Print the status of the floating point unit\n")); |
c906108c | 2896 | |
e76f1f2e | 2897 | add_info ("vector", vector_info, |
1bedd215 | 2898 | _("Print the status of the vector unit\n")); |
c906108c | 2899 | } |