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