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