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