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