* ada-lex.l (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int)
[deliverable/binutils-gdb.git] / gdb / infcmd.c
1 /* Memory-access and commands for "inferior" process, for GDB.
2
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
5 Free Software Foundation, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
23
24 #include "defs.h"
25 #include <signal.h>
26 #include "gdb_string.h"
27 #include "symtab.h"
28 #include "gdbtypes.h"
29 #include "frame.h"
30 #include "inferior.h"
31 #include "environ.h"
32 #include "value.h"
33 #include "gdbcmd.h"
34 #include "symfile.h"
35 #include "gdbcore.h"
36 #include "target.h"
37 #include "language.h"
38 #include "symfile.h"
39 #include "objfiles.h"
40 #include "completer.h"
41 #include "ui-out.h"
42 #include "event-top.h"
43 #include "parser-defs.h"
44 #include "regcache.h"
45 #include "reggroups.h"
46 #include "block.h"
47 #include "solib.h"
48 #include <ctype.h>
49 #include "gdb_assert.h"
50 #include "observer.h"
51
52 /* Functions exported for general use, in inferior.h: */
53
54 void all_registers_info (char *, int);
55
56 void registers_info (char *, int);
57
58 void nexti_command (char *, int);
59
60 void stepi_command (char *, int);
61
62 void continue_command (char *, int);
63
64 void interrupt_target_command (char *args, int from_tty);
65
66 /* Local functions: */
67
68 static void nofp_registers_info (char *, int);
69
70 static void print_return_value (int struct_return, struct type *value_type);
71
72 static void finish_command_continuation (struct continuation_arg *);
73
74 static void until_next_command (int);
75
76 static void until_command (char *, int);
77
78 static void path_info (char *, int);
79
80 static void path_command (char *, int);
81
82 static void unset_command (char *, int);
83
84 static void float_info (char *, int);
85
86 static void detach_command (char *, int);
87
88 static void disconnect_command (char *, int);
89
90 static void unset_environment_command (char *, int);
91
92 static void set_environment_command (char *, int);
93
94 static void environment_info (char *, int);
95
96 static void program_info (char *, int);
97
98 static void finish_command (char *, int);
99
100 static void signal_command (char *, int);
101
102 static void jump_command (char *, int);
103
104 static void step_1 (int, int, char *);
105 static void step_once (int skip_subroutines, int single_inst, int count);
106 static void step_1_continuation (struct continuation_arg *arg);
107
108 static void next_command (char *, int);
109
110 static void step_command (char *, int);
111
112 static void run_command (char *, int);
113
114 static void run_no_args_command (char *args, int from_tty);
115
116 static void go_command (char *line_no, int from_tty);
117
118 static int strip_bg_char (char **);
119
120 void _initialize_infcmd (void);
121
122 #define GO_USAGE "Usage: go <location>\n"
123
124 #define ERROR_NO_INFERIOR \
125 if (!target_has_execution) error (_("The program is not being run."));
126
127 /* String containing arguments to give to the program, separated by spaces.
128 Empty string (pointer to '\0') means no args. */
129
130 static char *inferior_args;
131
132 /* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
133 then we must compute INFERIOR_ARGS from this (via the target). */
134
135 static int inferior_argc;
136 static char **inferior_argv;
137
138 /* File name for default use for standard in/out in the inferior. */
139
140 static char *inferior_io_terminal;
141
142 /* Pid of our debugged inferior, or 0 if no inferior now.
143 Since various parts of infrun.c test this to see whether there is a program
144 being debugged it should be nonzero (currently 3 is used) for remote
145 debugging. */
146
147 ptid_t inferior_ptid;
148
149 /* Last signal that the inferior received (why it stopped). */
150
151 enum target_signal stop_signal;
152
153 /* Address at which inferior stopped. */
154
155 CORE_ADDR stop_pc;
156
157 /* Chain containing status of breakpoint(s) that we have stopped at. */
158
159 bpstat stop_bpstat;
160
161 /* Flag indicating that a command has proceeded the inferior past the
162 current breakpoint. */
163
164 int breakpoint_proceeded;
165
166 /* Nonzero if stopped due to a step command. */
167
168 int stop_step;
169
170 /* Nonzero if stopped due to completion of a stack dummy routine. */
171
172 int stop_stack_dummy;
173
174 /* Nonzero if stopped due to a random (unexpected) signal in inferior
175 process. */
176
177 int stopped_by_random_signal;
178
179 /* Range to single step within.
180 If this is nonzero, respond to a single-step signal
181 by continuing to step if the pc is in this range. */
182
183 CORE_ADDR step_range_start; /* Inclusive */
184 CORE_ADDR step_range_end; /* Exclusive */
185
186 /* Stack frame address as of when stepping command was issued.
187 This is how we know when we step into a subroutine call,
188 and how to set the frame for the breakpoint used to step out. */
189
190 struct frame_id step_frame_id;
191
192 enum step_over_calls_kind step_over_calls;
193
194 /* If stepping, nonzero means step count is > 1
195 so don't print frame next time inferior stops
196 if it stops due to stepping. */
197
198 int step_multi;
199
200 /* Environment to use for running inferior,
201 in format described in environ.h. */
202
203 struct gdb_environ *inferior_environ;
204 \f
205 /* Accessor routines. */
206
207 void
208 set_inferior_io_terminal (const char *terminal_name)
209 {
210 if (inferior_io_terminal)
211 xfree (inferior_io_terminal);
212
213 if (!terminal_name)
214 inferior_io_terminal = NULL;
215 else
216 inferior_io_terminal = savestring (terminal_name, strlen (terminal_name));
217 }
218
219 const char *
220 get_inferior_io_terminal (void)
221 {
222 return inferior_io_terminal;
223 }
224
225 char *
226 get_inferior_args (void)
227 {
228 if (inferior_argc != 0)
229 {
230 char *n, *old;
231
232 n = gdbarch_construct_inferior_arguments (current_gdbarch,
233 inferior_argc, inferior_argv);
234 old = set_inferior_args (n);
235 xfree (old);
236 }
237
238 if (inferior_args == NULL)
239 inferior_args = xstrdup ("");
240
241 return inferior_args;
242 }
243
244 char *
245 set_inferior_args (char *newargs)
246 {
247 char *saved_args = inferior_args;
248
249 inferior_args = newargs;
250 inferior_argc = 0;
251 inferior_argv = 0;
252
253 return saved_args;
254 }
255
256 void
257 set_inferior_args_vector (int argc, char **argv)
258 {
259 inferior_argc = argc;
260 inferior_argv = argv;
261 }
262
263 /* Notice when `set args' is run. */
264 static void
265 notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
266 {
267 inferior_argc = 0;
268 inferior_argv = 0;
269 }
270
271 /* Notice when `show args' is run. */
272 static void
273 notice_args_read (struct ui_file *file, int from_tty,
274 struct cmd_list_element *c, const char *value)
275 {
276 deprecated_show_value_hack (file, from_tty, c, value);
277 /* Might compute the value. */
278 get_inferior_args ();
279 }
280
281 \f
282 /* Compute command-line string given argument vector. This does the
283 same shell processing as fork_inferior. */
284 char *
285 construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
286 {
287 char *result;
288
289 if (STARTUP_WITH_SHELL)
290 {
291 /* This holds all the characters considered special to the
292 typical Unix shells. We include `^' because the SunOS
293 /bin/sh treats it as a synonym for `|'. */
294 char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
295 int i;
296 int length = 0;
297 char *out, *cp;
298
299 /* We over-compute the size. It shouldn't matter. */
300 for (i = 0; i < argc; ++i)
301 length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
302
303 result = (char *) xmalloc (length);
304 out = result;
305
306 for (i = 0; i < argc; ++i)
307 {
308 if (i > 0)
309 *out++ = ' ';
310
311 /* Need to handle empty arguments specially. */
312 if (argv[i][0] == '\0')
313 {
314 *out++ = '\'';
315 *out++ = '\'';
316 }
317 else
318 {
319 for (cp = argv[i]; *cp; ++cp)
320 {
321 if (strchr (special, *cp) != NULL)
322 *out++ = '\\';
323 *out++ = *cp;
324 }
325 }
326 }
327 *out = '\0';
328 }
329 else
330 {
331 /* In this case we can't handle arguments that contain spaces,
332 tabs, or newlines -- see breakup_args(). */
333 int i;
334 int length = 0;
335
336 for (i = 0; i < argc; ++i)
337 {
338 char *cp = strchr (argv[i], ' ');
339 if (cp == NULL)
340 cp = strchr (argv[i], '\t');
341 if (cp == NULL)
342 cp = strchr (argv[i], '\n');
343 if (cp != NULL)
344 error (_("can't handle command-line argument containing whitespace"));
345 length += strlen (argv[i]) + 1;
346 }
347
348 result = (char *) xmalloc (length);
349 result[0] = '\0';
350 for (i = 0; i < argc; ++i)
351 {
352 if (i > 0)
353 strcat (result, " ");
354 strcat (result, argv[i]);
355 }
356 }
357
358 return result;
359 }
360 \f
361
362 /* This function detects whether or not a '&' character (indicating
363 background execution) has been added as *the last* of the arguments ARGS
364 of a command. If it has, it removes it and returns 1. Otherwise it
365 does nothing and returns 0. */
366 static int
367 strip_bg_char (char **args)
368 {
369 char *p = NULL;
370
371 p = strchr (*args, '&');
372
373 if (p)
374 {
375 if (p == (*args + strlen (*args) - 1))
376 {
377 if (strlen (*args) > 1)
378 {
379 do
380 p--;
381 while (*p == ' ' || *p == '\t');
382 *(p + 1) = '\0';
383 }
384 else
385 *args = 0;
386 return 1;
387 }
388 }
389 return 0;
390 }
391
392 void
393 tty_command (char *file, int from_tty)
394 {
395 if (file == 0)
396 error_no_arg (_("terminal name for running target process"));
397
398 set_inferior_io_terminal (file);
399 }
400
401 /* Common actions to take after creating any sort of inferior, by any
402 means (running, attaching, connecting, et cetera). The target
403 should be stopped. */
404
405 void
406 post_create_inferior (struct target_ops *target, int from_tty)
407 {
408 if (exec_bfd)
409 {
410 /* Sometimes the platform-specific hook loads initial shared
411 libraries, and sometimes it doesn't. Try to do so first, so
412 that we can add them with the correct value for FROM_TTY. */
413 #ifdef SOLIB_ADD
414 SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
415 #else
416 solib_add (NULL, from_tty, target, auto_solib_add);
417 #endif
418
419 /* Create the hooks to handle shared library load and unload
420 events. */
421 #ifdef SOLIB_CREATE_INFERIOR_HOOK
422 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
423 #else
424 solib_create_inferior_hook ();
425 #endif
426
427 /* Enable any breakpoints which were disabled when the
428 underlying shared library was deleted. */
429 re_enable_breakpoints_in_shlibs ();
430 }
431
432 observer_notify_inferior_created (target, from_tty);
433 }
434
435 /* Kill the inferior if already running. This function is designed
436 to be called when we are about to start the execution of the program
437 from the beginning. Ask the user to confirm that he wants to restart
438 the program being debugged when FROM_TTY is non-null. */
439
440 void
441 kill_if_already_running (int from_tty)
442 {
443 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
444 {
445 if (from_tty
446 && !query ("The program being debugged has been started already.\n\
447 Start it from the beginning? "))
448 error (_("Program not restarted."));
449 target_kill ();
450 #if defined(SOLIB_RESTART)
451 SOLIB_RESTART ();
452 #endif
453 init_wait_for_inferior ();
454 }
455 }
456
457 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
458 a temporary breakpoint at the begining of the main program before
459 running the program. */
460
461 static void
462 run_command_1 (char *args, int from_tty, int tbreak_at_main)
463 {
464 char *exec_file;
465
466 dont_repeat ();
467
468 kill_if_already_running (from_tty);
469 clear_breakpoint_hit_counts ();
470
471 /* Purge old solib objfiles. */
472 objfile_purge_solibs ();
473
474 do_run_cleanups (NULL);
475
476 /* The comment here used to read, "The exec file is re-read every
477 time we do a generic_mourn_inferior, so we just have to worry
478 about the symbol file." The `generic_mourn_inferior' function
479 gets called whenever the program exits. However, suppose the
480 program exits, and *then* the executable file changes? We need
481 to check again here. Since reopen_exec_file doesn't do anything
482 if the timestamp hasn't changed, I don't see the harm. */
483 reopen_exec_file ();
484 reread_symbols ();
485
486 /* Insert the temporary breakpoint if a location was specified. */
487 if (tbreak_at_main)
488 tbreak_command (main_name (), 0);
489
490 exec_file = (char *) get_exec_file (0);
491
492 /* We keep symbols from add-symbol-file, on the grounds that the
493 user might want to add some symbols before running the program
494 (right?). But sometimes (dynamic loading where the user manually
495 introduces the new symbols with add-symbol-file), the code which
496 the symbols describe does not persist between runs. Currently
497 the user has to manually nuke all symbols between runs if they
498 want them to go away (PR 2207). This is probably reasonable. */
499
500 if (!args)
501 {
502 if (target_can_async_p ())
503 async_disable_stdin ();
504 }
505 else
506 {
507 int async_exec = strip_bg_char (&args);
508
509 /* If we get a request for running in the bg but the target
510 doesn't support it, error out. */
511 if (async_exec && !target_can_async_p ())
512 error (_("Asynchronous execution not supported on this target."));
513
514 /* If we don't get a request of running in the bg, then we need
515 to simulate synchronous (fg) execution. */
516 if (!async_exec && target_can_async_p ())
517 {
518 /* Simulate synchronous execution */
519 async_disable_stdin ();
520 }
521
522 /* If there were other args, beside '&', process them. */
523 if (args)
524 {
525 char *old_args = set_inferior_args (xstrdup (args));
526 xfree (old_args);
527 }
528 }
529
530 if (from_tty)
531 {
532 ui_out_field_string (uiout, NULL, "Starting program");
533 ui_out_text (uiout, ": ");
534 if (exec_file)
535 ui_out_field_string (uiout, "execfile", exec_file);
536 ui_out_spaces (uiout, 1);
537 /* We call get_inferior_args() because we might need to compute
538 the value now. */
539 ui_out_field_string (uiout, "infargs", get_inferior_args ());
540 ui_out_text (uiout, "\n");
541 ui_out_flush (uiout);
542 }
543
544 /* We call get_inferior_args() because we might need to compute
545 the value now. */
546 target_create_inferior (exec_file, get_inferior_args (),
547 environ_vector (inferior_environ), from_tty);
548
549 post_create_inferior (&current_target, from_tty);
550
551 /* Start the target running. */
552 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
553 }
554
555
556 static void
557 run_command (char *args, int from_tty)
558 {
559 run_command_1 (args, from_tty, 0);
560 }
561
562 static void
563 run_no_args_command (char *args, int from_tty)
564 {
565 char *old_args = set_inferior_args (xstrdup (""));
566 xfree (old_args);
567 }
568 \f
569
570 /* Start the execution of the program up until the beginning of the main
571 program. */
572
573 static void
574 start_command (char *args, int from_tty)
575 {
576 /* Some languages such as Ada need to search inside the program
577 minimal symbols for the location where to put the temporary
578 breakpoint before starting. */
579 if (!have_minimal_symbols ())
580 error (_("No symbol table loaded. Use the \"file\" command."));
581
582 /* Run the program until reaching the main procedure... */
583 run_command_1 (args, from_tty, 1);
584 }
585
586 void
587 continue_command (char *proc_count_exp, int from_tty)
588 {
589 int async_exec = 0;
590 ERROR_NO_INFERIOR;
591
592 /* Find out whether we must run in the background. */
593 if (proc_count_exp != NULL)
594 async_exec = strip_bg_char (&proc_count_exp);
595
596 /* If we must run in the background, but the target can't do it,
597 error out. */
598 if (async_exec && !target_can_async_p ())
599 error (_("Asynchronous execution not supported on this target."));
600
601 /* If we are not asked to run in the bg, then prepare to run in the
602 foreground, synchronously. */
603 if (!async_exec && target_can_async_p ())
604 {
605 /* Simulate synchronous execution */
606 async_disable_stdin ();
607 }
608
609 /* If have argument (besides '&'), set proceed count of breakpoint
610 we stopped at. */
611 if (proc_count_exp != NULL)
612 {
613 bpstat bs = stop_bpstat;
614 int num = bpstat_num (&bs);
615 if (num == 0 && from_tty)
616 {
617 printf_filtered
618 ("Not stopped at any breakpoint; argument ignored.\n");
619 }
620 while (num != 0)
621 {
622 set_ignore_count (num,
623 parse_and_eval_long (proc_count_exp) - 1,
624 from_tty);
625 /* set_ignore_count prints a message ending with a period.
626 So print two spaces before "Continuing.". */
627 if (from_tty)
628 printf_filtered (" ");
629 num = bpstat_num (&bs);
630 }
631 }
632
633 if (from_tty)
634 printf_filtered (_("Continuing.\n"));
635
636 clear_proceed_status ();
637
638 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
639 }
640 \f
641 /* Step until outside of current statement. */
642
643 static void
644 step_command (char *count_string, int from_tty)
645 {
646 step_1 (0, 0, count_string);
647 }
648
649 /* Likewise, but skip over subroutine calls as if single instructions. */
650
651 static void
652 next_command (char *count_string, int from_tty)
653 {
654 step_1 (1, 0, count_string);
655 }
656
657 /* Likewise, but step only one instruction. */
658
659 void
660 stepi_command (char *count_string, int from_tty)
661 {
662 step_1 (0, 1, count_string);
663 }
664
665 void
666 nexti_command (char *count_string, int from_tty)
667 {
668 step_1 (1, 1, count_string);
669 }
670
671 static void
672 disable_longjmp_breakpoint_cleanup (void *ignore)
673 {
674 disable_longjmp_breakpoint ();
675 }
676
677 static void
678 step_1 (int skip_subroutines, int single_inst, char *count_string)
679 {
680 int count = 1;
681 struct frame_info *frame;
682 struct cleanup *cleanups = 0;
683 int async_exec = 0;
684
685 ERROR_NO_INFERIOR;
686
687 if (count_string)
688 async_exec = strip_bg_char (&count_string);
689
690 /* If we get a request for running in the bg but the target
691 doesn't support it, error out. */
692 if (async_exec && !target_can_async_p ())
693 error (_("Asynchronous execution not supported on this target."));
694
695 /* If we don't get a request of running in the bg, then we need
696 to simulate synchronous (fg) execution. */
697 if (!async_exec && target_can_async_p ())
698 {
699 /* Simulate synchronous execution */
700 async_disable_stdin ();
701 }
702
703 count = count_string ? parse_and_eval_long (count_string) : 1;
704
705 if (!single_inst || skip_subroutines) /* leave si command alone */
706 {
707 enable_longjmp_breakpoint ();
708 if (!target_can_async_p ())
709 cleanups = make_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
710 else
711 make_exec_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
712 }
713
714 /* In synchronous case, all is well, just use the regular for loop. */
715 if (!target_can_async_p ())
716 {
717 for (; count > 0; count--)
718 {
719 clear_proceed_status ();
720
721 frame = get_current_frame ();
722 if (!frame) /* Avoid coredump here. Why tho? */
723 error (_("No current frame"));
724 step_frame_id = get_frame_id (frame);
725
726 if (!single_inst)
727 {
728 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
729 if (step_range_end == 0)
730 {
731 char *name;
732 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
733 &step_range_end) == 0)
734 error (_("Cannot find bounds of current function"));
735
736 target_terminal_ours ();
737 printf_filtered (_("\
738 Single stepping until exit from function %s, \n\
739 which has no line number information.\n"), name);
740 }
741 }
742 else
743 {
744 /* Say we are stepping, but stop after one insn whatever it does. */
745 step_range_start = step_range_end = 1;
746 if (!skip_subroutines)
747 /* It is stepi.
748 Don't step over function calls, not even to functions lacking
749 line numbers. */
750 step_over_calls = STEP_OVER_NONE;
751 }
752
753 if (skip_subroutines)
754 step_over_calls = STEP_OVER_ALL;
755
756 step_multi = (count > 1);
757 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
758
759 if (!stop_step)
760 break;
761 }
762
763 if (!single_inst || skip_subroutines)
764 do_cleanups (cleanups);
765 return;
766 }
767 /* In case of asynchronous target things get complicated, do only
768 one step for now, before returning control to the event loop. Let
769 the continuation figure out how many other steps we need to do,
770 and handle them one at the time, through step_once(). */
771 else
772 {
773 if (target_can_async_p ())
774 step_once (skip_subroutines, single_inst, count);
775 }
776 }
777
778 /* Called after we are done with one step operation, to check whether
779 we need to step again, before we print the prompt and return control
780 to the user. If count is > 1, we will need to do one more call to
781 proceed(), via step_once(). Basically it is like step_once and
782 step_1_continuation are co-recursive. */
783 static void
784 step_1_continuation (struct continuation_arg *arg)
785 {
786 int count;
787 int skip_subroutines;
788 int single_inst;
789
790 skip_subroutines = arg->data.integer;
791 single_inst = arg->next->data.integer;
792 count = arg->next->next->data.integer;
793
794 if (stop_step)
795 step_once (skip_subroutines, single_inst, count - 1);
796 else
797 if (!single_inst || skip_subroutines)
798 do_exec_cleanups (ALL_CLEANUPS);
799 }
800
801 /* Do just one step operation. If count >1 we will have to set up a
802 continuation to be done after the target stops (after this one
803 step). This is useful to implement the 'step n' kind of commands, in
804 case of asynchronous targets. We had to split step_1 into two parts,
805 one to be done before proceed() and one afterwards. This function is
806 called in case of step n with n>1, after the first step operation has
807 been completed.*/
808 static void
809 step_once (int skip_subroutines, int single_inst, int count)
810 {
811 struct continuation_arg *arg1;
812 struct continuation_arg *arg2;
813 struct continuation_arg *arg3;
814 struct frame_info *frame;
815
816 if (count > 0)
817 {
818 clear_proceed_status ();
819
820 frame = get_current_frame ();
821 if (!frame) /* Avoid coredump here. Why tho? */
822 error (_("No current frame"));
823 step_frame_id = get_frame_id (frame);
824
825 if (!single_inst)
826 {
827 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
828
829 /* If we have no line info, switch to stepi mode. */
830 if (step_range_end == 0 && step_stop_if_no_debug)
831 {
832 step_range_start = step_range_end = 1;
833 }
834 else if (step_range_end == 0)
835 {
836 char *name;
837 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
838 &step_range_end) == 0)
839 error (_("Cannot find bounds of current function"));
840
841 target_terminal_ours ();
842 printf_filtered (_("\
843 Single stepping until exit from function %s, \n\
844 which has no line number information.\n"), name);
845 }
846 }
847 else
848 {
849 /* Say we are stepping, but stop after one insn whatever it does. */
850 step_range_start = step_range_end = 1;
851 if (!skip_subroutines)
852 /* It is stepi.
853 Don't step over function calls, not even to functions lacking
854 line numbers. */
855 step_over_calls = STEP_OVER_NONE;
856 }
857
858 if (skip_subroutines)
859 step_over_calls = STEP_OVER_ALL;
860
861 step_multi = (count > 1);
862 arg1 =
863 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
864 arg2 =
865 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
866 arg3 =
867 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
868 arg1->next = arg2;
869 arg1->data.integer = skip_subroutines;
870 arg2->next = arg3;
871 arg2->data.integer = single_inst;
872 arg3->next = NULL;
873 arg3->data.integer = count;
874 add_intermediate_continuation (step_1_continuation, arg1);
875 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
876 }
877 }
878
879 \f
880 /* Continue program at specified address. */
881
882 static void
883 jump_command (char *arg, int from_tty)
884 {
885 CORE_ADDR addr;
886 struct symtabs_and_lines sals;
887 struct symtab_and_line sal;
888 struct symbol *fn;
889 struct symbol *sfn;
890 int async_exec = 0;
891
892 ERROR_NO_INFERIOR;
893
894 /* Find out whether we must run in the background. */
895 if (arg != NULL)
896 async_exec = strip_bg_char (&arg);
897
898 /* If we must run in the background, but the target can't do it,
899 error out. */
900 if (async_exec && !target_can_async_p ())
901 error (_("Asynchronous execution not supported on this target."));
902
903 /* If we are not asked to run in the bg, then prepare to run in the
904 foreground, synchronously. */
905 if (!async_exec && target_can_async_p ())
906 {
907 /* Simulate synchronous execution */
908 async_disable_stdin ();
909 }
910
911 if (!arg)
912 error_no_arg (_("starting address"));
913
914 sals = decode_line_spec_1 (arg, 1);
915 if (sals.nelts != 1)
916 {
917 error (_("Unreasonable jump request"));
918 }
919
920 sal = sals.sals[0];
921 xfree (sals.sals);
922
923 if (sal.symtab == 0 && sal.pc == 0)
924 error (_("No source file has been specified."));
925
926 resolve_sal_pc (&sal); /* May error out */
927
928 /* See if we are trying to jump to another function. */
929 fn = get_frame_function (get_current_frame ());
930 sfn = find_pc_function (sal.pc);
931 if (fn != NULL && sfn != fn)
932 {
933 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
934 SYMBOL_PRINT_NAME (fn)))
935 {
936 error (_("Not confirmed."));
937 /* NOTREACHED */
938 }
939 }
940
941 if (sfn != NULL)
942 {
943 fixup_symbol_section (sfn, 0);
944 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
945 !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
946 {
947 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
948 {
949 error (_("Not confirmed."));
950 /* NOTREACHED */
951 }
952 }
953 }
954
955 addr = sal.pc;
956
957 if (from_tty)
958 {
959 printf_filtered (_("Continuing at "));
960 deprecated_print_address_numeric (addr, 1, gdb_stdout);
961 printf_filtered (".\n");
962 }
963
964 clear_proceed_status ();
965 proceed (addr, TARGET_SIGNAL_0, 0);
966 }
967 \f
968
969 /* Go to line or address in current procedure */
970 static void
971 go_command (char *line_no, int from_tty)
972 {
973 if (line_no == (char *) NULL || !*line_no)
974 printf_filtered (GO_USAGE);
975 else
976 {
977 tbreak_command (line_no, from_tty);
978 jump_command (line_no, from_tty);
979 }
980 }
981 \f
982
983 /* Continue program giving it specified signal. */
984
985 static void
986 signal_command (char *signum_exp, int from_tty)
987 {
988 enum target_signal oursig;
989
990 dont_repeat (); /* Too dangerous. */
991 ERROR_NO_INFERIOR;
992
993 if (!signum_exp)
994 error_no_arg (_("signal number"));
995
996 /* It would be even slicker to make signal names be valid expressions,
997 (the type could be "enum $signal" or some such), then the user could
998 assign them to convenience variables. */
999 oursig = target_signal_from_name (signum_exp);
1000
1001 if (oursig == TARGET_SIGNAL_UNKNOWN)
1002 {
1003 /* No, try numeric. */
1004 int num = parse_and_eval_long (signum_exp);
1005
1006 if (num == 0)
1007 oursig = TARGET_SIGNAL_0;
1008 else
1009 oursig = target_signal_from_command (num);
1010 }
1011
1012 if (from_tty)
1013 {
1014 if (oursig == TARGET_SIGNAL_0)
1015 printf_filtered (_("Continuing with no signal.\n"));
1016 else
1017 printf_filtered (_("Continuing with signal %s.\n"),
1018 target_signal_to_name (oursig));
1019 }
1020
1021 clear_proceed_status ();
1022 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1023 FIXME: Neither should "signal foo" but when I tried passing
1024 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1025 tried to track down yet. */
1026 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
1027 }
1028
1029 /* Proceed until we reach a different source line with pc greater than
1030 our current one or exit the function. We skip calls in both cases.
1031
1032 Note that eventually this command should probably be changed so
1033 that only source lines are printed out when we hit the breakpoint
1034 we set. This may involve changes to wait_for_inferior and the
1035 proceed status code. */
1036
1037 static void
1038 until_next_command (int from_tty)
1039 {
1040 struct frame_info *frame;
1041 CORE_ADDR pc;
1042 struct symbol *func;
1043 struct symtab_and_line sal;
1044
1045 clear_proceed_status ();
1046
1047 frame = get_current_frame ();
1048
1049 /* Step until either exited from this function or greater
1050 than the current line (if in symbolic section) or pc (if
1051 not). */
1052
1053 pc = read_pc ();
1054 func = find_pc_function (pc);
1055
1056 if (!func)
1057 {
1058 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
1059
1060 if (msymbol == NULL)
1061 error (_("Execution is not within a known function."));
1062
1063 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
1064 step_range_end = pc;
1065 }
1066 else
1067 {
1068 sal = find_pc_line (pc, 0);
1069
1070 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1071 step_range_end = sal.end;
1072 }
1073
1074 step_over_calls = STEP_OVER_ALL;
1075 step_frame_id = get_frame_id (frame);
1076
1077 step_multi = 0; /* Only one call to proceed */
1078
1079 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1080 }
1081
1082 static void
1083 until_command (char *arg, int from_tty)
1084 {
1085 int async_exec = 0;
1086
1087 if (!target_has_execution)
1088 error (_("The program is not running."));
1089
1090 /* Find out whether we must run in the background. */
1091 if (arg != NULL)
1092 async_exec = strip_bg_char (&arg);
1093
1094 /* If we must run in the background, but the target can't do it,
1095 error out. */
1096 if (async_exec && !target_can_async_p ())
1097 error (_("Asynchronous execution not supported on this target."));
1098
1099 /* If we are not asked to run in the bg, then prepare to run in the
1100 foreground, synchronously. */
1101 if (!async_exec && target_can_async_p ())
1102 {
1103 /* Simulate synchronous execution */
1104 async_disable_stdin ();
1105 }
1106
1107 if (arg)
1108 until_break_command (arg, from_tty, 0);
1109 else
1110 until_next_command (from_tty);
1111 }
1112
1113 static void
1114 advance_command (char *arg, int from_tty)
1115 {
1116 int async_exec = 0;
1117
1118 if (!target_has_execution)
1119 error (_("The program is not running."));
1120
1121 if (arg == NULL)
1122 error_no_arg (_("a location"));
1123
1124 /* Find out whether we must run in the background. */
1125 if (arg != NULL)
1126 async_exec = strip_bg_char (&arg);
1127
1128 /* If we must run in the background, but the target can't do it,
1129 error out. */
1130 if (async_exec && !target_can_async_p ())
1131 error (_("Asynchronous execution not supported on this target."));
1132
1133 /* If we are not asked to run in the bg, then prepare to run in the
1134 foreground, synchronously. */
1135 if (!async_exec && target_can_async_p ())
1136 {
1137 /* Simulate synchronous execution. */
1138 async_disable_stdin ();
1139 }
1140
1141 until_break_command (arg, from_tty, 1);
1142 }
1143 \f
1144 /* Print the result of a function at the end of a 'finish' command. */
1145
1146 static void
1147 print_return_value (int struct_return, struct type *value_type)
1148 {
1149 struct gdbarch *gdbarch = current_gdbarch;
1150 struct cleanup *old_chain;
1151 struct ui_stream *stb;
1152 struct value *value;
1153
1154 CHECK_TYPEDEF (value_type);
1155 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1156
1157 /* FIXME: 2003-09-27: When returning from a nested inferior function
1158 call, it's possible (with no help from the architecture vector)
1159 to locate and return/print a "struct return" value. This is just
1160 a more complicated case of what is already being done in in the
1161 inferior function call code. In fact, when inferior function
1162 calls are made async, this will likely be made the norm. */
1163
1164 switch (gdbarch_return_value (gdbarch, value_type, NULL, NULL, NULL))
1165 {
1166 case RETURN_VALUE_REGISTER_CONVENTION:
1167 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1168 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1169 value = allocate_value (value_type);
1170 gdbarch_return_value (current_gdbarch, value_type, stop_registers,
1171 value_contents_raw (value), NULL);
1172 break;
1173 case RETURN_VALUE_STRUCT_CONVENTION:
1174 value = NULL;
1175 break;
1176 default:
1177 internal_error (__FILE__, __LINE__, _("bad switch"));
1178 }
1179
1180 if (value)
1181 {
1182 /* Print it. */
1183 stb = ui_out_stream_new (uiout);
1184 old_chain = make_cleanup_ui_out_stream_delete (stb);
1185 ui_out_text (uiout, "Value returned is ");
1186 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1187 record_latest_value (value));
1188 ui_out_text (uiout, " = ");
1189 value_print (value, stb->stream, 0, Val_no_prettyprint);
1190 ui_out_field_stream (uiout, "return-value", stb);
1191 ui_out_text (uiout, "\n");
1192 do_cleanups (old_chain);
1193 }
1194 else
1195 {
1196 ui_out_text (uiout, "Value returned has type: ");
1197 ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1198 ui_out_text (uiout, ".");
1199 ui_out_text (uiout, " Cannot determine contents\n");
1200 }
1201 }
1202
1203 /* Stuff that needs to be done by the finish command after the target
1204 has stopped. In asynchronous mode, we wait for the target to stop
1205 in the call to poll or select in the event loop, so it is
1206 impossible to do all the stuff as part of the finish_command
1207 function itself. The only chance we have to complete this command
1208 is in fetch_inferior_event, which is called by the event loop as
1209 soon as it detects that the target has stopped. This function is
1210 called via the cmd_continuation pointer. */
1211
1212 static void
1213 finish_command_continuation (struct continuation_arg *arg)
1214 {
1215 struct symbol *function;
1216 struct breakpoint *breakpoint;
1217 struct cleanup *cleanups;
1218
1219 breakpoint = (struct breakpoint *) arg->data.pointer;
1220 function = (struct symbol *) arg->next->data.pointer;
1221 cleanups = (struct cleanup *) arg->next->next->data.pointer;
1222
1223 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1224 && function != NULL)
1225 {
1226 struct type *value_type;
1227 int struct_return;
1228 int gcc_compiled;
1229
1230 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1231 if (!value_type)
1232 internal_error (__FILE__, __LINE__,
1233 _("finish_command: function has no target type"));
1234
1235 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
1236 {
1237 do_exec_cleanups (cleanups);
1238 return;
1239 }
1240
1241 CHECK_TYPEDEF (value_type);
1242 gcc_compiled = BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function));
1243 struct_return = using_struct_return (value_type, gcc_compiled);
1244
1245 print_return_value (struct_return, value_type);
1246 }
1247
1248 do_exec_cleanups (cleanups);
1249 }
1250
1251 /* "finish": Set a temporary breakpoint at the place the selected
1252 frame will return to, then continue. */
1253
1254 static void
1255 finish_command (char *arg, int from_tty)
1256 {
1257 struct symtab_and_line sal;
1258 struct frame_info *frame;
1259 struct symbol *function;
1260 struct breakpoint *breakpoint;
1261 struct cleanup *old_chain;
1262 struct continuation_arg *arg1, *arg2, *arg3;
1263
1264 int async_exec = 0;
1265
1266 /* Find out whether we must run in the background. */
1267 if (arg != NULL)
1268 async_exec = strip_bg_char (&arg);
1269
1270 /* If we must run in the background, but the target can't do it,
1271 error out. */
1272 if (async_exec && !target_can_async_p ())
1273 error (_("Asynchronous execution not supported on this target."));
1274
1275 /* If we are not asked to run in the bg, then prepare to run in the
1276 foreground, synchronously. */
1277 if (!async_exec && target_can_async_p ())
1278 {
1279 /* Simulate synchronous execution. */
1280 async_disable_stdin ();
1281 }
1282
1283 if (arg)
1284 error (_("The \"finish\" command does not take any arguments."));
1285 if (!target_has_execution)
1286 error (_("The program is not running."));
1287 if (deprecated_selected_frame == NULL)
1288 error (_("No selected frame."));
1289
1290 frame = get_prev_frame (deprecated_selected_frame);
1291 if (frame == 0)
1292 error (_("\"finish\" not meaningful in the outermost frame."));
1293
1294 clear_proceed_status ();
1295
1296 sal = find_pc_line (get_frame_pc (frame), 0);
1297 sal.pc = get_frame_pc (frame);
1298
1299 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish);
1300
1301 if (!target_can_async_p ())
1302 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1303 else
1304 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
1305
1306 /* Find the function we will return from. */
1307
1308 function = find_pc_function (get_frame_pc (deprecated_selected_frame));
1309
1310 /* Print info on the selected frame, including level number but not
1311 source. */
1312 if (from_tty)
1313 {
1314 printf_filtered (_("Run till exit from "));
1315 print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
1316 }
1317
1318 /* If running asynchronously and the target support asynchronous
1319 execution, set things up for the rest of the finish command to be
1320 completed later on, when gdb has detected that the target has
1321 stopped, in fetch_inferior_event. */
1322 if (target_can_async_p ())
1323 {
1324 arg1 =
1325 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1326 arg2 =
1327 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1328 arg3 =
1329 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1330 arg1->next = arg2;
1331 arg2->next = arg3;
1332 arg3->next = NULL;
1333 arg1->data.pointer = breakpoint;
1334 arg2->data.pointer = function;
1335 arg3->data.pointer = old_chain;
1336 add_continuation (finish_command_continuation, arg1);
1337 }
1338
1339 proceed_to_finish = 1; /* We want stop_registers, please... */
1340 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1341
1342 /* Do this only if not running asynchronously or if the target
1343 cannot do async execution. Otherwise, complete this command when
1344 the target actually stops, in fetch_inferior_event. */
1345 if (!target_can_async_p ())
1346 {
1347 /* Did we stop at our breakpoint? */
1348 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1349 && function != NULL)
1350 {
1351 struct type *value_type;
1352 int struct_return;
1353 int gcc_compiled;
1354
1355 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1356 if (!value_type)
1357 internal_error (__FILE__, __LINE__,
1358 _("finish_command: function has no target type"));
1359
1360 /* FIXME: Shouldn't we do the cleanups before returning? */
1361 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
1362 return;
1363
1364 CHECK_TYPEDEF (value_type);
1365 gcc_compiled = BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function));
1366 struct_return = using_struct_return (value_type, gcc_compiled);
1367
1368 print_return_value (struct_return, value_type);
1369 }
1370
1371 do_cleanups (old_chain);
1372 }
1373 }
1374 \f
1375
1376 static void
1377 program_info (char *args, int from_tty)
1378 {
1379 bpstat bs = stop_bpstat;
1380 int num = bpstat_num (&bs);
1381
1382 if (!target_has_execution)
1383 {
1384 printf_filtered (_("The program being debugged is not being run.\n"));
1385 return;
1386 }
1387
1388 target_files_info ();
1389 printf_filtered (_("Program stopped at %s.\n"),
1390 hex_string ((unsigned long) stop_pc));
1391 if (stop_step)
1392 printf_filtered (_("It stopped after being stepped.\n"));
1393 else if (num != 0)
1394 {
1395 /* There may be several breakpoints in the same place, so this
1396 isn't as strange as it seems. */
1397 while (num != 0)
1398 {
1399 if (num < 0)
1400 {
1401 printf_filtered (_("\
1402 It stopped at a breakpoint that has since been deleted.\n"));
1403 }
1404 else
1405 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1406 num = bpstat_num (&bs);
1407 }
1408 }
1409 else if (stop_signal != TARGET_SIGNAL_0)
1410 {
1411 printf_filtered (_("It stopped with signal %s, %s.\n"),
1412 target_signal_to_name (stop_signal),
1413 target_signal_to_string (stop_signal));
1414 }
1415
1416 if (!from_tty)
1417 {
1418 printf_filtered (_("\
1419 Type \"info stack\" or \"info registers\" for more information.\n"));
1420 }
1421 }
1422 \f
1423 static void
1424 environment_info (char *var, int from_tty)
1425 {
1426 if (var)
1427 {
1428 char *val = get_in_environ (inferior_environ, var);
1429 if (val)
1430 {
1431 puts_filtered (var);
1432 puts_filtered (" = ");
1433 puts_filtered (val);
1434 puts_filtered ("\n");
1435 }
1436 else
1437 {
1438 puts_filtered ("Environment variable \"");
1439 puts_filtered (var);
1440 puts_filtered ("\" not defined.\n");
1441 }
1442 }
1443 else
1444 {
1445 char **vector = environ_vector (inferior_environ);
1446 while (*vector)
1447 {
1448 puts_filtered (*vector++);
1449 puts_filtered ("\n");
1450 }
1451 }
1452 }
1453
1454 static void
1455 set_environment_command (char *arg, int from_tty)
1456 {
1457 char *p, *val, *var;
1458 int nullset = 0;
1459
1460 if (arg == 0)
1461 error_no_arg (_("environment variable and value"));
1462
1463 /* Find seperation between variable name and value */
1464 p = (char *) strchr (arg, '=');
1465 val = (char *) strchr (arg, ' ');
1466
1467 if (p != 0 && val != 0)
1468 {
1469 /* We have both a space and an equals. If the space is before the
1470 equals, walk forward over the spaces til we see a nonspace
1471 (possibly the equals). */
1472 if (p > val)
1473 while (*val == ' ')
1474 val++;
1475
1476 /* Now if the = is after the char following the spaces,
1477 take the char following the spaces. */
1478 if (p > val)
1479 p = val - 1;
1480 }
1481 else if (val != 0 && p == 0)
1482 p = val;
1483
1484 if (p == arg)
1485 error_no_arg (_("environment variable to set"));
1486
1487 if (p == 0 || p[1] == 0)
1488 {
1489 nullset = 1;
1490 if (p == 0)
1491 p = arg + strlen (arg); /* So that savestring below will work */
1492 }
1493 else
1494 {
1495 /* Not setting variable value to null */
1496 val = p + 1;
1497 while (*val == ' ' || *val == '\t')
1498 val++;
1499 }
1500
1501 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1502 p--;
1503
1504 var = savestring (arg, p - arg);
1505 if (nullset)
1506 {
1507 printf_filtered (_("\
1508 Setting environment variable \"%s\" to null value.\n"),
1509 var);
1510 set_in_environ (inferior_environ, var, "");
1511 }
1512 else
1513 set_in_environ (inferior_environ, var, val);
1514 xfree (var);
1515 }
1516
1517 static void
1518 unset_environment_command (char *var, int from_tty)
1519 {
1520 if (var == 0)
1521 {
1522 /* If there is no argument, delete all environment variables.
1523 Ask for confirmation if reading from the terminal. */
1524 if (!from_tty || query (_("Delete all environment variables? ")))
1525 {
1526 free_environ (inferior_environ);
1527 inferior_environ = make_environ ();
1528 }
1529 }
1530 else
1531 unset_in_environ (inferior_environ, var);
1532 }
1533
1534 /* Handle the execution path (PATH variable) */
1535
1536 static const char path_var_name[] = "PATH";
1537
1538 static void
1539 path_info (char *args, int from_tty)
1540 {
1541 puts_filtered ("Executable and object file path: ");
1542 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1543 puts_filtered ("\n");
1544 }
1545
1546 /* Add zero or more directories to the front of the execution path. */
1547
1548 static void
1549 path_command (char *dirname, int from_tty)
1550 {
1551 char *exec_path;
1552 char *env;
1553 dont_repeat ();
1554 env = get_in_environ (inferior_environ, path_var_name);
1555 /* Can be null if path is not set */
1556 if (!env)
1557 env = "";
1558 exec_path = xstrdup (env);
1559 mod_path (dirname, &exec_path);
1560 set_in_environ (inferior_environ, path_var_name, exec_path);
1561 xfree (exec_path);
1562 if (from_tty)
1563 path_info ((char *) NULL, from_tty);
1564 }
1565 \f
1566
1567 /* Print out the machine register regnum. If regnum is -1, print all
1568 registers (print_all == 1) or all non-float and non-vector
1569 registers (print_all == 0).
1570
1571 For most machines, having all_registers_info() print the
1572 register(s) one per line is good enough. If a different format is
1573 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1574 regs), or there is an existing convention for showing all the
1575 registers, define the architecture method PRINT_REGISTERS_INFO to
1576 provide that format. */
1577
1578 void
1579 default_print_registers_info (struct gdbarch *gdbarch,
1580 struct ui_file *file,
1581 struct frame_info *frame,
1582 int regnum, int print_all)
1583 {
1584 int i;
1585 const int numregs = NUM_REGS + NUM_PSEUDO_REGS;
1586 gdb_byte buffer[MAX_REGISTER_SIZE];
1587
1588 for (i = 0; i < numregs; i++)
1589 {
1590 /* Decide between printing all regs, non-float / vector regs, or
1591 specific reg. */
1592 if (regnum == -1)
1593 {
1594 if (print_all)
1595 {
1596 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1597 continue;
1598 }
1599 else
1600 {
1601 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
1602 continue;
1603 }
1604 }
1605 else
1606 {
1607 if (i != regnum)
1608 continue;
1609 }
1610
1611 /* If the register name is empty, it is undefined for this
1612 processor, so don't display anything. */
1613 if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0')
1614 continue;
1615
1616 fputs_filtered (REGISTER_NAME (i), file);
1617 print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), file);
1618
1619 /* Get the data in raw format. */
1620 if (! frame_register_read (frame, i, buffer))
1621 {
1622 fprintf_filtered (file, "*value not available*\n");
1623 continue;
1624 }
1625
1626 /* If virtual format is floating, print it that way, and in raw
1627 hex. */
1628 if (TYPE_CODE (register_type (current_gdbarch, i)) == TYPE_CODE_FLT)
1629 {
1630 int j;
1631
1632 val_print (register_type (current_gdbarch, i), buffer, 0, 0,
1633 file, 0, 1, 0, Val_pretty_default);
1634
1635 fprintf_filtered (file, "\t(raw 0x");
1636 for (j = 0; j < register_size (current_gdbarch, i); j++)
1637 {
1638 int idx;
1639 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1640 idx = j;
1641 else
1642 idx = register_size (current_gdbarch, i) - 1 - j;
1643 fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
1644 }
1645 fprintf_filtered (file, ")");
1646 }
1647 else
1648 {
1649 /* Print the register in hex. */
1650 val_print (register_type (current_gdbarch, i), buffer, 0, 0,
1651 file, 'x', 1, 0, Val_pretty_default);
1652 /* If not a vector register, print it also according to its
1653 natural format. */
1654 if (TYPE_VECTOR (register_type (current_gdbarch, i)) == 0)
1655 {
1656 fprintf_filtered (file, "\t");
1657 val_print (register_type (current_gdbarch, i), buffer, 0, 0,
1658 file, 0, 1, 0, Val_pretty_default);
1659 }
1660 }
1661
1662 fprintf_filtered (file, "\n");
1663 }
1664 }
1665
1666 void
1667 registers_info (char *addr_exp, int fpregs)
1668 {
1669 int regnum, numregs;
1670 char *end;
1671
1672 if (!target_has_registers)
1673 error (_("The program has no registers now."));
1674 if (deprecated_selected_frame == NULL)
1675 error (_("No selected frame."));
1676
1677 if (!addr_exp)
1678 {
1679 gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
1680 deprecated_selected_frame, -1, fpregs);
1681 return;
1682 }
1683
1684 while (*addr_exp != '\0')
1685 {
1686 char *start;
1687 const char *end;
1688
1689 /* Keep skipping leading white space. */
1690 if (isspace ((*addr_exp)))
1691 {
1692 addr_exp++;
1693 continue;
1694 }
1695
1696 /* Discard any leading ``$''. Check that there is something
1697 resembling a register following it. */
1698 if (addr_exp[0] == '$')
1699 addr_exp++;
1700 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
1701 error (_("Missing register name"));
1702
1703 /* Find the start/end of this register name/num/group. */
1704 start = addr_exp;
1705 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1706 addr_exp++;
1707 end = addr_exp;
1708
1709 /* Figure out what we've found and display it. */
1710
1711 /* A register name? */
1712 {
1713 int regnum = frame_map_name_to_regnum (deprecated_selected_frame,
1714 start, end - start);
1715 if (regnum >= 0)
1716 {
1717 gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
1718 deprecated_selected_frame, regnum, fpregs);
1719 continue;
1720 }
1721 }
1722
1723 /* A register number? (how portable is this one?). */
1724 {
1725 char *endptr;
1726 int regnum = strtol (start, &endptr, 0);
1727 if (endptr == end
1728 && regnum >= 0
1729 && regnum < NUM_REGS + NUM_PSEUDO_REGS)
1730 {
1731 gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
1732 deprecated_selected_frame, regnum, fpregs);
1733 continue;
1734 }
1735 }
1736
1737 /* A register group? */
1738 {
1739 struct reggroup *group;
1740 for (group = reggroup_next (current_gdbarch, NULL);
1741 group != NULL;
1742 group = reggroup_next (current_gdbarch, group))
1743 {
1744 /* Don't bother with a length check. Should the user
1745 enter a short register group name, go with the first
1746 group that matches. */
1747 if (strncmp (start, reggroup_name (group), end - start) == 0)
1748 break;
1749 }
1750 if (group != NULL)
1751 {
1752 int regnum;
1753 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1754 {
1755 if (gdbarch_register_reggroup_p (current_gdbarch, regnum,
1756 group))
1757 gdbarch_print_registers_info (current_gdbarch,
1758 gdb_stdout, deprecated_selected_frame,
1759 regnum, fpregs);
1760 }
1761 continue;
1762 }
1763 }
1764
1765 /* Nothing matched. */
1766 error (_("Invalid register `%.*s'"), (int) (end - start), start);
1767 }
1768 }
1769
1770 void
1771 all_registers_info (char *addr_exp, int from_tty)
1772 {
1773 registers_info (addr_exp, 1);
1774 }
1775
1776 static void
1777 nofp_registers_info (char *addr_exp, int from_tty)
1778 {
1779 registers_info (addr_exp, 0);
1780 }
1781
1782 static void
1783 print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1784 struct frame_info *frame, const char *args)
1785 {
1786 if (!target_has_registers)
1787 error (_("The program has no registers now."));
1788 if (deprecated_selected_frame == NULL)
1789 error (_("No selected frame."));
1790
1791 if (gdbarch_print_vector_info_p (gdbarch))
1792 gdbarch_print_vector_info (gdbarch, file, frame, args);
1793 else
1794 {
1795 int regnum;
1796 int printed_something = 0;
1797
1798 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1799 {
1800 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
1801 {
1802 printed_something = 1;
1803 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1804 }
1805 }
1806 if (!printed_something)
1807 fprintf_filtered (file, "No vector information\n");
1808 }
1809 }
1810
1811 static void
1812 vector_info (char *args, int from_tty)
1813 {
1814 print_vector_info (current_gdbarch, gdb_stdout, deprecated_selected_frame, args);
1815 }
1816 \f
1817
1818 /*
1819 * TODO:
1820 * Should save/restore the tty state since it might be that the
1821 * program to be debugged was started on this tty and it wants
1822 * the tty in some state other than what we want. If it's running
1823 * on another terminal or without a terminal, then saving and
1824 * restoring the tty state is a harmless no-op.
1825 * This only needs to be done if we are attaching to a process.
1826 */
1827
1828 /*
1829 attach_command --
1830 takes a program started up outside of gdb and ``attaches'' to it.
1831 This stops it cold in its tracks and allows us to start debugging it.
1832 and wait for the trace-trap that results from attaching. */
1833
1834 void
1835 attach_command (char *args, int from_tty)
1836 {
1837 char *exec_file;
1838 char *full_exec_path = NULL;
1839
1840 dont_repeat (); /* Not for the faint of heart */
1841
1842 if (target_has_execution)
1843 {
1844 if (query ("A program is being debugged already. Kill it? "))
1845 target_kill ();
1846 else
1847 error (_("Not killed."));
1848 }
1849
1850 /* Clear out solib state. Otherwise the solib state of the previous
1851 inferior might have survived and is entirely wrong for the new
1852 target. This has been observed on Linux using glibc 2.3. How to
1853 reproduce:
1854
1855 bash$ ./foo&
1856 [1] 4711
1857 bash$ ./foo&
1858 [1] 4712
1859 bash$ gdb ./foo
1860 [...]
1861 (gdb) attach 4711
1862 (gdb) detach
1863 (gdb) attach 4712
1864 Cannot access memory at address 0xdeadbeef
1865 */
1866 #ifdef CLEAR_SOLIB
1867 CLEAR_SOLIB ();
1868 #else
1869 clear_solib ();
1870 #endif
1871
1872 target_attach (args, from_tty);
1873
1874 /* Set up the "saved terminal modes" of the inferior
1875 based on what modes we are starting it with. */
1876 target_terminal_init ();
1877
1878 /* Set up execution context to know that we should return from
1879 wait_for_inferior as soon as the target reports a stop. */
1880 init_wait_for_inferior ();
1881 clear_proceed_status ();
1882
1883 /* No traps are generated when attaching to inferior under Mach 3
1884 or GNU hurd. */
1885 #ifndef ATTACH_NO_WAIT
1886 /* Careful here. See comments in inferior.h. Basically some OSes
1887 don't ignore SIGSTOPs on continue requests anymore. We need a
1888 way for handle_inferior_event to reset the stop_signal variable
1889 after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for. */
1890 stop_soon = STOP_QUIETLY_NO_SIGSTOP;
1891 wait_for_inferior ();
1892 stop_soon = NO_STOP_QUIETLY;
1893 #endif
1894
1895 /*
1896 * If no exec file is yet known, try to determine it from the
1897 * process itself.
1898 */
1899 exec_file = (char *) get_exec_file (0);
1900 if (!exec_file)
1901 {
1902 exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
1903 if (exec_file)
1904 {
1905 /* It's possible we don't have a full path, but rather just a
1906 filename. Some targets, such as HP-UX, don't provide the
1907 full path, sigh.
1908
1909 Attempt to qualify the filename against the source path.
1910 (If that fails, we'll just fall back on the original
1911 filename. Not much more we can do...)
1912 */
1913 if (!source_full_path_of (exec_file, &full_exec_path))
1914 full_exec_path = savestring (exec_file, strlen (exec_file));
1915
1916 exec_file_attach (full_exec_path, from_tty);
1917 symbol_file_add_main (full_exec_path, from_tty);
1918 }
1919 }
1920 else
1921 {
1922 reopen_exec_file ();
1923 reread_symbols ();
1924 }
1925
1926 /* Take any necessary post-attaching actions for this platform.
1927 */
1928 target_post_attach (PIDGET (inferior_ptid));
1929
1930 post_create_inferior (&current_target, from_tty);
1931
1932 /* Install inferior's terminal modes. */
1933 target_terminal_inferior ();
1934
1935 normal_stop ();
1936
1937 if (deprecated_attach_hook)
1938 deprecated_attach_hook ();
1939 }
1940
1941 /*
1942 * detach_command --
1943 * takes a program previously attached to and detaches it.
1944 * The program resumes execution and will no longer stop
1945 * on signals, etc. We better not have left any breakpoints
1946 * in the program or it'll die when it hits one. For this
1947 * to work, it may be necessary for the process to have been
1948 * previously attached. It *might* work if the program was
1949 * started via the normal ptrace (PTRACE_TRACEME).
1950 */
1951
1952 static void
1953 detach_command (char *args, int from_tty)
1954 {
1955 dont_repeat (); /* Not for the faint of heart. */
1956 target_detach (args, from_tty);
1957 #if defined(SOLIB_RESTART)
1958 SOLIB_RESTART ();
1959 #endif
1960 if (deprecated_detach_hook)
1961 deprecated_detach_hook ();
1962 }
1963
1964 /* Disconnect from the current target without resuming it (leaving it
1965 waiting for a debugger).
1966
1967 We'd better not have left any breakpoints in the program or the
1968 next debugger will get confused. Currently only supported for some
1969 remote targets, since the normal attach mechanisms don't work on
1970 stopped processes on some native platforms (e.g. GNU/Linux). */
1971
1972 static void
1973 disconnect_command (char *args, int from_tty)
1974 {
1975 dont_repeat (); /* Not for the faint of heart */
1976 target_disconnect (args, from_tty);
1977 #if defined(SOLIB_RESTART)
1978 SOLIB_RESTART ();
1979 #endif
1980 if (deprecated_detach_hook)
1981 deprecated_detach_hook ();
1982 }
1983
1984 /* Stop the execution of the target while running in async mode, in
1985 the backgound. */
1986 void
1987 interrupt_target_command (char *args, int from_tty)
1988 {
1989 if (target_can_async_p ())
1990 {
1991 dont_repeat (); /* Not for the faint of heart */
1992 target_stop ();
1993 }
1994 }
1995
1996 static void
1997 print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
1998 struct frame_info *frame, const char *args)
1999 {
2000 if (!target_has_registers)
2001 error (_("The program has no registers now."));
2002 if (deprecated_selected_frame == NULL)
2003 error (_("No selected frame."));
2004
2005 if (gdbarch_print_float_info_p (gdbarch))
2006 gdbarch_print_float_info (gdbarch, file, frame, args);
2007 else
2008 {
2009 int regnum;
2010 int printed_something = 0;
2011
2012 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
2013 {
2014 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2015 {
2016 printed_something = 1;
2017 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2018 }
2019 }
2020 if (!printed_something)
2021 fprintf_filtered (file, "\
2022 No floating-point info available for this processor.\n");
2023 }
2024 }
2025
2026 static void
2027 float_info (char *args, int from_tty)
2028 {
2029 print_float_info (current_gdbarch, gdb_stdout,
2030 deprecated_selected_frame, args);
2031 }
2032 \f
2033 static void
2034 unset_command (char *args, int from_tty)
2035 {
2036 printf_filtered (_("\
2037 \"unset\" must be followed by the name of an unset subcommand.\n"));
2038 help_list (unsetlist, "unset ", -1, gdb_stdout);
2039 }
2040
2041 void
2042 _initialize_infcmd (void)
2043 {
2044 struct cmd_list_element *c = NULL;
2045
2046 /* add the filename of the terminal connected to inferior I/O */
2047 add_setshow_filename_cmd ("inferior-tty", class_run,
2048 &inferior_io_terminal, _("\
2049 Set terminal for future runs of program being debugged."), _("\
2050 Show terminal for future runs of program being debugged."), _("\
2051 Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
2052 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2053
2054 add_setshow_optional_filename_cmd ("args", class_run,
2055 &inferior_args, _("\
2056 Set argument list to give program being debugged when it is started."), _("\
2057 Show argument list to give program being debugged when it is started."), _("\
2058 Follow this command with any number of args, to be passed to the program."),
2059 notice_args_set,
2060 notice_args_read,
2061 &setlist, &showlist);
2062
2063 c = add_cmd ("environment", no_class, environment_info, _("\
2064 The environment to give the program, or one variable's value.\n\
2065 With an argument VAR, prints the value of environment variable VAR to\n\
2066 give the program being debugged. With no arguments, prints the entire\n\
2067 environment to be given to the program."), &showlist);
2068 set_cmd_completer (c, noop_completer);
2069
2070 add_prefix_cmd ("unset", no_class, unset_command,
2071 _("Complement to certain \"set\" commands."),
2072 &unsetlist, "unset ", 0, &cmdlist);
2073
2074 c = add_cmd ("environment", class_run, unset_environment_command, _("\
2075 Cancel environment variable VAR for the program.\n\
2076 This does not affect the program until the next \"run\" command."),
2077 &unsetlist);
2078 set_cmd_completer (c, noop_completer);
2079
2080 c = add_cmd ("environment", class_run, set_environment_command, _("\
2081 Set environment variable value to give the program.\n\
2082 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2083 VALUES of environment variables are uninterpreted strings.\n\
2084 This does not affect the program until the next \"run\" command."),
2085 &setlist);
2086 set_cmd_completer (c, noop_completer);
2087
2088 c = add_com ("path", class_files, path_command, _("\
2089 Add directory DIR(s) to beginning of search path for object files.\n\
2090 $cwd in the path means the current working directory.\n\
2091 This path is equivalent to the $PATH shell variable. It is a list of\n\
2092 directories, separated by colons. These directories are searched to find\n\
2093 fully linked executable files and separately compiled object files as needed."));
2094 set_cmd_completer (c, filename_completer);
2095
2096 c = add_cmd ("paths", no_class, path_info, _("\
2097 Current search path for finding object files.\n\
2098 $cwd in the path means the current working directory.\n\
2099 This path is equivalent to the $PATH shell variable. It is a list of\n\
2100 directories, separated by colons. These directories are searched to find\n\
2101 fully linked executable files and separately compiled object files as needed."),
2102 &showlist);
2103 set_cmd_completer (c, noop_completer);
2104
2105 add_com ("attach", class_run, attach_command, _("\
2106 Attach to a process or file outside of GDB.\n\
2107 This command attaches to another target, of the same type as your last\n\
2108 \"target\" command (\"info files\" will show your target stack).\n\
2109 The command may take as argument a process id or a device file.\n\
2110 For a process id, you must have permission to send the process a signal,\n\
2111 and it must have the same effective uid as the debugger.\n\
2112 When using \"attach\" with a process id, the debugger finds the\n\
2113 program running in the process, looking first in the current working\n\
2114 directory, or (if not found there) using the source file search path\n\
2115 (see the \"directory\" command). You can also use the \"file\" command\n\
2116 to specify the program, and to load its symbol table."));
2117
2118 add_com ("detach", class_run, detach_command, _("\
2119 Detach a process or file previously attached.\n\
2120 If a process, it is no longer traced, and it continues its execution. If\n\
2121 you were debugging a file, the file is closed and gdb no longer accesses it."));
2122
2123 add_com ("disconnect", class_run, disconnect_command, _("\
2124 Disconnect from a target.\n\
2125 The target will wait for another debugger to connect. Not available for\n\
2126 all targets."));
2127
2128 add_com ("signal", class_run, signal_command, _("\
2129 Continue program giving it signal specified by the argument.\n\
2130 An argument of \"0\" means continue program without giving it a signal."));
2131
2132 add_com ("stepi", class_run, stepi_command, _("\
2133 Step one instruction exactly.\n\
2134 Argument N means do this N times (or till program stops for another reason)."));
2135 add_com_alias ("si", "stepi", class_alias, 0);
2136
2137 add_com ("nexti", class_run, nexti_command, _("\
2138 Step one instruction, but proceed through subroutine calls.\n\
2139 Argument N means do this N times (or till program stops for another reason)."));
2140 add_com_alias ("ni", "nexti", class_alias, 0);
2141
2142 add_com ("finish", class_run, finish_command, _("\
2143 Execute until selected stack frame returns.\n\
2144 Upon return, the value returned is printed and put in the value history."));
2145
2146 add_com ("next", class_run, next_command, _("\
2147 Step program, proceeding through subroutine calls.\n\
2148 Like the \"step\" command as long as subroutine calls do not happen;\n\
2149 when they do, the call is treated as one instruction.\n\
2150 Argument N means do this N times (or till program stops for another reason)."));
2151 add_com_alias ("n", "next", class_run, 1);
2152 if (xdb_commands)
2153 add_com_alias ("S", "next", class_run, 1);
2154
2155 add_com ("step", class_run, step_command, _("\
2156 Step program until it reaches a different source line.\n\
2157 Argument N means do this N times (or till program stops for another reason)."));
2158 add_com_alias ("s", "step", class_run, 1);
2159
2160 c = add_com ("until", class_run, until_command, _("\
2161 Execute until the program reaches a source line greater than the current\n\
2162 or a specified location (same args as break command) within the current frame."));
2163 set_cmd_completer (c, location_completer);
2164 add_com_alias ("u", "until", class_run, 1);
2165
2166 c = add_com ("advance", class_run, advance_command, _("\
2167 Continue the program up to the given location (same form as args for break command).\n\
2168 Execution will also stop upon exit from the current stack frame."));
2169 set_cmd_completer (c, location_completer);
2170
2171 c = add_com ("jump", class_run, jump_command, _("\
2172 Continue program being debugged at specified line or address.\n\
2173 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2174 for an address to start at."));
2175 set_cmd_completer (c, location_completer);
2176
2177 if (xdb_commands)
2178 {
2179 c = add_com ("go", class_run, go_command, _("\
2180 Usage: go <location>\n\
2181 Continue program being debugged, stopping at specified line or \n\
2182 address.\n\
2183 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2184 expression for an address to start at.\n\
2185 This command is a combination of tbreak and jump."));
2186 set_cmd_completer (c, location_completer);
2187 }
2188
2189 if (xdb_commands)
2190 add_com_alias ("g", "go", class_run, 1);
2191
2192 add_com ("continue", class_run, continue_command, _("\
2193 Continue program being debugged, after signal or breakpoint.\n\
2194 If proceeding from breakpoint, a number N may be used as an argument,\n\
2195 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2196 the breakpoint won't break until the Nth time it is reached)."));
2197 add_com_alias ("c", "cont", class_run, 1);
2198 add_com_alias ("fg", "cont", class_run, 1);
2199
2200 c = add_com ("run", class_run, run_command, _("\
2201 Start debugged program. You may specify arguments to give it.\n\
2202 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2203 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2204 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2205 To cancel previous arguments and run with no arguments,\n\
2206 use \"set args\" without arguments."));
2207 set_cmd_completer (c, filename_completer);
2208 add_com_alias ("r", "run", class_run, 1);
2209 if (xdb_commands)
2210 add_com ("R", class_run, run_no_args_command,
2211 _("Start debugged program with no arguments."));
2212
2213 c = add_com ("start", class_run, start_command, _("\
2214 Run the debugged program until the beginning of the main procedure.\n\
2215 You may specify arguments to give to your program, just as with the\n\
2216 \"run\" command."));
2217 set_cmd_completer (c, filename_completer);
2218
2219 add_com ("interrupt", class_run, interrupt_target_command,
2220 _("Interrupt the execution of the debugged program."));
2221
2222 add_info ("registers", nofp_registers_info, _("\
2223 List of integer registers and their contents, for selected stack frame.\n\
2224 Register name as argument means describe only that register."));
2225 add_info_alias ("r", "registers", 1);
2226
2227 if (xdb_commands)
2228 add_com ("lr", class_info, nofp_registers_info, _("\
2229 List of integer registers and their contents, for selected stack frame.\n\
2230 Register name as argument means describe only that register."));
2231 add_info ("all-registers", all_registers_info, _("\
2232 List of all registers and their contents, for selected stack frame.\n\
2233 Register name as argument means describe only that register."));
2234
2235 add_info ("program", program_info,
2236 _("Execution status of the program."));
2237
2238 add_info ("float", float_info,
2239 _("Print the status of the floating point unit\n"));
2240
2241 add_info ("vector", vector_info,
2242 _("Print the status of the vector unit\n"));
2243
2244 inferior_environ = make_environ ();
2245 init_environ (inferior_environ);
2246 }
This page took 0.074136 seconds and 5 git commands to generate.