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