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