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