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