Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Memory-access and commands for "inferior" process, for GDB. |
990a07ab | 2 | |
61baf725 | 3 | Copyright (C) 1986-2017 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
5af949e3 | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <signal.h> |
c906108c SS |
23 | #include "symtab.h" |
24 | #include "gdbtypes.h" | |
25 | #include "frame.h" | |
26 | #include "inferior.h" | |
45741a9c | 27 | #include "infrun.h" |
c906108c SS |
28 | #include "environ.h" |
29 | #include "value.h" | |
30 | #include "gdbcmd.h" | |
1adeb98a | 31 | #include "symfile.h" |
c906108c SS |
32 | #include "gdbcore.h" |
33 | #include "target.h" | |
34 | #include "language.h" | |
c906108c | 35 | #include "objfiles.h" |
c94fdfd0 | 36 | #include "completer.h" |
8b93c638 | 37 | #include "ui-out.h" |
6426a772 | 38 | #include "event-top.h" |
96baa820 | 39 | #include "parser-defs.h" |
36160dc4 | 40 | #include "regcache.h" |
f9418c0f | 41 | #include "reggroups.h" |
fe898f56 | 42 | #include "block.h" |
a77053c2 | 43 | #include "solib.h" |
f9418c0f | 44 | #include <ctype.h> |
281b533b | 45 | #include "observer.h" |
424163ea | 46 | #include "target-descriptions.h" |
ad842144 | 47 | #include "user-regs.h" |
700b53b1 | 48 | #include "cli/cli-decode.h" |
a0ef4274 | 49 | #include "gdbthread.h" |
79a45b7d | 50 | #include "valprint.h" |
edb3359d | 51 | #include "inline-frame.h" |
573cda03 | 52 | #include "tracepoint.h" |
09cee04b | 53 | #include "inf-loop.h" |
be34f849 | 54 | #include "continuations.h" |
f8eba3c6 | 55 | #include "linespec.h" |
529480d0 | 56 | #include "cli/cli-utils.h" |
8a6c4031 | 57 | #include "infcall.h" |
243a9253 | 58 | #include "thread-fsm.h" |
3b12939d | 59 | #include "top.h" |
8980e177 | 60 | #include "interps.h" |
d5551862 | 61 | |
a58dd373 EZ |
62 | /* Local functions: */ |
63 | ||
64 | static void nofp_registers_info (char *, int); | |
65 | ||
a14ed312 | 66 | static void until_next_command (int); |
c906108c | 67 | |
a14ed312 | 68 | static void until_command (char *, int); |
c906108c | 69 | |
a14ed312 | 70 | static void path_info (char *, int); |
c906108c | 71 | |
a14ed312 | 72 | static void path_command (char *, int); |
c906108c | 73 | |
a14ed312 | 74 | static void unset_command (char *, int); |
c906108c | 75 | |
a14ed312 | 76 | static void float_info (char *, int); |
c906108c | 77 | |
6ad8ae5c DJ |
78 | static void disconnect_command (char *, int); |
79 | ||
a14ed312 | 80 | static void unset_environment_command (char *, int); |
c906108c | 81 | |
a14ed312 | 82 | static void set_environment_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void environment_info (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void program_info (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void finish_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void signal_command (char *, int); |
c906108c | 91 | |
a14ed312 | 92 | static void jump_command (char *, int); |
c906108c | 93 | |
a14ed312 | 94 | static void step_1 (int, int, char *); |
c906108c | 95 | |
a14ed312 | 96 | static void next_command (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void step_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void run_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | void _initialize_infcmd (void); |
c906108c | 103 | |
c906108c | 104 | #define ERROR_NO_INFERIOR \ |
8a3fe4f8 | 105 | if (!target_has_execution) error (_("The program is not being run.")); |
c906108c | 106 | |
3e43a32a MS |
107 | /* Scratch area where string containing arguments to give to the |
108 | program will be stored by 'set args'. As soon as anything is | |
109 | stored, notice_args_set will move it into per-inferior storage. | |
1777feb0 | 110 | Arguments are separated by spaces. Empty string (pointer to '\0') |
3e43a32a | 111 | means no args. */ |
c906108c | 112 | |
3f81c18a | 113 | static char *inferior_args_scratch; |
c906108c | 114 | |
3f81c18a VP |
115 | /* Scratch area where 'set inferior-tty' will store user-provided value. |
116 | We'll immediate copy it into per-inferior storage. */ | |
552c04a7 | 117 | |
3f81c18a | 118 | static char *inferior_io_terminal_scratch; |
c906108c SS |
119 | |
120 | /* Pid of our debugged inferior, or 0 if no inferior now. | |
121 | Since various parts of infrun.c test this to see whether there is a program | |
122 | being debugged it should be nonzero (currently 3 is used) for remote | |
123 | debugging. */ | |
124 | ||
39f77062 | 125 | ptid_t inferior_ptid; |
c906108c | 126 | |
c906108c SS |
127 | /* Address at which inferior stopped. */ |
128 | ||
129 | CORE_ADDR stop_pc; | |
130 | ||
c906108c SS |
131 | /* Nonzero if stopped due to completion of a stack dummy routine. */ |
132 | ||
aa7d318d | 133 | enum stop_stack_kind stop_stack_dummy; |
c906108c SS |
134 | |
135 | /* Nonzero if stopped due to a random (unexpected) signal in inferior | |
136 | process. */ | |
137 | ||
138 | int stopped_by_random_signal; | |
139 | ||
98882a26 PA |
140 | /* See inferior.h. */ |
141 | ||
142 | int startup_with_shell = 1; | |
143 | ||
c906108c | 144 | \f |
1777feb0 | 145 | /* Accessor routines. */ |
07091751 | 146 | |
3f81c18a VP |
147 | /* Set the io terminal for the current inferior. Ownership of |
148 | TERMINAL_NAME is not transferred. */ | |
149 | ||
3cb3b8df BR |
150 | void |
151 | set_inferior_io_terminal (const char *terminal_name) | |
152 | { | |
3f81c18a | 153 | xfree (current_inferior ()->terminal); |
0a1ddfa6 SM |
154 | |
155 | if (terminal_name != NULL && *terminal_name != '\0') | |
156 | current_inferior ()->terminal = xstrdup (terminal_name); | |
157 | else | |
158 | current_inferior ()->terminal = NULL; | |
3cb3b8df BR |
159 | } |
160 | ||
161 | const char * | |
162 | get_inferior_io_terminal (void) | |
163 | { | |
3f81c18a VP |
164 | return current_inferior ()->terminal; |
165 | } | |
166 | ||
167 | static void | |
168 | set_inferior_tty_command (char *args, int from_tty, | |
169 | struct cmd_list_element *c) | |
170 | { | |
171 | /* CLI has assigned the user-provided value to inferior_io_terminal_scratch. | |
172 | Now route it to current inferior. */ | |
173 | set_inferior_io_terminal (inferior_io_terminal_scratch); | |
174 | } | |
175 | ||
176 | static void | |
177 | show_inferior_tty_command (struct ui_file *file, int from_tty, | |
178 | struct cmd_list_element *c, const char *value) | |
179 | { | |
180 | /* Note that we ignore the passed-in value in favor of computing it | |
181 | directly. */ | |
275f2e57 | 182 | const char *inferior_io_terminal = get_inferior_io_terminal (); |
abbb1732 | 183 | |
275f2e57 DJ |
184 | if (inferior_io_terminal == NULL) |
185 | inferior_io_terminal = ""; | |
3f81c18a | 186 | fprintf_filtered (gdb_stdout, |
275f2e57 DJ |
187 | _("Terminal for future runs of program being debugged " |
188 | "is \"%s\".\n"), inferior_io_terminal); | |
3cb3b8df BR |
189 | } |
190 | ||
07091751 FN |
191 | char * |
192 | get_inferior_args (void) | |
193 | { | |
3f81c18a | 194 | if (current_inferior ()->argc != 0) |
552c04a7 | 195 | { |
3f81c18a | 196 | char *n; |
552c04a7 | 197 | |
3f81c18a VP |
198 | n = construct_inferior_arguments (current_inferior ()->argc, |
199 | current_inferior ()->argv); | |
200 | set_inferior_args (n); | |
201 | xfree (n); | |
552c04a7 TT |
202 | } |
203 | ||
3f81c18a VP |
204 | if (current_inferior ()->args == NULL) |
205 | current_inferior ()->args = xstrdup (""); | |
552c04a7 | 206 | |
3f81c18a | 207 | return current_inferior ()->args; |
07091751 FN |
208 | } |
209 | ||
3f81c18a VP |
210 | /* Set the arguments for the current inferior. Ownership of |
211 | NEWARGS is not transferred. */ | |
212 | ||
213 | void | |
07091751 FN |
214 | set_inferior_args (char *newargs) |
215 | { | |
3f81c18a VP |
216 | xfree (current_inferior ()->args); |
217 | current_inferior ()->args = newargs ? xstrdup (newargs) : NULL; | |
218 | current_inferior ()->argc = 0; | |
219 | current_inferior ()->argv = 0; | |
07091751 | 220 | } |
c5aa993b | 221 | |
552c04a7 TT |
222 | void |
223 | set_inferior_args_vector (int argc, char **argv) | |
224 | { | |
3f81c18a VP |
225 | current_inferior ()->argc = argc; |
226 | current_inferior ()->argv = argv; | |
552c04a7 TT |
227 | } |
228 | ||
229 | /* Notice when `set args' is run. */ | |
6339bfc4 | 230 | |
552c04a7 | 231 | static void |
3f81c18a | 232 | set_args_command (char *args, int from_tty, struct cmd_list_element *c) |
552c04a7 | 233 | { |
3f81c18a VP |
234 | /* CLI has assigned the user-provided value to inferior_args_scratch. |
235 | Now route it to current inferior. */ | |
236 | set_inferior_args (inferior_args_scratch); | |
552c04a7 TT |
237 | } |
238 | ||
239 | /* Notice when `show args' is run. */ | |
6339bfc4 | 240 | |
552c04a7 | 241 | static void |
3f81c18a VP |
242 | show_args_command (struct ui_file *file, int from_tty, |
243 | struct cmd_list_element *c, const char *value) | |
552c04a7 | 244 | { |
258c00cc TT |
245 | /* Note that we ignore the passed-in value in favor of computing it |
246 | directly. */ | |
247 | deprecated_show_value_hack (file, from_tty, c, get_inferior_args ()); | |
552c04a7 TT |
248 | } |
249 | ||
c2a727fa TT |
250 | \f |
251 | /* Compute command-line string given argument vector. This does the | |
252 | same shell processing as fork_inferior. */ | |
6339bfc4 | 253 | |
c2a727fa | 254 | char * |
bd57a748 | 255 | construct_inferior_arguments (int argc, char **argv) |
c2a727fa TT |
256 | { |
257 | char *result; | |
258 | ||
98882a26 | 259 | if (startup_with_shell) |
c2a727fa | 260 | { |
5d60742e EZ |
261 | #ifdef __MINGW32__ |
262 | /* This holds all the characters considered special to the | |
263 | Windows shells. */ | |
a121b7c1 PA |
264 | static const char special[] = "\"!&*|[]{}<>?`~^=;, \t\n"; |
265 | static const char quote = '"'; | |
5d60742e | 266 | #else |
c2a727fa TT |
267 | /* This holds all the characters considered special to the |
268 | typical Unix shells. We include `^' because the SunOS | |
269 | /bin/sh treats it as a synonym for `|'. */ | |
a121b7c1 PA |
270 | static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n"; |
271 | static const char quote = '\''; | |
5d60742e | 272 | #endif |
c2a727fa TT |
273 | int i; |
274 | int length = 0; | |
275 | char *out, *cp; | |
276 | ||
277 | /* We over-compute the size. It shouldn't matter. */ | |
278 | for (i = 0; i < argc; ++i) | |
c2226152 | 279 | length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0'); |
c2a727fa TT |
280 | |
281 | result = (char *) xmalloc (length); | |
282 | out = result; | |
283 | ||
284 | for (i = 0; i < argc; ++i) | |
285 | { | |
286 | if (i > 0) | |
287 | *out++ = ' '; | |
288 | ||
03c6228e AS |
289 | /* Need to handle empty arguments specially. */ |
290 | if (argv[i][0] == '\0') | |
c2a727fa | 291 | { |
5d60742e EZ |
292 | *out++ = quote; |
293 | *out++ = quote; | |
03c6228e AS |
294 | } |
295 | else | |
296 | { | |
5d60742e EZ |
297 | #ifdef __MINGW32__ |
298 | int quoted = 0; | |
299 | ||
300 | if (strpbrk (argv[i], special)) | |
301 | { | |
302 | quoted = 1; | |
303 | *out++ = quote; | |
304 | } | |
305 | #endif | |
03c6228e AS |
306 | for (cp = argv[i]; *cp; ++cp) |
307 | { | |
c2226152 AS |
308 | if (*cp == '\n') |
309 | { | |
310 | /* A newline cannot be quoted with a backslash (it | |
311 | just disappears), only by putting it inside | |
312 | quotes. */ | |
5d60742e | 313 | *out++ = quote; |
c2226152 | 314 | *out++ = '\n'; |
5d60742e | 315 | *out++ = quote; |
c2226152 AS |
316 | } |
317 | else | |
318 | { | |
5d60742e EZ |
319 | #ifdef __MINGW32__ |
320 | if (*cp == quote) | |
321 | #else | |
c2226152 | 322 | if (strchr (special, *cp) != NULL) |
5d60742e | 323 | #endif |
c2226152 AS |
324 | *out++ = '\\'; |
325 | *out++ = *cp; | |
326 | } | |
03c6228e | 327 | } |
5d60742e EZ |
328 | #ifdef __MINGW32__ |
329 | if (quoted) | |
330 | *out++ = quote; | |
331 | #endif | |
c2a727fa TT |
332 | } |
333 | } | |
334 | *out = '\0'; | |
335 | } | |
336 | else | |
337 | { | |
338 | /* In this case we can't handle arguments that contain spaces, | |
339 | tabs, or newlines -- see breakup_args(). */ | |
340 | int i; | |
341 | int length = 0; | |
342 | ||
343 | for (i = 0; i < argc; ++i) | |
344 | { | |
345 | char *cp = strchr (argv[i], ' '); | |
346 | if (cp == NULL) | |
347 | cp = strchr (argv[i], '\t'); | |
348 | if (cp == NULL) | |
349 | cp = strchr (argv[i], '\n'); | |
350 | if (cp != NULL) | |
3e43a32a MS |
351 | error (_("can't handle command-line " |
352 | "argument containing whitespace")); | |
c2a727fa TT |
353 | length += strlen (argv[i]) + 1; |
354 | } | |
355 | ||
356 | result = (char *) xmalloc (length); | |
357 | result[0] = '\0'; | |
358 | for (i = 0; i < argc; ++i) | |
359 | { | |
360 | if (i > 0) | |
361 | strcat (result, " "); | |
362 | strcat (result, argv[i]); | |
363 | } | |
364 | } | |
365 | ||
366 | return result; | |
367 | } | |
552c04a7 TT |
368 | \f |
369 | ||
6c4486e6 PA |
370 | /* This function strips the '&' character (indicating background |
371 | execution) that is added as *the last* of the arguments ARGS of a | |
372 | command. A copy of the incoming ARGS without the '&' is returned, | |
373 | unless the resulting string after stripping is empty, in which case | |
374 | NULL is returned. *BG_CHAR_P is an output boolean that indicates | |
375 | whether the '&' character was found. */ | |
6339bfc4 | 376 | |
6c4486e6 PA |
377 | static char * |
378 | strip_bg_char (const char *args, int *bg_char_p) | |
43ff13b4 | 379 | { |
6c4486e6 | 380 | const char *p; |
c5aa993b | 381 | |
6c4486e6 PA |
382 | if (args == NULL || *args == '\0') |
383 | { | |
384 | *bg_char_p = 0; | |
385 | return NULL; | |
386 | } | |
c5aa993b | 387 | |
6c4486e6 PA |
388 | p = args + strlen (args); |
389 | if (p[-1] == '&') | |
43ff13b4 | 390 | { |
6c4486e6 PA |
391 | p--; |
392 | while (p > args && isspace (p[-1])) | |
393 | p--; | |
394 | ||
395 | *bg_char_p = 1; | |
396 | if (p != args) | |
397 | return savestring (args, p - args); | |
398 | else | |
399 | return NULL; | |
43ff13b4 | 400 | } |
6c4486e6 PA |
401 | |
402 | *bg_char_p = 0; | |
403 | return xstrdup (args); | |
43ff13b4 JM |
404 | } |
405 | ||
281b533b DJ |
406 | /* Common actions to take after creating any sort of inferior, by any |
407 | means (running, attaching, connecting, et cetera). The target | |
408 | should be stopped. */ | |
409 | ||
410 | void | |
411 | post_create_inferior (struct target_ops *target, int from_tty) | |
412 | { | |
ce406537 | 413 | |
b79599ff | 414 | /* Be sure we own the terminal in case write operations are performed. */ |
f8e3ef9d | 415 | target_terminal_ours_for_output (); |
b79599ff | 416 | |
424163ea DJ |
417 | /* If the target hasn't taken care of this already, do it now. |
418 | Targets which need to access registers during to_open, | |
419 | to_create_inferior, or to_attach should do it earlier; but many | |
420 | don't need to. */ | |
421 | target_find_description (); | |
422 | ||
ce406537 PA |
423 | /* Now that we know the register layout, retrieve current PC. But |
424 | if the PC is unavailable (e.g., we're opening a core file with | |
425 | missing registers info), ignore it. */ | |
426 | stop_pc = 0; | |
492d29ea | 427 | TRY |
ce406537 PA |
428 | { |
429 | stop_pc = regcache_read_pc (get_current_regcache ()); | |
430 | } | |
492d29ea | 431 | CATCH (ex, RETURN_MASK_ERROR) |
7556d4a4 PA |
432 | { |
433 | if (ex.error != NOT_AVAILABLE_ERROR) | |
434 | throw_exception (ex); | |
435 | } | |
492d29ea | 436 | END_CATCH |
f698437e | 437 | |
50c71eaf PA |
438 | if (exec_bfd) |
439 | { | |
2eff07b3 PP |
440 | const unsigned solib_add_generation |
441 | = current_program_space->solib_add_generation; | |
442 | ||
9353355f DJ |
443 | /* Create the hooks to handle shared library load and unload |
444 | events. */ | |
268a4a75 | 445 | solib_create_inferior_hook (from_tty); |
268a4a75 | 446 | |
2eff07b3 PP |
447 | if (current_program_space->solib_add_generation == solib_add_generation) |
448 | { | |
449 | /* The platform-specific hook should load initial shared libraries, | |
450 | but didn't. FROM_TTY will be incorrectly 0 but such solib | |
451 | targets should be fixed anyway. Call it only after the solib | |
452 | target has been initialized by solib_create_inferior_hook. */ | |
453 | ||
454 | if (info_verbose) | |
455 | warning (_("platform-specific solib_create_inferior_hook did " | |
456 | "not load initial shared libraries.")); | |
457 | ||
458 | /* If the solist is global across processes, there's no need to | |
459 | refetch it here. */ | |
f5656ead | 460 | if (!gdbarch_has_global_solist (target_gdbarch ())) |
e696b3ad | 461 | solib_add (NULL, 0, auto_solib_add); |
2eff07b3 | 462 | } |
9353355f DJ |
463 | } |
464 | ||
ea5d7a99 PM |
465 | /* If the user sets watchpoints before execution having started, |
466 | then she gets software watchpoints, because GDB can't know which | |
467 | target will end up being pushed, or if it supports hardware | |
468 | watchpoints or not. breakpoint_re_set takes care of promoting | |
469 | watchpoints to hardware watchpoints if possible, however, if this | |
470 | new inferior doesn't load shared libraries or we don't pull in | |
471 | symbols from any other source on this target/arch, | |
472 | breakpoint_re_set is never called. Call it now so that software | |
473 | watchpoints get a chance to be promoted to hardware watchpoints | |
474 | if the now pushed target supports hardware watchpoints. */ | |
475 | breakpoint_re_set (); | |
476 | ||
281b533b DJ |
477 | observer_notify_inferior_created (target, from_tty); |
478 | } | |
479 | ||
a4d5f2e0 JB |
480 | /* Kill the inferior if already running. This function is designed |
481 | to be called when we are about to start the execution of the program | |
482 | from the beginning. Ask the user to confirm that he wants to restart | |
483 | the program being debugged when FROM_TTY is non-null. */ | |
c906108c | 484 | |
8edfe269 | 485 | static void |
a4d5f2e0 JB |
486 | kill_if_already_running (int from_tty) |
487 | { | |
39f77062 | 488 | if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution) |
c906108c | 489 | { |
8edfe269 DJ |
490 | /* Bail out before killing the program if we will not be able to |
491 | restart it. */ | |
492 | target_require_runnable (); | |
493 | ||
adf40b2e | 494 | if (from_tty |
9e2f0ad4 HZ |
495 | && !query (_("The program being debugged has been started already.\n\ |
496 | Start it from the beginning? "))) | |
8a3fe4f8 | 497 | error (_("Program not restarted.")); |
c906108c | 498 | target_kill (); |
c906108c | 499 | } |
a4d5f2e0 JB |
500 | } |
501 | ||
329ea579 | 502 | /* See inferior.h. */ |
8bc2fe48 | 503 | |
329ea579 | 504 | void |
8bc2fe48 PA |
505 | prepare_execution_command (struct target_ops *target, int background) |
506 | { | |
507 | /* If we get a request for running in the bg but the target | |
508 | doesn't support it, error out. */ | |
509 | if (background && !target->to_can_async_p (target)) | |
510 | error (_("Asynchronous execution not supported on this target.")); | |
511 | ||
0b333c5e | 512 | if (!background) |
8bc2fe48 | 513 | { |
0b333c5e PA |
514 | /* If we get a request for running in the fg, then we need to |
515 | simulate synchronous (fg) execution. Note no cleanup is | |
516 | necessary for this. stdin is re-enabled whenever an error | |
517 | reaches the top level. */ | |
a8836c93 | 518 | all_uis_on_sync_execution_starting (); |
8bc2fe48 PA |
519 | } |
520 | } | |
521 | ||
1777feb0 | 522 | /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert |
f67a969f JB |
523 | a temporary breakpoint at the begining of the main program before |
524 | running the program. */ | |
525 | ||
a4d5f2e0 | 526 | static void |
f67a969f | 527 | run_command_1 (char *args, int from_tty, int tbreak_at_main) |
a4d5f2e0 | 528 | { |
7c5ded6a | 529 | const char *exec_file; |
29f49a6a PA |
530 | struct cleanup *old_chain; |
531 | ptid_t ptid; | |
79a45e25 | 532 | struct ui_out *uiout = current_uiout; |
b3ccfe11 | 533 | struct target_ops *run_target; |
6c4486e6 PA |
534 | int async_exec; |
535 | struct cleanup *args_chain; | |
c906108c | 536 | |
a4d5f2e0 JB |
537 | dont_repeat (); |
538 | ||
539 | kill_if_already_running (from_tty); | |
3c35e65b UW |
540 | |
541 | init_wait_for_inferior (); | |
c906108c SS |
542 | clear_breakpoint_hit_counts (); |
543 | ||
fd79ecee DJ |
544 | /* Clean up any leftovers from other runs. Some other things from |
545 | this function should probably be moved into target_pre_inferior. */ | |
546 | target_pre_inferior (from_tty); | |
547 | ||
39ad761d JB |
548 | /* The comment here used to read, "The exec file is re-read every |
549 | time we do a generic_mourn_inferior, so we just have to worry | |
550 | about the symbol file." The `generic_mourn_inferior' function | |
551 | gets called whenever the program exits. However, suppose the | |
552 | program exits, and *then* the executable file changes? We need | |
553 | to check again here. Since reopen_exec_file doesn't do anything | |
554 | if the timestamp hasn't changed, I don't see the harm. */ | |
555 | reopen_exec_file (); | |
c906108c SS |
556 | reread_symbols (); |
557 | ||
6c4486e6 PA |
558 | args = strip_bg_char (args, &async_exec); |
559 | args_chain = make_cleanup (xfree, args); | |
f67a969f | 560 | |
8bc2fe48 PA |
561 | /* Do validation and preparation before possibly changing anything |
562 | in the inferior. */ | |
39ad761d | 563 | |
b3ccfe11 TT |
564 | run_target = find_run_target (); |
565 | ||
8bc2fe48 PA |
566 | prepare_execution_command (run_target, async_exec); |
567 | ||
b3ccfe11 | 568 | if (non_stop && !run_target->to_supports_non_stop (run_target)) |
9908b566 VP |
569 | error (_("The target does not support running in non-stop mode.")); |
570 | ||
8bc2fe48 PA |
571 | /* Done. Can now set breakpoints, change inferior args, etc. */ |
572 | ||
573 | /* Insert the temporary breakpoint if a location was specified. */ | |
574 | if (tbreak_at_main) | |
575 | tbreak_command (main_name (), 0); | |
576 | ||
7c5ded6a | 577 | exec_file = get_exec_file (0); |
8bc2fe48 | 578 | |
c906108c SS |
579 | /* We keep symbols from add-symbol-file, on the grounds that the |
580 | user might want to add some symbols before running the program | |
581 | (right?). But sometimes (dynamic loading where the user manually | |
582 | introduces the new symbols with add-symbol-file), the code which | |
583 | the symbols describe does not persist between runs. Currently | |
584 | the user has to manually nuke all symbols between runs if they | |
585 | want them to go away (PR 2207). This is probably reasonable. */ | |
586 | ||
8bc2fe48 PA |
587 | /* If there were other args, beside '&', process them. */ |
588 | if (args != NULL) | |
589 | set_inferior_args (args); | |
c906108c SS |
590 | |
591 | if (from_tty) | |
592 | { | |
112e8700 SM |
593 | uiout->field_string (NULL, "Starting program"); |
594 | uiout->text (": "); | |
8b93c638 | 595 | if (exec_file) |
112e8700 SM |
596 | uiout->field_string ("execfile", exec_file); |
597 | uiout->spaces (1); | |
552c04a7 TT |
598 | /* We call get_inferior_args() because we might need to compute |
599 | the value now. */ | |
112e8700 SM |
600 | uiout->field_string ("infargs", get_inferior_args ()); |
601 | uiout->text ("\n"); | |
602 | uiout->flush (); | |
c906108c SS |
603 | } |
604 | ||
6c4486e6 PA |
605 | /* Done with ARGS. */ |
606 | do_cleanups (args_chain); | |
607 | ||
552c04a7 TT |
608 | /* We call get_inferior_args() because we might need to compute |
609 | the value now. */ | |
7c5ded6a SDJ |
610 | run_target->to_create_inferior (run_target, exec_file, |
611 | std::string (get_inferior_args ()), | |
b3ccfe11 TT |
612 | environ_vector (current_inferior ()->environment), |
613 | from_tty); | |
614 | /* to_create_inferior should push the target, so after this point we | |
615 | shouldn't refer to run_target again. */ | |
616 | run_target = NULL; | |
281b533b | 617 | |
29f49a6a PA |
618 | /* We're starting off a new process. When we get out of here, in |
619 | non-stop mode, finish the state of all threads of that process, | |
620 | but leave other threads alone, as they may be stopped in internal | |
621 | events --- the frontend shouldn't see them as stopped. In | |
622 | all-stop, always finish the state of all threads, as we may be | |
623 | resuming more than just the new process. */ | |
624 | if (non_stop) | |
625 | ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); | |
626 | else | |
627 | ptid = minus_one_ptid; | |
628 | old_chain = make_cleanup (finish_thread_state_cleanup, &ptid); | |
629 | ||
de1b3c3d PA |
630 | /* Pass zero for FROM_TTY, because at this point the "run" command |
631 | has done its thing; now we are setting up the running program. */ | |
632 | post_create_inferior (¤t_target, 0); | |
281b533b | 633 | |
74d1f91e JK |
634 | /* Start the target running. Do not use -1 continuation as it would skip |
635 | breakpoint right at the entry point. */ | |
64ce06e4 | 636 | proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0); |
c906108c | 637 | |
29f49a6a PA |
638 | /* Since there was no error, there's no need to finish the thread |
639 | states here. */ | |
640 | discard_cleanups (old_chain); | |
641 | } | |
c906108c | 642 | |
f67a969f JB |
643 | static void |
644 | run_command (char *args, int from_tty) | |
645 | { | |
646 | run_command_1 (args, from_tty, 0); | |
647 | } | |
648 | ||
a4d5f2e0 JB |
649 | /* Start the execution of the program up until the beginning of the main |
650 | program. */ | |
651 | ||
652 | static void | |
653 | start_command (char *args, int from_tty) | |
654 | { | |
655 | /* Some languages such as Ada need to search inside the program | |
656 | minimal symbols for the location where to put the temporary | |
657 | breakpoint before starting. */ | |
658 | if (!have_minimal_symbols ()) | |
8a3fe4f8 | 659 | error (_("No symbol table loaded. Use the \"file\" command.")); |
a4d5f2e0 | 660 | |
f67a969f JB |
661 | /* Run the program until reaching the main procedure... */ |
662 | run_command_1 (args, from_tty, 1); | |
a4d5f2e0 JB |
663 | } |
664 | ||
8cae4b3f PA |
665 | static int |
666 | proceed_thread_callback (struct thread_info *thread, void *arg) | |
667 | { | |
74531fed PA |
668 | /* We go through all threads individually instead of compressing |
669 | into a single target `resume_all' request, because some threads | |
670 | may be stopped in internal breakpoints/events, or stopped waiting | |
671 | for its turn in the displaced stepping queue (that is, they are | |
672 | running && !executing). The target side has no idea about why | |
673 | the thread is stopped, so a `resume_all' command would resume too | |
674 | much. If/when GDB gains a way to tell the target `hold this | |
675 | thread stopped until I say otherwise', then we can optimize | |
676 | this. */ | |
4f8d22e3 | 677 | if (!is_stopped (thread->ptid)) |
8cae4b3f PA |
678 | return 0; |
679 | ||
dcf4fbde | 680 | switch_to_thread (thread->ptid); |
70509625 | 681 | clear_proceed_status (0); |
64ce06e4 | 682 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
8cae4b3f PA |
683 | return 0; |
684 | } | |
685 | ||
70221824 | 686 | static void |
d729566a PA |
687 | ensure_valid_thread (void) |
688 | { | |
689 | if (ptid_equal (inferior_ptid, null_ptid) | |
690 | || is_exited (inferior_ptid)) | |
3e43a32a | 691 | error (_("Cannot execute this command without a live selected thread.")); |
d729566a PA |
692 | } |
693 | ||
573cda03 | 694 | /* If the user is looking at trace frames, any resumption of execution |
1777feb0 | 695 | is likely to mix up recorded and live target data. So simply |
573cda03 SS |
696 | disallow those commands. */ |
697 | ||
70221824 | 698 | static void |
573cda03 SS |
699 | ensure_not_tfind_mode (void) |
700 | { | |
701 | if (get_traceframe_number () >= 0) | |
3e43a32a | 702 | error (_("Cannot execute this command while looking at trace frames.")); |
573cda03 SS |
703 | } |
704 | ||
3d3fef6b YQ |
705 | /* Throw an error indicating the current thread is running. */ |
706 | ||
707 | static void | |
708 | error_is_running (void) | |
709 | { | |
710 | error (_("Cannot execute this command while " | |
711 | "the selected thread is running.")); | |
712 | } | |
713 | ||
714 | /* Calls error_is_running if the current thread is running. */ | |
715 | ||
716 | static void | |
717 | ensure_not_running (void) | |
718 | { | |
719 | if (is_running (inferior_ptid)) | |
720 | error_is_running (); | |
721 | } | |
722 | ||
77ebaa5a VP |
723 | void |
724 | continue_1 (int all_threads) | |
725 | { | |
3d488bfc | 726 | ERROR_NO_INFERIOR; |
573cda03 | 727 | ensure_not_tfind_mode (); |
3d488bfc | 728 | |
77ebaa5a VP |
729 | if (non_stop && all_threads) |
730 | { | |
731 | /* Don't error out if the current thread is running, because | |
abbb1732 | 732 | there may be other stopped threads. */ |
77ebaa5a VP |
733 | struct cleanup *old_chain; |
734 | ||
735 | /* Backup current thread and selected frame. */ | |
736 | old_chain = make_cleanup_restore_current_thread (); | |
737 | ||
738 | iterate_over_threads (proceed_thread_callback, NULL); | |
739 | ||
3b12939d | 740 | if (current_ui->prompt_state == PROMPT_BLOCKED) |
0ff33695 PA |
741 | { |
742 | /* If all threads in the target were already running, | |
743 | proceed_thread_callback ends up never calling proceed, | |
744 | and so nothing calls this to put the inferior's terminal | |
745 | settings in effect and remove stdin from the event loop, | |
746 | which we must when running a foreground command. E.g.: | |
747 | ||
748 | (gdb) c -a& | |
749 | Continuing. | |
750 | <all threads are running now> | |
751 | (gdb) c -a | |
752 | Continuing. | |
753 | <no thread was resumed, but the inferior now owns the terminal> | |
754 | */ | |
755 | target_terminal_inferior (); | |
756 | } | |
757 | ||
77ebaa5a VP |
758 | /* Restore selected ptid. */ |
759 | do_cleanups (old_chain); | |
760 | } | |
761 | else | |
762 | { | |
d729566a | 763 | ensure_valid_thread (); |
77ebaa5a | 764 | ensure_not_running (); |
70509625 | 765 | clear_proceed_status (0); |
64ce06e4 | 766 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
77ebaa5a VP |
767 | } |
768 | } | |
769 | ||
8cae4b3f | 770 | /* continue [-a] [proceed-count] [&] */ |
6339bfc4 | 771 | |
1dd5fedc | 772 | static void |
8cae4b3f | 773 | continue_command (char *args, int from_tty) |
c906108c | 774 | { |
6c4486e6 | 775 | int async_exec; |
8cae4b3f | 776 | int all_threads = 0; |
6c4486e6 PA |
777 | struct cleanup *args_chain; |
778 | ||
c906108c SS |
779 | ERROR_NO_INFERIOR; |
780 | ||
1777feb0 | 781 | /* Find out whether we must run in the background. */ |
6c4486e6 PA |
782 | args = strip_bg_char (args, &async_exec); |
783 | args_chain = make_cleanup (xfree, args); | |
43ff13b4 | 784 | |
8cae4b3f PA |
785 | if (args != NULL) |
786 | { | |
61012eef | 787 | if (startswith (args, "-a")) |
8cae4b3f PA |
788 | { |
789 | all_threads = 1; | |
790 | args += sizeof ("-a") - 1; | |
791 | if (*args == '\0') | |
792 | args = NULL; | |
793 | } | |
794 | } | |
795 | ||
796 | if (!non_stop && all_threads) | |
797 | error (_("`-a' is meaningless in all-stop mode.")); | |
798 | ||
799 | if (args != NULL && all_threads) | |
3e43a32a MS |
800 | error (_("Can't resume all threads and specify " |
801 | "proceed count simultaneously.")); | |
8cae4b3f PA |
802 | |
803 | /* If we have an argument left, set proceed count of breakpoint we | |
804 | stopped at. */ | |
805 | if (args != NULL) | |
c906108c | 806 | { |
347bddb7 | 807 | bpstat bs = NULL; |
8671a17b PA |
808 | int num, stat; |
809 | int stopped = 0; | |
347bddb7 PA |
810 | struct thread_info *tp; |
811 | ||
812 | if (non_stop) | |
e09875d4 | 813 | tp = find_thread_ptid (inferior_ptid); |
347bddb7 PA |
814 | else |
815 | { | |
816 | ptid_t last_ptid; | |
817 | struct target_waitstatus ws; | |
818 | ||
819 | get_last_target_status (&last_ptid, &ws); | |
e09875d4 | 820 | tp = find_thread_ptid (last_ptid); |
347bddb7 PA |
821 | } |
822 | if (tp != NULL) | |
16c381f0 | 823 | bs = tp->control.stop_bpstat; |
8671a17b PA |
824 | |
825 | while ((stat = bpstat_num (&bs, &num)) != 0) | |
826 | if (stat > 0) | |
827 | { | |
828 | set_ignore_count (num, | |
8cae4b3f | 829 | parse_and_eval_long (args) - 1, |
8671a17b PA |
830 | from_tty); |
831 | /* set_ignore_count prints a message ending with a period. | |
832 | So print two spaces before "Continuing.". */ | |
833 | if (from_tty) | |
834 | printf_filtered (" "); | |
835 | stopped = 1; | |
836 | } | |
837 | ||
838 | if (!stopped && from_tty) | |
c906108c SS |
839 | { |
840 | printf_filtered | |
841 | ("Not stopped at any breakpoint; argument ignored.\n"); | |
842 | } | |
c906108c SS |
843 | } |
844 | ||
6c4486e6 PA |
845 | /* Done with ARGS. */ |
846 | do_cleanups (args_chain); | |
847 | ||
3b12939d PA |
848 | ERROR_NO_INFERIOR; |
849 | ensure_not_tfind_mode (); | |
850 | ||
851 | if (!non_stop || !all_threads) | |
852 | { | |
853 | ensure_valid_thread (); | |
854 | ensure_not_running (); | |
855 | } | |
856 | ||
857 | prepare_execution_command (¤t_target, async_exec); | |
858 | ||
c906108c | 859 | if (from_tty) |
a3f17187 | 860 | printf_filtered (_("Continuing.\n")); |
c906108c | 861 | |
77ebaa5a | 862 | continue_1 (all_threads); |
c906108c SS |
863 | } |
864 | \f | |
edb3359d DJ |
865 | /* Record the starting point of a "step" or "next" command. */ |
866 | ||
867 | static void | |
868 | set_step_frame (void) | |
869 | { | |
870 | struct symtab_and_line sal; | |
64ce06e4 PA |
871 | CORE_ADDR pc; |
872 | struct frame_info *frame = get_current_frame (); | |
873 | struct thread_info *tp = inferior_thread (); | |
edb3359d | 874 | |
64ce06e4 PA |
875 | find_frame_sal (frame, &sal); |
876 | set_step_info (frame, sal); | |
877 | pc = get_frame_pc (frame); | |
878 | tp->control.step_start_function = find_pc_function (pc); | |
edb3359d DJ |
879 | } |
880 | ||
c906108c SS |
881 | /* Step until outside of current statement. */ |
882 | ||
c906108c | 883 | static void |
fba45db2 | 884 | step_command (char *count_string, int from_tty) |
c906108c SS |
885 | { |
886 | step_1 (0, 0, count_string); | |
887 | } | |
888 | ||
889 | /* Likewise, but skip over subroutine calls as if single instructions. */ | |
890 | ||
c906108c | 891 | static void |
fba45db2 | 892 | next_command (char *count_string, int from_tty) |
c906108c SS |
893 | { |
894 | step_1 (1, 0, count_string); | |
895 | } | |
896 | ||
897 | /* Likewise, but step only one instruction. */ | |
898 | ||
1dd5fedc | 899 | static void |
fba45db2 | 900 | stepi_command (char *count_string, int from_tty) |
c906108c SS |
901 | { |
902 | step_1 (0, 1, count_string); | |
903 | } | |
904 | ||
1dd5fedc | 905 | static void |
fba45db2 | 906 | nexti_command (char *count_string, int from_tty) |
c906108c SS |
907 | { |
908 | step_1 (1, 1, count_string); | |
909 | } | |
910 | ||
186c406b | 911 | void |
611c83ae | 912 | delete_longjmp_breakpoint_cleanup (void *arg) |
74b7792f | 913 | { |
611c83ae PA |
914 | int thread = * (int *) arg; |
915 | delete_longjmp_breakpoint (thread); | |
74b7792f AC |
916 | } |
917 | ||
243a9253 PA |
918 | /* Data for the FSM that manages the step/next/stepi/nexti |
919 | commands. */ | |
920 | ||
921 | struct step_command_fsm | |
922 | { | |
923 | /* The base class. */ | |
924 | struct thread_fsm thread_fsm; | |
925 | ||
926 | /* How many steps left in a "step N"-like command. */ | |
927 | int count; | |
928 | ||
929 | /* If true, this is a next/nexti, otherwise a step/stepi. */ | |
930 | int skip_subroutines; | |
931 | ||
932 | /* If true, this is a stepi/nexti, otherwise a step/step. */ | |
933 | int single_inst; | |
243a9253 PA |
934 | }; |
935 | ||
8980e177 PA |
936 | static void step_command_fsm_clean_up (struct thread_fsm *self, |
937 | struct thread_info *thread); | |
938 | static int step_command_fsm_should_stop (struct thread_fsm *self, | |
939 | struct thread_info *thread); | |
243a9253 PA |
940 | static enum async_reply_reason |
941 | step_command_fsm_async_reply_reason (struct thread_fsm *self); | |
942 | ||
943 | /* step_command_fsm's vtable. */ | |
944 | ||
945 | static struct thread_fsm_ops step_command_fsm_ops = | |
946 | { | |
947 | NULL, | |
948 | step_command_fsm_clean_up, | |
949 | step_command_fsm_should_stop, | |
950 | NULL, /* return_value */ | |
951 | step_command_fsm_async_reply_reason, | |
952 | }; | |
953 | ||
954 | /* Allocate a new step_command_fsm. */ | |
955 | ||
956 | static struct step_command_fsm * | |
8980e177 | 957 | new_step_command_fsm (struct interp *cmd_interp) |
243a9253 PA |
958 | { |
959 | struct step_command_fsm *sm; | |
960 | ||
961 | sm = XCNEW (struct step_command_fsm); | |
8980e177 | 962 | thread_fsm_ctor (&sm->thread_fsm, &step_command_fsm_ops, cmd_interp); |
243a9253 PA |
963 | |
964 | return sm; | |
965 | } | |
966 | ||
967 | /* Prepare for a step/next/etc. command. Any target resource | |
968 | allocated here is undone in the FSM's clean_up method. */ | |
969 | ||
970 | static void | |
971 | step_command_fsm_prepare (struct step_command_fsm *sm, | |
972 | int skip_subroutines, int single_inst, | |
973 | int count, struct thread_info *thread) | |
974 | { | |
975 | sm->skip_subroutines = skip_subroutines; | |
976 | sm->single_inst = single_inst; | |
977 | sm->count = count; | |
243a9253 PA |
978 | |
979 | /* Leave the si command alone. */ | |
980 | if (!sm->single_inst || sm->skip_subroutines) | |
981 | set_longjmp_breakpoint (thread, get_frame_id (get_current_frame ())); | |
982 | ||
983 | thread->control.stepping_command = 1; | |
984 | } | |
985 | ||
986 | static int prepare_one_step (struct step_command_fsm *sm); | |
987 | ||
c906108c | 988 | static void |
fba45db2 | 989 | step_1 (int skip_subroutines, int single_inst, char *count_string) |
c906108c | 990 | { |
243a9253 | 991 | int count; |
6c4486e6 | 992 | int async_exec; |
6c4486e6 | 993 | struct cleanup *args_chain; |
243a9253 PA |
994 | struct thread_info *thr; |
995 | struct step_command_fsm *step_sm; | |
c5aa993b | 996 | |
c906108c | 997 | ERROR_NO_INFERIOR; |
573cda03 | 998 | ensure_not_tfind_mode (); |
d729566a | 999 | ensure_valid_thread (); |
94cc34af | 1000 | ensure_not_running (); |
43ff13b4 | 1001 | |
6c4486e6 PA |
1002 | count_string = strip_bg_char (count_string, &async_exec); |
1003 | args_chain = make_cleanup (xfree, count_string); | |
c5aa993b | 1004 | |
8bc2fe48 | 1005 | prepare_execution_command (¤t_target, async_exec); |
43ff13b4 | 1006 | |
bb518678 | 1007 | count = count_string ? parse_and_eval_long (count_string) : 1; |
c906108c | 1008 | |
6c4486e6 PA |
1009 | /* Done with ARGS. */ |
1010 | do_cleanups (args_chain); | |
1011 | ||
243a9253 | 1012 | clear_proceed_status (1); |
611c83ae | 1013 | |
243a9253 PA |
1014 | /* Setup the execution command state machine to handle all the COUNT |
1015 | steps. */ | |
1016 | thr = inferior_thread (); | |
8980e177 | 1017 | step_sm = new_step_command_fsm (command_interp ()); |
243a9253 | 1018 | thr->thread_fsm = &step_sm->thread_fsm; |
611c83ae | 1019 | |
243a9253 PA |
1020 | step_command_fsm_prepare (step_sm, skip_subroutines, |
1021 | single_inst, count, thr); | |
c2d11a7d | 1022 | |
0b333c5e PA |
1023 | /* Do only one step for now, before returning control to the event |
1024 | loop. Let the continuation figure out how many other steps we | |
1025 | need to do, and handle them one at the time, through | |
1026 | step_once. */ | |
243a9253 PA |
1027 | if (!prepare_one_step (step_sm)) |
1028 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
1029 | else | |
1030 | { | |
3b12939d PA |
1031 | int proceeded; |
1032 | ||
243a9253 PA |
1033 | /* Stepped into an inline frame. Pretend that we've |
1034 | stopped. */ | |
8980e177 | 1035 | thread_fsm_clean_up (thr->thread_fsm, thr); |
3b12939d PA |
1036 | proceeded = normal_stop (); |
1037 | if (!proceeded) | |
1038 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); | |
1039 | all_uis_check_sync_execution_done (); | |
243a9253 | 1040 | } |
c2d11a7d | 1041 | } |
c906108c | 1042 | |
243a9253 PA |
1043 | /* Implementation of the 'should_stop' FSM method for stepping |
1044 | commands. Called after we are done with one step operation, to | |
1045 | check whether we need to step again, before we print the prompt and | |
1046 | return control to the user. If count is > 1, returns false, as we | |
1047 | will need to keep going. */ | |
6339bfc4 | 1048 | |
243a9253 | 1049 | static int |
8980e177 | 1050 | step_command_fsm_should_stop (struct thread_fsm *self, struct thread_info *tp) |
c2d11a7d | 1051 | { |
243a9253 | 1052 | struct step_command_fsm *sm = (struct step_command_fsm *) self; |
f13468d9 | 1053 | |
243a9253 | 1054 | if (tp->control.stop_step) |
f13468d9 | 1055 | { |
243a9253 PA |
1056 | /* There are more steps to make, and we did stop due to |
1057 | ending a stepping range. Do another step. */ | |
1058 | if (--sm->count > 0) | |
1059 | return prepare_one_step (sm); | |
af679fd0 | 1060 | |
243a9253 | 1061 | thread_fsm_set_finished (self); |
f107f563 | 1062 | } |
af679fd0 | 1063 | |
243a9253 | 1064 | return 1; |
c2d11a7d JM |
1065 | } |
1066 | ||
243a9253 | 1067 | /* Implementation of the 'clean_up' FSM method for stepping commands. */ |
37d94800 PA |
1068 | |
1069 | static void | |
8980e177 | 1070 | step_command_fsm_clean_up (struct thread_fsm *self, struct thread_info *thread) |
bfec99b2 | 1071 | { |
243a9253 PA |
1072 | struct step_command_fsm *sm = (struct step_command_fsm *) self; |
1073 | ||
1074 | if (!sm->single_inst || sm->skip_subroutines) | |
8980e177 | 1075 | delete_longjmp_breakpoint (thread->global_num); |
243a9253 PA |
1076 | } |
1077 | ||
1078 | /* Implementation of the 'async_reply_reason' FSM method for stepping | |
1079 | commands. */ | |
1080 | ||
1081 | static enum async_reply_reason | |
1082 | step_command_fsm_async_reply_reason (struct thread_fsm *self) | |
1083 | { | |
1084 | return EXEC_ASYNC_END_STEPPING_RANGE; | |
1085 | } | |
1086 | ||
1087 | /* Prepare for one step in "step N". The actual target resumption is | |
1088 | done by the caller. Return true if we're done and should thus | |
1089 | report a stop to the user. Returns false if the target needs to be | |
1090 | resumed. */ | |
c2d11a7d | 1091 | |
243a9253 PA |
1092 | static int |
1093 | prepare_one_step (struct step_command_fsm *sm) | |
1094 | { | |
1095 | if (sm->count > 0) | |
c906108c | 1096 | { |
243a9253 PA |
1097 | struct frame_info *frame = get_current_frame (); |
1098 | ||
4e1c45ea PA |
1099 | /* Don't assume THREAD is a valid thread id. It is set to -1 if |
1100 | the longjmp breakpoint was not required. Use the | |
1101 | INFERIOR_PTID thread instead, which is the same thread when | |
1102 | THREAD is set. */ | |
1103 | struct thread_info *tp = inferior_thread (); | |
abbb1732 | 1104 | |
edb3359d | 1105 | set_step_frame (); |
c906108c | 1106 | |
243a9253 | 1107 | if (!sm->single_inst) |
c906108c | 1108 | { |
1641cfcc PA |
1109 | CORE_ADDR pc; |
1110 | ||
edb3359d | 1111 | /* Step at an inlined function behaves like "down". */ |
243a9253 | 1112 | if (!sm->skip_subroutines |
edb3359d DJ |
1113 | && inline_skipped_frames (inferior_ptid)) |
1114 | { | |
09cee04b PA |
1115 | ptid_t resume_ptid; |
1116 | ||
1117 | /* Pretend that we've ran. */ | |
1118 | resume_ptid = user_visible_resume_ptid (1); | |
1119 | set_running (resume_ptid, 1); | |
1120 | ||
edb3359d | 1121 | step_into_inline_frame (inferior_ptid); |
243a9253 PA |
1122 | sm->count--; |
1123 | return prepare_one_step (sm); | |
edb3359d DJ |
1124 | } |
1125 | ||
1641cfcc PA |
1126 | pc = get_frame_pc (frame); |
1127 | find_pc_line_pc_range (pc, | |
16c381f0 JK |
1128 | &tp->control.step_range_start, |
1129 | &tp->control.step_range_end); | |
5fbbeb29 | 1130 | |
c1e36e3e PA |
1131 | tp->control.may_range_step = 1; |
1132 | ||
5fbbeb29 | 1133 | /* If we have no line info, switch to stepi mode. */ |
16c381f0 | 1134 | if (tp->control.step_range_end == 0 && step_stop_if_no_debug) |
c1e36e3e PA |
1135 | { |
1136 | tp->control.step_range_start = tp->control.step_range_end = 1; | |
1137 | tp->control.may_range_step = 0; | |
1138 | } | |
16c381f0 | 1139 | else if (tp->control.step_range_end == 0) |
c906108c | 1140 | { |
2c02bd72 | 1141 | const char *name; |
abbb1732 | 1142 | |
1641cfcc | 1143 | if (find_pc_partial_function (pc, &name, |
16c381f0 JK |
1144 | &tp->control.step_range_start, |
1145 | &tp->control.step_range_end) == 0) | |
8a3fe4f8 | 1146 | error (_("Cannot find bounds of current function")); |
c906108c | 1147 | |
f8e3ef9d | 1148 | target_terminal_ours_for_output (); |
3e43a32a MS |
1149 | printf_filtered (_("Single stepping until exit from function %s," |
1150 | "\nwhich has no line number information.\n"), | |
1151 | name); | |
c906108c SS |
1152 | } |
1153 | } | |
1154 | else | |
1155 | { | |
1156 | /* Say we are stepping, but stop after one insn whatever it does. */ | |
16c381f0 | 1157 | tp->control.step_range_start = tp->control.step_range_end = 1; |
243a9253 | 1158 | if (!sm->skip_subroutines) |
c906108c SS |
1159 | /* It is stepi. |
1160 | Don't step over function calls, not even to functions lacking | |
1161 | line numbers. */ | |
16c381f0 | 1162 | tp->control.step_over_calls = STEP_OVER_NONE; |
c906108c SS |
1163 | } |
1164 | ||
243a9253 | 1165 | if (sm->skip_subroutines) |
16c381f0 | 1166 | tp->control.step_over_calls = STEP_OVER_ALL; |
c906108c | 1167 | |
243a9253 | 1168 | return 0; |
c906108c | 1169 | } |
243a9253 PA |
1170 | |
1171 | /* Done. */ | |
1172 | thread_fsm_set_finished (&sm->thread_fsm); | |
1173 | return 1; | |
c906108c | 1174 | } |
c2d11a7d | 1175 | |
c906108c SS |
1176 | \f |
1177 | /* Continue program at specified address. */ | |
1178 | ||
1179 | static void | |
fba45db2 | 1180 | jump_command (char *arg, int from_tty) |
c906108c | 1181 | { |
5af949e3 | 1182 | struct gdbarch *gdbarch = get_current_arch (); |
52f0bd74 | 1183 | CORE_ADDR addr; |
c906108c SS |
1184 | struct symtabs_and_lines sals; |
1185 | struct symtab_and_line sal; | |
1186 | struct symbol *fn; | |
1187 | struct symbol *sfn; | |
6c4486e6 PA |
1188 | int async_exec; |
1189 | struct cleanup *args_chain; | |
c5aa993b | 1190 | |
c906108c | 1191 | ERROR_NO_INFERIOR; |
573cda03 | 1192 | ensure_not_tfind_mode (); |
d729566a | 1193 | ensure_valid_thread (); |
94cc34af | 1194 | ensure_not_running (); |
c906108c | 1195 | |
1777feb0 | 1196 | /* Find out whether we must run in the background. */ |
6c4486e6 PA |
1197 | arg = strip_bg_char (arg, &async_exec); |
1198 | args_chain = make_cleanup (xfree, arg); | |
43ff13b4 | 1199 | |
8bc2fe48 | 1200 | prepare_execution_command (¤t_target, async_exec); |
43ff13b4 | 1201 | |
c906108c | 1202 | if (!arg) |
e2e0b3e5 | 1203 | error_no_arg (_("starting address")); |
c906108c | 1204 | |
39cf75f7 | 1205 | sals = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE); |
c906108c SS |
1206 | if (sals.nelts != 1) |
1207 | { | |
8a3fe4f8 | 1208 | error (_("Unreasonable jump request")); |
c906108c SS |
1209 | } |
1210 | ||
1211 | sal = sals.sals[0]; | |
b8c9b27d | 1212 | xfree (sals.sals); |
c906108c | 1213 | |
6c4486e6 PA |
1214 | /* Done with ARGS. */ |
1215 | do_cleanups (args_chain); | |
1216 | ||
c906108c | 1217 | if (sal.symtab == 0 && sal.pc == 0) |
8a3fe4f8 | 1218 | error (_("No source file has been specified.")); |
c906108c | 1219 | |
1777feb0 | 1220 | resolve_sal_pc (&sal); /* May error out. */ |
c906108c | 1221 | |
1777feb0 | 1222 | /* See if we are trying to jump to another function. */ |
c906108c SS |
1223 | fn = get_frame_function (get_current_frame ()); |
1224 | sfn = find_pc_function (sal.pc); | |
1225 | if (fn != NULL && sfn != fn) | |
1226 | { | |
9e2f0ad4 | 1227 | if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal.line, |
de5ad195 | 1228 | SYMBOL_PRINT_NAME (fn))) |
c906108c | 1229 | { |
8a3fe4f8 | 1230 | error (_("Not confirmed.")); |
c906108c SS |
1231 | /* NOTREACHED */ |
1232 | } | |
1233 | } | |
1234 | ||
c5aa993b | 1235 | if (sfn != NULL) |
c906108c | 1236 | { |
253342b8 DE |
1237 | struct obj_section *section; |
1238 | ||
c906108c | 1239 | fixup_symbol_section (sfn, 0); |
08be3fe3 | 1240 | section = SYMBOL_OBJ_SECTION (symbol_objfile (sfn), sfn); |
253342b8 DE |
1241 | if (section_is_overlay (section) |
1242 | && !section_is_mapped (section)) | |
c906108c | 1243 | { |
3e43a32a MS |
1244 | if (!query (_("WARNING!!! Destination is in " |
1245 | "unmapped overlay! Jump anyway? "))) | |
c906108c | 1246 | { |
8a3fe4f8 | 1247 | error (_("Not confirmed.")); |
c906108c SS |
1248 | /* NOTREACHED */ |
1249 | } | |
1250 | } | |
1251 | } | |
1252 | ||
c906108c SS |
1253 | addr = sal.pc; |
1254 | ||
1255 | if (from_tty) | |
1256 | { | |
a3f17187 | 1257 | printf_filtered (_("Continuing at ")); |
5af949e3 | 1258 | fputs_filtered (paddress (gdbarch, addr), gdb_stdout); |
c906108c SS |
1259 | printf_filtered (".\n"); |
1260 | } | |
1261 | ||
70509625 | 1262 | clear_proceed_status (0); |
64ce06e4 | 1263 | proceed (addr, GDB_SIGNAL_0); |
c906108c | 1264 | } |
c906108c | 1265 | \f |
c906108c SS |
1266 | /* Continue program giving it specified signal. */ |
1267 | ||
1268 | static void | |
fba45db2 | 1269 | signal_command (char *signum_exp, int from_tty) |
c906108c | 1270 | { |
2ea28649 | 1271 | enum gdb_signal oursig; |
6c4486e6 PA |
1272 | int async_exec; |
1273 | struct cleanup *args_chain; | |
c906108c SS |
1274 | |
1275 | dont_repeat (); /* Too dangerous. */ | |
1276 | ERROR_NO_INFERIOR; | |
573cda03 | 1277 | ensure_not_tfind_mode (); |
d729566a | 1278 | ensure_valid_thread (); |
94cc34af | 1279 | ensure_not_running (); |
c906108c | 1280 | |
32c1e744 | 1281 | /* Find out whether we must run in the background. */ |
6c4486e6 PA |
1282 | signum_exp = strip_bg_char (signum_exp, &async_exec); |
1283 | args_chain = make_cleanup (xfree, signum_exp); | |
32c1e744 | 1284 | |
8bc2fe48 | 1285 | prepare_execution_command (¤t_target, async_exec); |
32c1e744 | 1286 | |
c906108c | 1287 | if (!signum_exp) |
e2e0b3e5 | 1288 | error_no_arg (_("signal number")); |
c906108c SS |
1289 | |
1290 | /* It would be even slicker to make signal names be valid expressions, | |
1291 | (the type could be "enum $signal" or some such), then the user could | |
1292 | assign them to convenience variables. */ | |
2ea28649 | 1293 | oursig = gdb_signal_from_name (signum_exp); |
c906108c | 1294 | |
a493e3e2 | 1295 | if (oursig == GDB_SIGNAL_UNKNOWN) |
c906108c SS |
1296 | { |
1297 | /* No, try numeric. */ | |
bb518678 | 1298 | int num = parse_and_eval_long (signum_exp); |
c906108c SS |
1299 | |
1300 | if (num == 0) | |
a493e3e2 | 1301 | oursig = GDB_SIGNAL_0; |
c906108c | 1302 | else |
2ea28649 | 1303 | oursig = gdb_signal_from_command (num); |
c906108c SS |
1304 | } |
1305 | ||
c6343a91 JK |
1306 | do_cleanups (args_chain); |
1307 | ||
70509625 PA |
1308 | /* Look for threads other than the current that this command ends up |
1309 | resuming too (due to schedlock off), and warn if they'll get a | |
1310 | signal delivered. "signal 0" is used to suppress a previous | |
1311 | signal, but if the current thread is no longer the one that got | |
1312 | the signal, then the user is potentially suppressing the signal | |
1313 | of the wrong thread. */ | |
1314 | if (!non_stop) | |
1315 | { | |
1316 | struct thread_info *tp; | |
1317 | ptid_t resume_ptid; | |
1318 | int must_confirm = 0; | |
1319 | ||
1320 | /* This indicates what will be resumed. Either a single thread, | |
1321 | a whole process, or all threads of all processes. */ | |
1322 | resume_ptid = user_visible_resume_ptid (0); | |
1323 | ||
1324 | ALL_NON_EXITED_THREADS (tp) | |
1325 | { | |
1326 | if (ptid_equal (tp->ptid, inferior_ptid)) | |
1327 | continue; | |
1328 | if (!ptid_match (tp->ptid, resume_ptid)) | |
1329 | continue; | |
1330 | ||
1331 | if (tp->suspend.stop_signal != GDB_SIGNAL_0 | |
1332 | && signal_pass_state (tp->suspend.stop_signal)) | |
1333 | { | |
1334 | if (!must_confirm) | |
1335 | printf_unfiltered (_("Note:\n")); | |
43792cf0 PA |
1336 | printf_unfiltered (_(" Thread %s previously stopped with signal %s, %s.\n"), |
1337 | print_thread_id (tp), | |
70509625 PA |
1338 | gdb_signal_to_name (tp->suspend.stop_signal), |
1339 | gdb_signal_to_string (tp->suspend.stop_signal)); | |
1340 | must_confirm = 1; | |
1341 | } | |
1342 | } | |
1343 | ||
1344 | if (must_confirm | |
43792cf0 | 1345 | && !query (_("Continuing thread %s (the current thread) with specified signal will\n" |
70509625 PA |
1346 | "still deliver the signals noted above to their respective threads.\n" |
1347 | "Continue anyway? "), | |
43792cf0 | 1348 | print_thread_id (inferior_thread ()))) |
70509625 PA |
1349 | error (_("Not confirmed.")); |
1350 | } | |
1351 | ||
c906108c SS |
1352 | if (from_tty) |
1353 | { | |
a493e3e2 | 1354 | if (oursig == GDB_SIGNAL_0) |
a3f17187 | 1355 | printf_filtered (_("Continuing with no signal.\n")); |
c906108c | 1356 | else |
a3f17187 | 1357 | printf_filtered (_("Continuing with signal %s.\n"), |
2ea28649 | 1358 | gdb_signal_to_name (oursig)); |
c906108c SS |
1359 | } |
1360 | ||
70509625 | 1361 | clear_proceed_status (0); |
64ce06e4 | 1362 | proceed ((CORE_ADDR) -1, oursig); |
c906108c SS |
1363 | } |
1364 | ||
81219e53 DE |
1365 | /* Queue a signal to be delivered to the current thread. */ |
1366 | ||
1367 | static void | |
1368 | queue_signal_command (char *signum_exp, int from_tty) | |
1369 | { | |
1370 | enum gdb_signal oursig; | |
1371 | struct thread_info *tp; | |
1372 | ||
1373 | ERROR_NO_INFERIOR; | |
1374 | ensure_not_tfind_mode (); | |
1375 | ensure_valid_thread (); | |
1376 | ensure_not_running (); | |
1377 | ||
1378 | if (signum_exp == NULL) | |
1379 | error_no_arg (_("signal number")); | |
1380 | ||
1381 | /* It would be even slicker to make signal names be valid expressions, | |
1382 | (the type could be "enum $signal" or some such), then the user could | |
1383 | assign them to convenience variables. */ | |
1384 | oursig = gdb_signal_from_name (signum_exp); | |
1385 | ||
1386 | if (oursig == GDB_SIGNAL_UNKNOWN) | |
1387 | { | |
1388 | /* No, try numeric. */ | |
1389 | int num = parse_and_eval_long (signum_exp); | |
1390 | ||
1391 | if (num == 0) | |
1392 | oursig = GDB_SIGNAL_0; | |
1393 | else | |
1394 | oursig = gdb_signal_from_command (num); | |
1395 | } | |
1396 | ||
1397 | if (oursig != GDB_SIGNAL_0 | |
1398 | && !signal_pass_state (oursig)) | |
1399 | error (_("Signal handling set to not pass this signal to the program.")); | |
1400 | ||
1401 | tp = inferior_thread (); | |
1402 | tp->suspend.stop_signal = oursig; | |
1403 | } | |
1404 | ||
cfc31633 PA |
1405 | /* Data for the FSM that manages the until (with no argument) |
1406 | command. */ | |
1407 | ||
1408 | struct until_next_fsm | |
fa4cd53f | 1409 | { |
cfc31633 PA |
1410 | /* The base class. */ |
1411 | struct thread_fsm thread_fsm; | |
1412 | ||
1413 | /* The thread that as current when the command was executed. */ | |
fa4cd53f PA |
1414 | int thread; |
1415 | }; | |
1416 | ||
8980e177 PA |
1417 | static int until_next_fsm_should_stop (struct thread_fsm *self, |
1418 | struct thread_info *thread); | |
1419 | static void until_next_fsm_clean_up (struct thread_fsm *self, | |
1420 | struct thread_info *thread); | |
cfc31633 PA |
1421 | static enum async_reply_reason |
1422 | until_next_fsm_async_reply_reason (struct thread_fsm *self); | |
1423 | ||
1424 | /* until_next_fsm's vtable. */ | |
1425 | ||
1426 | static struct thread_fsm_ops until_next_fsm_ops = | |
1427 | { | |
1428 | NULL, /* dtor */ | |
1429 | until_next_fsm_clean_up, | |
1430 | until_next_fsm_should_stop, | |
1431 | NULL, /* return_value */ | |
1432 | until_next_fsm_async_reply_reason, | |
1433 | }; | |
1434 | ||
1435 | /* Allocate a new until_next_fsm. */ | |
1436 | ||
1437 | static struct until_next_fsm * | |
8980e177 | 1438 | new_until_next_fsm (struct interp *cmd_interp, int thread) |
cfc31633 PA |
1439 | { |
1440 | struct until_next_fsm *sm; | |
1441 | ||
1442 | sm = XCNEW (struct until_next_fsm); | |
8980e177 | 1443 | thread_fsm_ctor (&sm->thread_fsm, &until_next_fsm_ops, cmd_interp); |
cfc31633 PA |
1444 | |
1445 | sm->thread = thread; | |
1446 | ||
1447 | return sm; | |
1448 | } | |
1449 | ||
1450 | /* Implementation of the 'should_stop' FSM method for the until (with | |
1451 | no arg) command. */ | |
1452 | ||
1453 | static int | |
8980e177 PA |
1454 | until_next_fsm_should_stop (struct thread_fsm *self, |
1455 | struct thread_info *tp) | |
cfc31633 | 1456 | { |
cfc31633 PA |
1457 | if (tp->control.stop_step) |
1458 | thread_fsm_set_finished (self); | |
1459 | ||
1460 | return 1; | |
1461 | } | |
1462 | ||
1463 | /* Implementation of the 'clean_up' FSM method for the until (with no | |
1464 | arg) command. */ | |
186c406b TT |
1465 | |
1466 | static void | |
8980e177 | 1467 | until_next_fsm_clean_up (struct thread_fsm *self, struct thread_info *thread) |
186c406b | 1468 | { |
cfc31633 | 1469 | struct until_next_fsm *sm = (struct until_next_fsm *) self; |
186c406b | 1470 | |
8980e177 | 1471 | delete_longjmp_breakpoint (thread->global_num); |
cfc31633 PA |
1472 | } |
1473 | ||
1474 | /* Implementation of the 'async_reply_reason' FSM method for the until | |
1475 | (with no arg) command. */ | |
1476 | ||
1477 | static enum async_reply_reason | |
1478 | until_next_fsm_async_reply_reason (struct thread_fsm *self) | |
1479 | { | |
1480 | return EXEC_ASYNC_END_STEPPING_RANGE; | |
186c406b TT |
1481 | } |
1482 | ||
c906108c SS |
1483 | /* Proceed until we reach a different source line with pc greater than |
1484 | our current one or exit the function. We skip calls in both cases. | |
1485 | ||
1486 | Note that eventually this command should probably be changed so | |
1487 | that only source lines are printed out when we hit the breakpoint | |
1488 | we set. This may involve changes to wait_for_inferior and the | |
1489 | proceed status code. */ | |
1490 | ||
c906108c | 1491 | static void |
fba45db2 | 1492 | until_next_command (int from_tty) |
c906108c SS |
1493 | { |
1494 | struct frame_info *frame; | |
1495 | CORE_ADDR pc; | |
1496 | struct symbol *func; | |
1497 | struct symtab_and_line sal; | |
4e1c45ea | 1498 | struct thread_info *tp = inferior_thread (); |
5d5658a1 | 1499 | int thread = tp->global_num; |
186c406b | 1500 | struct cleanup *old_chain; |
cfc31633 | 1501 | struct until_next_fsm *sm; |
c5aa993b | 1502 | |
70509625 | 1503 | clear_proceed_status (0); |
edb3359d | 1504 | set_step_frame (); |
c906108c SS |
1505 | |
1506 | frame = get_current_frame (); | |
1507 | ||
1508 | /* Step until either exited from this function or greater | |
1509 | than the current line (if in symbolic section) or pc (if | |
1777feb0 | 1510 | not). */ |
c906108c | 1511 | |
1c7819ef | 1512 | pc = get_frame_pc (frame); |
c906108c | 1513 | func = find_pc_function (pc); |
c5aa993b | 1514 | |
c906108c SS |
1515 | if (!func) |
1516 | { | |
7cbd4a93 | 1517 | struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc); |
c5aa993b | 1518 | |
7cbd4a93 | 1519 | if (msymbol.minsym == NULL) |
8a3fe4f8 | 1520 | error (_("Execution is not within a known function.")); |
c5aa993b | 1521 | |
77e371c0 | 1522 | tp->control.step_range_start = BMSYMBOL_VALUE_ADDRESS (msymbol); |
7e09a223 YQ |
1523 | /* The upper-bound of step_range is exclusive. In order to make PC |
1524 | within the range, set the step_range_end with PC + 1. */ | |
1525 | tp->control.step_range_end = pc + 1; | |
c906108c SS |
1526 | } |
1527 | else | |
1528 | { | |
1529 | sal = find_pc_line (pc, 0); | |
c5aa993b | 1530 | |
16c381f0 JK |
1531 | tp->control.step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func)); |
1532 | tp->control.step_range_end = sal.end; | |
c906108c | 1533 | } |
c1e36e3e | 1534 | tp->control.may_range_step = 1; |
c5aa993b | 1535 | |
16c381f0 | 1536 | tp->control.step_over_calls = STEP_OVER_ALL; |
c906108c | 1537 | |
186c406b TT |
1538 | set_longjmp_breakpoint (tp, get_frame_id (frame)); |
1539 | old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
1540 | ||
8980e177 | 1541 | sm = new_until_next_fsm (command_interp (), tp->global_num); |
cfc31633 PA |
1542 | tp->thread_fsm = &sm->thread_fsm; |
1543 | discard_cleanups (old_chain); | |
fa4cd53f | 1544 | |
cfc31633 | 1545 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
c906108c SS |
1546 | } |
1547 | ||
c5aa993b | 1548 | static void |
fba45db2 | 1549 | until_command (char *arg, int from_tty) |
c906108c | 1550 | { |
6c4486e6 PA |
1551 | int async_exec; |
1552 | struct cleanup *args_chain; | |
43ff13b4 | 1553 | |
4247603b | 1554 | ERROR_NO_INFERIOR; |
573cda03 | 1555 | ensure_not_tfind_mode (); |
4247603b PA |
1556 | ensure_valid_thread (); |
1557 | ensure_not_running (); | |
573cda03 | 1558 | |
1777feb0 | 1559 | /* Find out whether we must run in the background. */ |
6c4486e6 PA |
1560 | arg = strip_bg_char (arg, &async_exec); |
1561 | args_chain = make_cleanup (xfree, arg); | |
43ff13b4 | 1562 | |
8bc2fe48 | 1563 | prepare_execution_command (¤t_target, async_exec); |
43ff13b4 | 1564 | |
c906108c | 1565 | if (arg) |
ae66c1fc | 1566 | until_break_command (arg, from_tty, 0); |
c906108c SS |
1567 | else |
1568 | until_next_command (from_tty); | |
6c4486e6 PA |
1569 | |
1570 | /* Done with ARGS. */ | |
1571 | do_cleanups (args_chain); | |
c906108c | 1572 | } |
ae66c1fc EZ |
1573 | |
1574 | static void | |
1575 | advance_command (char *arg, int from_tty) | |
1576 | { | |
6c4486e6 PA |
1577 | int async_exec; |
1578 | struct cleanup *args_chain; | |
ae66c1fc | 1579 | |
4247603b | 1580 | ERROR_NO_INFERIOR; |
573cda03 | 1581 | ensure_not_tfind_mode (); |
4247603b PA |
1582 | ensure_valid_thread (); |
1583 | ensure_not_running (); | |
573cda03 | 1584 | |
ae66c1fc | 1585 | if (arg == NULL) |
e2e0b3e5 | 1586 | error_no_arg (_("a location")); |
ae66c1fc EZ |
1587 | |
1588 | /* Find out whether we must run in the background. */ | |
6c4486e6 PA |
1589 | arg = strip_bg_char (arg, &async_exec); |
1590 | args_chain = make_cleanup (xfree, arg); | |
ae66c1fc | 1591 | |
8bc2fe48 | 1592 | prepare_execution_command (¤t_target, async_exec); |
ae66c1fc EZ |
1593 | |
1594 | until_break_command (arg, from_tty, 1); | |
6c4486e6 PA |
1595 | |
1596 | /* Done with ARGS. */ | |
1597 | do_cleanups (args_chain); | |
ae66c1fc | 1598 | } |
c906108c | 1599 | \f |
cc72b2a2 | 1600 | /* Return the value of the result of a function at the end of a 'finish' |
8a6c4031 JK |
1601 | command/BP. DTOR_DATA (if not NULL) can represent inferior registers |
1602 | right after an inferior call has finished. */ | |
f941662f | 1603 | |
cc72b2a2 | 1604 | struct value * |
0700e23e | 1605 | get_return_value (struct value *function, struct type *value_type) |
11cf8741 | 1606 | { |
07495424 YQ |
1607 | regcache stop_regs (regcache::readonly, *get_current_regcache ()); |
1608 | struct gdbarch *gdbarch = stop_regs.arch (); | |
44e5158b AC |
1609 | struct value *value; |
1610 | ||
f168693b | 1611 | value_type = check_typedef (value_type); |
44e5158b | 1612 | gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID); |
11cf8741 | 1613 | |
92ad9cd9 AC |
1614 | /* FIXME: 2003-09-27: When returning from a nested inferior function |
1615 | call, it's possible (with no help from the architecture vector) | |
1616 | to locate and return/print a "struct return" value. This is just | |
7a9dd1b2 | 1617 | a more complicated case of what is already being done in the |
92ad9cd9 AC |
1618 | inferior function call code. In fact, when inferior function |
1619 | calls are made async, this will likely be made the norm. */ | |
31db7b6c | 1620 | |
6a3a010b | 1621 | switch (gdbarch_return_value (gdbarch, function, value_type, |
c055b101 | 1622 | NULL, NULL, NULL)) |
44e5158b | 1623 | { |
750eb019 AC |
1624 | case RETURN_VALUE_REGISTER_CONVENTION: |
1625 | case RETURN_VALUE_ABI_RETURNS_ADDRESS: | |
181fc57c | 1626 | case RETURN_VALUE_ABI_PRESERVES_ADDRESS: |
44e5158b | 1627 | value = allocate_value (value_type); |
07495424 | 1628 | gdbarch_return_value (gdbarch, function, value_type, &stop_regs, |
990a07ab | 1629 | value_contents_raw (value), NULL); |
750eb019 AC |
1630 | break; |
1631 | case RETURN_VALUE_STRUCT_CONVENTION: | |
1632 | value = NULL; | |
1633 | break; | |
1634 | default: | |
e2e0b3e5 | 1635 | internal_error (__FILE__, __LINE__, _("bad switch")); |
44e5158b | 1636 | } |
bb472c1e | 1637 | |
cc72b2a2 KP |
1638 | return value; |
1639 | } | |
1640 | ||
243a9253 PA |
1641 | /* The captured function return value/type and its position in the |
1642 | value history. */ | |
cc72b2a2 | 1643 | |
243a9253 | 1644 | struct return_value_info |
cc72b2a2 | 1645 | { |
243a9253 PA |
1646 | /* The captured return value. May be NULL if we weren't able to |
1647 | retrieve it. See get_return_value. */ | |
1648 | struct value *value; | |
1649 | ||
1650 | /* The return type. In some cases, we'll not be able extract the | |
1651 | return value, but we always know the type. */ | |
1652 | struct type *type; | |
1653 | ||
1654 | /* If we captured a value, this is the value history index. */ | |
1655 | int value_history_index; | |
1656 | }; | |
1657 | ||
1658 | /* Helper for print_return_value. */ | |
cc72b2a2 | 1659 | |
243a9253 PA |
1660 | static void |
1661 | print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv) | |
1662 | { | |
1663 | if (rv->value != NULL) | |
31db7b6c | 1664 | { |
79a45b7d TT |
1665 | struct value_print_options opts; |
1666 | ||
31db7b6c | 1667 | /* Print it. */ |
112e8700 SM |
1668 | uiout->text ("Value returned is "); |
1669 | uiout->field_fmt ("gdb-result-var", "$%d", | |
d7e74731 | 1670 | rv->value_history_index); |
112e8700 | 1671 | uiout->text (" = "); |
2a998fc0 | 1672 | get_no_prettyformat_print_options (&opts); |
d7e74731 PA |
1673 | |
1674 | string_file stb; | |
1675 | ||
1676 | value_print (rv->value, &stb, &opts); | |
112e8700 SM |
1677 | uiout->field_stream ("return-value", stb); |
1678 | uiout->text ("\n"); | |
31db7b6c MK |
1679 | } |
1680 | else | |
1681 | { | |
2f408ecb | 1682 | std::string type_name = type_to_string (rv->type); |
112e8700 SM |
1683 | uiout->text ("Value returned has type: "); |
1684 | uiout->field_string ("return-type", type_name.c_str ()); | |
1685 | uiout->text ("."); | |
1686 | uiout->text (" Cannot determine contents\n"); | |
31db7b6c | 1687 | } |
11cf8741 JM |
1688 | } |
1689 | ||
243a9253 PA |
1690 | /* Print the result of a function at the end of a 'finish' command. |
1691 | RV points at an object representing the captured return value/type | |
1692 | and its position in the value history. */ | |
1693 | ||
1694 | void | |
1695 | print_return_value (struct ui_out *uiout, struct return_value_info *rv) | |
1696 | { | |
1697 | if (rv->type == NULL || TYPE_CODE (rv->type) == TYPE_CODE_VOID) | |
1698 | return; | |
1699 | ||
1700 | TRY | |
1701 | { | |
1702 | /* print_return_value_1 can throw an exception in some | |
1703 | circumstances. We need to catch this so that we still | |
1704 | delete the breakpoint. */ | |
1705 | print_return_value_1 (uiout, rv); | |
1706 | } | |
1707 | CATCH (ex, RETURN_MASK_ALL) | |
1708 | { | |
1709 | exception_print (gdb_stdout, ex); | |
1710 | } | |
1711 | END_CATCH | |
1712 | } | |
1713 | ||
1714 | /* Data for the FSM that manages the finish command. */ | |
f941662f | 1715 | |
243a9253 | 1716 | struct finish_command_fsm |
43ff13b4 | 1717 | { |
243a9253 PA |
1718 | /* The base class. */ |
1719 | struct thread_fsm thread_fsm; | |
1720 | ||
243a9253 PA |
1721 | /* The momentary breakpoint set at the function's return address in |
1722 | the caller. */ | |
43ff13b4 | 1723 | struct breakpoint *breakpoint; |
243a9253 PA |
1724 | |
1725 | /* The function that we're stepping out of. */ | |
bfec99b2 | 1726 | struct symbol *function; |
8a6c4031 | 1727 | |
243a9253 PA |
1728 | /* If the FSM finishes successfully, this stores the function's |
1729 | return value. */ | |
1730 | struct return_value_info return_value; | |
bfec99b2 | 1731 | }; |
c5aa993b | 1732 | |
8980e177 PA |
1733 | static int finish_command_fsm_should_stop (struct thread_fsm *self, |
1734 | struct thread_info *thread); | |
1735 | static void finish_command_fsm_clean_up (struct thread_fsm *self, | |
1736 | struct thread_info *thread); | |
243a9253 PA |
1737 | static struct return_value_info * |
1738 | finish_command_fsm_return_value (struct thread_fsm *self); | |
1739 | static enum async_reply_reason | |
1740 | finish_command_fsm_async_reply_reason (struct thread_fsm *self); | |
1741 | ||
1742 | /* finish_command_fsm's vtable. */ | |
1743 | ||
1744 | static struct thread_fsm_ops finish_command_fsm_ops = | |
1745 | { | |
1746 | NULL, /* dtor */ | |
1747 | finish_command_fsm_clean_up, | |
1748 | finish_command_fsm_should_stop, | |
1749 | finish_command_fsm_return_value, | |
1750 | finish_command_fsm_async_reply_reason, | |
8980e177 | 1751 | NULL, /* should_notify_stop */ |
243a9253 PA |
1752 | }; |
1753 | ||
1754 | /* Allocate a new finish_command_fsm. */ | |
1755 | ||
1756 | static struct finish_command_fsm * | |
8980e177 | 1757 | new_finish_command_fsm (struct interp *cmd_interp) |
bfec99b2 | 1758 | { |
243a9253 PA |
1759 | struct finish_command_fsm *sm; |
1760 | ||
1761 | sm = XCNEW (struct finish_command_fsm); | |
8980e177 | 1762 | thread_fsm_ctor (&sm->thread_fsm, &finish_command_fsm_ops, cmd_interp); |
243a9253 PA |
1763 | |
1764 | return sm; | |
1765 | } | |
347bddb7 | 1766 | |
243a9253 PA |
1767 | /* Implementation of the 'should_stop' FSM method for the finish |
1768 | commands. Detects whether the thread stepped out of the function | |
1769 | successfully, and if so, captures the function's return value and | |
1770 | marks the FSM finished. */ | |
1771 | ||
1772 | static int | |
8980e177 PA |
1773 | finish_command_fsm_should_stop (struct thread_fsm *self, |
1774 | struct thread_info *tp) | |
243a9253 PA |
1775 | { |
1776 | struct finish_command_fsm *f = (struct finish_command_fsm *) self; | |
1777 | struct return_value_info *rv = &f->return_value; | |
243a9253 PA |
1778 | |
1779 | if (f->function != NULL | |
1780 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
1781 | f->breakpoint) != NULL) | |
43ff13b4 | 1782 | { |
243a9253 PA |
1783 | /* We're done. */ |
1784 | thread_fsm_set_finished (self); | |
bfec99b2 | 1785 | |
243a9253 PA |
1786 | rv->type = TYPE_TARGET_TYPE (SYMBOL_TYPE (f->function)); |
1787 | if (rv->type == NULL) | |
1788 | internal_error (__FILE__, __LINE__, | |
1789 | _("finish_command: function has no target type")); | |
f5871ec0 | 1790 | |
243a9253 | 1791 | if (TYPE_CODE (rv->type) != TYPE_CODE_VOID) |
40c549d6 | 1792 | { |
243a9253 PA |
1793 | struct value *func; |
1794 | ||
1795 | func = read_var_value (f->function, NULL, get_current_frame ()); | |
0700e23e | 1796 | rv->value = get_return_value (func, rv->type); |
aca20ec4 KB |
1797 | if (rv->value != NULL) |
1798 | rv->value_history_index = record_latest_value (rv->value); | |
243a9253 PA |
1799 | } |
1800 | } | |
1801 | else if (tp->control.stop_step) | |
1802 | { | |
1803 | /* Finishing from an inline frame, or reverse finishing. In | |
1804 | either case, there's no way to retrieve the return value. */ | |
1805 | thread_fsm_set_finished (self); | |
1806 | } | |
fa4cd53f | 1807 | |
243a9253 PA |
1808 | return 1; |
1809 | } | |
40c549d6 | 1810 | |
243a9253 PA |
1811 | /* Implementation of the 'clean_up' FSM method for the finish |
1812 | commands. */ | |
fa4cd53f | 1813 | |
243a9253 | 1814 | static void |
8980e177 PA |
1815 | finish_command_fsm_clean_up (struct thread_fsm *self, |
1816 | struct thread_info *thread) | |
243a9253 PA |
1817 | { |
1818 | struct finish_command_fsm *f = (struct finish_command_fsm *) self; | |
fa4cd53f | 1819 | |
243a9253 PA |
1820 | if (f->breakpoint != NULL) |
1821 | { | |
1822 | delete_breakpoint (f->breakpoint); | |
1823 | f->breakpoint = NULL; | |
43ff13b4 | 1824 | } |
8980e177 | 1825 | delete_longjmp_breakpoint (thread->global_num); |
243a9253 | 1826 | } |
f941662f | 1827 | |
243a9253 PA |
1828 | /* Implementation of the 'return_value' FSM method for the finish |
1829 | commands. */ | |
1830 | ||
1831 | static struct return_value_info * | |
1832 | finish_command_fsm_return_value (struct thread_fsm *self) | |
1833 | { | |
1834 | struct finish_command_fsm *f = (struct finish_command_fsm *) self; | |
1835 | ||
1836 | return &f->return_value; | |
43ff13b4 JM |
1837 | } |
1838 | ||
243a9253 PA |
1839 | /* Implementation of the 'async_reply_reason' FSM method for the |
1840 | finish commands. */ | |
1841 | ||
1842 | static enum async_reply_reason | |
1843 | finish_command_fsm_async_reply_reason (struct thread_fsm *self) | |
604ead4a | 1844 | { |
243a9253 PA |
1845 | if (execution_direction == EXEC_REVERSE) |
1846 | return EXEC_ASYNC_END_STEPPING_RANGE; | |
1847 | else | |
1848 | return EXEC_ASYNC_FUNCTION_FINISHED; | |
604ead4a PA |
1849 | } |
1850 | ||
b2175913 MS |
1851 | /* finish_backward -- helper function for finish_command. */ |
1852 | ||
1853 | static void | |
243a9253 | 1854 | finish_backward (struct finish_command_fsm *sm) |
b2175913 MS |
1855 | { |
1856 | struct symtab_and_line sal; | |
1857 | struct thread_info *tp = inferior_thread (); | |
1c7819ef | 1858 | CORE_ADDR pc; |
b2175913 | 1859 | CORE_ADDR func_addr; |
b2175913 | 1860 | |
1c7819ef PA |
1861 | pc = get_frame_pc (get_current_frame ()); |
1862 | ||
1863 | if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0) | |
1f267ae3 | 1864 | error (_("Cannot find bounds of current function")); |
b2175913 MS |
1865 | |
1866 | sal = find_pc_line (func_addr, 0); | |
1867 | ||
9da8c2a0 | 1868 | tp->control.proceed_to_finish = 1; |
b2175913 MS |
1869 | /* Special case: if we're sitting at the function entry point, |
1870 | then all we need to do is take a reverse singlestep. We | |
1871 | don't need to set a breakpoint, and indeed it would do us | |
1872 | no good to do so. | |
1873 | ||
1874 | Note that this can only happen at frame #0, since there's | |
1875 | no way that a function up the stack can have a return address | |
1876 | that's equal to its entry point. */ | |
1877 | ||
1c7819ef | 1878 | if (sal.pc != pc) |
b2175913 | 1879 | { |
a6d9a66e UW |
1880 | struct frame_info *frame = get_selected_frame (NULL); |
1881 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
9da8c2a0 PA |
1882 | struct symtab_and_line sr_sal; |
1883 | ||
1884 | /* Set a step-resume at the function's entry point. Once that's | |
1885 | hit, we'll do one more step backwards. */ | |
1886 | init_sal (&sr_sal); | |
1887 | sr_sal.pc = sal.pc; | |
1888 | sr_sal.pspace = get_frame_program_space (frame); | |
1889 | insert_step_resume_breakpoint_at_sal (gdbarch, | |
1890 | sr_sal, null_frame_id); | |
a6d9a66e | 1891 | |
64ce06e4 | 1892 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
b2175913 MS |
1893 | } |
1894 | else | |
b2175913 | 1895 | { |
9da8c2a0 PA |
1896 | /* We're almost there -- we just need to back up by one more |
1897 | single-step. */ | |
16c381f0 | 1898 | tp->control.step_range_start = tp->control.step_range_end = 1; |
64ce06e4 | 1899 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
b2175913 | 1900 | } |
b2175913 MS |
1901 | } |
1902 | ||
243a9253 PA |
1903 | /* finish_forward -- helper function for finish_command. FRAME is the |
1904 | frame that called the function we're about to step out of. */ | |
b2175913 MS |
1905 | |
1906 | static void | |
243a9253 | 1907 | finish_forward (struct finish_command_fsm *sm, struct frame_info *frame) |
b2175913 | 1908 | { |
def166f6 | 1909 | struct frame_id frame_id = get_frame_id (frame); |
a6d9a66e | 1910 | struct gdbarch *gdbarch = get_frame_arch (frame); |
b2175913 MS |
1911 | struct symtab_and_line sal; |
1912 | struct thread_info *tp = inferior_thread (); | |
b2175913 MS |
1913 | |
1914 | sal = find_pc_line (get_frame_pc (frame), 0); | |
1915 | sal.pc = get_frame_pc (frame); | |
1916 | ||
243a9253 PA |
1917 | sm->breakpoint = set_momentary_breakpoint (gdbarch, sal, |
1918 | get_stack_frame_id (frame), | |
1919 | bp_finish); | |
b2175913 | 1920 | |
c70a6932 JK |
1921 | /* set_momentary_breakpoint invalidates FRAME. */ |
1922 | frame = NULL; | |
1923 | ||
def166f6 | 1924 | set_longjmp_breakpoint (tp, frame_id); |
186c406b | 1925 | |
46c03469 | 1926 | /* We want to print return value, please... */ |
16c381f0 | 1927 | tp->control.proceed_to_finish = 1; |
b2175913 | 1928 | |
243a9253 | 1929 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
b2175913 MS |
1930 | } |
1931 | ||
e3b5daf9 MM |
1932 | /* Skip frames for "finish". */ |
1933 | ||
1934 | static struct frame_info * | |
1935 | skip_finish_frames (struct frame_info *frame) | |
1936 | { | |
1937 | struct frame_info *start; | |
1938 | ||
1939 | do | |
1940 | { | |
1941 | start = frame; | |
1942 | ||
1943 | frame = skip_tailcall_frames (frame); | |
1944 | if (frame == NULL) | |
1945 | break; | |
1946 | ||
1947 | frame = skip_unwritable_frames (frame); | |
1948 | if (frame == NULL) | |
1949 | break; | |
1950 | } | |
1951 | while (start != frame); | |
1952 | ||
1953 | return frame; | |
1954 | } | |
1955 | ||
f941662f MK |
1956 | /* "finish": Set a temporary breakpoint at the place the selected |
1957 | frame will return to, then continue. */ | |
c906108c SS |
1958 | |
1959 | static void | |
fba45db2 | 1960 | finish_command (char *arg, int from_tty) |
c906108c | 1961 | { |
52f0bd74 | 1962 | struct frame_info *frame; |
6c4486e6 PA |
1963 | int async_exec; |
1964 | struct cleanup *args_chain; | |
243a9253 PA |
1965 | struct finish_command_fsm *sm; |
1966 | struct thread_info *tp; | |
43ff13b4 | 1967 | |
4247603b | 1968 | ERROR_NO_INFERIOR; |
573cda03 | 1969 | ensure_not_tfind_mode (); |
4247603b PA |
1970 | ensure_valid_thread (); |
1971 | ensure_not_running (); | |
573cda03 | 1972 | |
f941662f | 1973 | /* Find out whether we must run in the background. */ |
6c4486e6 PA |
1974 | arg = strip_bg_char (arg, &async_exec); |
1975 | args_chain = make_cleanup (xfree, arg); | |
43ff13b4 | 1976 | |
8bc2fe48 | 1977 | prepare_execution_command (¤t_target, async_exec); |
c906108c SS |
1978 | |
1979 | if (arg) | |
8a3fe4f8 | 1980 | error (_("The \"finish\" command does not take any arguments.")); |
c906108c | 1981 | |
6c4486e6 PA |
1982 | /* Done with ARGS. */ |
1983 | do_cleanups (args_chain); | |
1984 | ||
206415a3 | 1985 | frame = get_prev_frame (get_selected_frame (_("No selected frame."))); |
c906108c | 1986 | if (frame == 0) |
8a3fe4f8 | 1987 | error (_("\"finish\" not meaningful in the outermost frame.")); |
c906108c | 1988 | |
70509625 | 1989 | clear_proceed_status (0); |
c906108c | 1990 | |
243a9253 PA |
1991 | tp = inferior_thread (); |
1992 | ||
8980e177 | 1993 | sm = new_finish_command_fsm (command_interp ()); |
243a9253 PA |
1994 | |
1995 | tp->thread_fsm = &sm->thread_fsm; | |
1996 | ||
edb3359d | 1997 | /* Finishing from an inline frame is completely different. We don't |
243a9253 | 1998 | try to show the "return value" - no way to locate it. */ |
edb3359d DJ |
1999 | if (get_frame_type (get_selected_frame (_("No selected frame."))) |
2000 | == INLINE_FRAME) | |
2001 | { | |
2002 | /* Claim we are stepping in the calling frame. An empty step | |
2003 | range means that we will stop once we aren't in a function | |
2004 | called by that frame. We don't use the magic "1" value for | |
2005 | step_range_end, because then infrun will think this is nexti, | |
2006 | and not step over the rest of this inlined function call. */ | |
edb3359d | 2007 | struct symtab_and_line empty_sal; |
abbb1732 | 2008 | |
edb3359d DJ |
2009 | init_sal (&empty_sal); |
2010 | set_step_info (frame, empty_sal); | |
16c381f0 JK |
2011 | tp->control.step_range_start = get_frame_pc (frame); |
2012 | tp->control.step_range_end = tp->control.step_range_start; | |
2013 | tp->control.step_over_calls = STEP_OVER_ALL; | |
edb3359d DJ |
2014 | |
2015 | /* Print info on the selected frame, including level number but not | |
2016 | source. */ | |
2017 | if (from_tty) | |
2018 | { | |
2019 | printf_filtered (_("Run till exit from ")); | |
08d72866 | 2020 | print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0); |
edb3359d DJ |
2021 | } |
2022 | ||
64ce06e4 | 2023 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
edb3359d DJ |
2024 | return; |
2025 | } | |
2026 | ||
c906108c SS |
2027 | /* Find the function we will return from. */ |
2028 | ||
243a9253 | 2029 | sm->function = find_pc_function (get_frame_pc (get_selected_frame (NULL))); |
c906108c | 2030 | |
f941662f MK |
2031 | /* Print info on the selected frame, including level number but not |
2032 | source. */ | |
c906108c SS |
2033 | if (from_tty) |
2034 | { | |
b2175913 MS |
2035 | if (execution_direction == EXEC_REVERSE) |
2036 | printf_filtered (_("Run back to call of ")); | |
2037 | else | |
743649fd | 2038 | { |
243a9253 | 2039 | if (sm->function != NULL && TYPE_NO_RETURN (sm->function->type) |
743649fd MW |
2040 | && !query (_("warning: Function %s does not return normally.\n" |
2041 | "Try to finish anyway? "), | |
243a9253 | 2042 | SYMBOL_PRINT_NAME (sm->function))) |
743649fd MW |
2043 | error (_("Not confirmed.")); |
2044 | printf_filtered (_("Run till exit from ")); | |
2045 | } | |
b2175913 | 2046 | |
08d72866 | 2047 | print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0); |
c906108c SS |
2048 | } |
2049 | ||
b2175913 | 2050 | if (execution_direction == EXEC_REVERSE) |
243a9253 | 2051 | finish_backward (sm); |
b2175913 | 2052 | else |
33b4777c | 2053 | { |
e3b5daf9 | 2054 | frame = skip_finish_frames (frame); |
7eb89530 | 2055 | |
33b4777c MM |
2056 | if (frame == NULL) |
2057 | error (_("Cannot find the caller frame.")); | |
2058 | ||
2059 | finish_forward (sm, frame); | |
2060 | } | |
c906108c SS |
2061 | } |
2062 | \f | |
f941662f | 2063 | |
c906108c | 2064 | static void |
fba45db2 | 2065 | program_info (char *args, int from_tty) |
c906108c | 2066 | { |
347bddb7 PA |
2067 | bpstat bs; |
2068 | int num, stat; | |
2069 | struct thread_info *tp; | |
2070 | ptid_t ptid; | |
c5aa993b | 2071 | |
c906108c SS |
2072 | if (!target_has_execution) |
2073 | { | |
a3f17187 | 2074 | printf_filtered (_("The program being debugged is not being run.\n")); |
c906108c SS |
2075 | return; |
2076 | } | |
2077 | ||
347bddb7 PA |
2078 | if (non_stop) |
2079 | ptid = inferior_ptid; | |
2080 | else | |
2081 | { | |
2082 | struct target_waitstatus ws; | |
abbb1732 | 2083 | |
347bddb7 PA |
2084 | get_last_target_status (&ptid, &ws); |
2085 | } | |
2086 | ||
2087 | if (ptid_equal (ptid, null_ptid) || is_exited (ptid)) | |
2088 | error (_("Invalid selected thread.")); | |
2089 | else if (is_running (ptid)) | |
2090 | error (_("Selected thread is running.")); | |
2091 | ||
e09875d4 | 2092 | tp = find_thread_ptid (ptid); |
16c381f0 | 2093 | bs = tp->control.stop_bpstat; |
347bddb7 PA |
2094 | stat = bpstat_num (&bs, &num); |
2095 | ||
c906108c | 2096 | target_files_info (); |
5af949e3 | 2097 | printf_filtered (_("Program stopped at %s.\n"), |
f5656ead | 2098 | paddress (target_gdbarch (), stop_pc)); |
16c381f0 | 2099 | if (tp->control.stop_step) |
a3f17187 | 2100 | printf_filtered (_("It stopped after being stepped.\n")); |
8671a17b | 2101 | else if (stat != 0) |
c906108c SS |
2102 | { |
2103 | /* There may be several breakpoints in the same place, so this | |
c5aa993b | 2104 | isn't as strange as it seems. */ |
8671a17b | 2105 | while (stat != 0) |
c906108c | 2106 | { |
8671a17b | 2107 | if (stat < 0) |
c906108c | 2108 | { |
3e43a32a MS |
2109 | printf_filtered (_("It stopped at a breakpoint " |
2110 | "that has since been deleted.\n")); | |
c906108c SS |
2111 | } |
2112 | else | |
a3f17187 | 2113 | printf_filtered (_("It stopped at breakpoint %d.\n"), num); |
8671a17b | 2114 | stat = bpstat_num (&bs, &num); |
c906108c SS |
2115 | } |
2116 | } | |
a493e3e2 | 2117 | else if (tp->suspend.stop_signal != GDB_SIGNAL_0) |
c906108c | 2118 | { |
a3f17187 | 2119 | printf_filtered (_("It stopped with signal %s, %s.\n"), |
2ea28649 PA |
2120 | gdb_signal_to_name (tp->suspend.stop_signal), |
2121 | gdb_signal_to_string (tp->suspend.stop_signal)); | |
c906108c SS |
2122 | } |
2123 | ||
0d41ba00 | 2124 | if (from_tty) |
c906108c | 2125 | { |
3e43a32a MS |
2126 | printf_filtered (_("Type \"info stack\" or \"info " |
2127 | "registers\" for more information.\n")); | |
c906108c SS |
2128 | } |
2129 | } | |
2130 | \f | |
2131 | static void | |
fba45db2 | 2132 | environment_info (char *var, int from_tty) |
c906108c SS |
2133 | { |
2134 | if (var) | |
2135 | { | |
3f81c18a | 2136 | char *val = get_in_environ (current_inferior ()->environment, var); |
abbb1732 | 2137 | |
c906108c SS |
2138 | if (val) |
2139 | { | |
2140 | puts_filtered (var); | |
2141 | puts_filtered (" = "); | |
2142 | puts_filtered (val); | |
2143 | puts_filtered ("\n"); | |
2144 | } | |
2145 | else | |
2146 | { | |
2147 | puts_filtered ("Environment variable \""); | |
2148 | puts_filtered (var); | |
2149 | puts_filtered ("\" not defined.\n"); | |
2150 | } | |
2151 | } | |
2152 | else | |
2153 | { | |
3f81c18a | 2154 | char **vector = environ_vector (current_inferior ()->environment); |
abbb1732 | 2155 | |
c906108c SS |
2156 | while (*vector) |
2157 | { | |
2158 | puts_filtered (*vector++); | |
2159 | puts_filtered ("\n"); | |
2160 | } | |
2161 | } | |
2162 | } | |
2163 | ||
2164 | static void | |
fba45db2 | 2165 | set_environment_command (char *arg, int from_tty) |
c906108c | 2166 | { |
52f0bd74 | 2167 | char *p, *val, *var; |
c906108c SS |
2168 | int nullset = 0; |
2169 | ||
2170 | if (arg == 0) | |
e2e0b3e5 | 2171 | error_no_arg (_("environment variable and value")); |
c906108c | 2172 | |
1777feb0 | 2173 | /* Find seperation between variable name and value. */ |
c906108c SS |
2174 | p = (char *) strchr (arg, '='); |
2175 | val = (char *) strchr (arg, ' '); | |
2176 | ||
2177 | if (p != 0 && val != 0) | |
2178 | { | |
2179 | /* We have both a space and an equals. If the space is before the | |
c5aa993b | 2180 | equals, walk forward over the spaces til we see a nonspace |
1777feb0 | 2181 | (possibly the equals). */ |
c906108c SS |
2182 | if (p > val) |
2183 | while (*val == ' ') | |
2184 | val++; | |
2185 | ||
2186 | /* Now if the = is after the char following the spaces, | |
c5aa993b | 2187 | take the char following the spaces. */ |
c906108c SS |
2188 | if (p > val) |
2189 | p = val - 1; | |
2190 | } | |
2191 | else if (val != 0 && p == 0) | |
2192 | p = val; | |
2193 | ||
2194 | if (p == arg) | |
e2e0b3e5 | 2195 | error_no_arg (_("environment variable to set")); |
c906108c SS |
2196 | |
2197 | if (p == 0 || p[1] == 0) | |
2198 | { | |
2199 | nullset = 1; | |
2200 | if (p == 0) | |
1777feb0 | 2201 | p = arg + strlen (arg); /* So that savestring below will work. */ |
c906108c SS |
2202 | } |
2203 | else | |
2204 | { | |
1777feb0 | 2205 | /* Not setting variable value to null. */ |
c906108c SS |
2206 | val = p + 1; |
2207 | while (*val == ' ' || *val == '\t') | |
2208 | val++; | |
2209 | } | |
2210 | ||
c5aa993b JM |
2211 | while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) |
2212 | p--; | |
c906108c SS |
2213 | |
2214 | var = savestring (arg, p - arg); | |
2215 | if (nullset) | |
2216 | { | |
3e43a32a MS |
2217 | printf_filtered (_("Setting environment variable " |
2218 | "\"%s\" to null value.\n"), | |
a3f17187 | 2219 | var); |
3f81c18a | 2220 | set_in_environ (current_inferior ()->environment, var, ""); |
c906108c SS |
2221 | } |
2222 | else | |
3f81c18a | 2223 | set_in_environ (current_inferior ()->environment, var, val); |
b8c9b27d | 2224 | xfree (var); |
c906108c SS |
2225 | } |
2226 | ||
2227 | static void | |
fba45db2 | 2228 | unset_environment_command (char *var, int from_tty) |
c906108c SS |
2229 | { |
2230 | if (var == 0) | |
2231 | { | |
2232 | /* If there is no argument, delete all environment variables. | |
c5aa993b | 2233 | Ask for confirmation if reading from the terminal. */ |
e2e0b3e5 | 2234 | if (!from_tty || query (_("Delete all environment variables? "))) |
c906108c | 2235 | { |
3f81c18a VP |
2236 | free_environ (current_inferior ()->environment); |
2237 | current_inferior ()->environment = make_environ (); | |
c906108c SS |
2238 | } |
2239 | } | |
2240 | else | |
3f81c18a | 2241 | unset_in_environ (current_inferior ()->environment, var); |
c906108c SS |
2242 | } |
2243 | ||
1777feb0 | 2244 | /* Handle the execution path (PATH variable). */ |
c906108c SS |
2245 | |
2246 | static const char path_var_name[] = "PATH"; | |
2247 | ||
c906108c | 2248 | static void |
fba45db2 | 2249 | path_info (char *args, int from_tty) |
c906108c SS |
2250 | { |
2251 | puts_filtered ("Executable and object file path: "); | |
3e43a32a MS |
2252 | puts_filtered (get_in_environ (current_inferior ()->environment, |
2253 | path_var_name)); | |
c906108c SS |
2254 | puts_filtered ("\n"); |
2255 | } | |
2256 | ||
2257 | /* Add zero or more directories to the front of the execution path. */ | |
2258 | ||
2259 | static void | |
fba45db2 | 2260 | path_command (char *dirname, int from_tty) |
c906108c SS |
2261 | { |
2262 | char *exec_path; | |
a121b7c1 | 2263 | const char *env; |
abbb1732 | 2264 | |
c906108c | 2265 | dont_repeat (); |
3f81c18a | 2266 | env = get_in_environ (current_inferior ()->environment, path_var_name); |
1777feb0 | 2267 | /* Can be null if path is not set. */ |
c906108c SS |
2268 | if (!env) |
2269 | env = ""; | |
4fcf66da | 2270 | exec_path = xstrdup (env); |
c906108c | 2271 | mod_path (dirname, &exec_path); |
3f81c18a | 2272 | set_in_environ (current_inferior ()->environment, path_var_name, exec_path); |
b8c9b27d | 2273 | xfree (exec_path); |
c906108c | 2274 | if (from_tty) |
c5aa993b | 2275 | path_info ((char *) NULL, from_tty); |
c906108c | 2276 | } |
c906108c | 2277 | \f |
c5aa993b | 2278 | |
1292279a PA |
2279 | /* Print out the register NAME with value VAL, to FILE, in the default |
2280 | fashion. */ | |
2281 | ||
2282 | static void | |
2283 | default_print_one_register_info (struct ui_file *file, | |
2284 | const char *name, | |
2285 | struct value *val) | |
2286 | { | |
2287 | struct type *regtype = value_type (val); | |
f69d9aef | 2288 | int print_raw_format; |
1292279a PA |
2289 | |
2290 | fputs_filtered (name, file); | |
2291 | print_spaces_filtered (15 - strlen (name), file); | |
2292 | ||
f69d9aef AB |
2293 | print_raw_format = (value_entirely_available (val) |
2294 | && !value_optimized_out (val)); | |
1292279a PA |
2295 | |
2296 | /* If virtual format is floating, print it that way, and in raw | |
2297 | hex. */ | |
2298 | if (TYPE_CODE (regtype) == TYPE_CODE_FLT | |
2299 | || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT) | |
2300 | { | |
1292279a PA |
2301 | struct value_print_options opts; |
2302 | const gdb_byte *valaddr = value_contents_for_printing (val); | |
2303 | enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype)); | |
2304 | ||
2305 | get_user_print_options (&opts); | |
2306 | opts.deref_ref = 1; | |
2307 | ||
2308 | val_print (regtype, | |
1292279a PA |
2309 | value_embedded_offset (val), 0, |
2310 | file, 0, val, &opts, current_language); | |
2311 | ||
f69d9aef AB |
2312 | if (print_raw_format) |
2313 | { | |
2314 | fprintf_filtered (file, "\t(raw "); | |
2315 | print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order); | |
2316 | fprintf_filtered (file, ")"); | |
2317 | } | |
1292279a PA |
2318 | } |
2319 | else | |
2320 | { | |
2321 | struct value_print_options opts; | |
2322 | ||
2323 | /* Print the register in hex. */ | |
2324 | get_formatted_print_options (&opts, 'x'); | |
2325 | opts.deref_ref = 1; | |
2326 | val_print (regtype, | |
1292279a PA |
2327 | value_embedded_offset (val), 0, |
2328 | file, 0, val, &opts, current_language); | |
2329 | /* If not a vector register, print it also according to its | |
2330 | natural format. */ | |
f69d9aef | 2331 | if (print_raw_format && TYPE_VECTOR (regtype) == 0) |
1292279a PA |
2332 | { |
2333 | get_user_print_options (&opts); | |
2334 | opts.deref_ref = 1; | |
2335 | fprintf_filtered (file, "\t"); | |
2336 | val_print (regtype, | |
1292279a PA |
2337 | value_embedded_offset (val), 0, |
2338 | file, 0, val, &opts, current_language); | |
2339 | } | |
2340 | } | |
2341 | ||
2342 | fprintf_filtered (file, "\n"); | |
2343 | } | |
2344 | ||
1777feb0 | 2345 | /* Print out the machine register regnum. If regnum is -1, print all |
0ab7a791 AC |
2346 | registers (print_all == 1) or all non-float and non-vector |
2347 | registers (print_all == 0). | |
c906108c SS |
2348 | |
2349 | For most machines, having all_registers_info() print the | |
0ab7a791 AC |
2350 | register(s) one per line is good enough. If a different format is |
2351 | required, (eg, for MIPS or Pyramid 90x, which both have lots of | |
2352 | regs), or there is an existing convention for showing all the | |
2353 | registers, define the architecture method PRINT_REGISTERS_INFO to | |
2354 | provide that format. */ | |
c906108c | 2355 | |
666e11c5 | 2356 | void |
0ab7a791 AC |
2357 | default_print_registers_info (struct gdbarch *gdbarch, |
2358 | struct ui_file *file, | |
2359 | struct frame_info *frame, | |
2360 | int regnum, int print_all) | |
c906108c | 2361 | { |
0ab7a791 | 2362 | int i; |
a4bd449d UW |
2363 | const int numregs = gdbarch_num_regs (gdbarch) |
2364 | + gdbarch_num_pseudo_regs (gdbarch); | |
0ab7a791 | 2365 | |
c906108c SS |
2366 | for (i = 0; i < numregs; i++) |
2367 | { | |
4782dc19 AC |
2368 | /* Decide between printing all regs, non-float / vector regs, or |
2369 | specific reg. */ | |
c5aa993b JM |
2370 | if (regnum == -1) |
2371 | { | |
f9418c0f | 2372 | if (print_all) |
4782dc19 | 2373 | { |
f9418c0f | 2374 | if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup)) |
4782dc19 | 2375 | continue; |
f9418c0f AC |
2376 | } |
2377 | else | |
2378 | { | |
2379 | if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup)) | |
4782dc19 AC |
2380 | continue; |
2381 | } | |
c5aa993b JM |
2382 | } |
2383 | else | |
2384 | { | |
2385 | if (i != regnum) | |
2386 | continue; | |
2387 | } | |
c906108c SS |
2388 | |
2389 | /* If the register name is empty, it is undefined for this | |
c5aa993b | 2390 | processor, so don't display anything. */ |
a4bd449d UW |
2391 | if (gdbarch_register_name (gdbarch, i) == NULL |
2392 | || *(gdbarch_register_name (gdbarch, i)) == '\0') | |
c906108c SS |
2393 | continue; |
2394 | ||
1292279a PA |
2395 | default_print_one_register_info (file, |
2396 | gdbarch_register_name (gdbarch, i), | |
901461f8 | 2397 | value_of_register (i, frame)); |
c906108c SS |
2398 | } |
2399 | } | |
c906108c | 2400 | |
c906108c | 2401 | void |
fba45db2 | 2402 | registers_info (char *addr_exp, int fpregs) |
c906108c | 2403 | { |
206415a3 | 2404 | struct frame_info *frame; |
a4bd449d | 2405 | struct gdbarch *gdbarch; |
c906108c SS |
2406 | |
2407 | if (!target_has_registers) | |
8a3fe4f8 | 2408 | error (_("The program has no registers now.")); |
206415a3 | 2409 | frame = get_selected_frame (NULL); |
a4bd449d | 2410 | gdbarch = get_frame_arch (frame); |
c906108c SS |
2411 | |
2412 | if (!addr_exp) | |
2413 | { | |
a4bd449d | 2414 | gdbarch_print_registers_info (gdbarch, gdb_stdout, |
206415a3 | 2415 | frame, -1, fpregs); |
c906108c SS |
2416 | return; |
2417 | } | |
2418 | ||
f9418c0f | 2419 | while (*addr_exp != '\0') |
c5aa993b | 2420 | { |
f9418c0f AC |
2421 | char *start; |
2422 | const char *end; | |
c906108c | 2423 | |
529480d0 KS |
2424 | /* Skip leading white space. */ |
2425 | addr_exp = skip_spaces (addr_exp); | |
c906108c | 2426 | |
f9418c0f AC |
2427 | /* Discard any leading ``$''. Check that there is something |
2428 | resembling a register following it. */ | |
2429 | if (addr_exp[0] == '$') | |
2430 | addr_exp++; | |
2431 | if (isspace ((*addr_exp)) || (*addr_exp) == '\0') | |
8a3fe4f8 | 2432 | error (_("Missing register name")); |
c906108c | 2433 | |
f9418c0f AC |
2434 | /* Find the start/end of this register name/num/group. */ |
2435 | start = addr_exp; | |
2436 | while ((*addr_exp) != '\0' && !isspace ((*addr_exp))) | |
2437 | addr_exp++; | |
2438 | end = addr_exp; | |
ad842144 | 2439 | |
f9418c0f AC |
2440 | /* Figure out what we've found and display it. */ |
2441 | ||
2442 | /* A register name? */ | |
2443 | { | |
029a67e4 | 2444 | int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start); |
abbb1732 | 2445 | |
f9418c0f AC |
2446 | if (regnum >= 0) |
2447 | { | |
ad842144 MR |
2448 | /* User registers lie completely outside of the range of |
2449 | normal registers. Catch them early so that the target | |
2450 | never sees them. */ | |
2451 | if (regnum >= gdbarch_num_regs (gdbarch) | |
2452 | + gdbarch_num_pseudo_regs (gdbarch)) | |
2453 | { | |
1292279a PA |
2454 | struct value *regval = value_of_user_reg (regnum, frame); |
2455 | const char *regname = user_reg_map_regnum_to_name (gdbarch, | |
2456 | regnum); | |
2457 | ||
2458 | /* Print in the same fashion | |
2459 | gdbarch_print_registers_info's default | |
2460 | implementation prints. */ | |
2461 | default_print_one_register_info (gdb_stdout, | |
2462 | regname, | |
2463 | regval); | |
ad842144 MR |
2464 | } |
2465 | else | |
2466 | gdbarch_print_registers_info (gdbarch, gdb_stdout, | |
2467 | frame, regnum, fpregs); | |
f9418c0f AC |
2468 | continue; |
2469 | } | |
2470 | } | |
ad842144 | 2471 | |
f9418c0f AC |
2472 | /* A register group? */ |
2473 | { | |
6c7d17ba | 2474 | struct reggroup *group; |
abbb1732 | 2475 | |
a4bd449d | 2476 | for (group = reggroup_next (gdbarch, NULL); |
6c7d17ba | 2477 | group != NULL; |
a4bd449d | 2478 | group = reggroup_next (gdbarch, group)) |
f9418c0f AC |
2479 | { |
2480 | /* Don't bother with a length check. Should the user | |
2481 | enter a short register group name, go with the first | |
2482 | group that matches. */ | |
6c7d17ba | 2483 | if (strncmp (start, reggroup_name (group), end - start) == 0) |
f9418c0f AC |
2484 | break; |
2485 | } | |
6c7d17ba | 2486 | if (group != NULL) |
f9418c0f AC |
2487 | { |
2488 | int regnum; | |
abbb1732 | 2489 | |
f57d151a | 2490 | for (regnum = 0; |
a4bd449d UW |
2491 | regnum < gdbarch_num_regs (gdbarch) |
2492 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 2493 | regnum++) |
f9418c0f | 2494 | { |
a4bd449d UW |
2495 | if (gdbarch_register_reggroup_p (gdbarch, regnum, group)) |
2496 | gdbarch_print_registers_info (gdbarch, | |
206415a3 | 2497 | gdb_stdout, frame, |
f9418c0f AC |
2498 | regnum, fpregs); |
2499 | } | |
2500 | continue; | |
2501 | } | |
2502 | } | |
c906108c | 2503 | |
f9418c0f | 2504 | /* Nothing matched. */ |
8a3fe4f8 | 2505 | error (_("Invalid register `%.*s'"), (int) (end - start), start); |
c5aa993b | 2506 | } |
c906108c SS |
2507 | } |
2508 | ||
1dd5fedc | 2509 | static void |
fba45db2 | 2510 | all_registers_info (char *addr_exp, int from_tty) |
c906108c SS |
2511 | { |
2512 | registers_info (addr_exp, 1); | |
2513 | } | |
2514 | ||
a58dd373 | 2515 | static void |
fba45db2 | 2516 | nofp_registers_info (char *addr_exp, int from_tty) |
c906108c SS |
2517 | { |
2518 | registers_info (addr_exp, 0); | |
2519 | } | |
e76f1f2e AC |
2520 | |
2521 | static void | |
d80b854b | 2522 | print_vector_info (struct ui_file *file, |
e76f1f2e AC |
2523 | struct frame_info *frame, const char *args) |
2524 | { | |
d80b854b UW |
2525 | struct gdbarch *gdbarch = get_frame_arch (frame); |
2526 | ||
e76f1f2e AC |
2527 | if (gdbarch_print_vector_info_p (gdbarch)) |
2528 | gdbarch_print_vector_info (gdbarch, file, frame, args); | |
2529 | else | |
2530 | { | |
2531 | int regnum; | |
2532 | int printed_something = 0; | |
ab4327e0 | 2533 | |
f57d151a | 2534 | for (regnum = 0; |
a4bd449d UW |
2535 | regnum < gdbarch_num_regs (gdbarch) |
2536 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 2537 | regnum++) |
e76f1f2e | 2538 | { |
f9418c0f | 2539 | if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup)) |
e76f1f2e AC |
2540 | { |
2541 | printed_something = 1; | |
e76f1f2e | 2542 | gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1); |
e76f1f2e AC |
2543 | } |
2544 | } | |
2545 | if (!printed_something) | |
2546 | fprintf_filtered (file, "No vector information\n"); | |
2547 | } | |
2548 | } | |
2549 | ||
2550 | static void | |
2551 | vector_info (char *args, int from_tty) | |
2552 | { | |
206415a3 DJ |
2553 | if (!target_has_registers) |
2554 | error (_("The program has no registers now.")); | |
2555 | ||
d80b854b | 2556 | print_vector_info (gdb_stdout, get_selected_frame (NULL), args); |
e76f1f2e | 2557 | } |
c906108c | 2558 | \f |
5fd62852 PA |
2559 | /* Kill the inferior process. Make us have no inferior. */ |
2560 | ||
2561 | static void | |
2562 | kill_command (char *arg, int from_tty) | |
2563 | { | |
2564 | /* FIXME: This should not really be inferior_ptid (or target_has_execution). | |
2565 | It should be a distinct flag that indicates that a target is active, cuz | |
1777feb0 | 2566 | some targets don't have processes! */ |
5fd62852 PA |
2567 | |
2568 | if (ptid_equal (inferior_ptid, null_ptid)) | |
2569 | error (_("The program is not being run.")); | |
2570 | if (!query (_("Kill the program being debugged? "))) | |
2571 | error (_("Not confirmed.")); | |
2572 | target_kill (); | |
2573 | ||
c35b1492 PA |
2574 | /* If we still have other inferiors to debug, then don't mess with |
2575 | with their threads. */ | |
2576 | if (!have_inferiors ()) | |
5fd62852 | 2577 | { |
1777feb0 | 2578 | init_thread_list (); /* Destroy thread info. */ |
5fd62852 PA |
2579 | |
2580 | /* Killing off the inferior can leave us with a core file. If | |
2581 | so, print the state we are left in. */ | |
2582 | if (target_has_stack) | |
2583 | { | |
2584 | printf_filtered (_("In %s,\n"), target_longname); | |
08d72866 | 2585 | print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1); |
5fd62852 PA |
2586 | } |
2587 | } | |
2588 | bfd_cache_close_all (); | |
2589 | } | |
c5aa993b | 2590 | |
74531fed PA |
2591 | /* Used in `attach&' command. ARG is a point to an integer |
2592 | representing a process id. Proceed threads of this process iff | |
2593 | they stopped due to debugger request, and when they did, they | |
a493e3e2 | 2594 | reported a clean stop (GDB_SIGNAL_0). Do not proceed threads |
74531fed PA |
2595 | that have been explicitly been told to stop. */ |
2596 | ||
2597 | static int | |
2598 | proceed_after_attach_callback (struct thread_info *thread, | |
2599 | void *arg) | |
2600 | { | |
2601 | int pid = * (int *) arg; | |
2602 | ||
2603 | if (ptid_get_pid (thread->ptid) == pid | |
2604 | && !is_exited (thread->ptid) | |
2605 | && !is_executing (thread->ptid) | |
2606 | && !thread->stop_requested | |
a493e3e2 | 2607 | && thread->suspend.stop_signal == GDB_SIGNAL_0) |
74531fed PA |
2608 | { |
2609 | switch_to_thread (thread->ptid); | |
70509625 | 2610 | clear_proceed_status (0); |
64ce06e4 | 2611 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
74531fed PA |
2612 | } |
2613 | ||
2614 | return 0; | |
2615 | } | |
2616 | ||
2617 | static void | |
2618 | proceed_after_attach (int pid) | |
2619 | { | |
2620 | /* Don't error out if the current thread is running, because | |
2621 | there may be other stopped threads. */ | |
2622 | struct cleanup *old_chain; | |
2623 | ||
2624 | /* Backup current thread and selected frame. */ | |
2625 | old_chain = make_cleanup_restore_current_thread (); | |
2626 | ||
2627 | iterate_over_threads (proceed_after_attach_callback, &pid); | |
2628 | ||
2629 | /* Restore selected ptid. */ | |
2630 | do_cleanups (old_chain); | |
2631 | } | |
2632 | ||
6efcd9a8 | 2633 | /* See inferior.h. */ |
c906108c | 2634 | |
6efcd9a8 PA |
2635 | void |
2636 | setup_inferior (int from_tty) | |
9356cf8d | 2637 | { |
d6b48e9c | 2638 | struct inferior *inferior; |
9356cf8d | 2639 | |
d6b48e9c | 2640 | inferior = current_inferior (); |
6efcd9a8 | 2641 | inferior->needs_setup = 0; |
9356cf8d PA |
2642 | |
2643 | /* If no exec file is yet known, try to determine it from the | |
2644 | process itself. */ | |
a10de604 | 2645 | if (get_exec_file (0) == NULL) |
bb805577 | 2646 | exec_file_locate_attach (ptid_get_pid (inferior_ptid), 1, from_tty); |
9356cf8d PA |
2647 | else |
2648 | { | |
2649 | reopen_exec_file (); | |
2650 | reread_symbols (); | |
2651 | } | |
2652 | ||
2653 | /* Take any necessary post-attaching actions for this platform. */ | |
dfd4cc63 | 2654 | target_post_attach (ptid_get_pid (inferior_ptid)); |
9356cf8d PA |
2655 | |
2656 | post_create_inferior (¤t_target, from_tty); | |
6efcd9a8 PA |
2657 | } |
2658 | ||
2659 | /* What to do after the first program stops after attaching. */ | |
2660 | enum attach_post_wait_mode | |
2661 | { | |
2662 | /* Do nothing. Leaves threads as they are. */ | |
2663 | ATTACH_POST_WAIT_NOTHING, | |
2664 | ||
2665 | /* Re-resume threads that are marked running. */ | |
2666 | ATTACH_POST_WAIT_RESUME, | |
2667 | ||
2668 | /* Stop all threads. */ | |
2669 | ATTACH_POST_WAIT_STOP, | |
2670 | }; | |
2671 | ||
2672 | /* Called after we've attached to a process and we've seen it stop for | |
2673 | the first time. If ASYNC_EXEC is true, re-resume threads that | |
2674 | should be running. Else if ATTACH, */ | |
2675 | ||
2676 | static void | |
a121b7c1 | 2677 | attach_post_wait (const char *args, int from_tty, enum attach_post_wait_mode mode) |
6efcd9a8 PA |
2678 | { |
2679 | struct inferior *inferior; | |
9356cf8d | 2680 | |
6efcd9a8 PA |
2681 | inferior = current_inferior (); |
2682 | inferior->control.stop_soon = NO_STOP_QUIETLY; | |
2683 | ||
2684 | if (inferior->needs_setup) | |
2685 | setup_inferior (from_tty); | |
2686 | ||
2687 | if (mode == ATTACH_POST_WAIT_RESUME) | |
74531fed PA |
2688 | { |
2689 | /* The user requested an `attach&', so be sure to leave threads | |
2690 | that didn't get a signal running. */ | |
2691 | ||
2692 | /* Immediatelly resume all suspended threads of this inferior, | |
2693 | and this inferior only. This should have no effect on | |
2694 | already running threads. If a thread has been stopped with a | |
2695 | signal, leave it be. */ | |
2696 | if (non_stop) | |
2697 | proceed_after_attach (inferior->pid); | |
2698 | else | |
2699 | { | |
a493e3e2 | 2700 | if (inferior_thread ()->suspend.stop_signal == GDB_SIGNAL_0) |
74531fed | 2701 | { |
70509625 | 2702 | clear_proceed_status (0); |
64ce06e4 | 2703 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
74531fed PA |
2704 | } |
2705 | } | |
2706 | } | |
6efcd9a8 | 2707 | else if (mode == ATTACH_POST_WAIT_STOP) |
9356cf8d | 2708 | { |
74531fed PA |
2709 | /* The user requested a plain `attach', so be sure to leave |
2710 | the inferior stopped. */ | |
2711 | ||
74531fed PA |
2712 | /* At least the current thread is already stopped. */ |
2713 | ||
2714 | /* In all-stop, by definition, all threads have to be already | |
2715 | stopped at this point. In non-stop, however, although the | |
2716 | selected thread is stopped, others may still be executing. | |
2717 | Be sure to explicitly stop all threads of the process. This | |
2718 | should have no effect on already stopped threads. */ | |
066f6b6e | 2719 | if (non_stop) |
74531fed | 2720 | target_stop (pid_to_ptid (inferior->pid)); |
066f6b6e PA |
2721 | else if (target_is_non_stop_p ()) |
2722 | { | |
2723 | struct thread_info *thread; | |
2724 | struct thread_info *lowest = inferior_thread (); | |
2725 | int pid = current_inferior ()->pid; | |
2726 | ||
2727 | stop_all_threads (); | |
2728 | ||
2729 | /* It's not defined which thread will report the attach | |
2730 | stop. For consistency, always select the thread with | |
2731 | lowest GDB number, which should be the main thread, if it | |
2732 | still exists. */ | |
2733 | ALL_NON_EXITED_THREADS (thread) | |
2734 | { | |
2735 | if (ptid_get_pid (thread->ptid) == pid) | |
2736 | { | |
5d5658a1 PA |
2737 | if (thread->inf->num < lowest->inf->num |
2738 | || thread->per_inf_num < lowest->per_inf_num) | |
066f6b6e PA |
2739 | lowest = thread; |
2740 | } | |
2741 | } | |
2742 | ||
2743 | switch_to_thread (lowest->ptid); | |
2744 | } | |
74531fed PA |
2745 | |
2746 | /* Tell the user/frontend where we're stopped. */ | |
9356cf8d PA |
2747 | normal_stop (); |
2748 | if (deprecated_attach_hook) | |
2749 | deprecated_attach_hook (); | |
2750 | } | |
2751 | } | |
2752 | ||
bfec99b2 | 2753 | struct attach_command_continuation_args |
9356cf8d PA |
2754 | { |
2755 | char *args; | |
2756 | int from_tty; | |
6efcd9a8 | 2757 | enum attach_post_wait_mode mode; |
bfec99b2 | 2758 | }; |
9356cf8d | 2759 | |
bfec99b2 | 2760 | static void |
fa4cd53f | 2761 | attach_command_continuation (void *args, int err) |
bfec99b2 | 2762 | { |
9a3c8263 SM |
2763 | struct attach_command_continuation_args *a |
2764 | = (struct attach_command_continuation_args *) args; | |
abbb1732 | 2765 | |
fa4cd53f PA |
2766 | if (err) |
2767 | return; | |
2768 | ||
6efcd9a8 | 2769 | attach_post_wait (a->args, a->from_tty, a->mode); |
9356cf8d PA |
2770 | } |
2771 | ||
604ead4a PA |
2772 | static void |
2773 | attach_command_continuation_free_args (void *args) | |
2774 | { | |
9a3c8263 SM |
2775 | struct attach_command_continuation_args *a |
2776 | = (struct attach_command_continuation_args *) args; | |
abbb1732 | 2777 | |
604ead4a PA |
2778 | xfree (a->args); |
2779 | xfree (a); | |
2780 | } | |
2781 | ||
6efcd9a8 PA |
2782 | /* "attach" command entry point. Takes a program started up outside |
2783 | of gdb and ``attaches'' to it. This stops it cold in its tracks | |
2784 | and allows us to start debugging it. */ | |
2785 | ||
c906108c | 2786 | void |
fba45db2 | 2787 | attach_command (char *args, int from_tty) |
c906108c | 2788 | { |
6c4486e6 PA |
2789 | int async_exec; |
2790 | struct cleanup *args_chain; | |
b3ccfe11 | 2791 | struct target_ops *attach_target; |
6efcd9a8 PA |
2792 | struct inferior *inferior = current_inferior (); |
2793 | enum attach_post_wait_mode mode; | |
c906108c | 2794 | |
c5aa993b | 2795 | dont_repeat (); /* Not for the faint of heart */ |
c906108c | 2796 | |
f5656ead | 2797 | if (gdbarch_has_global_solist (target_gdbarch ())) |
2567c7d9 PA |
2798 | /* Don't complain if all processes share the same symbol |
2799 | space. */ | |
8a305172 PA |
2800 | ; |
2801 | else if (target_has_execution) | |
c906108c | 2802 | { |
9e2f0ad4 | 2803 | if (query (_("A program is being debugged already. Kill it? "))) |
c906108c SS |
2804 | target_kill (); |
2805 | else | |
8a3fe4f8 | 2806 | error (_("Not killed.")); |
c906108c SS |
2807 | } |
2808 | ||
fd79ecee DJ |
2809 | /* Clean up any leftovers from other runs. Some other things from |
2810 | this function should probably be moved into target_pre_inferior. */ | |
2811 | target_pre_inferior (from_tty); | |
2812 | ||
6c4486e6 PA |
2813 | args = strip_bg_char (args, &async_exec); |
2814 | args_chain = make_cleanup (xfree, args); | |
8bc2fe48 | 2815 | |
b3ccfe11 TT |
2816 | attach_target = find_attach_target (); |
2817 | ||
8bc2fe48 PA |
2818 | prepare_execution_command (attach_target, async_exec); |
2819 | ||
b3ccfe11 | 2820 | if (non_stop && !attach_target->to_supports_non_stop (attach_target)) |
9908b566 VP |
2821 | error (_("Cannot attach to this target in non-stop mode")); |
2822 | ||
b3ccfe11 TT |
2823 | attach_target->to_attach (attach_target, args, from_tty); |
2824 | /* to_attach should push the target, so after this point we | |
2825 | shouldn't refer to attach_target again. */ | |
2826 | attach_target = NULL; | |
c906108c SS |
2827 | |
2828 | /* Set up the "saved terminal modes" of the inferior | |
2829 | based on what modes we are starting it with. */ | |
2830 | target_terminal_init (); | |
2831 | ||
7180e04a PA |
2832 | /* Install inferior's terminal modes. This may look like a no-op, |
2833 | as we've just saved them above, however, this does more than | |
2834 | restore terminal settings: | |
2835 | ||
2836 | - installs a SIGINT handler that forwards SIGINT to the inferior. | |
2837 | Otherwise a Ctrl-C pressed just while waiting for the initial | |
2838 | stop would end up as a spurious Quit. | |
2839 | ||
2840 | - removes stdin from the event loop, which we need if attaching | |
2841 | in the foreground, otherwise on targets that report an initial | |
2842 | stop on attach (which are most) we'd process input/commands | |
2843 | while we're in the event loop waiting for that stop. That is, | |
2844 | before the attach continuation runs and the command is really | |
2845 | finished. */ | |
2846 | target_terminal_inferior (); | |
2847 | ||
c906108c SS |
2848 | /* Set up execution context to know that we should return from |
2849 | wait_for_inferior as soon as the target reports a stop. */ | |
2850 | init_wait_for_inferior (); | |
70509625 | 2851 | clear_proceed_status (0); |
c906108c | 2852 | |
6efcd9a8 PA |
2853 | inferior->needs_setup = 1; |
2854 | ||
fbea99ea | 2855 | if (target_is_non_stop_p ()) |
74531fed PA |
2856 | { |
2857 | /* If we find that the current thread isn't stopped, explicitly | |
2858 | do so now, because we're going to install breakpoints and | |
2859 | poke at memory. */ | |
2860 | ||
2861 | if (async_exec) | |
2862 | /* The user requested an `attach&'; stop just one thread. */ | |
2863 | target_stop (inferior_ptid); | |
2864 | else | |
2865 | /* The user requested an `attach', so stop all threads of this | |
2866 | inferior. */ | |
2867 | target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid))); | |
2868 | } | |
2869 | ||
6efcd9a8 PA |
2870 | mode = async_exec ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_STOP; |
2871 | ||
dc177b7a PA |
2872 | /* Some system don't generate traps when attaching to inferior. |
2873 | E.g. Mach 3 or GNU hurd. */ | |
2874 | if (!target_attach_no_wait) | |
c5aa993b | 2875 | { |
0b333c5e | 2876 | struct attach_command_continuation_args *a; |
d6b48e9c | 2877 | |
1777feb0 | 2878 | /* Careful here. See comments in inferior.h. Basically some |
dc177b7a PA |
2879 | OSes don't ignore SIGSTOPs on continue requests anymore. We |
2880 | need a way for handle_inferior_event to reset the stop_signal | |
2881 | variable after an attach, and this is what | |
2882 | STOP_QUIETLY_NO_SIGSTOP is for. */ | |
16c381f0 | 2883 | inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP; |
c5aa993b | 2884 | |
3b12939d | 2885 | /* Wait for stop. */ |
0b333c5e PA |
2886 | a = XNEW (struct attach_command_continuation_args); |
2887 | a->args = xstrdup (args); | |
2888 | a->from_tty = from_tty; | |
6efcd9a8 | 2889 | a->mode = mode; |
0b333c5e PA |
2890 | add_inferior_continuation (attach_command_continuation, a, |
2891 | attach_command_continuation_free_args); | |
2892 | /* Done with ARGS. */ | |
2893 | do_cleanups (args_chain); | |
2894 | ||
2895 | if (!target_is_async_p ()) | |
2896 | mark_infrun_async_event_handler (); | |
2897 | return; | |
dc177b7a | 2898 | } |
6426a772 | 2899 | |
978b9495 JK |
2900 | /* Done with ARGS. */ |
2901 | do_cleanups (args_chain); | |
2902 | ||
6efcd9a8 | 2903 | attach_post_wait (args, from_tty, mode); |
c906108c SS |
2904 | } |
2905 | ||
1941c569 PA |
2906 | /* We had just found out that the target was already attached to an |
2907 | inferior. PTID points at a thread of this new inferior, that is | |
2908 | the most likely to be stopped right now, but not necessarily so. | |
2909 | The new inferior is assumed to be already added to the inferior | |
2910 | list at this point. If LEAVE_RUNNING, then leave the threads of | |
2911 | this inferior running, except those we've explicitly seen reported | |
2912 | as stopped. */ | |
2913 | ||
2914 | void | |
2915 | notice_new_inferior (ptid_t ptid, int leave_running, int from_tty) | |
2916 | { | |
2917 | struct cleanup* old_chain; | |
6efcd9a8 | 2918 | enum attach_post_wait_mode mode; |
1941c569 PA |
2919 | |
2920 | old_chain = make_cleanup (null_cleanup, NULL); | |
2921 | ||
0d5b594f | 2922 | mode = leave_running ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_NOTHING; |
1941c569 PA |
2923 | |
2924 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2925 | make_cleanup_restore_current_thread (); | |
2926 | ||
6efcd9a8 PA |
2927 | /* Avoid reading registers -- we haven't fetched the target |
2928 | description yet. */ | |
2929 | switch_to_thread_no_regs (find_thread_ptid (ptid)); | |
1941c569 PA |
2930 | |
2931 | /* When we "notice" a new inferior we need to do all the things we | |
2932 | would normally do if we had just attached to it. */ | |
2933 | ||
2934 | if (is_executing (inferior_ptid)) | |
2935 | { | |
0b333c5e | 2936 | struct attach_command_continuation_args *a; |
1941c569 PA |
2937 | struct inferior *inferior = current_inferior (); |
2938 | ||
2939 | /* We're going to install breakpoints, and poke at memory, | |
2940 | ensure that the inferior is stopped for a moment while we do | |
2941 | that. */ | |
2942 | target_stop (inferior_ptid); | |
2943 | ||
16c381f0 | 2944 | inferior->control.stop_soon = STOP_QUIETLY_REMOTE; |
1941c569 PA |
2945 | |
2946 | /* Wait for stop before proceeding. */ | |
0b333c5e PA |
2947 | a = XNEW (struct attach_command_continuation_args); |
2948 | a->args = xstrdup (""); | |
2949 | a->from_tty = from_tty; | |
6efcd9a8 | 2950 | a->mode = mode; |
0b333c5e PA |
2951 | add_inferior_continuation (attach_command_continuation, a, |
2952 | attach_command_continuation_free_args); | |
1941c569 | 2953 | |
0b333c5e PA |
2954 | do_cleanups (old_chain); |
2955 | return; | |
1941c569 PA |
2956 | } |
2957 | ||
6efcd9a8 | 2958 | attach_post_wait ("" /* args */, from_tty, mode); |
1941c569 PA |
2959 | |
2960 | do_cleanups (old_chain); | |
2961 | } | |
2962 | ||
c906108c SS |
2963 | /* |
2964 | * detach_command -- | |
2965 | * takes a program previously attached to and detaches it. | |
2966 | * The program resumes execution and will no longer stop | |
2967 | * on signals, etc. We better not have left any breakpoints | |
2968 | * in the program or it'll die when it hits one. For this | |
2969 | * to work, it may be necessary for the process to have been | |
2970 | * previously attached. It *might* work if the program was | |
2971 | * started via the normal ptrace (PTRACE_TRACEME). | |
2972 | */ | |
2973 | ||
6418d433 | 2974 | void |
fba45db2 | 2975 | detach_command (char *args, int from_tty) |
c906108c | 2976 | { |
1f5d0fc9 | 2977 | dont_repeat (); /* Not for the faint of heart. */ |
d729566a PA |
2978 | |
2979 | if (ptid_equal (inferior_ptid, null_ptid)) | |
2980 | error (_("The program is not being run.")); | |
2981 | ||
2f9d54cf PA |
2982 | query_if_trace_running (from_tty); |
2983 | ||
2984 | disconnect_tracing (); | |
d5551862 | 2985 | |
c906108c | 2986 | target_detach (args, from_tty); |
50c71eaf | 2987 | |
63000888 PA |
2988 | /* The current inferior process was just detached successfully. Get |
2989 | rid of breakpoints that no longer make sense. Note we don't do | |
2990 | this within target_detach because that is also used when | |
2991 | following child forks, and in that case we will want to transfer | |
2992 | breakpoints to the child, not delete them. */ | |
2993 | breakpoint_init_inferior (inf_exited); | |
2994 | ||
50c71eaf PA |
2995 | /* If the solist is global across inferiors, don't clear it when we |
2996 | detach from a single inferior. */ | |
f5656ead | 2997 | if (!gdbarch_has_global_solist (target_gdbarch ())) |
50c71eaf | 2998 | no_shared_libraries (NULL, from_tty); |
8a305172 | 2999 | |
c35b1492 PA |
3000 | /* If we still have inferiors to debug, then don't mess with their |
3001 | threads. */ | |
3002 | if (!have_inferiors ()) | |
8a305172 PA |
3003 | init_thread_list (); |
3004 | ||
9a4105ab AC |
3005 | if (deprecated_detach_hook) |
3006 | deprecated_detach_hook (); | |
c906108c SS |
3007 | } |
3008 | ||
6ad8ae5c DJ |
3009 | /* Disconnect from the current target without resuming it (leaving it |
3010 | waiting for a debugger). | |
3011 | ||
3012 | We'd better not have left any breakpoints in the program or the | |
3013 | next debugger will get confused. Currently only supported for some | |
3014 | remote targets, since the normal attach mechanisms don't work on | |
3015 | stopped processes on some native platforms (e.g. GNU/Linux). */ | |
3016 | ||
3017 | static void | |
3018 | disconnect_command (char *args, int from_tty) | |
3019 | { | |
1777feb0 | 3020 | dont_repeat (); /* Not for the faint of heart. */ |
2f9d54cf PA |
3021 | query_if_trace_running (from_tty); |
3022 | disconnect_tracing (); | |
6ad8ae5c | 3023 | target_disconnect (args, from_tty); |
e85a822c | 3024 | no_shared_libraries (NULL, from_tty); |
a0ef4274 | 3025 | init_thread_list (); |
9a4105ab AC |
3026 | if (deprecated_detach_hook) |
3027 | deprecated_detach_hook (); | |
6ad8ae5c DJ |
3028 | } |
3029 | ||
77ebaa5a VP |
3030 | void |
3031 | interrupt_target_1 (int all_threads) | |
3032 | { | |
3033 | ptid_t ptid; | |
abbb1732 | 3034 | |
77ebaa5a VP |
3035 | if (all_threads) |
3036 | ptid = minus_one_ptid; | |
3037 | else | |
3038 | ptid = inferior_ptid; | |
e42de8c7 PA |
3039 | |
3040 | if (non_stop) | |
3041 | target_stop (ptid); | |
3042 | else | |
3043 | target_interrupt (ptid); | |
252fbfc8 PA |
3044 | |
3045 | /* Tag the thread as having been explicitly requested to stop, so | |
3046 | other parts of gdb know not to resume this thread automatically, | |
3047 | if it was stopped due to an internal event. Limit this to | |
3048 | non-stop mode, as when debugging a multi-threaded application in | |
3049 | all-stop mode, we will only get one stop event --- it's undefined | |
3050 | which thread will report the event. */ | |
3051 | if (non_stop) | |
3052 | set_stop_requested (ptid, 1); | |
77ebaa5a VP |
3053 | } |
3054 | ||
6339bfc4 DE |
3055 | /* interrupt [-a] |
3056 | Stop the execution of the target while running in async mode, in | |
17e5269b | 3057 | the background. In all-stop, stop the whole process. In non-stop |
8cae4b3f PA |
3058 | mode, stop the current thread only by default, or stop all threads |
3059 | if the `-a' switch is used. */ | |
3060 | ||
1dd5fedc | 3061 | static void |
0a07590b | 3062 | interrupt_command (char *args, int from_tty) |
43ff13b4 | 3063 | { |
362646f5 | 3064 | if (target_can_async_p ()) |
43ff13b4 | 3065 | { |
8cae4b3f PA |
3066 | int all_threads = 0; |
3067 | ||
1777feb0 | 3068 | dont_repeat (); /* Not for the faint of heart. */ |
94cc34af | 3069 | |
8cae4b3f | 3070 | if (args != NULL |
61012eef | 3071 | && startswith (args, "-a")) |
8cae4b3f PA |
3072 | all_threads = 1; |
3073 | ||
3074 | if (!non_stop && all_threads) | |
3075 | error (_("-a is meaningless in all-stop mode.")); | |
3076 | ||
77ebaa5a | 3077 | interrupt_target_1 (all_threads); |
43ff13b4 JM |
3078 | } |
3079 | } | |
3080 | ||
cc86d1cb YQ |
3081 | /* See inferior.h. */ |
3082 | ||
3083 | void | |
3084 | default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file, | |
3085 | struct frame_info *frame, const char *args) | |
c906108c | 3086 | { |
cc86d1cb YQ |
3087 | int regnum; |
3088 | int printed_something = 0; | |
d80b854b | 3089 | |
cc86d1cb YQ |
3090 | for (regnum = 0; |
3091 | regnum < gdbarch_num_regs (gdbarch) | |
3092 | + gdbarch_num_pseudo_regs (gdbarch); | |
3093 | regnum++) | |
23e3a7ac | 3094 | { |
cc86d1cb | 3095 | if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup)) |
23e3a7ac | 3096 | { |
cc86d1cb YQ |
3097 | printed_something = 1; |
3098 | gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1); | |
23e3a7ac | 3099 | } |
23e3a7ac | 3100 | } |
cc86d1cb YQ |
3101 | if (!printed_something) |
3102 | fprintf_filtered (file, "No floating-point info " | |
3103 | "available for this processor.\n"); | |
23e3a7ac AC |
3104 | } |
3105 | ||
3106 | static void | |
3107 | float_info (char *args, int from_tty) | |
3108 | { | |
cc86d1cb YQ |
3109 | struct frame_info *frame; |
3110 | ||
206415a3 DJ |
3111 | if (!target_has_registers) |
3112 | error (_("The program has no registers now.")); | |
3113 | ||
cc86d1cb YQ |
3114 | frame = get_selected_frame (NULL); |
3115 | gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args); | |
c906108c SS |
3116 | } |
3117 | \f | |
c906108c | 3118 | static void |
fba45db2 | 3119 | unset_command (char *args, int from_tty) |
c906108c | 3120 | { |
3e43a32a MS |
3121 | printf_filtered (_("\"unset\" must be followed by the " |
3122 | "name of an unset subcommand.\n")); | |
635c7e8a | 3123 | help_list (unsetlist, "unset ", all_commands, gdb_stdout); |
c906108c SS |
3124 | } |
3125 | ||
145b16a9 UW |
3126 | /* Implement `info proc' family of commands. */ |
3127 | ||
3128 | static void | |
3129 | info_proc_cmd_1 (char *args, enum info_proc_what what, int from_tty) | |
3130 | { | |
3030c96e UW |
3131 | struct gdbarch *gdbarch = get_current_arch (); |
3132 | ||
451b7c33 TT |
3133 | if (!target_info_proc (args, what)) |
3134 | { | |
3135 | if (gdbarch_info_proc_p (gdbarch)) | |
3136 | gdbarch_info_proc (gdbarch, args, what); | |
3137 | else | |
3138 | error (_("Not supported on this target.")); | |
3139 | } | |
145b16a9 UW |
3140 | } |
3141 | ||
3142 | /* Implement `info proc' when given without any futher parameters. */ | |
3143 | ||
3144 | static void | |
3145 | info_proc_cmd (char *args, int from_tty) | |
3146 | { | |
3147 | info_proc_cmd_1 (args, IP_MINIMAL, from_tty); | |
3148 | } | |
3149 | ||
3150 | /* Implement `info proc mappings'. */ | |
3151 | ||
3152 | static void | |
3153 | info_proc_cmd_mappings (char *args, int from_tty) | |
3154 | { | |
3155 | info_proc_cmd_1 (args, IP_MAPPINGS, from_tty); | |
3156 | } | |
3157 | ||
3158 | /* Implement `info proc stat'. */ | |
3159 | ||
3160 | static void | |
3161 | info_proc_cmd_stat (char *args, int from_tty) | |
3162 | { | |
3163 | info_proc_cmd_1 (args, IP_STAT, from_tty); | |
3164 | } | |
3165 | ||
3166 | /* Implement `info proc status'. */ | |
3167 | ||
3168 | static void | |
3169 | info_proc_cmd_status (char *args, int from_tty) | |
3170 | { | |
3171 | info_proc_cmd_1 (args, IP_STATUS, from_tty); | |
3172 | } | |
3173 | ||
3174 | /* Implement `info proc cwd'. */ | |
3175 | ||
3176 | static void | |
3177 | info_proc_cmd_cwd (char *args, int from_tty) | |
3178 | { | |
3179 | info_proc_cmd_1 (args, IP_CWD, from_tty); | |
3180 | } | |
3181 | ||
3182 | /* Implement `info proc cmdline'. */ | |
3183 | ||
3184 | static void | |
3185 | info_proc_cmd_cmdline (char *args, int from_tty) | |
3186 | { | |
3187 | info_proc_cmd_1 (args, IP_CMDLINE, from_tty); | |
3188 | } | |
3189 | ||
3190 | /* Implement `info proc exe'. */ | |
3191 | ||
3192 | static void | |
3193 | info_proc_cmd_exe (char *args, int from_tty) | |
3194 | { | |
3195 | info_proc_cmd_1 (args, IP_EXE, from_tty); | |
3196 | } | |
3197 | ||
3198 | /* Implement `info proc all'. */ | |
3199 | ||
3200 | static void | |
3201 | info_proc_cmd_all (char *args, int from_tty) | |
3202 | { | |
3203 | info_proc_cmd_1 (args, IP_ALL, from_tty); | |
3204 | } | |
3205 | ||
c906108c | 3206 | void |
fba45db2 | 3207 | _initialize_infcmd (void) |
c906108c | 3208 | { |
145b16a9 | 3209 | static struct cmd_list_element *info_proc_cmdlist; |
3cb3b8df | 3210 | struct cmd_list_element *c = NULL; |
6f937416 | 3211 | const char *cmd_name; |
3cb3b8df | 3212 | |
1777feb0 | 3213 | /* Add the filename of the terminal connected to inferior I/O. */ |
0a1ddfa6 SM |
3214 | add_setshow_optional_filename_cmd ("inferior-tty", class_run, |
3215 | &inferior_io_terminal_scratch, _("\ | |
3cb3b8df BR |
3216 | Set terminal for future runs of program being debugged."), _("\ |
3217 | Show terminal for future runs of program being debugged."), _("\ | |
0a1ddfa6 SM |
3218 | Usage: set inferior-tty [TTY]\n\n\ |
3219 | If TTY is omitted, the default behavior of using the same terminal as GDB\n\ | |
3220 | is restored."), | |
3221 | set_inferior_tty_command, | |
3222 | show_inferior_tty_command, | |
3223 | &setlist, &showlist); | |
3cb3b8df | 3224 | add_com_alias ("tty", "set inferior-tty", class_alias, 0); |
c906108c | 3225 | |
6ace3df1 YQ |
3226 | cmd_name = "args"; |
3227 | add_setshow_string_noescape_cmd (cmd_name, class_run, | |
3228 | &inferior_args_scratch, _("\ | |
b4b4ac0b AC |
3229 | Set argument list to give program being debugged when it is started."), _("\ |
3230 | Show argument list to give program being debugged when it is started."), _("\ | |
3231 | Follow this command with any number of args, to be passed to the program."), | |
6ace3df1 YQ |
3232 | set_args_command, |
3233 | show_args_command, | |
3234 | &setlist, &showlist); | |
3235 | c = lookup_cmd (&cmd_name, setlist, "", -1, 1); | |
3236 | gdb_assert (c != NULL); | |
3237 | set_cmd_completer (c, filename_completer); | |
c906108c | 3238 | |
1a966eab AC |
3239 | c = add_cmd ("environment", no_class, environment_info, _("\ |
3240 | The environment to give the program, or one variable's value.\n\ | |
c906108c SS |
3241 | With an argument VAR, prints the value of environment variable VAR to\n\ |
3242 | give the program being debugged. With no arguments, prints the entire\n\ | |
1a966eab | 3243 | environment to be given to the program."), &showlist); |
5ba2abeb | 3244 | set_cmd_completer (c, noop_completer); |
c906108c SS |
3245 | |
3246 | add_prefix_cmd ("unset", no_class, unset_command, | |
1bedd215 | 3247 | _("Complement to certain \"set\" commands."), |
c906108c | 3248 | &unsetlist, "unset ", 0, &cmdlist); |
c5aa993b | 3249 | |
1a966eab AC |
3250 | c = add_cmd ("environment", class_run, unset_environment_command, _("\ |
3251 | Cancel environment variable VAR for the program.\n\ | |
3252 | This does not affect the program until the next \"run\" command."), | |
c5aa993b | 3253 | &unsetlist); |
5ba2abeb | 3254 | set_cmd_completer (c, noop_completer); |
c906108c | 3255 | |
1a966eab AC |
3256 | c = add_cmd ("environment", class_run, set_environment_command, _("\ |
3257 | Set environment variable value to give the program.\n\ | |
c906108c SS |
3258 | Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\ |
3259 | VALUES of environment variables are uninterpreted strings.\n\ | |
1a966eab | 3260 | This does not affect the program until the next \"run\" command."), |
c5aa993b | 3261 | &setlist); |
5ba2abeb | 3262 | set_cmd_completer (c, noop_completer); |
c5aa993b | 3263 | |
1bedd215 AC |
3264 | c = add_com ("path", class_files, path_command, _("\ |
3265 | Add directory DIR(s) to beginning of search path for object files.\n\ | |
c906108c SS |
3266 | $cwd in the path means the current working directory.\n\ |
3267 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
3268 | directories, separated by colons. These directories are searched to find\n\ | |
3e43a32a MS |
3269 | fully linked executable files and separately compiled object files as \ |
3270 | needed.")); | |
5ba2abeb | 3271 | set_cmd_completer (c, filename_completer); |
c906108c | 3272 | |
1a966eab AC |
3273 | c = add_cmd ("paths", no_class, path_info, _("\ |
3274 | Current search path for finding object files.\n\ | |
c906108c SS |
3275 | $cwd in the path means the current working directory.\n\ |
3276 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
3277 | directories, separated by colons. These directories are searched to find\n\ | |
3e43a32a MS |
3278 | fully linked executable files and separately compiled object files as \ |
3279 | needed."), | |
c906108c | 3280 | &showlist); |
5ba2abeb | 3281 | set_cmd_completer (c, noop_completer); |
c906108c | 3282 | |
2277426b PA |
3283 | add_prefix_cmd ("kill", class_run, kill_command, |
3284 | _("Kill execution of program being debugged."), | |
3285 | &killlist, "kill ", 0, &cmdlist); | |
5fd62852 | 3286 | |
1bedd215 AC |
3287 | add_com ("attach", class_run, attach_command, _("\ |
3288 | Attach to a process or file outside of GDB.\n\ | |
c906108c SS |
3289 | This command attaches to another target, of the same type as your last\n\ |
3290 | \"target\" command (\"info files\" will show your target stack).\n\ | |
3291 | The command may take as argument a process id or a device file.\n\ | |
3292 | For a process id, you must have permission to send the process a signal,\n\ | |
3293 | and it must have the same effective uid as the debugger.\n\ | |
3294 | When using \"attach\" with a process id, the debugger finds the\n\ | |
3295 | program running in the process, looking first in the current working\n\ | |
3296 | directory, or (if not found there) using the source file search path\n\ | |
3297 | (see the \"directory\" command). You can also use the \"file\" command\n\ | |
1bedd215 | 3298 | to specify the program, and to load its symbol table.")); |
c906108c | 3299 | |
f73adfeb | 3300 | add_prefix_cmd ("detach", class_run, detach_command, _("\ |
1bedd215 | 3301 | Detach a process or file previously attached.\n\ |
c906108c | 3302 | If a process, it is no longer traced, and it continues its execution. If\n\ |
f73adfeb AS |
3303 | you were debugging a file, the file is closed and gdb no longer accesses it."), |
3304 | &detachlist, "detach ", 0, &cmdlist); | |
c906108c | 3305 | |
1bedd215 AC |
3306 | add_com ("disconnect", class_run, disconnect_command, _("\ |
3307 | Disconnect from a target.\n\ | |
6ad8ae5c | 3308 | The target will wait for another debugger to connect. Not available for\n\ |
1bedd215 | 3309 | all targets.")); |
6ad8ae5c | 3310 | |
de0bea00 | 3311 | c = add_com ("signal", class_run, signal_command, _("\ |
486c7739 MF |
3312 | Continue program with the specified signal.\n\ |
3313 | Usage: signal SIGNAL\n\ | |
2edda2ff | 3314 | The SIGNAL argument is processed the same as the handle command.\n\ |
486c7739 MF |
3315 | \n\ |
3316 | An argument of \"0\" means continue the program without sending it a signal.\n\ | |
3317 | This is useful in cases where the program stopped because of a signal,\n\ | |
81219e53 DE |
3318 | and you want to resume the program while discarding the signal.\n\ |
3319 | \n\ | |
3320 | In a multi-threaded program the signal is delivered to, or discarded from,\n\ | |
3321 | the current thread only.")); | |
3322 | set_cmd_completer (c, signal_completer); | |
3323 | ||
3324 | c = add_com ("queue-signal", class_run, queue_signal_command, _("\ | |
3325 | Queue a signal to be delivered to the current thread when it is resumed.\n\ | |
3326 | Usage: queue-signal SIGNAL\n\ | |
3327 | The SIGNAL argument is processed the same as the handle command.\n\ | |
3328 | It is an error if the handling state of SIGNAL is \"nopass\".\n\ | |
3329 | \n\ | |
3330 | An argument of \"0\" means remove any currently queued signal from\n\ | |
3331 | the current thread. This is useful in cases where the program stopped\n\ | |
3332 | because of a signal, and you want to resume it while discarding the signal.\n\ | |
3333 | \n\ | |
3334 | In a multi-threaded program the signal is queued with, or discarded from,\n\ | |
3335 | the current thread only.")); | |
de0bea00 | 3336 | set_cmd_completer (c, signal_completer); |
c906108c | 3337 | |
1bedd215 AC |
3338 | add_com ("stepi", class_run, stepi_command, _("\ |
3339 | Step one instruction exactly.\n\ | |
486c7739 MF |
3340 | Usage: stepi [N]\n\ |
3341 | Argument N means step N times (or till program stops for another \ | |
3e43a32a | 3342 | reason).")); |
c906108c SS |
3343 | add_com_alias ("si", "stepi", class_alias, 0); |
3344 | ||
1bedd215 AC |
3345 | add_com ("nexti", class_run, nexti_command, _("\ |
3346 | Step one instruction, but proceed through subroutine calls.\n\ | |
486c7739 MF |
3347 | Usage: nexti [N]\n\ |
3348 | Argument N means step N times (or till program stops for another \ | |
3e43a32a | 3349 | reason).")); |
c906108c SS |
3350 | add_com_alias ("ni", "nexti", class_alias, 0); |
3351 | ||
1bedd215 AC |
3352 | add_com ("finish", class_run, finish_command, _("\ |
3353 | Execute until selected stack frame returns.\n\ | |
486c7739 | 3354 | Usage: finish\n\ |
1bedd215 | 3355 | Upon return, the value returned is printed and put in the value history.")); |
0e479716 | 3356 | add_com_alias ("fin", "finish", class_run, 1); |
c906108c | 3357 | |
1bedd215 AC |
3358 | add_com ("next", class_run, next_command, _("\ |
3359 | Step program, proceeding through subroutine calls.\n\ | |
486c7739 MF |
3360 | Usage: next [N]\n\ |
3361 | Unlike \"step\", if the current source line calls a subroutine,\n\ | |
3362 | this command does not enter the subroutine, but instead steps over\n\ | |
dbf6a605 | 3363 | the call, in effect treating it as a single source line.")); |
c906108c | 3364 | add_com_alias ("n", "next", class_run, 1); |
c906108c | 3365 | |
1bedd215 AC |
3366 | add_com ("step", class_run, step_command, _("\ |
3367 | Step program until it reaches a different source line.\n\ | |
486c7739 MF |
3368 | Usage: step [N]\n\ |
3369 | Argument N means step N times (or till program stops for another \ | |
3e43a32a | 3370 | reason).")); |
c906108c SS |
3371 | add_com_alias ("s", "step", class_run, 1); |
3372 | ||
1bedd215 AC |
3373 | c = add_com ("until", class_run, until_command, _("\ |
3374 | Execute until the program reaches a source line greater than the current\n\ | |
3e43a32a MS |
3375 | or a specified location (same args as break command) within the current \ |
3376 | frame.")); | |
5ba2abeb | 3377 | set_cmd_completer (c, location_completer); |
c906108c | 3378 | add_com_alias ("u", "until", class_run, 1); |
c5aa993b | 3379 | |
1bedd215 | 3380 | c = add_com ("advance", class_run, advance_command, _("\ |
3e43a32a MS |
3381 | Continue the program up to the given location (same form as args for break \ |
3382 | command).\n\ | |
1bedd215 | 3383 | Execution will also stop upon exit from the current stack frame.")); |
ae66c1fc EZ |
3384 | set_cmd_completer (c, location_completer); |
3385 | ||
1bedd215 AC |
3386 | c = add_com ("jump", class_run, jump_command, _("\ |
3387 | Continue program being debugged at specified line or address.\n\ | |
486c7739 | 3388 | Usage: jump <location>\n\ |
c906108c | 3389 | Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\ |
1bedd215 | 3390 | for an address to start at.")); |
5ba2abeb | 3391 | set_cmd_completer (c, location_completer); |
c1d780c2 | 3392 | add_com_alias ("j", "jump", class_run, 1); |
c906108c | 3393 | |
df983543 | 3394 | add_com ("continue", class_run, continue_command, _("\ |
1bedd215 | 3395 | Continue program being debugged, after signal or breakpoint.\n\ |
486c7739 | 3396 | Usage: continue [N]\n\ |
c906108c SS |
3397 | If proceeding from breakpoint, a number N may be used as an argument,\n\ |
3398 | which means to set the ignore count of that breakpoint to N - 1 (so that\n\ | |
8cae4b3f PA |
3399 | the breakpoint won't break until the Nth time it is reached).\n\ |
3400 | \n\ | |
3401 | If non-stop mode is enabled, continue only the current thread,\n\ | |
3402 | otherwise all the threads in the program are continued. To \n\ | |
3403 | continue all stopped threads in non-stop mode, use the -a option.\n\ | |
3404 | Specifying -a and an ignore count simultaneously is an error.")); | |
c906108c SS |
3405 | add_com_alias ("c", "cont", class_run, 1); |
3406 | add_com_alias ("fg", "cont", class_run, 1); | |
3407 | ||
1bedd215 AC |
3408 | c = add_com ("run", class_run, run_command, _("\ |
3409 | Start debugged program. You may specify arguments to give it.\n\ | |
c906108c | 3410 | Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\ |
3e43a32a MS |
3411 | Input and output redirection with \">\", \"<\", or \">>\" are also \ |
3412 | allowed.\n\n\ | |
3413 | With no arguments, uses arguments last specified (with \"run\" \ | |
3414 | or \"set args\").\n\ | |
c906108c | 3415 | To cancel previous arguments and run with no arguments,\n\ |
1bedd215 | 3416 | use \"set args\" without arguments.")); |
5ba2abeb | 3417 | set_cmd_completer (c, filename_completer); |
c906108c | 3418 | add_com_alias ("r", "run", class_run, 1); |
c906108c | 3419 | |
1bedd215 | 3420 | c = add_com ("start", class_run, start_command, _("\ |
a4d5f2e0 JB |
3421 | Run the debugged program until the beginning of the main procedure.\n\ |
3422 | You may specify arguments to give to your program, just as with the\n\ | |
1bedd215 | 3423 | \"run\" command.")); |
a4d5f2e0 JB |
3424 | set_cmd_completer (c, filename_completer); |
3425 | ||
0a07590b | 3426 | add_com ("interrupt", class_run, interrupt_command, |
df983543 | 3427 | _("Interrupt the execution of the debugged program.\n\ |
8cae4b3f PA |
3428 | If non-stop mode is enabled, interrupt only the current thread,\n\ |
3429 | otherwise all the threads in the program are stopped. To \n\ | |
3430 | interrupt all running threads in non-stop mode, use the -a option.")); | |
43ff13b4 | 3431 | |
71c24708 | 3432 | c = add_info ("registers", nofp_registers_info, _("\ |
1bedd215 AC |
3433 | List of integer registers and their contents, for selected stack frame.\n\ |
3434 | Register name as argument means describe only that register.")); | |
7194c49b | 3435 | add_info_alias ("r", "registers", 1); |
71c24708 | 3436 | set_cmd_completer (c, reg_or_group_completer); |
c906108c | 3437 | |
71c24708 | 3438 | c = add_info ("all-registers", all_registers_info, _("\ |
1bedd215 AC |
3439 | List of all registers and their contents, for selected stack frame.\n\ |
3440 | Register name as argument means describe only that register.")); | |
71c24708 | 3441 | set_cmd_completer (c, reg_or_group_completer); |
c906108c SS |
3442 | |
3443 | add_info ("program", program_info, | |
1bedd215 | 3444 | _("Execution status of the program.")); |
c906108c SS |
3445 | |
3446 | add_info ("float", float_info, | |
1bedd215 | 3447 | _("Print the status of the floating point unit\n")); |
c906108c | 3448 | |
e76f1f2e | 3449 | add_info ("vector", vector_info, |
1bedd215 | 3450 | _("Print the status of the vector unit\n")); |
145b16a9 UW |
3451 | |
3452 | add_prefix_cmd ("proc", class_info, info_proc_cmd, | |
3453 | _("\ | |
3454 | Show /proc process information about any running process.\n\ | |
3455 | Specify any process id, or use the program being debugged by default."), | |
3456 | &info_proc_cmdlist, "info proc ", | |
3457 | 1/*allow-unknown*/, &infolist); | |
3458 | ||
3459 | add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\ | |
3460 | List of mapped memory regions."), | |
3461 | &info_proc_cmdlist); | |
3462 | ||
3463 | add_cmd ("stat", class_info, info_proc_cmd_stat, _("\ | |
3464 | List process info from /proc/PID/stat."), | |
3465 | &info_proc_cmdlist); | |
3466 | ||
3467 | add_cmd ("status", class_info, info_proc_cmd_status, _("\ | |
3468 | List process info from /proc/PID/status."), | |
3469 | &info_proc_cmdlist); | |
3470 | ||
3471 | add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\ | |
3472 | List current working directory of the process."), | |
3473 | &info_proc_cmdlist); | |
3474 | ||
3475 | add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\ | |
3476 | List command line arguments of the process."), | |
3477 | &info_proc_cmdlist); | |
3478 | ||
3479 | add_cmd ("exe", class_info, info_proc_cmd_exe, _("\ | |
3480 | List absolute filename for executable of the process."), | |
3481 | &info_proc_cmdlist); | |
3482 | ||
3483 | add_cmd ("all", class_info, info_proc_cmd_all, _("\ | |
3484 | List all available /proc info."), | |
3485 | &info_proc_cmdlist); | |
c906108c | 3486 | } |