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