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