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