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