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