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