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