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