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