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