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