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