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