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