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