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