Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Memory-access and commands for "inferior" process, for GDB. |
990a07ab | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 DJ |
4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
5 | 2008 Free Software Foundation, Inc. | |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include <signal.h> | |
24 | #include "gdb_string.h" | |
25 | #include "symtab.h" | |
26 | #include "gdbtypes.h" | |
27 | #include "frame.h" | |
28 | #include "inferior.h" | |
29 | #include "environ.h" | |
30 | #include "value.h" | |
31 | #include "gdbcmd.h" | |
1adeb98a | 32 | #include "symfile.h" |
c906108c SS |
33 | #include "gdbcore.h" |
34 | #include "target.h" | |
35 | #include "language.h" | |
36 | #include "symfile.h" | |
37 | #include "objfiles.h" | |
c94fdfd0 | 38 | #include "completer.h" |
8b93c638 | 39 | #include "ui-out.h" |
6426a772 | 40 | #include "event-top.h" |
96baa820 | 41 | #include "parser-defs.h" |
36160dc4 | 42 | #include "regcache.h" |
f9418c0f | 43 | #include "reggroups.h" |
fe898f56 | 44 | #include "block.h" |
a77053c2 | 45 | #include "solib.h" |
f9418c0f | 46 | #include <ctype.h> |
92ad9cd9 | 47 | #include "gdb_assert.h" |
281b533b | 48 | #include "observer.h" |
424163ea | 49 | #include "target-descriptions.h" |
ad842144 | 50 | #include "user-regs.h" |
32c1e744 | 51 | #include "exceptions.h" |
700b53b1 | 52 | #include "cli/cli-decode.h" |
a0ef4274 | 53 | #include "gdbthread.h" |
72cec141 | 54 | |
a58dd373 | 55 | /* Functions exported for general use, in inferior.h: */ |
c906108c | 56 | |
a14ed312 | 57 | void all_registers_info (char *, int); |
c906108c | 58 | |
a14ed312 | 59 | void registers_info (char *, int); |
c906108c | 60 | |
a58dd373 EZ |
61 | void nexti_command (char *, int); |
62 | ||
63 | void stepi_command (char *, int); | |
c906108c | 64 | |
a14ed312 | 65 | void continue_command (char *, int); |
c906108c | 66 | |
a58dd373 EZ |
67 | void interrupt_target_command (char *args, int from_tty); |
68 | ||
69 | /* Local functions: */ | |
70 | ||
71 | static void nofp_registers_info (char *, int); | |
72 | ||
c055b101 CV |
73 | static void print_return_value (struct type *func_type, |
74 | struct type *value_type); | |
11cf8741 | 75 | |
a14ed312 | 76 | static void until_next_command (int); |
c906108c | 77 | |
a14ed312 | 78 | static void until_command (char *, int); |
c906108c | 79 | |
a14ed312 | 80 | static void path_info (char *, int); |
c906108c | 81 | |
a14ed312 | 82 | static void path_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void unset_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void float_info (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void detach_command (char *, int); |
c906108c | 89 | |
6ad8ae5c DJ |
90 | static void disconnect_command (char *, int); |
91 | ||
a14ed312 | 92 | static void unset_environment_command (char *, int); |
c906108c | 93 | |
a14ed312 | 94 | static void set_environment_command (char *, int); |
c906108c | 95 | |
a14ed312 | 96 | static void environment_info (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void program_info (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void finish_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void signal_command (char *, int); |
c906108c | 103 | |
a14ed312 | 104 | static void jump_command (char *, int); |
c906108c | 105 | |
a14ed312 | 106 | static void step_1 (int, int, char *); |
611c83ae | 107 | static void step_once (int skip_subroutines, int single_inst, int count, int thread); |
c906108c | 108 | |
a14ed312 | 109 | static void next_command (char *, int); |
c906108c | 110 | |
a14ed312 | 111 | static void step_command (char *, int); |
c906108c | 112 | |
a14ed312 | 113 | static void run_command (char *, int); |
c906108c | 114 | |
a14ed312 | 115 | static void run_no_args_command (char *args, int from_tty); |
392a587b | 116 | |
a14ed312 | 117 | static void go_command (char *line_no, int from_tty); |
392a587b | 118 | |
a14ed312 | 119 | static int strip_bg_char (char **); |
43ff13b4 | 120 | |
a14ed312 | 121 | void _initialize_infcmd (void); |
c906108c SS |
122 | |
123 | #define GO_USAGE "Usage: go <location>\n" | |
124 | ||
c906108c | 125 | #define ERROR_NO_INFERIOR \ |
8a3fe4f8 | 126 | if (!target_has_execution) error (_("The program is not being run.")); |
c906108c SS |
127 | |
128 | /* String containing arguments to give to the program, separated by spaces. | |
129 | Empty string (pointer to '\0') means no args. */ | |
130 | ||
131 | static char *inferior_args; | |
132 | ||
552c04a7 TT |
133 | /* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero, |
134 | then we must compute INFERIOR_ARGS from this (via the target). */ | |
135 | ||
136 | static int inferior_argc; | |
137 | static char **inferior_argv; | |
138 | ||
c906108c SS |
139 | /* File name for default use for standard in/out in the inferior. */ |
140 | ||
3cb3b8df | 141 | static char *inferior_io_terminal; |
c906108c SS |
142 | |
143 | /* Pid of our debugged inferior, or 0 if no inferior now. | |
144 | Since various parts of infrun.c test this to see whether there is a program | |
145 | being debugged it should be nonzero (currently 3 is used) for remote | |
146 | debugging. */ | |
147 | ||
39f77062 | 148 | ptid_t inferior_ptid; |
c906108c SS |
149 | |
150 | /* Last signal that the inferior received (why it stopped). */ | |
151 | ||
152 | enum target_signal stop_signal; | |
153 | ||
154 | /* Address at which inferior stopped. */ | |
155 | ||
156 | CORE_ADDR stop_pc; | |
157 | ||
158 | /* Chain containing status of breakpoint(s) that we have stopped at. */ | |
159 | ||
160 | bpstat stop_bpstat; | |
161 | ||
162 | /* Flag indicating that a command has proceeded the inferior past the | |
163 | current breakpoint. */ | |
164 | ||
165 | int breakpoint_proceeded; | |
166 | ||
167 | /* Nonzero if stopped due to a step command. */ | |
168 | ||
169 | int stop_step; | |
170 | ||
171 | /* Nonzero if stopped due to completion of a stack dummy routine. */ | |
172 | ||
173 | int stop_stack_dummy; | |
174 | ||
175 | /* Nonzero if stopped due to a random (unexpected) signal in inferior | |
176 | process. */ | |
177 | ||
178 | int stopped_by_random_signal; | |
179 | ||
180 | /* Range to single step within. | |
181 | If this is nonzero, respond to a single-step signal | |
182 | by continuing to step if the pc is in this range. */ | |
183 | ||
c5aa993b JM |
184 | CORE_ADDR step_range_start; /* Inclusive */ |
185 | CORE_ADDR step_range_end; /* Exclusive */ | |
c906108c SS |
186 | |
187 | /* Stack frame address as of when stepping command was issued. | |
188 | This is how we know when we step into a subroutine call, | |
189 | and how to set the frame for the breakpoint used to step out. */ | |
190 | ||
aa0cd9c1 | 191 | struct frame_id step_frame_id; |
c906108c | 192 | |
5fbbeb29 | 193 | enum step_over_calls_kind step_over_calls; |
c906108c SS |
194 | |
195 | /* If stepping, nonzero means step count is > 1 | |
196 | so don't print frame next time inferior stops | |
197 | if it stops due to stepping. */ | |
198 | ||
199 | int step_multi; | |
200 | ||
201 | /* Environment to use for running inferior, | |
202 | in format described in environ.h. */ | |
203 | ||
1bf1958d | 204 | struct gdb_environ *inferior_environ; |
f5871ec0 | 205 | |
8f6a8e84 VP |
206 | /* When set, no calls to target_resumed observer will be made. */ |
207 | int suppress_resume_observer = 0; | |
208 | /* When set, normal_stop will not call the normal_stop observer. */ | |
209 | int suppress_stop_observer = 0; | |
c906108c | 210 | \f |
07091751 FN |
211 | /* Accessor routines. */ |
212 | ||
3cb3b8df BR |
213 | void |
214 | set_inferior_io_terminal (const char *terminal_name) | |
215 | { | |
216 | if (inferior_io_terminal) | |
217 | xfree (inferior_io_terminal); | |
218 | ||
219 | if (!terminal_name) | |
220 | inferior_io_terminal = NULL; | |
221 | else | |
222 | inferior_io_terminal = savestring (terminal_name, strlen (terminal_name)); | |
223 | } | |
224 | ||
225 | const char * | |
226 | get_inferior_io_terminal (void) | |
227 | { | |
228 | return inferior_io_terminal; | |
229 | } | |
230 | ||
07091751 FN |
231 | char * |
232 | get_inferior_args (void) | |
233 | { | |
552c04a7 TT |
234 | if (inferior_argc != 0) |
235 | { | |
236 | char *n, *old; | |
237 | ||
238 | n = gdbarch_construct_inferior_arguments (current_gdbarch, | |
239 | inferior_argc, inferior_argv); | |
240 | old = set_inferior_args (n); | |
241 | xfree (old); | |
242 | } | |
243 | ||
244 | if (inferior_args == NULL) | |
245 | inferior_args = xstrdup (""); | |
246 | ||
07091751 FN |
247 | return inferior_args; |
248 | } | |
249 | ||
250 | char * | |
251 | set_inferior_args (char *newargs) | |
252 | { | |
253 | char *saved_args = inferior_args; | |
254 | ||
255 | inferior_args = newargs; | |
552c04a7 TT |
256 | inferior_argc = 0; |
257 | inferior_argv = 0; | |
07091751 FN |
258 | |
259 | return saved_args; | |
260 | } | |
c5aa993b | 261 | |
552c04a7 TT |
262 | void |
263 | set_inferior_args_vector (int argc, char **argv) | |
264 | { | |
265 | inferior_argc = argc; | |
266 | inferior_argv = argv; | |
267 | } | |
268 | ||
269 | /* Notice when `set args' is run. */ | |
270 | static void | |
271 | notice_args_set (char *args, int from_tty, struct cmd_list_element *c) | |
272 | { | |
273 | inferior_argc = 0; | |
274 | inferior_argv = 0; | |
275 | } | |
276 | ||
277 | /* Notice when `show args' is run. */ | |
278 | static void | |
b4b4ac0b AC |
279 | notice_args_read (struct ui_file *file, int from_tty, |
280 | struct cmd_list_element *c, const char *value) | |
552c04a7 | 281 | { |
258c00cc TT |
282 | /* Note that we ignore the passed-in value in favor of computing it |
283 | directly. */ | |
284 | deprecated_show_value_hack (file, from_tty, c, get_inferior_args ()); | |
552c04a7 TT |
285 | } |
286 | ||
c2a727fa TT |
287 | \f |
288 | /* Compute command-line string given argument vector. This does the | |
289 | same shell processing as fork_inferior. */ | |
c2a727fa TT |
290 | char * |
291 | construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv) | |
292 | { | |
293 | char *result; | |
294 | ||
295 | if (STARTUP_WITH_SHELL) | |
296 | { | |
297 | /* This holds all the characters considered special to the | |
298 | typical Unix shells. We include `^' because the SunOS | |
299 | /bin/sh treats it as a synonym for `|'. */ | |
300 | char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n"; | |
301 | int i; | |
302 | int length = 0; | |
303 | char *out, *cp; | |
304 | ||
305 | /* We over-compute the size. It shouldn't matter. */ | |
306 | for (i = 0; i < argc; ++i) | |
03c6228e | 307 | length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0'); |
c2a727fa TT |
308 | |
309 | result = (char *) xmalloc (length); | |
310 | out = result; | |
311 | ||
312 | for (i = 0; i < argc; ++i) | |
313 | { | |
314 | if (i > 0) | |
315 | *out++ = ' '; | |
316 | ||
03c6228e AS |
317 | /* Need to handle empty arguments specially. */ |
318 | if (argv[i][0] == '\0') | |
c2a727fa | 319 | { |
03c6228e AS |
320 | *out++ = '\''; |
321 | *out++ = '\''; | |
322 | } | |
323 | else | |
324 | { | |
325 | for (cp = argv[i]; *cp; ++cp) | |
326 | { | |
327 | if (strchr (special, *cp) != NULL) | |
328 | *out++ = '\\'; | |
329 | *out++ = *cp; | |
330 | } | |
c2a727fa TT |
331 | } |
332 | } | |
333 | *out = '\0'; | |
334 | } | |
335 | else | |
336 | { | |
337 | /* In this case we can't handle arguments that contain spaces, | |
338 | tabs, or newlines -- see breakup_args(). */ | |
339 | int i; | |
340 | int length = 0; | |
341 | ||
342 | for (i = 0; i < argc; ++i) | |
343 | { | |
344 | char *cp = strchr (argv[i], ' '); | |
345 | if (cp == NULL) | |
346 | cp = strchr (argv[i], '\t'); | |
347 | if (cp == NULL) | |
348 | cp = strchr (argv[i], '\n'); | |
349 | if (cp != NULL) | |
8a3fe4f8 | 350 | error (_("can't handle command-line argument containing whitespace")); |
c2a727fa TT |
351 | length += strlen (argv[i]) + 1; |
352 | } | |
353 | ||
354 | result = (char *) xmalloc (length); | |
355 | result[0] = '\0'; | |
356 | for (i = 0; i < argc; ++i) | |
357 | { | |
358 | if (i > 0) | |
359 | strcat (result, " "); | |
360 | strcat (result, argv[i]); | |
361 | } | |
362 | } | |
363 | ||
364 | return result; | |
365 | } | |
552c04a7 TT |
366 | \f |
367 | ||
43ff13b4 JM |
368 | /* This function detects whether or not a '&' character (indicating |
369 | background execution) has been added as *the last* of the arguments ARGS | |
370 | of a command. If it has, it removes it and returns 1. Otherwise it | |
371 | does nothing and returns 0. */ | |
c5aa993b | 372 | static int |
fba45db2 | 373 | strip_bg_char (char **args) |
43ff13b4 JM |
374 | { |
375 | char *p = NULL; | |
c5aa993b | 376 | |
9846de1b | 377 | p = strchr (*args, '&'); |
c5aa993b | 378 | |
9846de1b | 379 | if (p) |
43ff13b4 JM |
380 | { |
381 | if (p == (*args + strlen (*args) - 1)) | |
382 | { | |
c5aa993b | 383 | if (strlen (*args) > 1) |
43ff13b4 JM |
384 | { |
385 | do | |
386 | p--; | |
387 | while (*p == ' ' || *p == '\t'); | |
388 | *(p + 1) = '\0'; | |
389 | } | |
390 | else | |
391 | *args = 0; | |
392 | return 1; | |
393 | } | |
394 | } | |
395 | return 0; | |
396 | } | |
397 | ||
c906108c | 398 | void |
fba45db2 | 399 | tty_command (char *file, int from_tty) |
c906108c SS |
400 | { |
401 | if (file == 0) | |
e2e0b3e5 | 402 | error_no_arg (_("terminal name for running target process")); |
c906108c | 403 | |
3cb3b8df | 404 | set_inferior_io_terminal (file); |
c906108c SS |
405 | } |
406 | ||
281b533b DJ |
407 | /* Common actions to take after creating any sort of inferior, by any |
408 | means (running, attaching, connecting, et cetera). The target | |
409 | should be stopped. */ | |
410 | ||
411 | void | |
412 | post_create_inferior (struct target_ops *target, int from_tty) | |
413 | { | |
b79599ff DP |
414 | /* Be sure we own the terminal in case write operations are performed. */ |
415 | target_terminal_ours (); | |
416 | ||
424163ea DJ |
417 | /* If the target hasn't taken care of this already, do it now. |
418 | Targets which need to access registers during to_open, | |
419 | to_create_inferior, or to_attach should do it earlier; but many | |
420 | don't need to. */ | |
421 | target_find_description (); | |
422 | ||
9353355f DJ |
423 | if (exec_bfd) |
424 | { | |
425 | /* Sometimes the platform-specific hook loads initial shared | |
426 | libraries, and sometimes it doesn't. Try to do so first, so | |
de1b3c3d PA |
427 | that we can add them with the correct value for FROM_TTY. |
428 | If we made all the inferior hook methods consistent, | |
429 | this call could be removed. */ | |
9353355f DJ |
430 | #ifdef SOLIB_ADD |
431 | SOLIB_ADD (NULL, from_tty, target, auto_solib_add); | |
432 | #else | |
433 | solib_add (NULL, from_tty, target, auto_solib_add); | |
434 | #endif | |
435 | ||
436 | /* Create the hooks to handle shared library load and unload | |
437 | events. */ | |
438 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
37706b70 | 439 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
9353355f DJ |
440 | #else |
441 | solib_create_inferior_hook (); | |
442 | #endif | |
9353355f DJ |
443 | } |
444 | ||
281b533b DJ |
445 | observer_notify_inferior_created (target, from_tty); |
446 | } | |
447 | ||
a4d5f2e0 JB |
448 | /* Kill the inferior if already running. This function is designed |
449 | to be called when we are about to start the execution of the program | |
450 | from the beginning. Ask the user to confirm that he wants to restart | |
451 | the program being debugged when FROM_TTY is non-null. */ | |
c906108c | 452 | |
8edfe269 | 453 | static void |
a4d5f2e0 JB |
454 | kill_if_already_running (int from_tty) |
455 | { | |
39f77062 | 456 | if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution) |
c906108c | 457 | { |
8edfe269 DJ |
458 | /* Bail out before killing the program if we will not be able to |
459 | restart it. */ | |
460 | target_require_runnable (); | |
461 | ||
adf40b2e JM |
462 | if (from_tty |
463 | && !query ("The program being debugged has been started already.\n\ | |
c906108c | 464 | Start it from the beginning? ")) |
8a3fe4f8 | 465 | error (_("Program not restarted.")); |
c906108c | 466 | target_kill (); |
e85a822c | 467 | no_shared_libraries (NULL, from_tty); |
c906108c SS |
468 | init_wait_for_inferior (); |
469 | } | |
a4d5f2e0 JB |
470 | } |
471 | ||
f67a969f JB |
472 | /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert |
473 | a temporary breakpoint at the begining of the main program before | |
474 | running the program. */ | |
475 | ||
a4d5f2e0 | 476 | static void |
f67a969f | 477 | run_command_1 (char *args, int from_tty, int tbreak_at_main) |
a4d5f2e0 JB |
478 | { |
479 | char *exec_file; | |
c906108c | 480 | |
a4d5f2e0 JB |
481 | dont_repeat (); |
482 | ||
483 | kill_if_already_running (from_tty); | |
c906108c SS |
484 | clear_breakpoint_hit_counts (); |
485 | ||
fd79ecee DJ |
486 | /* Clean up any leftovers from other runs. Some other things from |
487 | this function should probably be moved into target_pre_inferior. */ | |
488 | target_pre_inferior (from_tty); | |
489 | ||
39ad761d JB |
490 | /* The comment here used to read, "The exec file is re-read every |
491 | time we do a generic_mourn_inferior, so we just have to worry | |
492 | about the symbol file." The `generic_mourn_inferior' function | |
493 | gets called whenever the program exits. However, suppose the | |
494 | program exits, and *then* the executable file changes? We need | |
495 | to check again here. Since reopen_exec_file doesn't do anything | |
496 | if the timestamp hasn't changed, I don't see the harm. */ | |
497 | reopen_exec_file (); | |
c906108c SS |
498 | reread_symbols (); |
499 | ||
f67a969f JB |
500 | /* Insert the temporary breakpoint if a location was specified. */ |
501 | if (tbreak_at_main) | |
502 | tbreak_command (main_name (), 0); | |
503 | ||
39ad761d JB |
504 | exec_file = (char *) get_exec_file (0); |
505 | ||
c906108c SS |
506 | /* We keep symbols from add-symbol-file, on the grounds that the |
507 | user might want to add some symbols before running the program | |
508 | (right?). But sometimes (dynamic loading where the user manually | |
509 | introduces the new symbols with add-symbol-file), the code which | |
510 | the symbols describe does not persist between runs. Currently | |
511 | the user has to manually nuke all symbols between runs if they | |
512 | want them to go away (PR 2207). This is probably reasonable. */ | |
513 | ||
43ff13b4 | 514 | if (!args) |
6426a772 | 515 | { |
362646f5 | 516 | if (target_can_async_p ()) |
6426a772 JM |
517 | async_disable_stdin (); |
518 | } | |
43ff13b4 | 519 | else |
c906108c | 520 | { |
43ff13b4 JM |
521 | int async_exec = strip_bg_char (&args); |
522 | ||
523 | /* If we get a request for running in the bg but the target | |
524 | doesn't support it, error out. */ | |
362646f5 | 525 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 526 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 JM |
527 | |
528 | /* If we don't get a request of running in the bg, then we need | |
c5aa993b | 529 | to simulate synchronous (fg) execution. */ |
362646f5 | 530 | if (!async_exec && target_can_async_p ()) |
43ff13b4 JM |
531 | { |
532 | /* Simulate synchronous execution */ | |
6426a772 | 533 | async_disable_stdin (); |
43ff13b4 JM |
534 | } |
535 | ||
536 | /* If there were other args, beside '&', process them. */ | |
537 | if (args) | |
538 | { | |
07091751 FN |
539 | char *old_args = set_inferior_args (xstrdup (args)); |
540 | xfree (old_args); | |
43ff13b4 | 541 | } |
c906108c SS |
542 | } |
543 | ||
544 | if (from_tty) | |
545 | { | |
8b93c638 JM |
546 | ui_out_field_string (uiout, NULL, "Starting program"); |
547 | ui_out_text (uiout, ": "); | |
548 | if (exec_file) | |
549 | ui_out_field_string (uiout, "execfile", exec_file); | |
550 | ui_out_spaces (uiout, 1); | |
552c04a7 TT |
551 | /* We call get_inferior_args() because we might need to compute |
552 | the value now. */ | |
553 | ui_out_field_string (uiout, "infargs", get_inferior_args ()); | |
8b93c638 JM |
554 | ui_out_text (uiout, "\n"); |
555 | ui_out_flush (uiout); | |
c906108c SS |
556 | } |
557 | ||
552c04a7 TT |
558 | /* We call get_inferior_args() because we might need to compute |
559 | the value now. */ | |
560 | target_create_inferior (exec_file, get_inferior_args (), | |
c27cda74 | 561 | environ_vector (inferior_environ), from_tty); |
281b533b | 562 | |
de1b3c3d PA |
563 | /* Pass zero for FROM_TTY, because at this point the "run" command |
564 | has done its thing; now we are setting up the running program. */ | |
565 | post_create_inferior (¤t_target, 0); | |
281b533b DJ |
566 | |
567 | /* Start the target running. */ | |
568 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0); | |
c906108c SS |
569 | } |
570 | ||
571 | ||
f67a969f JB |
572 | static void |
573 | run_command (char *args, int from_tty) | |
574 | { | |
575 | run_command_1 (args, from_tty, 0); | |
576 | } | |
577 | ||
c906108c | 578 | static void |
fba45db2 | 579 | run_no_args_command (char *args, int from_tty) |
c906108c | 580 | { |
07091751 FN |
581 | char *old_args = set_inferior_args (xstrdup ("")); |
582 | xfree (old_args); | |
c906108c | 583 | } |
c906108c | 584 | \f |
c5aa993b | 585 | |
a4d5f2e0 JB |
586 | /* Start the execution of the program up until the beginning of the main |
587 | program. */ | |
588 | ||
589 | static void | |
590 | start_command (char *args, int from_tty) | |
591 | { | |
592 | /* Some languages such as Ada need to search inside the program | |
593 | minimal symbols for the location where to put the temporary | |
594 | breakpoint before starting. */ | |
595 | if (!have_minimal_symbols ()) | |
8a3fe4f8 | 596 | error (_("No symbol table loaded. Use the \"file\" command.")); |
a4d5f2e0 | 597 | |
f67a969f JB |
598 | /* Run the program until reaching the main procedure... */ |
599 | run_command_1 (args, from_tty, 1); | |
a4d5f2e0 JB |
600 | } |
601 | ||
8cae4b3f PA |
602 | static int |
603 | proceed_thread_callback (struct thread_info *thread, void *arg) | |
604 | { | |
4f8d22e3 | 605 | if (!is_stopped (thread->ptid)) |
8cae4b3f PA |
606 | return 0; |
607 | ||
608 | context_switch_to (thread->ptid); | |
609 | clear_proceed_status (); | |
610 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); | |
611 | return 0; | |
612 | } | |
613 | ||
77ebaa5a VP |
614 | void |
615 | continue_1 (int all_threads) | |
616 | { | |
617 | if (non_stop && all_threads) | |
618 | { | |
619 | /* Don't error out if the current thread is running, because | |
620 | there may be other stopped threads. */ | |
621 | struct cleanup *old_chain; | |
622 | ||
623 | /* Backup current thread and selected frame. */ | |
624 | old_chain = make_cleanup_restore_current_thread (); | |
625 | ||
626 | iterate_over_threads (proceed_thread_callback, NULL); | |
627 | ||
628 | /* Restore selected ptid. */ | |
629 | do_cleanups (old_chain); | |
630 | } | |
631 | else | |
632 | { | |
633 | ensure_not_running (); | |
634 | clear_proceed_status (); | |
635 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); | |
636 | } | |
637 | } | |
638 | ||
8cae4b3f | 639 | /* continue [-a] [proceed-count] [&] */ |
c906108c | 640 | void |
8cae4b3f | 641 | continue_command (char *args, int from_tty) |
c906108c | 642 | { |
c5aa993b | 643 | int async_exec = 0; |
8cae4b3f | 644 | int all_threads = 0; |
c906108c SS |
645 | ERROR_NO_INFERIOR; |
646 | ||
43ff13b4 | 647 | /* Find out whether we must run in the background. */ |
8cae4b3f PA |
648 | if (args != NULL) |
649 | async_exec = strip_bg_char (&args); | |
43ff13b4 JM |
650 | |
651 | /* If we must run in the background, but the target can't do it, | |
652 | error out. */ | |
362646f5 | 653 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 654 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 JM |
655 | |
656 | /* If we are not asked to run in the bg, then prepare to run in the | |
657 | foreground, synchronously. */ | |
362646f5 | 658 | if (!async_exec && target_can_async_p ()) |
c5aa993b | 659 | { |
43ff13b4 | 660 | /* Simulate synchronous execution */ |
6426a772 | 661 | async_disable_stdin (); |
43ff13b4 | 662 | } |
c906108c | 663 | |
8cae4b3f PA |
664 | if (args != NULL) |
665 | { | |
666 | if (strncmp (args, "-a", sizeof ("-a") - 1) == 0) | |
667 | { | |
668 | all_threads = 1; | |
669 | args += sizeof ("-a") - 1; | |
670 | if (*args == '\0') | |
671 | args = NULL; | |
672 | } | |
673 | } | |
674 | ||
675 | if (!non_stop && all_threads) | |
676 | error (_("`-a' is meaningless in all-stop mode.")); | |
677 | ||
678 | if (args != NULL && all_threads) | |
679 | error (_("\ | |
680 | Can't resume all threads and specify proceed count simultaneously.")); | |
681 | ||
682 | /* If we have an argument left, set proceed count of breakpoint we | |
683 | stopped at. */ | |
684 | if (args != NULL) | |
c906108c SS |
685 | { |
686 | bpstat bs = stop_bpstat; | |
8671a17b PA |
687 | int num, stat; |
688 | int stopped = 0; | |
689 | ||
690 | while ((stat = bpstat_num (&bs, &num)) != 0) | |
691 | if (stat > 0) | |
692 | { | |
693 | set_ignore_count (num, | |
8cae4b3f | 694 | parse_and_eval_long (args) - 1, |
8671a17b PA |
695 | from_tty); |
696 | /* set_ignore_count prints a message ending with a period. | |
697 | So print two spaces before "Continuing.". */ | |
698 | if (from_tty) | |
699 | printf_filtered (" "); | |
700 | stopped = 1; | |
701 | } | |
702 | ||
703 | if (!stopped && from_tty) | |
c906108c SS |
704 | { |
705 | printf_filtered | |
706 | ("Not stopped at any breakpoint; argument ignored.\n"); | |
707 | } | |
c906108c SS |
708 | } |
709 | ||
710 | if (from_tty) | |
a3f17187 | 711 | printf_filtered (_("Continuing.\n")); |
c906108c | 712 | |
77ebaa5a | 713 | continue_1 (all_threads); |
c906108c SS |
714 | } |
715 | \f | |
716 | /* Step until outside of current statement. */ | |
717 | ||
c906108c | 718 | static void |
fba45db2 | 719 | step_command (char *count_string, int from_tty) |
c906108c SS |
720 | { |
721 | step_1 (0, 0, count_string); | |
722 | } | |
723 | ||
724 | /* Likewise, but skip over subroutine calls as if single instructions. */ | |
725 | ||
c906108c | 726 | static void |
fba45db2 | 727 | next_command (char *count_string, int from_tty) |
c906108c SS |
728 | { |
729 | step_1 (1, 0, count_string); | |
730 | } | |
731 | ||
732 | /* Likewise, but step only one instruction. */ | |
733 | ||
c906108c | 734 | void |
fba45db2 | 735 | stepi_command (char *count_string, int from_tty) |
c906108c SS |
736 | { |
737 | step_1 (0, 1, count_string); | |
738 | } | |
739 | ||
c906108c | 740 | void |
fba45db2 | 741 | nexti_command (char *count_string, int from_tty) |
c906108c SS |
742 | { |
743 | step_1 (1, 1, count_string); | |
744 | } | |
745 | ||
74b7792f | 746 | static void |
611c83ae | 747 | delete_longjmp_breakpoint_cleanup (void *arg) |
74b7792f | 748 | { |
611c83ae PA |
749 | int thread = * (int *) arg; |
750 | delete_longjmp_breakpoint (thread); | |
74b7792f AC |
751 | } |
752 | ||
c906108c | 753 | static void |
fba45db2 | 754 | step_1 (int skip_subroutines, int single_inst, char *count_string) |
c906108c | 755 | { |
52f0bd74 | 756 | int count = 1; |
c906108c | 757 | struct frame_info *frame; |
f107f563 | 758 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
43ff13b4 | 759 | int async_exec = 0; |
b3dc826b | 760 | int thread = -1; |
c5aa993b | 761 | |
c906108c | 762 | ERROR_NO_INFERIOR; |
94cc34af | 763 | ensure_not_running (); |
43ff13b4 JM |
764 | |
765 | if (count_string) | |
766 | async_exec = strip_bg_char (&count_string); | |
c5aa993b | 767 | |
43ff13b4 JM |
768 | /* If we get a request for running in the bg but the target |
769 | doesn't support it, error out. */ | |
362646f5 | 770 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 771 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 JM |
772 | |
773 | /* If we don't get a request of running in the bg, then we need | |
774 | to simulate synchronous (fg) execution. */ | |
362646f5 | 775 | if (!async_exec && target_can_async_p ()) |
43ff13b4 JM |
776 | { |
777 | /* Simulate synchronous execution */ | |
6426a772 | 778 | async_disable_stdin (); |
43ff13b4 JM |
779 | } |
780 | ||
bb518678 | 781 | count = count_string ? parse_and_eval_long (count_string) : 1; |
c906108c | 782 | |
c5aa993b | 783 | if (!single_inst || skip_subroutines) /* leave si command alone */ |
c906108c | 784 | { |
611c83ae | 785 | if (in_thread_list (inferior_ptid)) |
b3dc826b | 786 | thread = pid_to_thread_id (inferior_ptid); |
611c83ae PA |
787 | |
788 | set_longjmp_breakpoint (); | |
789 | ||
b3dc826b | 790 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c2d11a7d JM |
791 | } |
792 | ||
793 | /* In synchronous case, all is well, just use the regular for loop. */ | |
362646f5 | 794 | if (!target_can_async_p ()) |
c2d11a7d JM |
795 | { |
796 | for (; count > 0; count--) | |
797 | { | |
798 | clear_proceed_status (); | |
799 | ||
800 | frame = get_current_frame (); | |
801 | if (!frame) /* Avoid coredump here. Why tho? */ | |
8a3fe4f8 | 802 | error (_("No current frame")); |
aa0cd9c1 | 803 | step_frame_id = get_frame_id (frame); |
c2d11a7d JM |
804 | |
805 | if (!single_inst) | |
806 | { | |
807 | find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end); | |
808 | if (step_range_end == 0) | |
809 | { | |
810 | char *name; | |
811 | if (find_pc_partial_function (stop_pc, &name, &step_range_start, | |
812 | &step_range_end) == 0) | |
8a3fe4f8 | 813 | error (_("Cannot find bounds of current function")); |
c2d11a7d JM |
814 | |
815 | target_terminal_ours (); | |
a3f17187 | 816 | printf_filtered (_("\ |
c2d11a7d | 817 | Single stepping until exit from function %s, \n\ |
a3f17187 | 818 | which has no line number information.\n"), name); |
c2d11a7d JM |
819 | } |
820 | } | |
821 | else | |
822 | { | |
823 | /* Say we are stepping, but stop after one insn whatever it does. */ | |
824 | step_range_start = step_range_end = 1; | |
825 | if (!skip_subroutines) | |
826 | /* It is stepi. | |
827 | Don't step over function calls, not even to functions lacking | |
828 | line numbers. */ | |
5fbbeb29 | 829 | step_over_calls = STEP_OVER_NONE; |
c2d11a7d JM |
830 | } |
831 | ||
832 | if (skip_subroutines) | |
5fbbeb29 | 833 | step_over_calls = STEP_OVER_ALL; |
c2d11a7d JM |
834 | |
835 | step_multi = (count > 1); | |
836 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); | |
837 | ||
838 | if (!stop_step) | |
839 | break; | |
c2d11a7d JM |
840 | } |
841 | ||
f107f563 | 842 | do_cleanups (cleanups); |
c2d11a7d JM |
843 | return; |
844 | } | |
845 | /* In case of asynchronous target things get complicated, do only | |
846 | one step for now, before returning control to the event loop. Let | |
847 | the continuation figure out how many other steps we need to do, | |
848 | and handle them one at the time, through step_once(). */ | |
849 | else | |
850 | { | |
b3dc826b | 851 | step_once (skip_subroutines, single_inst, count, thread); |
611c83ae | 852 | /* We are running, and the continuation is installed. It will |
f107f563 VP |
853 | disable the longjmp breakpoint as appropriate. */ |
854 | discard_cleanups (cleanups); | |
c906108c | 855 | } |
c2d11a7d | 856 | } |
c906108c | 857 | |
bfec99b2 PA |
858 | struct step_1_continuation_args |
859 | { | |
860 | int count; | |
861 | int skip_subroutines; | |
862 | int single_inst; | |
863 | int thread; | |
864 | }; | |
865 | ||
c2d11a7d JM |
866 | /* Called after we are done with one step operation, to check whether |
867 | we need to step again, before we print the prompt and return control | |
868 | to the user. If count is > 1, we will need to do one more call to | |
869 | proceed(), via step_once(). Basically it is like step_once and | |
870 | step_1_continuation are co-recursive. */ | |
871 | static void | |
604ead4a | 872 | step_1_continuation (void *args) |
c2d11a7d | 873 | { |
bfec99b2 | 874 | struct step_1_continuation_args *a = args; |
f13468d9 | 875 | |
604ead4a | 876 | if (!step_multi || !stop_step) |
f13468d9 | 877 | { |
604ead4a PA |
878 | /* If we stopped for some reason that is not stepping there are |
879 | no further steps to make. Cleanup. */ | |
bfec99b2 PA |
880 | if (!a->single_inst || a->skip_subroutines) |
881 | delete_longjmp_breakpoint (a->thread); | |
f13468d9 | 882 | step_multi = 0; |
f107f563 | 883 | } |
f13468d9 | 884 | else |
bfec99b2 | 885 | step_once (a->skip_subroutines, a->single_inst, a->count - 1, a->thread); |
c2d11a7d JM |
886 | } |
887 | ||
888 | /* Do just one step operation. If count >1 we will have to set up a | |
889 | continuation to be done after the target stops (after this one | |
890 | step). This is useful to implement the 'step n' kind of commands, in | |
891 | case of asynchronous targets. We had to split step_1 into two parts, | |
892 | one to be done before proceed() and one afterwards. This function is | |
893 | called in case of step n with n>1, after the first step operation has | |
894 | been completed.*/ | |
895 | static void | |
611c83ae | 896 | step_once (int skip_subroutines, int single_inst, int count, int thread) |
bfec99b2 | 897 | { |
0d06e24b | 898 | struct frame_info *frame; |
bfec99b2 | 899 | struct step_1_continuation_args *args; |
c2d11a7d JM |
900 | |
901 | if (count > 0) | |
c906108c SS |
902 | { |
903 | clear_proceed_status (); | |
904 | ||
905 | frame = get_current_frame (); | |
c5aa993b | 906 | if (!frame) /* Avoid coredump here. Why tho? */ |
8a3fe4f8 | 907 | error (_("No current frame")); |
aa0cd9c1 | 908 | step_frame_id = get_frame_id (frame); |
c906108c | 909 | |
c5aa993b | 910 | if (!single_inst) |
c906108c SS |
911 | { |
912 | find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end); | |
5fbbeb29 CF |
913 | |
914 | /* If we have no line info, switch to stepi mode. */ | |
915 | if (step_range_end == 0 && step_stop_if_no_debug) | |
916 | { | |
917 | step_range_start = step_range_end = 1; | |
918 | } | |
919 | else if (step_range_end == 0) | |
c906108c SS |
920 | { |
921 | char *name; | |
922 | if (find_pc_partial_function (stop_pc, &name, &step_range_start, | |
923 | &step_range_end) == 0) | |
8a3fe4f8 | 924 | error (_("Cannot find bounds of current function")); |
c906108c SS |
925 | |
926 | target_terminal_ours (); | |
a3f17187 | 927 | printf_filtered (_("\ |
c906108c | 928 | Single stepping until exit from function %s, \n\ |
a3f17187 | 929 | which has no line number information.\n"), name); |
c906108c SS |
930 | } |
931 | } | |
932 | else | |
933 | { | |
934 | /* Say we are stepping, but stop after one insn whatever it does. */ | |
935 | step_range_start = step_range_end = 1; | |
936 | if (!skip_subroutines) | |
937 | /* It is stepi. | |
938 | Don't step over function calls, not even to functions lacking | |
939 | line numbers. */ | |
5fbbeb29 | 940 | step_over_calls = STEP_OVER_NONE; |
c906108c SS |
941 | } |
942 | ||
943 | if (skip_subroutines) | |
5fbbeb29 | 944 | step_over_calls = STEP_OVER_ALL; |
c906108c SS |
945 | |
946 | step_multi = (count > 1); | |
f107f563 | 947 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); |
bfec99b2 PA |
948 | |
949 | args = xmalloc (sizeof (*args)); | |
950 | args->skip_subroutines = skip_subroutines; | |
951 | args->single_inst = single_inst; | |
952 | args->count = count; | |
953 | args->thread = thread; | |
604ead4a | 954 | add_intermediate_continuation (step_1_continuation, args, xfree); |
c906108c | 955 | } |
c906108c | 956 | } |
c2d11a7d | 957 | |
c906108c SS |
958 | \f |
959 | /* Continue program at specified address. */ | |
960 | ||
961 | static void | |
fba45db2 | 962 | jump_command (char *arg, int from_tty) |
c906108c | 963 | { |
52f0bd74 | 964 | CORE_ADDR addr; |
c906108c SS |
965 | struct symtabs_and_lines sals; |
966 | struct symtab_and_line sal; | |
967 | struct symbol *fn; | |
968 | struct symbol *sfn; | |
43ff13b4 | 969 | int async_exec = 0; |
c5aa993b | 970 | |
c906108c | 971 | ERROR_NO_INFERIOR; |
94cc34af | 972 | ensure_not_running (); |
c906108c | 973 | |
43ff13b4 JM |
974 | /* Find out whether we must run in the background. */ |
975 | if (arg != NULL) | |
976 | async_exec = strip_bg_char (&arg); | |
977 | ||
978 | /* If we must run in the background, but the target can't do it, | |
979 | error out. */ | |
362646f5 | 980 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 981 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 | 982 | |
c906108c | 983 | if (!arg) |
e2e0b3e5 | 984 | error_no_arg (_("starting address")); |
c906108c SS |
985 | |
986 | sals = decode_line_spec_1 (arg, 1); | |
987 | if (sals.nelts != 1) | |
988 | { | |
8a3fe4f8 | 989 | error (_("Unreasonable jump request")); |
c906108c SS |
990 | } |
991 | ||
992 | sal = sals.sals[0]; | |
b8c9b27d | 993 | xfree (sals.sals); |
c906108c SS |
994 | |
995 | if (sal.symtab == 0 && sal.pc == 0) | |
8a3fe4f8 | 996 | error (_("No source file has been specified.")); |
c906108c | 997 | |
c5aa993b | 998 | resolve_sal_pc (&sal); /* May error out */ |
c906108c SS |
999 | |
1000 | /* See if we are trying to jump to another function. */ | |
1001 | fn = get_frame_function (get_current_frame ()); | |
1002 | sfn = find_pc_function (sal.pc); | |
1003 | if (fn != NULL && sfn != fn) | |
1004 | { | |
1005 | if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line, | |
de5ad195 | 1006 | SYMBOL_PRINT_NAME (fn))) |
c906108c | 1007 | { |
8a3fe4f8 | 1008 | error (_("Not confirmed.")); |
c906108c SS |
1009 | /* NOTREACHED */ |
1010 | } | |
1011 | } | |
1012 | ||
c5aa993b | 1013 | if (sfn != NULL) |
c906108c SS |
1014 | { |
1015 | fixup_symbol_section (sfn, 0); | |
c5aa993b | 1016 | if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) && |
c906108c SS |
1017 | !section_is_mapped (SYMBOL_BFD_SECTION (sfn))) |
1018 | { | |
1019 | if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? ")) | |
1020 | { | |
8a3fe4f8 | 1021 | error (_("Not confirmed.")); |
c906108c SS |
1022 | /* NOTREACHED */ |
1023 | } | |
1024 | } | |
1025 | } | |
1026 | ||
c906108c SS |
1027 | addr = sal.pc; |
1028 | ||
1029 | if (from_tty) | |
1030 | { | |
a3f17187 | 1031 | printf_filtered (_("Continuing at ")); |
ed49a04f | 1032 | fputs_filtered (paddress (addr), gdb_stdout); |
c906108c SS |
1033 | printf_filtered (".\n"); |
1034 | } | |
1035 | ||
89113898 PA |
1036 | /* If we are not asked to run in the bg, then prepare to run in the |
1037 | foreground, synchronously. */ | |
1038 | if (!async_exec && target_can_async_p ()) | |
1039 | { | |
1040 | /* Simulate synchronous execution */ | |
1041 | async_disable_stdin (); | |
1042 | } | |
1043 | ||
c906108c SS |
1044 | clear_proceed_status (); |
1045 | proceed (addr, TARGET_SIGNAL_0, 0); | |
1046 | } | |
c906108c | 1047 | \f |
c5aa993b | 1048 | |
c906108c SS |
1049 | /* Go to line or address in current procedure */ |
1050 | static void | |
fba45db2 | 1051 | go_command (char *line_no, int from_tty) |
c906108c | 1052 | { |
c5aa993b | 1053 | if (line_no == (char *) NULL || !*line_no) |
b83266a0 | 1054 | printf_filtered (GO_USAGE); |
c906108c SS |
1055 | else |
1056 | { | |
b83266a0 SS |
1057 | tbreak_command (line_no, from_tty); |
1058 | jump_command (line_no, from_tty); | |
c906108c SS |
1059 | } |
1060 | } | |
c906108c | 1061 | \f |
c5aa993b | 1062 | |
c906108c SS |
1063 | /* Continue program giving it specified signal. */ |
1064 | ||
1065 | static void | |
fba45db2 | 1066 | signal_command (char *signum_exp, int from_tty) |
c906108c SS |
1067 | { |
1068 | enum target_signal oursig; | |
32c1e744 | 1069 | int async_exec = 0; |
c906108c SS |
1070 | |
1071 | dont_repeat (); /* Too dangerous. */ | |
1072 | ERROR_NO_INFERIOR; | |
94cc34af | 1073 | ensure_not_running (); |
c906108c | 1074 | |
32c1e744 VP |
1075 | /* Find out whether we must run in the background. */ |
1076 | if (signum_exp != NULL) | |
1077 | async_exec = strip_bg_char (&signum_exp); | |
1078 | ||
1079 | /* If we must run in the background, but the target can't do it, | |
1080 | error out. */ | |
1081 | if (async_exec && !target_can_async_p ()) | |
1082 | error (_("Asynchronous execution not supported on this target.")); | |
1083 | ||
1084 | /* If we are not asked to run in the bg, then prepare to run in the | |
1085 | foreground, synchronously. */ | |
1086 | if (!async_exec && target_can_async_p ()) | |
1087 | { | |
1088 | /* Simulate synchronous execution. */ | |
1089 | async_disable_stdin (); | |
1090 | } | |
1091 | ||
c906108c | 1092 | if (!signum_exp) |
e2e0b3e5 | 1093 | error_no_arg (_("signal number")); |
c906108c SS |
1094 | |
1095 | /* It would be even slicker to make signal names be valid expressions, | |
1096 | (the type could be "enum $signal" or some such), then the user could | |
1097 | assign them to convenience variables. */ | |
1098 | oursig = target_signal_from_name (signum_exp); | |
1099 | ||
1100 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
1101 | { | |
1102 | /* No, try numeric. */ | |
bb518678 | 1103 | int num = parse_and_eval_long (signum_exp); |
c906108c SS |
1104 | |
1105 | if (num == 0) | |
1106 | oursig = TARGET_SIGNAL_0; | |
1107 | else | |
1108 | oursig = target_signal_from_command (num); | |
1109 | } | |
1110 | ||
1111 | if (from_tty) | |
1112 | { | |
1113 | if (oursig == TARGET_SIGNAL_0) | |
a3f17187 | 1114 | printf_filtered (_("Continuing with no signal.\n")); |
c906108c | 1115 | else |
a3f17187 | 1116 | printf_filtered (_("Continuing with signal %s.\n"), |
c906108c SS |
1117 | target_signal_to_name (oursig)); |
1118 | } | |
1119 | ||
1120 | clear_proceed_status (); | |
1121 | /* "signal 0" should not get stuck if we are stopped at a breakpoint. | |
1122 | FIXME: Neither should "signal foo" but when I tried passing | |
1123 | (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't | |
1124 | tried to track down yet. */ | |
2acceee2 | 1125 | proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0); |
c906108c SS |
1126 | } |
1127 | ||
c906108c SS |
1128 | /* Proceed until we reach a different source line with pc greater than |
1129 | our current one or exit the function. We skip calls in both cases. | |
1130 | ||
1131 | Note that eventually this command should probably be changed so | |
1132 | that only source lines are printed out when we hit the breakpoint | |
1133 | we set. This may involve changes to wait_for_inferior and the | |
1134 | proceed status code. */ | |
1135 | ||
c906108c | 1136 | static void |
fba45db2 | 1137 | until_next_command (int from_tty) |
c906108c SS |
1138 | { |
1139 | struct frame_info *frame; | |
1140 | CORE_ADDR pc; | |
1141 | struct symbol *func; | |
1142 | struct symtab_and_line sal; | |
c5aa993b | 1143 | |
c906108c SS |
1144 | clear_proceed_status (); |
1145 | ||
1146 | frame = get_current_frame (); | |
1147 | ||
1148 | /* Step until either exited from this function or greater | |
1149 | than the current line (if in symbolic section) or pc (if | |
1150 | not). */ | |
1151 | ||
1152 | pc = read_pc (); | |
1153 | func = find_pc_function (pc); | |
c5aa993b | 1154 | |
c906108c SS |
1155 | if (!func) |
1156 | { | |
1157 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc); | |
c5aa993b | 1158 | |
c906108c | 1159 | if (msymbol == NULL) |
8a3fe4f8 | 1160 | error (_("Execution is not within a known function.")); |
c5aa993b | 1161 | |
c906108c SS |
1162 | step_range_start = SYMBOL_VALUE_ADDRESS (msymbol); |
1163 | step_range_end = pc; | |
1164 | } | |
1165 | else | |
1166 | { | |
1167 | sal = find_pc_line (pc, 0); | |
c5aa993b | 1168 | |
c906108c SS |
1169 | step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func)); |
1170 | step_range_end = sal.end; | |
1171 | } | |
c5aa993b | 1172 | |
5fbbeb29 | 1173 | step_over_calls = STEP_OVER_ALL; |
aa0cd9c1 | 1174 | step_frame_id = get_frame_id (frame); |
c906108c SS |
1175 | |
1176 | step_multi = 0; /* Only one call to proceed */ | |
c5aa993b | 1177 | |
2acceee2 | 1178 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); |
c906108c SS |
1179 | } |
1180 | ||
c5aa993b | 1181 | static void |
fba45db2 | 1182 | until_command (char *arg, int from_tty) |
c906108c | 1183 | { |
43ff13b4 JM |
1184 | int async_exec = 0; |
1185 | ||
c906108c | 1186 | if (!target_has_execution) |
8a3fe4f8 | 1187 | error (_("The program is not running.")); |
43ff13b4 JM |
1188 | |
1189 | /* Find out whether we must run in the background. */ | |
1190 | if (arg != NULL) | |
1191 | async_exec = strip_bg_char (&arg); | |
1192 | ||
1193 | /* If we must run in the background, but the target can't do it, | |
1194 | error out. */ | |
362646f5 | 1195 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 1196 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 JM |
1197 | |
1198 | /* If we are not asked to run in the bg, then prepare to run in the | |
1199 | foreground, synchronously. */ | |
362646f5 | 1200 | if (!async_exec && target_can_async_p ()) |
c5aa993b | 1201 | { |
43ff13b4 | 1202 | /* Simulate synchronous execution */ |
6426a772 | 1203 | async_disable_stdin (); |
43ff13b4 JM |
1204 | } |
1205 | ||
c906108c | 1206 | if (arg) |
ae66c1fc | 1207 | until_break_command (arg, from_tty, 0); |
c906108c SS |
1208 | else |
1209 | until_next_command (from_tty); | |
1210 | } | |
ae66c1fc EZ |
1211 | |
1212 | static void | |
1213 | advance_command (char *arg, int from_tty) | |
1214 | { | |
1215 | int async_exec = 0; | |
1216 | ||
1217 | if (!target_has_execution) | |
8a3fe4f8 | 1218 | error (_("The program is not running.")); |
ae66c1fc EZ |
1219 | |
1220 | if (arg == NULL) | |
e2e0b3e5 | 1221 | error_no_arg (_("a location")); |
ae66c1fc EZ |
1222 | |
1223 | /* Find out whether we must run in the background. */ | |
1224 | if (arg != NULL) | |
1225 | async_exec = strip_bg_char (&arg); | |
1226 | ||
1227 | /* If we must run in the background, but the target can't do it, | |
1228 | error out. */ | |
362646f5 | 1229 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 1230 | error (_("Asynchronous execution not supported on this target.")); |
ae66c1fc EZ |
1231 | |
1232 | /* If we are not asked to run in the bg, then prepare to run in the | |
1233 | foreground, synchronously. */ | |
362646f5 | 1234 | if (!async_exec && target_can_async_p ()) |
ae66c1fc EZ |
1235 | { |
1236 | /* Simulate synchronous execution. */ | |
1237 | async_disable_stdin (); | |
1238 | } | |
1239 | ||
1240 | until_break_command (arg, from_tty, 1); | |
1241 | } | |
c906108c | 1242 | \f |
f941662f MK |
1243 | /* Print the result of a function at the end of a 'finish' command. */ |
1244 | ||
11cf8741 | 1245 | static void |
c055b101 | 1246 | print_return_value (struct type *func_type, struct type *value_type) |
11cf8741 | 1247 | { |
31db7b6c | 1248 | struct gdbarch *gdbarch = current_gdbarch; |
bb472c1e MK |
1249 | struct cleanup *old_chain; |
1250 | struct ui_stream *stb; | |
44e5158b AC |
1251 | struct value *value; |
1252 | ||
181fc57c | 1253 | CHECK_TYPEDEF (value_type); |
44e5158b | 1254 | gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID); |
11cf8741 | 1255 | |
92ad9cd9 AC |
1256 | /* FIXME: 2003-09-27: When returning from a nested inferior function |
1257 | call, it's possible (with no help from the architecture vector) | |
1258 | to locate and return/print a "struct return" value. This is just | |
1259 | a more complicated case of what is already being done in in the | |
1260 | inferior function call code. In fact, when inferior function | |
1261 | calls are made async, this will likely be made the norm. */ | |
31db7b6c | 1262 | |
c055b101 CV |
1263 | switch (gdbarch_return_value (gdbarch, func_type, value_type, |
1264 | NULL, NULL, NULL)) | |
44e5158b | 1265 | { |
750eb019 AC |
1266 | case RETURN_VALUE_REGISTER_CONVENTION: |
1267 | case RETURN_VALUE_ABI_RETURNS_ADDRESS: | |
181fc57c | 1268 | case RETURN_VALUE_ABI_PRESERVES_ADDRESS: |
44e5158b | 1269 | value = allocate_value (value_type); |
c055b101 | 1270 | gdbarch_return_value (gdbarch, func_type, value_type, stop_registers, |
990a07ab | 1271 | value_contents_raw (value), NULL); |
750eb019 AC |
1272 | break; |
1273 | case RETURN_VALUE_STRUCT_CONVENTION: | |
1274 | value = NULL; | |
1275 | break; | |
1276 | default: | |
e2e0b3e5 | 1277 | internal_error (__FILE__, __LINE__, _("bad switch")); |
44e5158b | 1278 | } |
bb472c1e | 1279 | |
31db7b6c MK |
1280 | if (value) |
1281 | { | |
1282 | /* Print it. */ | |
1d751abe PA |
1283 | stb = ui_out_stream_new (uiout); |
1284 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
31db7b6c MK |
1285 | ui_out_text (uiout, "Value returned is "); |
1286 | ui_out_field_fmt (uiout, "gdb-result-var", "$%d", | |
1287 | record_latest_value (value)); | |
1288 | ui_out_text (uiout, " = "); | |
1289 | value_print (value, stb->stream, 0, Val_no_prettyprint); | |
1290 | ui_out_field_stream (uiout, "return-value", stb); | |
1291 | ui_out_text (uiout, "\n"); | |
1d751abe | 1292 | do_cleanups (old_chain); |
31db7b6c MK |
1293 | } |
1294 | else | |
1295 | { | |
1296 | ui_out_text (uiout, "Value returned has type: "); | |
1d751abe PA |
1297 | ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type)); |
1298 | ui_out_text (uiout, "."); | |
1299 | ui_out_text (uiout, " Cannot determine contents\n"); | |
31db7b6c | 1300 | } |
11cf8741 JM |
1301 | } |
1302 | ||
43ff13b4 | 1303 | /* Stuff that needs to be done by the finish command after the target |
f941662f MK |
1304 | has stopped. In asynchronous mode, we wait for the target to stop |
1305 | in the call to poll or select in the event loop, so it is | |
1306 | impossible to do all the stuff as part of the finish_command | |
1307 | function itself. The only chance we have to complete this command | |
1308 | is in fetch_inferior_event, which is called by the event loop as | |
1309 | soon as it detects that the target has stopped. This function is | |
1310 | called via the cmd_continuation pointer. */ | |
1311 | ||
bfec99b2 | 1312 | struct finish_command_continuation_args |
43ff13b4 | 1313 | { |
43ff13b4 | 1314 | struct breakpoint *breakpoint; |
bfec99b2 PA |
1315 | struct symbol *function; |
1316 | }; | |
c5aa993b | 1317 | |
bfec99b2 | 1318 | static void |
604ead4a | 1319 | finish_command_continuation (void *arg) |
bfec99b2 PA |
1320 | { |
1321 | struct finish_command_continuation_args *a = arg; | |
43ff13b4 | 1322 | |
604ead4a PA |
1323 | if (bpstat_find_breakpoint (stop_bpstat, a->breakpoint) != NULL |
1324 | && a->function != NULL) | |
43ff13b4 | 1325 | { |
604ead4a | 1326 | struct type *value_type; |
bfec99b2 | 1327 | |
604ead4a PA |
1328 | value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function)); |
1329 | if (!value_type) | |
1330 | internal_error (__FILE__, __LINE__, | |
1331 | _("finish_command: function has no target type")); | |
f5871ec0 | 1332 | |
604ead4a PA |
1333 | if (TYPE_CODE (value_type) != TYPE_CODE_VOID) |
1334 | print_return_value (SYMBOL_TYPE (a->function), value_type); | |
43ff13b4 | 1335 | } |
f941662f | 1336 | |
604ead4a PA |
1337 | /* We suppress normal call of normal_stop observer and do it here so |
1338 | that that *stopped notification includes the return value. */ | |
1339 | /* NOTE: This is broken in non-stop mode. There is no guarantee the | |
1340 | next stop will be in the same thread that we started doing a | |
1341 | finish on. This suppressing (or some other replacement means) | |
1342 | should be a thread property. */ | |
1343 | observer_notify_normal_stop (stop_bpstat); | |
8f6a8e84 | 1344 | suppress_stop_observer = 0; |
bfec99b2 | 1345 | delete_breakpoint (a->breakpoint); |
43ff13b4 JM |
1346 | } |
1347 | ||
604ead4a PA |
1348 | static void |
1349 | finish_command_continuation_free_arg (void *arg) | |
1350 | { | |
1351 | /* NOTE: See finish_command_continuation. This would go away, if | |
1352 | this suppressing is made a thread property. */ | |
1353 | suppress_stop_observer = 0; | |
1354 | xfree (arg); | |
1355 | } | |
1356 | ||
f941662f MK |
1357 | /* "finish": Set a temporary breakpoint at the place the selected |
1358 | frame will return to, then continue. */ | |
c906108c SS |
1359 | |
1360 | static void | |
fba45db2 | 1361 | finish_command (char *arg, int from_tty) |
c906108c SS |
1362 | { |
1363 | struct symtab_and_line sal; | |
52f0bd74 AC |
1364 | struct frame_info *frame; |
1365 | struct symbol *function; | |
c906108c SS |
1366 | struct breakpoint *breakpoint; |
1367 | struct cleanup *old_chain; | |
bfec99b2 | 1368 | struct finish_command_continuation_args *cargs; |
43ff13b4 JM |
1369 | |
1370 | int async_exec = 0; | |
1371 | ||
f941662f | 1372 | /* Find out whether we must run in the background. */ |
43ff13b4 JM |
1373 | if (arg != NULL) |
1374 | async_exec = strip_bg_char (&arg); | |
1375 | ||
1376 | /* If we must run in the background, but the target can't do it, | |
f941662f | 1377 | error out. */ |
362646f5 | 1378 | if (async_exec && !target_can_async_p ()) |
8a3fe4f8 | 1379 | error (_("Asynchronous execution not supported on this target.")); |
43ff13b4 JM |
1380 | |
1381 | /* If we are not asked to run in the bg, then prepare to run in the | |
f941662f | 1382 | foreground, synchronously. */ |
362646f5 | 1383 | if (!async_exec && target_can_async_p ()) |
c5aa993b | 1384 | { |
f941662f | 1385 | /* Simulate synchronous execution. */ |
6426a772 | 1386 | async_disable_stdin (); |
43ff13b4 | 1387 | } |
c906108c SS |
1388 | |
1389 | if (arg) | |
8a3fe4f8 | 1390 | error (_("The \"finish\" command does not take any arguments.")); |
c906108c | 1391 | if (!target_has_execution) |
8a3fe4f8 | 1392 | error (_("The program is not running.")); |
c906108c | 1393 | |
206415a3 | 1394 | frame = get_prev_frame (get_selected_frame (_("No selected frame."))); |
c906108c | 1395 | if (frame == 0) |
8a3fe4f8 | 1396 | error (_("\"finish\" not meaningful in the outermost frame.")); |
c906108c SS |
1397 | |
1398 | clear_proceed_status (); | |
1399 | ||
bdd78e62 AC |
1400 | sal = find_pc_line (get_frame_pc (frame), 0); |
1401 | sal.pc = get_frame_pc (frame); | |
c906108c | 1402 | |
818dd999 | 1403 | breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish); |
c906108c | 1404 | |
f107f563 | 1405 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c SS |
1406 | |
1407 | /* Find the function we will return from. */ | |
1408 | ||
206415a3 | 1409 | function = find_pc_function (get_frame_pc (get_selected_frame (NULL))); |
c906108c | 1410 | |
f941662f MK |
1411 | /* Print info on the selected frame, including level number but not |
1412 | source. */ | |
c906108c SS |
1413 | if (from_tty) |
1414 | { | |
a3f17187 | 1415 | printf_filtered (_("Run till exit from ")); |
b04f3ab4 | 1416 | print_stack_frame (get_selected_frame (NULL), 1, LOCATION); |
c906108c SS |
1417 | } |
1418 | ||
32c1e744 | 1419 | proceed_to_finish = 1; /* We want stop_registers, please... */ |
8f6a8e84 VP |
1420 | make_cleanup_restore_integer (&suppress_stop_observer); |
1421 | suppress_stop_observer = 1; | |
32c1e744 VP |
1422 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); |
1423 | ||
bfec99b2 PA |
1424 | cargs = xmalloc (sizeof (*cargs)); |
1425 | ||
1426 | cargs->breakpoint = breakpoint; | |
1427 | cargs->function = function; | |
604ead4a PA |
1428 | add_continuation (finish_command_continuation, cargs, |
1429 | finish_command_continuation_free_arg); | |
bfec99b2 | 1430 | |
f107f563 | 1431 | discard_cleanups (old_chain); |
362646f5 | 1432 | if (!target_can_async_p ()) |
604ead4a | 1433 | do_all_continuations (); |
c906108c SS |
1434 | } |
1435 | \f | |
f941662f | 1436 | |
c906108c | 1437 | static void |
fba45db2 | 1438 | program_info (char *args, int from_tty) |
c906108c SS |
1439 | { |
1440 | bpstat bs = stop_bpstat; | |
8671a17b PA |
1441 | int num; |
1442 | int stat = bpstat_num (&bs, &num); | |
c5aa993b | 1443 | |
c906108c SS |
1444 | if (!target_has_execution) |
1445 | { | |
a3f17187 | 1446 | printf_filtered (_("The program being debugged is not being run.\n")); |
c906108c SS |
1447 | return; |
1448 | } | |
1449 | ||
1450 | target_files_info (); | |
a3f17187 | 1451 | printf_filtered (_("Program stopped at %s.\n"), |
bb599908 | 1452 | hex_string ((unsigned long) stop_pc)); |
c906108c | 1453 | if (stop_step) |
a3f17187 | 1454 | printf_filtered (_("It stopped after being stepped.\n")); |
8671a17b | 1455 | else if (stat != 0) |
c906108c SS |
1456 | { |
1457 | /* There may be several breakpoints in the same place, so this | |
c5aa993b | 1458 | isn't as strange as it seems. */ |
8671a17b | 1459 | while (stat != 0) |
c906108c | 1460 | { |
8671a17b | 1461 | if (stat < 0) |
c906108c | 1462 | { |
a3f17187 AC |
1463 | printf_filtered (_("\ |
1464 | It stopped at a breakpoint that has since been deleted.\n")); | |
c906108c SS |
1465 | } |
1466 | else | |
a3f17187 | 1467 | printf_filtered (_("It stopped at breakpoint %d.\n"), num); |
8671a17b | 1468 | stat = bpstat_num (&bs, &num); |
c906108c SS |
1469 | } |
1470 | } | |
1471 | else if (stop_signal != TARGET_SIGNAL_0) | |
1472 | { | |
a3f17187 | 1473 | printf_filtered (_("It stopped with signal %s, %s.\n"), |
c906108c SS |
1474 | target_signal_to_name (stop_signal), |
1475 | target_signal_to_string (stop_signal)); | |
1476 | } | |
1477 | ||
1478 | if (!from_tty) | |
1479 | { | |
a3f17187 AC |
1480 | printf_filtered (_("\ |
1481 | Type \"info stack\" or \"info registers\" for more information.\n")); | |
c906108c SS |
1482 | } |
1483 | } | |
1484 | \f | |
1485 | static void | |
fba45db2 | 1486 | environment_info (char *var, int from_tty) |
c906108c SS |
1487 | { |
1488 | if (var) | |
1489 | { | |
aa1ee363 | 1490 | char *val = get_in_environ (inferior_environ, var); |
c906108c SS |
1491 | if (val) |
1492 | { | |
1493 | puts_filtered (var); | |
1494 | puts_filtered (" = "); | |
1495 | puts_filtered (val); | |
1496 | puts_filtered ("\n"); | |
1497 | } | |
1498 | else | |
1499 | { | |
1500 | puts_filtered ("Environment variable \""); | |
1501 | puts_filtered (var); | |
1502 | puts_filtered ("\" not defined.\n"); | |
1503 | } | |
1504 | } | |
1505 | else | |
1506 | { | |
aa1ee363 | 1507 | char **vector = environ_vector (inferior_environ); |
c906108c SS |
1508 | while (*vector) |
1509 | { | |
1510 | puts_filtered (*vector++); | |
1511 | puts_filtered ("\n"); | |
1512 | } | |
1513 | } | |
1514 | } | |
1515 | ||
1516 | static void | |
fba45db2 | 1517 | set_environment_command (char *arg, int from_tty) |
c906108c | 1518 | { |
52f0bd74 | 1519 | char *p, *val, *var; |
c906108c SS |
1520 | int nullset = 0; |
1521 | ||
1522 | if (arg == 0) | |
e2e0b3e5 | 1523 | error_no_arg (_("environment variable and value")); |
c906108c SS |
1524 | |
1525 | /* Find seperation between variable name and value */ | |
1526 | p = (char *) strchr (arg, '='); | |
1527 | val = (char *) strchr (arg, ' '); | |
1528 | ||
1529 | if (p != 0 && val != 0) | |
1530 | { | |
1531 | /* We have both a space and an equals. If the space is before the | |
c5aa993b JM |
1532 | equals, walk forward over the spaces til we see a nonspace |
1533 | (possibly the equals). */ | |
c906108c SS |
1534 | if (p > val) |
1535 | while (*val == ' ') | |
1536 | val++; | |
1537 | ||
1538 | /* Now if the = is after the char following the spaces, | |
c5aa993b | 1539 | take the char following the spaces. */ |
c906108c SS |
1540 | if (p > val) |
1541 | p = val - 1; | |
1542 | } | |
1543 | else if (val != 0 && p == 0) | |
1544 | p = val; | |
1545 | ||
1546 | if (p == arg) | |
e2e0b3e5 | 1547 | error_no_arg (_("environment variable to set")); |
c906108c SS |
1548 | |
1549 | if (p == 0 || p[1] == 0) | |
1550 | { | |
1551 | nullset = 1; | |
1552 | if (p == 0) | |
1553 | p = arg + strlen (arg); /* So that savestring below will work */ | |
1554 | } | |
1555 | else | |
1556 | { | |
1557 | /* Not setting variable value to null */ | |
1558 | val = p + 1; | |
1559 | while (*val == ' ' || *val == '\t') | |
1560 | val++; | |
1561 | } | |
1562 | ||
c5aa993b JM |
1563 | while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) |
1564 | p--; | |
c906108c SS |
1565 | |
1566 | var = savestring (arg, p - arg); | |
1567 | if (nullset) | |
1568 | { | |
a3f17187 AC |
1569 | printf_filtered (_("\ |
1570 | Setting environment variable \"%s\" to null value.\n"), | |
1571 | var); | |
c906108c SS |
1572 | set_in_environ (inferior_environ, var, ""); |
1573 | } | |
1574 | else | |
1575 | set_in_environ (inferior_environ, var, val); | |
b8c9b27d | 1576 | xfree (var); |
c906108c SS |
1577 | } |
1578 | ||
1579 | static void | |
fba45db2 | 1580 | unset_environment_command (char *var, int from_tty) |
c906108c SS |
1581 | { |
1582 | if (var == 0) | |
1583 | { | |
1584 | /* If there is no argument, delete all environment variables. | |
c5aa993b | 1585 | Ask for confirmation if reading from the terminal. */ |
e2e0b3e5 | 1586 | if (!from_tty || query (_("Delete all environment variables? "))) |
c906108c SS |
1587 | { |
1588 | free_environ (inferior_environ); | |
1589 | inferior_environ = make_environ (); | |
1590 | } | |
1591 | } | |
1592 | else | |
1593 | unset_in_environ (inferior_environ, var); | |
1594 | } | |
1595 | ||
1596 | /* Handle the execution path (PATH variable) */ | |
1597 | ||
1598 | static const char path_var_name[] = "PATH"; | |
1599 | ||
c906108c | 1600 | static void |
fba45db2 | 1601 | path_info (char *args, int from_tty) |
c906108c SS |
1602 | { |
1603 | puts_filtered ("Executable and object file path: "); | |
1604 | puts_filtered (get_in_environ (inferior_environ, path_var_name)); | |
1605 | puts_filtered ("\n"); | |
1606 | } | |
1607 | ||
1608 | /* Add zero or more directories to the front of the execution path. */ | |
1609 | ||
1610 | static void | |
fba45db2 | 1611 | path_command (char *dirname, int from_tty) |
c906108c SS |
1612 | { |
1613 | char *exec_path; | |
1614 | char *env; | |
1615 | dont_repeat (); | |
1616 | env = get_in_environ (inferior_environ, path_var_name); | |
1617 | /* Can be null if path is not set */ | |
1618 | if (!env) | |
1619 | env = ""; | |
4fcf66da | 1620 | exec_path = xstrdup (env); |
c906108c SS |
1621 | mod_path (dirname, &exec_path); |
1622 | set_in_environ (inferior_environ, path_var_name, exec_path); | |
b8c9b27d | 1623 | xfree (exec_path); |
c906108c | 1624 | if (from_tty) |
c5aa993b | 1625 | path_info ((char *) NULL, from_tty); |
c906108c | 1626 | } |
c906108c | 1627 | \f |
c5aa993b | 1628 | |
4782dc19 | 1629 | /* Print out the machine register regnum. If regnum is -1, print all |
0ab7a791 AC |
1630 | registers (print_all == 1) or all non-float and non-vector |
1631 | registers (print_all == 0). | |
c906108c SS |
1632 | |
1633 | For most machines, having all_registers_info() print the | |
0ab7a791 AC |
1634 | register(s) one per line is good enough. If a different format is |
1635 | required, (eg, for MIPS or Pyramid 90x, which both have lots of | |
1636 | regs), or there is an existing convention for showing all the | |
1637 | registers, define the architecture method PRINT_REGISTERS_INFO to | |
1638 | provide that format. */ | |
c906108c | 1639 | |
666e11c5 | 1640 | void |
0ab7a791 AC |
1641 | default_print_registers_info (struct gdbarch *gdbarch, |
1642 | struct ui_file *file, | |
1643 | struct frame_info *frame, | |
1644 | int regnum, int print_all) | |
c906108c | 1645 | { |
0ab7a791 | 1646 | int i; |
a4bd449d UW |
1647 | const int numregs = gdbarch_num_regs (gdbarch) |
1648 | + gdbarch_num_pseudo_regs (gdbarch); | |
10c42a71 | 1649 | gdb_byte buffer[MAX_REGISTER_SIZE]; |
0ab7a791 | 1650 | |
c906108c SS |
1651 | for (i = 0; i < numregs; i++) |
1652 | { | |
4782dc19 AC |
1653 | /* Decide between printing all regs, non-float / vector regs, or |
1654 | specific reg. */ | |
c5aa993b JM |
1655 | if (regnum == -1) |
1656 | { | |
f9418c0f | 1657 | if (print_all) |
4782dc19 | 1658 | { |
f9418c0f | 1659 | if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup)) |
4782dc19 | 1660 | continue; |
f9418c0f AC |
1661 | } |
1662 | else | |
1663 | { | |
1664 | if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup)) | |
4782dc19 AC |
1665 | continue; |
1666 | } | |
c5aa993b JM |
1667 | } |
1668 | else | |
1669 | { | |
1670 | if (i != regnum) | |
1671 | continue; | |
1672 | } | |
c906108c SS |
1673 | |
1674 | /* If the register name is empty, it is undefined for this | |
c5aa993b | 1675 | processor, so don't display anything. */ |
a4bd449d UW |
1676 | if (gdbarch_register_name (gdbarch, i) == NULL |
1677 | || *(gdbarch_register_name (gdbarch, i)) == '\0') | |
c906108c SS |
1678 | continue; |
1679 | ||
a4bd449d | 1680 | fputs_filtered (gdbarch_register_name (gdbarch, i), file); |
c9f4d572 | 1681 | print_spaces_filtered (15 - strlen (gdbarch_register_name |
a4bd449d | 1682 | (gdbarch, i)), file); |
c906108c SS |
1683 | |
1684 | /* Get the data in raw format. */ | |
9730f241 | 1685 | if (! frame_register_read (frame, i, buffer)) |
c906108c | 1686 | { |
0ab7a791 | 1687 | fprintf_filtered (file, "*value not available*\n"); |
c906108c SS |
1688 | continue; |
1689 | } | |
1690 | ||
0ab7a791 AC |
1691 | /* If virtual format is floating, print it that way, and in raw |
1692 | hex. */ | |
f949c649 TJB |
1693 | if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT |
1694 | || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT) | |
c906108c | 1695 | { |
0ab7a791 | 1696 | int j; |
c906108c | 1697 | |
a4bd449d | 1698 | val_print (register_type (gdbarch, i), buffer, 0, 0, |
d8ca156b | 1699 | file, 0, 1, 0, Val_pretty_default, current_language); |
c906108c | 1700 | |
0ab7a791 | 1701 | fprintf_filtered (file, "\t(raw 0x"); |
a4bd449d | 1702 | for (j = 0; j < register_size (gdbarch, i); j++) |
c906108c | 1703 | { |
0ab7a791 | 1704 | int idx; |
a4bd449d | 1705 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
0ab7a791 AC |
1706 | idx = j; |
1707 | else | |
a4bd449d | 1708 | idx = register_size (gdbarch, i) - 1 - j; |
9730f241 | 1709 | fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]); |
c906108c | 1710 | } |
0ab7a791 | 1711 | fprintf_filtered (file, ")"); |
c906108c | 1712 | } |
c906108c SS |
1713 | else |
1714 | { | |
ab4327e0 | 1715 | /* Print the register in hex. */ |
a4bd449d | 1716 | val_print (register_type (gdbarch, i), buffer, 0, 0, |
d8ca156b | 1717 | file, 'x', 1, 0, Val_pretty_default, current_language); |
ab4327e0 EZ |
1718 | /* If not a vector register, print it also according to its |
1719 | natural format. */ | |
a4bd449d | 1720 | if (TYPE_VECTOR (register_type (gdbarch, i)) == 0) |
ab4327e0 | 1721 | { |
9d84ac84 | 1722 | fprintf_filtered (file, "\t"); |
a4bd449d | 1723 | val_print (register_type (gdbarch, i), buffer, 0, 0, |
d8ca156b | 1724 | file, 0, 1, 0, Val_pretty_default, current_language); |
ab4327e0 | 1725 | } |
c906108c SS |
1726 | } |
1727 | ||
0ab7a791 | 1728 | fprintf_filtered (file, "\n"); |
c906108c SS |
1729 | } |
1730 | } | |
c906108c | 1731 | |
c906108c | 1732 | void |
fba45db2 | 1733 | registers_info (char *addr_exp, int fpregs) |
c906108c | 1734 | { |
206415a3 | 1735 | struct frame_info *frame; |
a4bd449d | 1736 | struct gdbarch *gdbarch; |
c906108c | 1737 | int regnum, numregs; |
52f0bd74 | 1738 | char *end; |
c906108c SS |
1739 | |
1740 | if (!target_has_registers) | |
8a3fe4f8 | 1741 | error (_("The program has no registers now.")); |
206415a3 | 1742 | frame = get_selected_frame (NULL); |
a4bd449d | 1743 | gdbarch = get_frame_arch (frame); |
c906108c SS |
1744 | |
1745 | if (!addr_exp) | |
1746 | { | |
a4bd449d | 1747 | gdbarch_print_registers_info (gdbarch, gdb_stdout, |
206415a3 | 1748 | frame, -1, fpregs); |
c906108c SS |
1749 | return; |
1750 | } | |
1751 | ||
f9418c0f | 1752 | while (*addr_exp != '\0') |
c5aa993b | 1753 | { |
f9418c0f AC |
1754 | char *start; |
1755 | const char *end; | |
c906108c | 1756 | |
f9418c0f AC |
1757 | /* Keep skipping leading white space. */ |
1758 | if (isspace ((*addr_exp))) | |
1759 | { | |
1760 | addr_exp++; | |
1761 | continue; | |
1762 | } | |
c906108c | 1763 | |
f9418c0f AC |
1764 | /* Discard any leading ``$''. Check that there is something |
1765 | resembling a register following it. */ | |
1766 | if (addr_exp[0] == '$') | |
1767 | addr_exp++; | |
1768 | if (isspace ((*addr_exp)) || (*addr_exp) == '\0') | |
8a3fe4f8 | 1769 | error (_("Missing register name")); |
c906108c | 1770 | |
f9418c0f AC |
1771 | /* Find the start/end of this register name/num/group. */ |
1772 | start = addr_exp; | |
1773 | while ((*addr_exp) != '\0' && !isspace ((*addr_exp))) | |
1774 | addr_exp++; | |
1775 | end = addr_exp; | |
ad842144 | 1776 | |
f9418c0f AC |
1777 | /* Figure out what we've found and display it. */ |
1778 | ||
1779 | /* A register name? */ | |
1780 | { | |
ad842144 | 1781 | int regnum = frame_map_name_to_regnum (frame, start, end - start); |
f9418c0f AC |
1782 | if (regnum >= 0) |
1783 | { | |
ad842144 MR |
1784 | /* User registers lie completely outside of the range of |
1785 | normal registers. Catch them early so that the target | |
1786 | never sees them. */ | |
1787 | if (regnum >= gdbarch_num_regs (gdbarch) | |
1788 | + gdbarch_num_pseudo_regs (gdbarch)) | |
1789 | { | |
1790 | struct value *val = value_of_user_reg (regnum, frame); | |
1791 | ||
1792 | printf_filtered ("%s: ", start); | |
1793 | print_scalar_formatted (value_contents (val), | |
1794 | check_typedef (value_type (val)), | |
1795 | 'x', 0, gdb_stdout); | |
1796 | printf_filtered ("\n"); | |
1797 | } | |
1798 | else | |
1799 | gdbarch_print_registers_info (gdbarch, gdb_stdout, | |
1800 | frame, regnum, fpregs); | |
f9418c0f AC |
1801 | continue; |
1802 | } | |
1803 | } | |
ad842144 | 1804 | |
f9418c0f AC |
1805 | /* A register number? (how portable is this one?). */ |
1806 | { | |
1807 | char *endptr; | |
1808 | int regnum = strtol (start, &endptr, 0); | |
1809 | if (endptr == end | |
1810 | && regnum >= 0 | |
a4bd449d UW |
1811 | && regnum < gdbarch_num_regs (gdbarch) |
1812 | + gdbarch_num_pseudo_regs (gdbarch)) | |
f9418c0f | 1813 | { |
a4bd449d | 1814 | gdbarch_print_registers_info (gdbarch, gdb_stdout, |
206415a3 | 1815 | frame, regnum, fpregs); |
f9418c0f AC |
1816 | continue; |
1817 | } | |
1818 | } | |
1819 | ||
1820 | /* A register group? */ | |
1821 | { | |
6c7d17ba | 1822 | struct reggroup *group; |
a4bd449d | 1823 | for (group = reggroup_next (gdbarch, NULL); |
6c7d17ba | 1824 | group != NULL; |
a4bd449d | 1825 | group = reggroup_next (gdbarch, group)) |
f9418c0f AC |
1826 | { |
1827 | /* Don't bother with a length check. Should the user | |
1828 | enter a short register group name, go with the first | |
1829 | group that matches. */ | |
6c7d17ba | 1830 | if (strncmp (start, reggroup_name (group), end - start) == 0) |
f9418c0f AC |
1831 | break; |
1832 | } | |
6c7d17ba | 1833 | if (group != NULL) |
f9418c0f AC |
1834 | { |
1835 | int regnum; | |
f57d151a | 1836 | for (regnum = 0; |
a4bd449d UW |
1837 | regnum < gdbarch_num_regs (gdbarch) |
1838 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 1839 | regnum++) |
f9418c0f | 1840 | { |
a4bd449d UW |
1841 | if (gdbarch_register_reggroup_p (gdbarch, regnum, group)) |
1842 | gdbarch_print_registers_info (gdbarch, | |
206415a3 | 1843 | gdb_stdout, frame, |
f9418c0f AC |
1844 | regnum, fpregs); |
1845 | } | |
1846 | continue; | |
1847 | } | |
1848 | } | |
c906108c | 1849 | |
f9418c0f | 1850 | /* Nothing matched. */ |
8a3fe4f8 | 1851 | error (_("Invalid register `%.*s'"), (int) (end - start), start); |
c5aa993b | 1852 | } |
c906108c SS |
1853 | } |
1854 | ||
1855 | void | |
fba45db2 | 1856 | all_registers_info (char *addr_exp, int from_tty) |
c906108c SS |
1857 | { |
1858 | registers_info (addr_exp, 1); | |
1859 | } | |
1860 | ||
a58dd373 | 1861 | static void |
fba45db2 | 1862 | nofp_registers_info (char *addr_exp, int from_tty) |
c906108c SS |
1863 | { |
1864 | registers_info (addr_exp, 0); | |
1865 | } | |
e76f1f2e AC |
1866 | |
1867 | static void | |
1868 | print_vector_info (struct gdbarch *gdbarch, struct ui_file *file, | |
1869 | struct frame_info *frame, const char *args) | |
1870 | { | |
1871 | if (gdbarch_print_vector_info_p (gdbarch)) | |
1872 | gdbarch_print_vector_info (gdbarch, file, frame, args); | |
1873 | else | |
1874 | { | |
1875 | int regnum; | |
1876 | int printed_something = 0; | |
ab4327e0 | 1877 | |
f57d151a | 1878 | for (regnum = 0; |
a4bd449d UW |
1879 | regnum < gdbarch_num_regs (gdbarch) |
1880 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 1881 | regnum++) |
e76f1f2e | 1882 | { |
f9418c0f | 1883 | if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup)) |
e76f1f2e AC |
1884 | { |
1885 | printed_something = 1; | |
e76f1f2e | 1886 | gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1); |
e76f1f2e AC |
1887 | } |
1888 | } | |
1889 | if (!printed_something) | |
1890 | fprintf_filtered (file, "No vector information\n"); | |
1891 | } | |
1892 | } | |
1893 | ||
1894 | static void | |
1895 | vector_info (char *args, int from_tty) | |
1896 | { | |
206415a3 DJ |
1897 | if (!target_has_registers) |
1898 | error (_("The program has no registers now.")); | |
1899 | ||
1900 | print_vector_info (current_gdbarch, gdb_stdout, | |
1901 | get_selected_frame (NULL), args); | |
e76f1f2e | 1902 | } |
c906108c | 1903 | \f |
c5aa993b | 1904 | |
c906108c SS |
1905 | /* |
1906 | * TODO: | |
1907 | * Should save/restore the tty state since it might be that the | |
1908 | * program to be debugged was started on this tty and it wants | |
1909 | * the tty in some state other than what we want. If it's running | |
1910 | * on another terminal or without a terminal, then saving and | |
1911 | * restoring the tty state is a harmless no-op. | |
1912 | * This only needs to be done if we are attaching to a process. | |
1913 | */ | |
1914 | ||
1915 | /* | |
1916 | attach_command -- | |
1917 | takes a program started up outside of gdb and ``attaches'' to it. | |
1918 | This stops it cold in its tracks and allows us to start debugging it. | |
1919 | and wait for the trace-trap that results from attaching. */ | |
1920 | ||
9356cf8d PA |
1921 | static void |
1922 | attach_command_post_wait (char *args, int from_tty, int async_exec) | |
1923 | { | |
1924 | char *exec_file; | |
1925 | char *full_exec_path = NULL; | |
1926 | ||
1927 | stop_soon = NO_STOP_QUIETLY; | |
1928 | ||
1929 | /* If no exec file is yet known, try to determine it from the | |
1930 | process itself. */ | |
1931 | exec_file = (char *) get_exec_file (0); | |
1932 | if (!exec_file) | |
1933 | { | |
1934 | exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid)); | |
1935 | if (exec_file) | |
1936 | { | |
1937 | /* It's possible we don't have a full path, but rather just a | |
1938 | filename. Some targets, such as HP-UX, don't provide the | |
1939 | full path, sigh. | |
1940 | ||
1941 | Attempt to qualify the filename against the source path. | |
1942 | (If that fails, we'll just fall back on the original | |
1943 | filename. Not much more we can do...) | |
1944 | */ | |
1945 | if (!source_full_path_of (exec_file, &full_exec_path)) | |
1946 | full_exec_path = savestring (exec_file, strlen (exec_file)); | |
1947 | ||
1948 | exec_file_attach (full_exec_path, from_tty); | |
1949 | symbol_file_add_main (full_exec_path, from_tty); | |
1950 | } | |
1951 | } | |
1952 | else | |
1953 | { | |
1954 | reopen_exec_file (); | |
1955 | reread_symbols (); | |
1956 | } | |
1957 | ||
1958 | /* Take any necessary post-attaching actions for this platform. */ | |
1959 | target_post_attach (PIDGET (inferior_ptid)); | |
1960 | ||
1961 | post_create_inferior (¤t_target, from_tty); | |
1962 | ||
1963 | /* Install inferior's terminal modes. */ | |
1964 | target_terminal_inferior (); | |
1965 | ||
1966 | if (async_exec) | |
1967 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0); | |
1968 | else | |
1969 | { | |
1970 | if (target_can_async_p ()) | |
1971 | async_enable_stdin (); | |
1972 | normal_stop (); | |
1973 | if (deprecated_attach_hook) | |
1974 | deprecated_attach_hook (); | |
1975 | } | |
1976 | } | |
1977 | ||
bfec99b2 | 1978 | struct attach_command_continuation_args |
9356cf8d PA |
1979 | { |
1980 | char *args; | |
1981 | int from_tty; | |
1982 | int async_exec; | |
bfec99b2 | 1983 | }; |
9356cf8d | 1984 | |
bfec99b2 | 1985 | static void |
604ead4a | 1986 | attach_command_continuation (void *args) |
bfec99b2 PA |
1987 | { |
1988 | struct attach_command_continuation_args *a = args; | |
1989 | attach_command_post_wait (a->args, a->from_tty, a->async_exec); | |
9356cf8d PA |
1990 | } |
1991 | ||
604ead4a PA |
1992 | static void |
1993 | attach_command_continuation_free_args (void *args) | |
1994 | { | |
1995 | struct attach_command_continuation_args *a = args; | |
1996 | xfree (a->args); | |
1997 | xfree (a); | |
1998 | } | |
1999 | ||
c906108c | 2000 | void |
fba45db2 | 2001 | attach_command (char *args, int from_tty) |
c906108c | 2002 | { |
c5aa993b JM |
2003 | char *exec_file; |
2004 | char *full_exec_path = NULL; | |
9356cf8d | 2005 | int async_exec = 0; |
c906108c | 2006 | |
c5aa993b | 2007 | dont_repeat (); /* Not for the faint of heart */ |
c906108c SS |
2008 | |
2009 | if (target_has_execution) | |
2010 | { | |
2011 | if (query ("A program is being debugged already. Kill it? ")) | |
2012 | target_kill (); | |
2013 | else | |
8a3fe4f8 | 2014 | error (_("Not killed.")); |
c906108c SS |
2015 | } |
2016 | ||
fd79ecee DJ |
2017 | /* Clean up any leftovers from other runs. Some other things from |
2018 | this function should probably be moved into target_pre_inferior. */ | |
2019 | target_pre_inferior (from_tty); | |
2020 | ||
9356cf8d PA |
2021 | if (args) |
2022 | { | |
2023 | async_exec = strip_bg_char (&args); | |
2024 | ||
2025 | /* If we get a request for running in the bg but the target | |
2026 | doesn't support it, error out. */ | |
2027 | if (async_exec && !target_can_async_p ()) | |
2028 | error (_("Asynchronous execution not supported on this target.")); | |
2029 | } | |
2030 | ||
2031 | /* If we don't get a request of running in the bg, then we need | |
2032 | to simulate synchronous (fg) execution. */ | |
2033 | if (!async_exec && target_can_async_p ()) | |
2034 | { | |
2035 | /* Simulate synchronous execution */ | |
2036 | async_disable_stdin (); | |
2037 | } | |
2038 | ||
c906108c SS |
2039 | target_attach (args, from_tty); |
2040 | ||
2041 | /* Set up the "saved terminal modes" of the inferior | |
2042 | based on what modes we are starting it with. */ | |
2043 | target_terminal_init (); | |
2044 | ||
c906108c SS |
2045 | /* Set up execution context to know that we should return from |
2046 | wait_for_inferior as soon as the target reports a stop. */ | |
2047 | init_wait_for_inferior (); | |
2048 | clear_proceed_status (); | |
c906108c | 2049 | |
dc177b7a PA |
2050 | /* Some system don't generate traps when attaching to inferior. |
2051 | E.g. Mach 3 or GNU hurd. */ | |
2052 | if (!target_attach_no_wait) | |
c5aa993b | 2053 | { |
dc177b7a PA |
2054 | /* Careful here. See comments in inferior.h. Basically some |
2055 | OSes don't ignore SIGSTOPs on continue requests anymore. We | |
2056 | need a way for handle_inferior_event to reset the stop_signal | |
2057 | variable after an attach, and this is what | |
2058 | STOP_QUIETLY_NO_SIGSTOP is for. */ | |
2059 | stop_soon = STOP_QUIETLY_NO_SIGSTOP; | |
c5aa993b | 2060 | |
dc177b7a PA |
2061 | if (target_can_async_p ()) |
2062 | { | |
2063 | /* sync_execution mode. Wait for stop. */ | |
bfec99b2 PA |
2064 | struct attach_command_continuation_args *a; |
2065 | ||
2066 | a = xmalloc (sizeof (*a)); | |
2067 | a->args = xstrdup (args); | |
2068 | a->from_tty = from_tty; | |
2069 | a->async_exec = async_exec; | |
604ead4a PA |
2070 | add_continuation (attach_command_continuation, a, |
2071 | attach_command_continuation_free_args); | |
dc177b7a PA |
2072 | return; |
2073 | } | |
c906108c | 2074 | |
dc177b7a PA |
2075 | wait_for_inferior (0); |
2076 | } | |
6426a772 | 2077 | |
9356cf8d | 2078 | attach_command_post_wait (args, from_tty, async_exec); |
c906108c SS |
2079 | } |
2080 | ||
2081 | /* | |
2082 | * detach_command -- | |
2083 | * takes a program previously attached to and detaches it. | |
2084 | * The program resumes execution and will no longer stop | |
2085 | * on signals, etc. We better not have left any breakpoints | |
2086 | * in the program or it'll die when it hits one. For this | |
2087 | * to work, it may be necessary for the process to have been | |
2088 | * previously attached. It *might* work if the program was | |
2089 | * started via the normal ptrace (PTRACE_TRACEME). | |
2090 | */ | |
2091 | ||
2092 | static void | |
fba45db2 | 2093 | detach_command (char *args, int from_tty) |
c906108c | 2094 | { |
1f5d0fc9 | 2095 | dont_repeat (); /* Not for the faint of heart. */ |
c906108c | 2096 | target_detach (args, from_tty); |
e85a822c | 2097 | no_shared_libraries (NULL, from_tty); |
a0ef4274 | 2098 | init_thread_list (); |
9a4105ab AC |
2099 | if (deprecated_detach_hook) |
2100 | deprecated_detach_hook (); | |
c906108c SS |
2101 | } |
2102 | ||
6ad8ae5c DJ |
2103 | /* Disconnect from the current target without resuming it (leaving it |
2104 | waiting for a debugger). | |
2105 | ||
2106 | We'd better not have left any breakpoints in the program or the | |
2107 | next debugger will get confused. Currently only supported for some | |
2108 | remote targets, since the normal attach mechanisms don't work on | |
2109 | stopped processes on some native platforms (e.g. GNU/Linux). */ | |
2110 | ||
2111 | static void | |
2112 | disconnect_command (char *args, int from_tty) | |
2113 | { | |
2114 | dont_repeat (); /* Not for the faint of heart */ | |
2115 | target_disconnect (args, from_tty); | |
e85a822c | 2116 | no_shared_libraries (NULL, from_tty); |
a0ef4274 | 2117 | init_thread_list (); |
9a4105ab AC |
2118 | if (deprecated_detach_hook) |
2119 | deprecated_detach_hook (); | |
6ad8ae5c DJ |
2120 | } |
2121 | ||
77ebaa5a VP |
2122 | void |
2123 | interrupt_target_1 (int all_threads) | |
2124 | { | |
2125 | ptid_t ptid; | |
2126 | if (all_threads) | |
2127 | ptid = minus_one_ptid; | |
2128 | else | |
2129 | ptid = inferior_ptid; | |
2130 | target_stop (ptid); | |
2131 | } | |
2132 | ||
43ff13b4 | 2133 | /* Stop the execution of the target while running in async mode, in |
8cae4b3f PA |
2134 | the backgound. In all-stop, stop the whole process. In non-stop |
2135 | mode, stop the current thread only by default, or stop all threads | |
2136 | if the `-a' switch is used. */ | |
2137 | ||
2138 | /* interrupt [-a] */ | |
8b93c638 | 2139 | void |
fba45db2 | 2140 | interrupt_target_command (char *args, int from_tty) |
43ff13b4 | 2141 | { |
362646f5 | 2142 | if (target_can_async_p ()) |
43ff13b4 | 2143 | { |
8cae4b3f PA |
2144 | int all_threads = 0; |
2145 | ||
c5aa993b | 2146 | dont_repeat (); /* Not for the faint of heart */ |
94cc34af | 2147 | |
8cae4b3f PA |
2148 | if (args != NULL |
2149 | && strncmp (args, "-a", sizeof ("-a") - 1) == 0) | |
2150 | all_threads = 1; | |
2151 | ||
2152 | if (!non_stop && all_threads) | |
2153 | error (_("-a is meaningless in all-stop mode.")); | |
2154 | ||
77ebaa5a | 2155 | interrupt_target_1 (all_threads); |
43ff13b4 JM |
2156 | } |
2157 | } | |
2158 | ||
c906108c | 2159 | static void |
23e3a7ac AC |
2160 | print_float_info (struct gdbarch *gdbarch, struct ui_file *file, |
2161 | struct frame_info *frame, const char *args) | |
c906108c | 2162 | { |
23e3a7ac AC |
2163 | if (gdbarch_print_float_info_p (gdbarch)) |
2164 | gdbarch_print_float_info (gdbarch, file, frame, args); | |
2165 | else | |
2166 | { | |
23e3a7ac AC |
2167 | int regnum; |
2168 | int printed_something = 0; | |
ab4327e0 | 2169 | |
f57d151a | 2170 | for (regnum = 0; |
a4bd449d UW |
2171 | regnum < gdbarch_num_regs (gdbarch) |
2172 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 2173 | regnum++) |
23e3a7ac | 2174 | { |
f9418c0f | 2175 | if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup)) |
23e3a7ac AC |
2176 | { |
2177 | printed_something = 1; | |
23e3a7ac | 2178 | gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1); |
23e3a7ac AC |
2179 | } |
2180 | } | |
2181 | if (!printed_something) | |
2182 | fprintf_filtered (file, "\ | |
2183 | No floating-point info available for this processor.\n"); | |
23e3a7ac AC |
2184 | } |
2185 | } | |
2186 | ||
2187 | static void | |
2188 | float_info (char *args, int from_tty) | |
2189 | { | |
206415a3 DJ |
2190 | if (!target_has_registers) |
2191 | error (_("The program has no registers now.")); | |
2192 | ||
1f5d0fc9 | 2193 | print_float_info (current_gdbarch, gdb_stdout, |
206415a3 | 2194 | get_selected_frame (NULL), args); |
c906108c SS |
2195 | } |
2196 | \f | |
c906108c | 2197 | static void |
fba45db2 | 2198 | unset_command (char *args, int from_tty) |
c906108c | 2199 | { |
a3f17187 AC |
2200 | printf_filtered (_("\ |
2201 | \"unset\" must be followed by the name of an unset subcommand.\n")); | |
c906108c SS |
2202 | help_list (unsetlist, "unset ", -1, gdb_stdout); |
2203 | } | |
2204 | ||
2205 | void | |
fba45db2 | 2206 | _initialize_infcmd (void) |
c906108c | 2207 | { |
3cb3b8df BR |
2208 | struct cmd_list_element *c = NULL; |
2209 | ||
2210 | /* add the filename of the terminal connected to inferior I/O */ | |
2211 | add_setshow_filename_cmd ("inferior-tty", class_run, | |
2212 | &inferior_io_terminal, _("\ | |
2213 | Set terminal for future runs of program being debugged."), _("\ | |
2214 | Show terminal for future runs of program being debugged."), _("\ | |
2215 | Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist); | |
2216 | add_com_alias ("tty", "set inferior-tty", class_alias, 0); | |
c906108c | 2217 | |
b4b4ac0b AC |
2218 | add_setshow_optional_filename_cmd ("args", class_run, |
2219 | &inferior_args, _("\ | |
2220 | Set argument list to give program being debugged when it is started."), _("\ | |
2221 | Show argument list to give program being debugged when it is started."), _("\ | |
2222 | Follow this command with any number of args, to be passed to the program."), | |
2223 | notice_args_set, | |
2224 | notice_args_read, | |
2225 | &setlist, &showlist); | |
c906108c | 2226 | |
1a966eab AC |
2227 | c = add_cmd ("environment", no_class, environment_info, _("\ |
2228 | The environment to give the program, or one variable's value.\n\ | |
c906108c SS |
2229 | With an argument VAR, prints the value of environment variable VAR to\n\ |
2230 | give the program being debugged. With no arguments, prints the entire\n\ | |
1a966eab | 2231 | environment to be given to the program."), &showlist); |
5ba2abeb | 2232 | set_cmd_completer (c, noop_completer); |
c906108c SS |
2233 | |
2234 | add_prefix_cmd ("unset", no_class, unset_command, | |
1bedd215 | 2235 | _("Complement to certain \"set\" commands."), |
c906108c | 2236 | &unsetlist, "unset ", 0, &cmdlist); |
c5aa993b | 2237 | |
1a966eab AC |
2238 | c = add_cmd ("environment", class_run, unset_environment_command, _("\ |
2239 | Cancel environment variable VAR for the program.\n\ | |
2240 | This does not affect the program until the next \"run\" command."), | |
c5aa993b | 2241 | &unsetlist); |
5ba2abeb | 2242 | set_cmd_completer (c, noop_completer); |
c906108c | 2243 | |
1a966eab AC |
2244 | c = add_cmd ("environment", class_run, set_environment_command, _("\ |
2245 | Set environment variable value to give the program.\n\ | |
c906108c SS |
2246 | Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\ |
2247 | VALUES of environment variables are uninterpreted strings.\n\ | |
1a966eab | 2248 | This does not affect the program until the next \"run\" command."), |
c5aa993b | 2249 | &setlist); |
5ba2abeb | 2250 | set_cmd_completer (c, noop_completer); |
c5aa993b | 2251 | |
1bedd215 AC |
2252 | c = add_com ("path", class_files, path_command, _("\ |
2253 | Add directory DIR(s) to beginning of search path for object files.\n\ | |
c906108c SS |
2254 | $cwd in the path means the current working directory.\n\ |
2255 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
2256 | directories, separated by colons. These directories are searched to find\n\ | |
1bedd215 | 2257 | fully linked executable files and separately compiled object files as needed.")); |
5ba2abeb | 2258 | set_cmd_completer (c, filename_completer); |
c906108c | 2259 | |
1a966eab AC |
2260 | c = add_cmd ("paths", no_class, path_info, _("\ |
2261 | Current search path for finding object files.\n\ | |
c906108c SS |
2262 | $cwd in the path means the current working directory.\n\ |
2263 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
2264 | directories, separated by colons. These directories are searched to find\n\ | |
1a966eab | 2265 | fully linked executable files and separately compiled object files as needed."), |
c906108c | 2266 | &showlist); |
5ba2abeb | 2267 | set_cmd_completer (c, noop_completer); |
c906108c | 2268 | |
1bedd215 AC |
2269 | add_com ("attach", class_run, attach_command, _("\ |
2270 | Attach to a process or file outside of GDB.\n\ | |
c906108c SS |
2271 | This command attaches to another target, of the same type as your last\n\ |
2272 | \"target\" command (\"info files\" will show your target stack).\n\ | |
2273 | The command may take as argument a process id or a device file.\n\ | |
2274 | For a process id, you must have permission to send the process a signal,\n\ | |
2275 | and it must have the same effective uid as the debugger.\n\ | |
2276 | When using \"attach\" with a process id, the debugger finds the\n\ | |
2277 | program running in the process, looking first in the current working\n\ | |
2278 | directory, or (if not found there) using the source file search path\n\ | |
2279 | (see the \"directory\" command). You can also use the \"file\" command\n\ | |
1bedd215 | 2280 | to specify the program, and to load its symbol table.")); |
c906108c | 2281 | |
f73adfeb | 2282 | add_prefix_cmd ("detach", class_run, detach_command, _("\ |
1bedd215 | 2283 | Detach a process or file previously attached.\n\ |
c906108c | 2284 | If a process, it is no longer traced, and it continues its execution. If\n\ |
f73adfeb AS |
2285 | you were debugging a file, the file is closed and gdb no longer accesses it."), |
2286 | &detachlist, "detach ", 0, &cmdlist); | |
c906108c | 2287 | |
1bedd215 AC |
2288 | add_com ("disconnect", class_run, disconnect_command, _("\ |
2289 | Disconnect from a target.\n\ | |
6ad8ae5c | 2290 | The target will wait for another debugger to connect. Not available for\n\ |
1bedd215 | 2291 | all targets.")); |
6ad8ae5c | 2292 | |
1bedd215 AC |
2293 | add_com ("signal", class_run, signal_command, _("\ |
2294 | Continue program giving it signal specified by the argument.\n\ | |
2295 | An argument of \"0\" means continue program without giving it a signal.")); | |
c906108c | 2296 | |
1bedd215 AC |
2297 | add_com ("stepi", class_run, stepi_command, _("\ |
2298 | Step one instruction exactly.\n\ | |
2299 | Argument N means do this N times (or till program stops for another reason).")); | |
c906108c SS |
2300 | add_com_alias ("si", "stepi", class_alias, 0); |
2301 | ||
1bedd215 AC |
2302 | add_com ("nexti", class_run, nexti_command, _("\ |
2303 | Step one instruction, but proceed through subroutine calls.\n\ | |
2304 | Argument N means do this N times (or till program stops for another reason).")); | |
c906108c SS |
2305 | add_com_alias ("ni", "nexti", class_alias, 0); |
2306 | ||
1bedd215 AC |
2307 | add_com ("finish", class_run, finish_command, _("\ |
2308 | Execute until selected stack frame returns.\n\ | |
2309 | Upon return, the value returned is printed and put in the value history.")); | |
0e479716 | 2310 | add_com_alias ("fin", "finish", class_run, 1); |
c906108c | 2311 | |
1bedd215 AC |
2312 | add_com ("next", class_run, next_command, _("\ |
2313 | Step program, proceeding through subroutine calls.\n\ | |
c906108c SS |
2314 | Like the \"step\" command as long as subroutine calls do not happen;\n\ |
2315 | when they do, the call is treated as one instruction.\n\ | |
1bedd215 | 2316 | Argument N means do this N times (or till program stops for another reason).")); |
c906108c SS |
2317 | add_com_alias ("n", "next", class_run, 1); |
2318 | if (xdb_commands) | |
c5aa993b | 2319 | add_com_alias ("S", "next", class_run, 1); |
c906108c | 2320 | |
1bedd215 AC |
2321 | add_com ("step", class_run, step_command, _("\ |
2322 | Step program until it reaches a different source line.\n\ | |
2323 | Argument N means do this N times (or till program stops for another reason).")); | |
c906108c SS |
2324 | add_com_alias ("s", "step", class_run, 1); |
2325 | ||
1bedd215 AC |
2326 | c = add_com ("until", class_run, until_command, _("\ |
2327 | Execute until the program reaches a source line greater than the current\n\ | |
2328 | or a specified location (same args as break command) within the current frame.")); | |
5ba2abeb | 2329 | set_cmd_completer (c, location_completer); |
c906108c | 2330 | add_com_alias ("u", "until", class_run, 1); |
c5aa993b | 2331 | |
1bedd215 AC |
2332 | c = add_com ("advance", class_run, advance_command, _("\ |
2333 | Continue the program up to the given location (same form as args for break command).\n\ | |
2334 | Execution will also stop upon exit from the current stack frame.")); | |
ae66c1fc EZ |
2335 | set_cmd_completer (c, location_completer); |
2336 | ||
1bedd215 AC |
2337 | c = add_com ("jump", class_run, jump_command, _("\ |
2338 | Continue program being debugged at specified line or address.\n\ | |
c906108c | 2339 | Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\ |
1bedd215 | 2340 | for an address to start at.")); |
5ba2abeb | 2341 | set_cmd_completer (c, location_completer); |
c906108c | 2342 | |
b83266a0 | 2343 | if (xdb_commands) |
c94fdfd0 | 2344 | { |
1bedd215 AC |
2345 | c = add_com ("go", class_run, go_command, _("\ |
2346 | Usage: go <location>\n\ | |
c906108c SS |
2347 | Continue program being debugged, stopping at specified line or \n\ |
2348 | address.\n\ | |
2349 | Give as argument either LINENUM or *ADDR, where ADDR is an \n\ | |
2350 | expression for an address to start at.\n\ | |
1bedd215 | 2351 | This command is a combination of tbreak and jump.")); |
5ba2abeb | 2352 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 2353 | } |
b83266a0 | 2354 | |
c906108c | 2355 | if (xdb_commands) |
c5aa993b | 2356 | add_com_alias ("g", "go", class_run, 1); |
c906108c | 2357 | |
8cae4b3f | 2358 | c = add_com ("continue", class_run, continue_command, _("\ |
1bedd215 | 2359 | Continue program being debugged, after signal or breakpoint.\n\ |
c906108c SS |
2360 | If proceeding from breakpoint, a number N may be used as an argument,\n\ |
2361 | which means to set the ignore count of that breakpoint to N - 1 (so that\n\ | |
8cae4b3f PA |
2362 | the breakpoint won't break until the Nth time it is reached).\n\ |
2363 | \n\ | |
2364 | If non-stop mode is enabled, continue only the current thread,\n\ | |
2365 | otherwise all the threads in the program are continued. To \n\ | |
2366 | continue all stopped threads in non-stop mode, use the -a option.\n\ | |
2367 | Specifying -a and an ignore count simultaneously is an error.")); | |
c906108c SS |
2368 | add_com_alias ("c", "cont", class_run, 1); |
2369 | add_com_alias ("fg", "cont", class_run, 1); | |
2370 | ||
1bedd215 AC |
2371 | c = add_com ("run", class_run, run_command, _("\ |
2372 | Start debugged program. You may specify arguments to give it.\n\ | |
c906108c SS |
2373 | Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\ |
2374 | Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\ | |
2375 | With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\ | |
2376 | To cancel previous arguments and run with no arguments,\n\ | |
1bedd215 | 2377 | use \"set args\" without arguments.")); |
5ba2abeb | 2378 | set_cmd_completer (c, filename_completer); |
c906108c SS |
2379 | add_com_alias ("r", "run", class_run, 1); |
2380 | if (xdb_commands) | |
2381 | add_com ("R", class_run, run_no_args_command, | |
1bedd215 | 2382 | _("Start debugged program with no arguments.")); |
c906108c | 2383 | |
1bedd215 | 2384 | c = add_com ("start", class_run, start_command, _("\ |
a4d5f2e0 JB |
2385 | Run the debugged program until the beginning of the main procedure.\n\ |
2386 | You may specify arguments to give to your program, just as with the\n\ | |
1bedd215 | 2387 | \"run\" command.")); |
a4d5f2e0 JB |
2388 | set_cmd_completer (c, filename_completer); |
2389 | ||
700b53b1 | 2390 | c = add_com ("interrupt", class_run, interrupt_target_command, |
8cae4b3f PA |
2391 | _("Interrupt the execution of the debugged program.\n\ |
2392 | If non-stop mode is enabled, interrupt only the current thread,\n\ | |
2393 | otherwise all the threads in the program are stopped. To \n\ | |
2394 | interrupt all running threads in non-stop mode, use the -a option.")); | |
43ff13b4 | 2395 | |
1bedd215 AC |
2396 | add_info ("registers", nofp_registers_info, _("\ |
2397 | List of integer registers and their contents, for selected stack frame.\n\ | |
2398 | Register name as argument means describe only that register.")); | |
7194c49b | 2399 | add_info_alias ("r", "registers", 1); |
c906108c SS |
2400 | |
2401 | if (xdb_commands) | |
1bedd215 AC |
2402 | add_com ("lr", class_info, nofp_registers_info, _("\ |
2403 | List of integer registers and their contents, for selected stack frame.\n\ | |
2404 | Register name as argument means describe only that register.")); | |
2405 | add_info ("all-registers", all_registers_info, _("\ | |
2406 | List of all registers and their contents, for selected stack frame.\n\ | |
2407 | Register name as argument means describe only that register.")); | |
c906108c SS |
2408 | |
2409 | add_info ("program", program_info, | |
1bedd215 | 2410 | _("Execution status of the program.")); |
c906108c SS |
2411 | |
2412 | add_info ("float", float_info, | |
1bedd215 | 2413 | _("Print the status of the floating point unit\n")); |
c906108c | 2414 | |
e76f1f2e | 2415 | add_info ("vector", vector_info, |
1bedd215 | 2416 | _("Print the status of the vector unit\n")); |
e76f1f2e | 2417 | |
c906108c SS |
2418 | inferior_environ = make_environ (); |
2419 | init_environ (inferior_environ); | |
2420 | } |