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