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