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.
5 This file is part of GDB.
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.
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.
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. */
24 #include "gdb_string.h"
37 #include "event-loop.h"
38 #include "event-top.h"
39 #include "parser-defs.h"
41 /* Functions exported for general use: */
43 void nofp_registers_info
PARAMS ((char *, int));
45 void all_registers_info
PARAMS ((char *, int));
47 void registers_info
PARAMS ((char *, int));
49 /* Local functions: */
51 void continue_command
PARAMS ((char *, int));
53 static void finish_command_continuation
PARAMS ((struct continuation_arg
*));
55 static void until_next_command
PARAMS ((int));
57 static void until_command
PARAMS ((char *, int));
59 static void path_info
PARAMS ((char *, int));
61 static void path_command
PARAMS ((char *, int));
63 static void unset_command
PARAMS ((char *, int));
65 static void float_info
PARAMS ((char *, int));
67 static void detach_command
PARAMS ((char *, int));
69 static void interrupt_target_command (char *args
, int from_tty
);
71 #if !defined (DO_REGISTERS_INFO)
72 static void do_registers_info
PARAMS ((int, int));
75 static void unset_environment_command
PARAMS ((char *, int));
77 static void set_environment_command
PARAMS ((char *, int));
79 static void environment_info
PARAMS ((char *, int));
81 static void program_info
PARAMS ((char *, int));
83 static void finish_command
PARAMS ((char *, int));
85 static void signal_command
PARAMS ((char *, int));
87 static void jump_command
PARAMS ((char *, int));
89 static void step_1
PARAMS ((int, int, char *));
91 void nexti_command
PARAMS ((char *, int));
93 void stepi_command
PARAMS ((char *, int));
95 static void next_command
PARAMS ((char *, int));
97 static void step_command
PARAMS ((char *, int));
99 static void run_command
PARAMS ((char *, int));
101 static void run_no_args_command
PARAMS ((char *args
, int from_tty
));
103 static void go_command
PARAMS ((char *line_no
, int from_tty
));
105 static int strip_bg_char
PARAMS ((char **));
107 void _initialize_infcmd
PARAMS ((void));
109 #define GO_USAGE "Usage: go <location>\n"
111 static void breakpoint_auto_delete_contents
PARAMS ((PTR
));
113 #define ERROR_NO_INFERIOR \
114 if (!target_has_execution) error ("The program is not being run.");
116 /* String containing arguments to give to the program, separated by spaces.
117 Empty string (pointer to '\0') means no args. */
119 static char *inferior_args
;
121 /* File name for default use for standard in/out in the inferior. */
123 char *inferior_io_terminal
;
125 /* Pid of our debugged inferior, or 0 if no inferior now.
126 Since various parts of infrun.c test this to see whether there is a program
127 being debugged it should be nonzero (currently 3 is used) for remote
132 /* Last signal that the inferior received (why it stopped). */
134 enum target_signal stop_signal
;
136 /* Address at which inferior stopped. */
140 /* Chain containing status of breakpoint(s) that we have stopped at. */
144 /* Flag indicating that a command has proceeded the inferior past the
145 current breakpoint. */
147 int breakpoint_proceeded
;
149 /* Nonzero if stopped due to a step command. */
153 /* Nonzero if stopped due to completion of a stack dummy routine. */
155 int stop_stack_dummy
;
157 /* Nonzero if stopped due to a random (unexpected) signal in inferior
160 int stopped_by_random_signal
;
162 /* Range to single step within.
163 If this is nonzero, respond to a single-step signal
164 by continuing to step if the pc is in this range. */
166 CORE_ADDR step_range_start
; /* Inclusive */
167 CORE_ADDR step_range_end
; /* Exclusive */
169 /* Stack frame address as of when stepping command was issued.
170 This is how we know when we step into a subroutine call,
171 and how to set the frame for the breakpoint used to step out. */
173 CORE_ADDR step_frame_address
;
175 /* Our notion of the current stack pointer. */
179 /* 1 means step over all subroutine calls.
180 0 means don't step over calls (used by stepi).
181 -1 means step over calls to undebuggable functions. */
185 /* If stepping, nonzero means step count is > 1
186 so don't print frame next time inferior stops
187 if it stops due to stepping. */
191 /* Environment to use for running inferior,
192 in format described in environ.h. */
194 struct environ
*inferior_environ
;
197 /* This function detects whether or not a '&' character (indicating
198 background execution) has been added as *the last* of the arguments ARGS
199 of a command. If it has, it removes it and returns 1. Otherwise it
200 does nothing and returns 0. */
207 p
= strchr (*args
, '&');
211 if (p
== (*args
+ strlen (*args
) - 1))
213 if (strlen (*args
) > 1)
217 while (*p
== ' ' || *p
== '\t');
230 tty_command (file
, from_tty
)
235 error_no_arg ("terminal name for running target process");
237 inferior_io_terminal
= savestring (file
, strlen (file
));
241 run_command (args
, from_tty
)
249 if (inferior_pid
!= 0 && target_has_execution
)
252 && !query ("The program being debugged has been started already.\n\
253 Start it from the beginning? "))
254 error ("Program not restarted.");
256 #if defined(SOLIB_RESTART)
259 init_wait_for_inferior ();
262 clear_breakpoint_hit_counts ();
264 exec_file
= (char *) get_exec_file (0);
266 /* Purge old solib objfiles. */
267 objfile_purge_solibs ();
269 do_run_cleanups (NULL
);
271 /* The exec file is re-read every time we do a generic_mourn_inferior, so
272 we just have to worry about the symbol file. */
275 /* We keep symbols from add-symbol-file, on the grounds that the
276 user might want to add some symbols before running the program
277 (right?). But sometimes (dynamic loading where the user manually
278 introduces the new symbols with add-symbol-file), the code which
279 the symbols describe does not persist between runs. Currently
280 the user has to manually nuke all symbols between runs if they
281 want them to go away (PR 2207). This is probably reasonable. */
285 if (event_loop_p
&& target_can_async_p ())
286 async_disable_stdin ();
291 int async_exec
= strip_bg_char (&args
);
293 /* If we get a request for running in the bg but the target
294 doesn't support it, error out. */
295 if (event_loop_p
&& async_exec
&& !target_can_async_p ())
296 error ("Asynchronous execution not supported on this target.");
298 /* If we don't get a request of running in the bg, then we need
299 to simulate synchronous (fg) execution. */
300 if (event_loop_p
&& !async_exec
&& target_can_async_p ())
302 /* Simulate synchronous execution */
303 async_disable_stdin ();
306 /* If there were other args, beside '&', process them. */
309 cmd
= concat ("set args ", args
, NULL
);
310 make_cleanup (free
, cmd
);
311 execute_command (cmd
, from_tty
);
317 puts_filtered ("Starting program: ");
319 puts_filtered (exec_file
);
321 puts_filtered (inferior_args
);
322 puts_filtered ("\n");
323 gdb_flush (gdb_stdout
);
326 target_create_inferior (exec_file
, inferior_args
,
327 environ_vector (inferior_environ
));
332 run_no_args_command (args
, from_tty
)
336 execute_command ("set args", from_tty
);
337 run_command ((char *) NULL
, from_tty
);
342 continue_command (proc_count_exp
, from_tty
)
343 char *proc_count_exp
;
349 /* Find out whether we must run in the background. */
350 if (proc_count_exp
!= NULL
)
351 async_exec
= strip_bg_char (&proc_count_exp
);
353 /* If we must run in the background, but the target can't do it,
355 if (event_loop_p
&& async_exec
&& !target_can_async_p ())
356 error ("Asynchronous execution not supported on this target.");
358 /* If we are not asked to run in the bg, then prepare to run in the
359 foreground, synchronously. */
360 if (event_loop_p
&& !async_exec
&& target_can_async_p ())
362 /* Simulate synchronous execution */
363 async_disable_stdin ();
366 /* If have argument (besides '&'), set proceed count of breakpoint
368 if (proc_count_exp
!= NULL
)
370 bpstat bs
= stop_bpstat
;
371 int num
= bpstat_num (&bs
);
372 if (num
== 0 && from_tty
)
375 ("Not stopped at any breakpoint; argument ignored.\n");
379 set_ignore_count (num
,
380 parse_and_eval_address (proc_count_exp
) - 1,
382 /* set_ignore_count prints a message ending with a period.
383 So print two spaces before "Continuing.". */
385 printf_filtered (" ");
386 num
= bpstat_num (&bs
);
391 printf_filtered ("Continuing.\n");
393 clear_proceed_status ();
395 proceed ((CORE_ADDR
) - 1, TARGET_SIGNAL_DEFAULT
, 0);
398 /* Step until outside of current statement. */
402 step_command (count_string
, from_tty
)
406 step_1 (0, 0, count_string
);
409 /* Likewise, but skip over subroutine calls as if single instructions. */
413 next_command (count_string
, from_tty
)
417 step_1 (1, 0, count_string
);
420 /* Likewise, but step only one instruction. */
424 stepi_command (count_string
, from_tty
)
428 step_1 (0, 1, count_string
);
433 nexti_command (count_string
, from_tty
)
437 step_1 (1, 1, count_string
);
441 step_1 (skip_subroutines
, single_inst
, count_string
)
442 int skip_subroutines
;
446 register int count
= 1;
447 struct frame_info
*frame
;
448 struct cleanup
*cleanups
= 0;
454 async_exec
= strip_bg_char (&count_string
);
456 /* If we get a request for running in the bg but the target
457 doesn't support it, error out. */
458 if (event_loop_p
&& async_exec
&& !target_can_async_p ())
459 error ("Asynchronous execution not supported on this target.");
461 /* If we don't get a request of running in the bg, then we need
462 to simulate synchronous (fg) execution. */
463 if (event_loop_p
&& !async_exec
&& target_can_async_p ())
465 /* Simulate synchronous execution */
466 async_disable_stdin ();
469 count
= count_string
? parse_and_eval_address (count_string
) : 1;
471 if (!single_inst
|| skip_subroutines
) /* leave si command alone */
473 enable_longjmp_breakpoint ();
474 cleanups
= make_cleanup ((make_cleanup_func
) disable_longjmp_breakpoint
,
478 for (; count
> 0; count
--)
480 clear_proceed_status ();
482 frame
= get_current_frame ();
483 if (!frame
) /* Avoid coredump here. Why tho? */
484 error ("No current frame");
485 step_frame_address
= FRAME_FP (frame
);
486 step_sp
= read_sp ();
490 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
491 if (step_range_end
== 0)
494 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
495 &step_range_end
) == 0)
496 error ("Cannot find bounds of current function");
498 target_terminal_ours ();
500 Single stepping until exit from function %s, \n\
501 which has no line number information.\n", name
);
506 /* Say we are stepping, but stop after one insn whatever it does. */
507 step_range_start
= step_range_end
= 1;
508 if (!skip_subroutines
)
510 Don't step over function calls, not even to functions lacking
515 if (skip_subroutines
)
518 step_multi
= (count
> 1);
519 proceed ((CORE_ADDR
) - 1, TARGET_SIGNAL_DEFAULT
, 1);
523 /* FIXME: On nexti, this may have already been done (when we hit the
524 step resume break, I think). Probably this should be moved to
525 wait_for_inferior (near the top). */
526 #if defined (SHIFT_INST_REGS)
531 if (!single_inst
|| skip_subroutines
)
532 do_cleanups (cleanups
);
535 /* Continue program at specified address. */
538 jump_command (arg
, from_tty
)
542 register CORE_ADDR addr
;
543 struct symtabs_and_lines sals
;
544 struct symtab_and_line sal
;
551 /* Find out whether we must run in the background. */
553 async_exec
= strip_bg_char (&arg
);
555 /* If we must run in the background, but the target can't do it,
557 if (event_loop_p
&& async_exec
&& !target_can_async_p ())
558 error ("Asynchronous execution not supported on this target.");
560 /* If we are not asked to run in the bg, then prepare to run in the
561 foreground, synchronously. */
562 if (event_loop_p
&& !async_exec
&& target_can_async_p ())
564 /* Simulate synchronous execution */
565 async_disable_stdin ();
569 error_no_arg ("starting address");
571 sals
= decode_line_spec_1 (arg
, 1);
574 error ("Unreasonable jump request");
578 free ((PTR
) sals
.sals
);
580 if (sal
.symtab
== 0 && sal
.pc
== 0)
581 error ("No source file has been specified.");
583 resolve_sal_pc (&sal
); /* May error out */
585 /* See if we are trying to jump to another function. */
586 fn
= get_frame_function (get_current_frame ());
587 sfn
= find_pc_function (sal
.pc
);
588 if (fn
!= NULL
&& sfn
!= fn
)
590 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal
.line
,
591 SYMBOL_SOURCE_NAME (fn
)))
593 error ("Not confirmed.");
600 fixup_symbol_section (sfn
, 0);
601 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn
)) &&
602 !section_is_mapped (SYMBOL_BFD_SECTION (sfn
)))
604 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
606 error ("Not confirmed.");
616 printf_filtered ("Continuing at ");
617 print_address_numeric (addr
, 1, gdb_stdout
);
618 printf_filtered (".\n");
621 clear_proceed_status ();
622 proceed (addr
, TARGET_SIGNAL_0
, 0);
626 /* Go to line or address in current procedure */
628 go_command (line_no
, from_tty
)
632 if (line_no
== (char *) NULL
|| !*line_no
)
633 printf_filtered (GO_USAGE
);
636 tbreak_command (line_no
, from_tty
);
637 jump_command (line_no
, from_tty
);
642 /* Continue program giving it specified signal. */
645 signal_command (signum_exp
, from_tty
)
649 enum target_signal oursig
;
651 dont_repeat (); /* Too dangerous. */
655 error_no_arg ("signal number");
657 /* It would be even slicker to make signal names be valid expressions,
658 (the type could be "enum $signal" or some such), then the user could
659 assign them to convenience variables. */
660 oursig
= target_signal_from_name (signum_exp
);
662 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
664 /* No, try numeric. */
665 int num
= parse_and_eval_address (signum_exp
);
668 oursig
= TARGET_SIGNAL_0
;
670 oursig
= target_signal_from_command (num
);
675 if (oursig
== TARGET_SIGNAL_0
)
676 printf_filtered ("Continuing with no signal.\n");
678 printf_filtered ("Continuing with signal %s.\n",
679 target_signal_to_name (oursig
));
682 clear_proceed_status ();
683 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
684 FIXME: Neither should "signal foo" but when I tried passing
685 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
686 tried to track down yet. */
687 proceed (oursig
== TARGET_SIGNAL_0
? (CORE_ADDR
) - 1 : stop_pc
, oursig
, 0);
690 /* Call breakpoint_auto_delete on the current contents of the bpstat
691 pointed to by arg (which is really a bpstat *). */
694 breakpoint_auto_delete_contents (arg
)
697 breakpoint_auto_delete (*(bpstat
*) arg
);
701 /* Execute a "stack dummy", a piece of code stored in the stack
702 by the debugger to be executed in the inferior.
704 To call: first, do PUSH_DUMMY_FRAME.
705 Then push the contents of the dummy. It should end with a breakpoint insn.
706 Then call here, passing address at which to start the dummy.
708 The contents of all registers are saved before the dummy frame is popped
709 and copied into the buffer BUFFER.
711 The dummy's frame is automatically popped whenever that break is hit.
712 If that is the first time the program stops, run_stack_dummy
713 returns to its caller with that frame already gone and returns 0.
714 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
715 when we do hit that breakpoint). */
718 run_stack_dummy (addr
, buffer
)
722 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, 0);
724 /* Now proceed, having reached the desired place. */
725 clear_proceed_status ();
727 if (CALL_DUMMY_BREAKPOINT_OFFSET_P
)
729 struct breakpoint
*bpt
;
730 struct symtab_and_line sal
;
732 INIT_SAL (&sal
); /* initialize to zeroes */
733 if (CALL_DUMMY_LOCATION
== AT_ENTRY_POINT
)
735 sal
.pc
= CALL_DUMMY_ADDRESS ();
739 sal
.pc
= addr
- CALL_DUMMY_START_OFFSET
+ CALL_DUMMY_BREAKPOINT_OFFSET
;
741 sal
.section
= find_pc_overlay (sal
.pc
);
743 /* Set up a FRAME for the dummy frame so we can pass it to
744 set_momentary_breakpoint. We need to give the breakpoint a
745 frame in case there is only one copy of the dummy (e.g.
746 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
747 flush_cached_frames ();
748 set_current_frame (create_new_frame (read_fp (), sal
.pc
));
750 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
751 a breakpoint instruction. If not, the call dummy already has the
752 breakpoint instruction in it.
754 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
755 so we need to subtract the CALL_DUMMY_START_OFFSET. */
756 bpt
= set_momentary_breakpoint (sal
,
757 get_current_frame (),
759 bpt
->disposition
= del
;
761 /* If all error()s out of proceed ended up calling normal_stop (and
762 perhaps they should; it already does in the special case of error
763 out of resume()), then we wouldn't need this. */
764 make_cleanup (breakpoint_auto_delete_contents
, &stop_bpstat
);
767 disable_watchpoints_before_interactive_call_start ();
768 proceed_to_finish
= 1; /* We want stop_registers, please... */
769 proceed (addr
, TARGET_SIGNAL_0
, 0);
770 enable_watchpoints_after_interactive_call_stop ();
772 discard_cleanups (old_cleanups
);
774 if (!stop_stack_dummy
)
777 /* On return, the stack dummy has been popped already. */
779 memcpy (buffer
, stop_registers
, REGISTER_BYTES
);
783 /* Proceed until we reach a different source line with pc greater than
784 our current one or exit the function. We skip calls in both cases.
786 Note that eventually this command should probably be changed so
787 that only source lines are printed out when we hit the breakpoint
788 we set. This may involve changes to wait_for_inferior and the
789 proceed status code. */
793 until_next_command (from_tty
)
796 struct frame_info
*frame
;
799 struct symtab_and_line sal
;
801 clear_proceed_status ();
803 frame
= get_current_frame ();
805 /* Step until either exited from this function or greater
806 than the current line (if in symbolic section) or pc (if
810 func
= find_pc_function (pc
);
814 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
817 error ("Execution is not within a known function.");
819 step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
824 sal
= find_pc_line (pc
, 0);
826 step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
827 step_range_end
= sal
.end
;
831 step_frame_address
= FRAME_FP (frame
);
832 step_sp
= read_sp ();
834 step_multi
= 0; /* Only one call to proceed */
836 proceed ((CORE_ADDR
) - 1, TARGET_SIGNAL_DEFAULT
, 1);
840 until_command (arg
, from_tty
)
846 if (!target_has_execution
)
847 error ("The program is not running.");
849 /* Find out whether we must run in the background. */
851 async_exec
= strip_bg_char (&arg
);
853 /* If we must run in the background, but the target can't do it,
855 if (event_loop_p
&& async_exec
&& !target_can_async_p ())
856 error ("Asynchronous execution not supported on this target.");
858 /* If we are not asked to run in the bg, then prepare to run in the
859 foreground, synchronously. */
860 if (event_loop_p
&& !async_exec
&& target_can_async_p ())
862 /* Simulate synchronous execution */
863 async_disable_stdin ();
867 until_break_command (arg
, from_tty
);
869 until_next_command (from_tty
);
873 /* Stuff that needs to be done by the finish command after the target
874 has stopped. In asynchronous mode, we wait for the target to stop in
875 the call to poll or select in the event loop, so it is impossible to
876 do all the stuff as part of the finish_command function itself. The
877 only chance we have to complete this command is in
878 fetch_inferior_event, which is called by the event loop as soon as it
879 detects that the target has stopped. This function is called via the
880 cmd_continaution pointer. */
882 finish_command_continuation (arg
)
883 struct continuation_arg
*arg
;
885 register struct symbol
*function
;
886 struct breakpoint
*breakpoint
;
888 breakpoint
= (struct breakpoint
*) arg
->data
;
889 function
= (struct symbol
*) (arg
->next
)->data
;
891 if (bpstat_find_breakpoint (stop_bpstat
, breakpoint
) != NULL
894 struct type
*value_type
;
895 register value_ptr val
;
899 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
901 internal_error ("finish_command: function has no target type");
903 if (TYPE_CODE (value_type
) == TYPE_CODE_VOID
)
905 do_exec_cleanups (ALL_CLEANUPS
);
909 funcaddr
= BLOCK_START (SYMBOL_BLOCK_VALUE (function
));
911 struct_return
= using_struct_return (value_of_variable (function
, NULL
),
914 check_typedef (value_type
),
915 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function
)));
919 val
= value_being_returned (value_type
, stop_registers
, struct_return
);
920 printf_filtered ("Value returned is $%d = ", record_latest_value (val
));
921 value_print (val
, gdb_stdout
, 0, Val_no_prettyprint
);
922 printf_filtered ("\n");
926 /* We cannot determine the contents of the structure because
927 it is on the stack, and we don't know where, since we did not
928 initiate the call, as opposed to the call_function_by_hand case */
929 #ifdef VALUE_RETURNED_FROM_STACK
931 printf_filtered ("Value returned has type: %s.",
932 TYPE_NAME (value_type
));
933 printf_filtered (" Cannot determine contents\n");
935 val
= value_being_returned (value_type
, stop_registers
,
937 printf_filtered ("Value returned is $%d = ",
938 record_latest_value (val
));
939 value_print (val
, gdb_stdout
, 0, Val_no_prettyprint
);
940 printf_filtered ("\n");
945 do_exec_cleanups (ALL_CLEANUPS
);
948 /* "finish": Set a temporary breakpoint at the place
949 the selected frame will return to, then continue. */
952 finish_command (arg
, from_tty
)
956 struct symtab_and_line sal
;
957 register struct frame_info
*frame
;
958 register struct symbol
*function
;
959 struct breakpoint
*breakpoint
;
960 struct cleanup
*old_chain
;
961 struct continuation_arg
*arg1
, *arg2
;
965 /* Find out whether we must run in the background. */
967 async_exec
= strip_bg_char (&arg
);
969 /* If we must run in the background, but the target can't do it,
971 if (event_loop_p
&& async_exec
&& !target_can_async_p ())
972 error ("Asynchronous execution not supported on this target.");
974 /* If we are not asked to run in the bg, then prepare to run in the
975 foreground, synchronously. */
976 if (event_loop_p
&& !async_exec
&& target_can_async_p ())
978 /* Simulate synchronous execution */
979 async_disable_stdin ();
983 error ("The \"finish\" command does not take any arguments.");
984 if (!target_has_execution
)
985 error ("The program is not running.");
986 if (selected_frame
== NULL
)
987 error ("No selected frame.");
989 frame
= get_prev_frame (selected_frame
);
991 error ("\"finish\" not meaningful in the outermost frame.");
993 clear_proceed_status ();
995 sal
= find_pc_line (frame
->pc
, 0);
998 breakpoint
= set_momentary_breakpoint (sal
, frame
, bp_finish
);
1000 if (!event_loop_p
|| !target_can_async_p ())
1001 old_chain
= make_cleanup ((make_cleanup_func
) delete_breakpoint
, breakpoint
);
1003 make_exec_cleanup ((make_cleanup_func
) delete_breakpoint
, breakpoint
);
1005 /* Find the function we will return from. */
1007 function
= find_pc_function (selected_frame
->pc
);
1009 /* Print info on the selected frame, including level number
1013 printf_filtered ("Run till exit from ");
1014 print_stack_frame (selected_frame
, selected_frame_level
, 0);
1017 /* If running asynchronously and the target support asynchronous
1018 execution, set things up for the rest of the finish command to be
1019 completed later on, when gdb has detected that the target has
1020 stopped, in fetch_inferior_event. */
1021 if (event_loop_p
&& target_can_async_p ())
1024 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1026 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1029 arg1
->data
= (PTR
) breakpoint
;
1030 arg2
->data
= (PTR
) function
;
1031 add_continuation (finish_command_continuation
, arg1
);
1034 proceed_to_finish
= 1; /* We want stop_registers, please... */
1035 proceed ((CORE_ADDR
) - 1, TARGET_SIGNAL_DEFAULT
, 0);
1037 /* Do this only if not running asynchronously or if the target
1038 cannot do async execution. Otherwise, complete this command when
1039 the target actually stops, in fetch_inferior_event. */
1040 if (!event_loop_p
|| !target_can_async_p ())
1043 /* Did we stop at our breakpoint? */
1044 if (bpstat_find_breakpoint (stop_bpstat
, breakpoint
) != NULL
1047 struct type
*value_type
;
1048 register value_ptr val
;
1052 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1054 internal_error ("finish_command: function has no target type");
1056 /* FIXME: Shouldn't we do the cleanups before returning? */
1057 if (TYPE_CODE (value_type
) == TYPE_CODE_VOID
)
1060 funcaddr
= BLOCK_START (SYMBOL_BLOCK_VALUE (function
));
1063 using_struct_return (value_of_variable (function
, NULL
),
1065 check_typedef (value_type
),
1066 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function
)));
1071 value_being_returned (value_type
, stop_registers
, struct_return
);
1072 printf_filtered ("Value returned is $%d = ",
1073 record_latest_value (val
));
1074 value_print (val
, gdb_stdout
, 0, Val_no_prettyprint
);
1075 printf_filtered ("\n");
1079 /* We cannot determine the contents of the structure
1080 because it is on the stack, and we don't know
1081 where, since we did not initiate the call, as
1082 opposed to the call_function_by_hand case */
1083 #ifdef VALUE_RETURNED_FROM_STACK
1085 printf_filtered ("Value returned has type: %s.",
1086 TYPE_NAME (value_type
));
1087 printf_filtered (" Cannot determine contents\n");
1089 val
= value_being_returned (value_type
, stop_registers
,
1091 printf_filtered ("Value returned is $%d = ",
1092 record_latest_value (val
));
1093 value_print (val
, gdb_stdout
, 0, Val_no_prettyprint
);
1094 printf_filtered ("\n");
1098 do_cleanups (old_chain
);
1104 program_info (args
, from_tty
)
1108 bpstat bs
= stop_bpstat
;
1109 int num
= bpstat_num (&bs
);
1111 if (!target_has_execution
)
1113 printf_filtered ("The program being debugged is not being run.\n");
1117 target_files_info ();
1118 printf_filtered ("Program stopped at %s.\n",
1119 local_hex_string ((unsigned long) stop_pc
));
1121 printf_filtered ("It stopped after being stepped.\n");
1124 /* There may be several breakpoints in the same place, so this
1125 isn't as strange as it seems. */
1130 printf_filtered ("It stopped at a breakpoint that has ");
1131 printf_filtered ("since been deleted.\n");
1134 printf_filtered ("It stopped at breakpoint %d.\n", num
);
1135 num
= bpstat_num (&bs
);
1138 else if (stop_signal
!= TARGET_SIGNAL_0
)
1140 printf_filtered ("It stopped with signal %s, %s.\n",
1141 target_signal_to_name (stop_signal
),
1142 target_signal_to_string (stop_signal
));
1147 printf_filtered ("Type \"info stack\" or \"info registers\" ");
1148 printf_filtered ("for more information.\n");
1153 environment_info (var
, from_tty
)
1159 register char *val
= get_in_environ (inferior_environ
, var
);
1162 puts_filtered (var
);
1163 puts_filtered (" = ");
1164 puts_filtered (val
);
1165 puts_filtered ("\n");
1169 puts_filtered ("Environment variable \"");
1170 puts_filtered (var
);
1171 puts_filtered ("\" not defined.\n");
1176 register char **vector
= environ_vector (inferior_environ
);
1179 puts_filtered (*vector
++);
1180 puts_filtered ("\n");
1186 set_environment_command (arg
, from_tty
)
1190 register char *p
, *val
, *var
;
1194 error_no_arg ("environment variable and value");
1196 /* Find seperation between variable name and value */
1197 p
= (char *) strchr (arg
, '=');
1198 val
= (char *) strchr (arg
, ' ');
1200 if (p
!= 0 && val
!= 0)
1202 /* We have both a space and an equals. If the space is before the
1203 equals, walk forward over the spaces til we see a nonspace
1204 (possibly the equals). */
1209 /* Now if the = is after the char following the spaces,
1210 take the char following the spaces. */
1214 else if (val
!= 0 && p
== 0)
1218 error_no_arg ("environment variable to set");
1220 if (p
== 0 || p
[1] == 0)
1224 p
= arg
+ strlen (arg
); /* So that savestring below will work */
1228 /* Not setting variable value to null */
1230 while (*val
== ' ' || *val
== '\t')
1234 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1237 var
= savestring (arg
, p
- arg
);
1240 printf_filtered ("Setting environment variable ");
1241 printf_filtered ("\"%s\" to null value.\n", var
);
1242 set_in_environ (inferior_environ
, var
, "");
1245 set_in_environ (inferior_environ
, var
, val
);
1250 unset_environment_command (var
, from_tty
)
1256 /* If there is no argument, delete all environment variables.
1257 Ask for confirmation if reading from the terminal. */
1258 if (!from_tty
|| query ("Delete all environment variables? "))
1260 free_environ (inferior_environ
);
1261 inferior_environ
= make_environ ();
1265 unset_in_environ (inferior_environ
, var
);
1268 /* Handle the execution path (PATH variable) */
1270 static const char path_var_name
[] = "PATH";
1274 path_info (args
, from_tty
)
1278 puts_filtered ("Executable and object file path: ");
1279 puts_filtered (get_in_environ (inferior_environ
, path_var_name
));
1280 puts_filtered ("\n");
1283 /* Add zero or more directories to the front of the execution path. */
1286 path_command (dirname
, from_tty
)
1293 env
= get_in_environ (inferior_environ
, path_var_name
);
1294 /* Can be null if path is not set */
1297 exec_path
= strsave (env
);
1298 mod_path (dirname
, &exec_path
);
1299 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
1302 path_info ((char *) NULL
, from_tty
);
1306 #ifdef REGISTER_NAMES
1307 char *gdb_register_names
[] = REGISTER_NAMES
;
1309 /* Print out the machine register regnum. If regnum is -1,
1310 print all registers (fpregs == 1) or all non-float registers
1313 For most machines, having all_registers_info() print the
1314 register(s) one per line is good enough. If a different format
1315 is required, (eg, for MIPS or Pyramid 90x, which both have
1316 lots of regs), or there is an existing convention for showing
1317 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
1318 to provide that format. */
1320 #if !defined (DO_REGISTERS_INFO)
1322 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
1325 do_registers_info (regnum
, fpregs
)
1330 int numregs
= ARCH_NUM_REGS
;
1332 for (i
= 0; i
< numregs
; i
++)
1334 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1335 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
1337 /* Decide between printing all regs, nonfloat regs, or specific reg. */
1340 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i
)) == TYPE_CODE_FLT
&& !fpregs
)
1349 /* If the register name is empty, it is undefined for this
1350 processor, so don't display anything. */
1351 if (REGISTER_NAME (i
) == NULL
|| *(REGISTER_NAME (i
)) == '\0')
1354 fputs_filtered (REGISTER_NAME (i
), gdb_stdout
);
1355 print_spaces_filtered (15 - strlen (REGISTER_NAME (i
)), gdb_stdout
);
1357 /* Get the data in raw format. */
1358 if (read_relative_register_raw_bytes (i
, raw_buffer
))
1360 printf_filtered ("*value not available*\n");
1364 /* Convert raw data to virtual format if necessary. */
1365 if (REGISTER_CONVERTIBLE (i
))
1367 REGISTER_CONVERT_TO_VIRTUAL (i
, REGISTER_VIRTUAL_TYPE (i
),
1368 raw_buffer
, virtual_buffer
);
1372 memcpy (virtual_buffer
, raw_buffer
,
1373 REGISTER_VIRTUAL_SIZE (i
));
1376 /* If virtual format is floating, print it that way, and in raw hex. */
1377 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i
)) == TYPE_CODE_FLT
)
1381 #ifdef INVALID_FLOAT
1382 if (INVALID_FLOAT (virtual_buffer
, REGISTER_VIRTUAL_SIZE (i
)))
1383 printf_filtered ("<invalid float>");
1386 val_print (REGISTER_VIRTUAL_TYPE (i
), virtual_buffer
, 0, 0,
1387 gdb_stdout
, 0, 1, 0, Val_pretty_default
);
1389 printf_filtered ("\t(raw 0x");
1390 for (j
= 0; j
< REGISTER_RAW_SIZE (i
); j
++)
1392 register int idx
= TARGET_BYTE_ORDER
== BIG_ENDIAN
? j
1393 : REGISTER_RAW_SIZE (i
) - 1 - j
;
1394 printf_filtered ("%02x", (unsigned char) raw_buffer
[idx
]);
1396 printf_filtered (")");
1399 /* FIXME! val_print probably can handle all of these cases now... */
1401 /* Else if virtual format is too long for printf,
1402 print in hex a byte at a time. */
1403 else if (REGISTER_VIRTUAL_SIZE (i
) > (int) sizeof (long))
1406 printf_filtered ("0x");
1407 for (j
= 0; j
< REGISTER_VIRTUAL_SIZE (i
); j
++)
1408 printf_filtered ("%02x", (unsigned char) virtual_buffer
[j
]);
1410 /* Else print as integer in hex and in decimal. */
1413 val_print (REGISTER_VIRTUAL_TYPE (i
), virtual_buffer
, 0, 0,
1414 gdb_stdout
, 'x', 1, 0, Val_pretty_default
);
1415 printf_filtered ("\t");
1416 val_print (REGISTER_VIRTUAL_TYPE (i
), virtual_buffer
, 0, 0,
1417 gdb_stdout
, 0, 1, 0, Val_pretty_default
);
1420 /* The SPARC wants to print even-numbered float regs as doubles
1421 in addition to printing them as floats. */
1422 #ifdef PRINT_REGISTER_HOOK
1423 PRINT_REGISTER_HOOK (i
);
1426 printf_filtered ("\n");
1429 #endif /* no DO_REGISTERS_INFO. */
1432 registers_info (addr_exp
, fpregs
)
1436 int regnum
, numregs
;
1439 if (!target_has_registers
)
1440 error ("The program has no registers now.");
1441 if (selected_frame
== NULL
)
1442 error ("No selected frame.");
1446 DO_REGISTERS_INFO (-1, fpregs
);
1452 if (addr_exp
[0] == '$')
1455 while (*end
!= '\0' && *end
!= ' ' && *end
!= '\t')
1457 numregs
= ARCH_NUM_REGS
;
1459 regnum
= target_map_name_to_register (addr_exp
, end
- addr_exp
);
1465 if (*addr_exp
>= '0' && *addr_exp
<= '9')
1466 regnum
= atoi (addr_exp
); /* Take a number */
1467 if (regnum
>= numregs
) /* Bad name, or bad number */
1468 error ("%.*s: invalid register", end
- addr_exp
, addr_exp
);
1471 DO_REGISTERS_INFO (regnum
, fpregs
);
1474 while (*addr_exp
== ' ' || *addr_exp
== '\t')
1477 while (*addr_exp
!= '\0');
1481 all_registers_info (addr_exp
, from_tty
)
1485 registers_info (addr_exp
, 1);
1489 nofp_registers_info (addr_exp
, from_tty
)
1493 registers_info (addr_exp
, 0);
1499 * Should save/restore the tty state since it might be that the
1500 * program to be debugged was started on this tty and it wants
1501 * the tty in some state other than what we want. If it's running
1502 * on another terminal or without a terminal, then saving and
1503 * restoring the tty state is a harmless no-op.
1504 * This only needs to be done if we are attaching to a process.
1509 takes a program started up outside of gdb and ``attaches'' to it.
1510 This stops it cold in its tracks and allows us to start debugging it.
1511 and wait for the trace-trap that results from attaching. */
1514 attach_command (args
, from_tty
)
1519 extern int auto_solib_add
;
1523 char *full_exec_path
= NULL
;
1525 dont_repeat (); /* Not for the faint of heart */
1527 if (target_has_execution
)
1529 if (query ("A program is being debugged already. Kill it? "))
1532 error ("Not killed.");
1535 target_attach (args
, from_tty
);
1537 /* Set up the "saved terminal modes" of the inferior
1538 based on what modes we are starting it with. */
1539 target_terminal_init ();
1541 /* Install inferior's terminal modes. */
1542 target_terminal_inferior ();
1544 /* Set up execution context to know that we should return from
1545 wait_for_inferior as soon as the target reports a stop. */
1546 init_wait_for_inferior ();
1547 clear_proceed_status ();
1548 stop_soon_quietly
= 1;
1550 /* No traps are generated when attaching to inferior under Mach 3
1552 #ifndef ATTACH_NO_WAIT
1553 wait_for_inferior ();
1557 * If no exec file is yet known, try to determine it from the
1560 exec_file
= (char *) get_exec_file (0);
1563 exec_file
= target_pid_to_exec_file (inferior_pid
);
1566 /* It's possible we don't have a full path, but rather just a
1567 filename. Some targets, such as HP-UX, don't provide the
1570 Attempt to qualify the filename against the source path.
1571 (If that fails, we'll just fall back on the original
1572 filename. Not much more we can do...)
1574 if (!source_full_path_of (exec_file
, &full_exec_path
))
1575 full_exec_path
= savestring (exec_file
, strlen (exec_file
));
1577 exec_file_attach (full_exec_path
, from_tty
);
1578 symbol_file_command (full_exec_path
, from_tty
);
1585 /* Add shared library symbols from the newly attached process, if any. */
1586 SOLIB_ADD ((char *) 0, from_tty
, ¤t_target
);
1587 re_enable_breakpoints_in_shlibs ();
1591 /* Take any necessary post-attaching actions for this platform.
1593 target_post_attach (inferior_pid
);
1603 * takes a program previously attached to and detaches it.
1604 * The program resumes execution and will no longer stop
1605 * on signals, etc. We better not have left any breakpoints
1606 * in the program or it'll die when it hits one. For this
1607 * to work, it may be necessary for the process to have been
1608 * previously attached. It *might* work if the program was
1609 * started via the normal ptrace (PTRACE_TRACEME).
1613 detach_command (args
, from_tty
)
1617 dont_repeat (); /* Not for the faint of heart */
1618 target_detach (args
, from_tty
);
1619 #if defined(SOLIB_RESTART)
1626 /* Stop the execution of the target while running in async mode, in
1629 interrupt_target_command (args
, from_tty
)
1633 if (event_loop_p
&& target_can_async_p ())
1635 dont_repeat (); /* Not for the faint of heart */
1642 float_info (addr_exp
, from_tty
)
1649 printf_filtered ("No floating point info available for this processor.\n");
1655 unset_command (args
, from_tty
)
1659 printf_filtered ("\"unset\" must be followed by the name of ");
1660 printf_filtered ("an unset subcommand.\n");
1661 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
1665 _initialize_infcmd ()
1667 struct cmd_list_element
*c
;
1669 add_com ("tty", class_run
, tty_command
,
1670 "Set terminal for future runs of program being debugged.");
1673 (add_set_cmd ("args", class_run
, var_string_noescape
,
1674 (char *) &inferior_args
,
1675 "Set argument list to give program being debugged when it is started.\n\
1676 Follow this command with any number of args, to be passed to the program.",
1681 ("environment", no_class
, environment_info
,
1682 "The environment to give the program, or one variable's value.\n\
1683 With an argument VAR, prints the value of environment variable VAR to\n\
1684 give the program being debugged. With no arguments, prints the entire\n\
1685 environment to be given to the program.", &showlist
);
1686 c
->completer
= noop_completer
;
1688 add_prefix_cmd ("unset", no_class
, unset_command
,
1689 "Complement to certain \"set\" commands",
1690 &unsetlist
, "unset ", 0, &cmdlist
);
1692 c
= add_cmd ("environment", class_run
, unset_environment_command
,
1693 "Cancel environment variable VAR for the program.\n\
1694 This does not affect the program until the next \"run\" command.",
1696 c
->completer
= noop_completer
;
1698 c
= add_cmd ("environment", class_run
, set_environment_command
,
1699 "Set environment variable value to give the program.\n\
1700 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1701 VALUES of environment variables are uninterpreted strings.\n\
1702 This does not affect the program until the next \"run\" command.",
1704 c
->completer
= noop_completer
;
1706 add_com ("path", class_files
, path_command
,
1707 "Add directory DIR(s) to beginning of search path for object files.\n\
1708 $cwd in the path means the current working directory.\n\
1709 This path is equivalent to the $PATH shell variable. It is a list of\n\
1710 directories, separated by colons. These directories are searched to find\n\
1711 fully linked executable files and separately compiled object files as needed.");
1713 c
= add_cmd ("paths", no_class
, path_info
,
1714 "Current search path for finding object files.\n\
1715 $cwd in the path means the current working directory.\n\
1716 This path is equivalent to the $PATH shell variable. It is a list of\n\
1717 directories, separated by colons. These directories are searched to find\n\
1718 fully linked executable files and separately compiled object files as needed.",
1720 c
->completer
= noop_completer
;
1722 add_com ("attach", class_run
, attach_command
,
1723 "Attach to a process or file outside of GDB.\n\
1724 This command attaches to another target, of the same type as your last\n\
1725 \"target\" command (\"info files\" will show your target stack).\n\
1726 The command may take as argument a process id or a device file.\n\
1727 For a process id, you must have permission to send the process a signal,\n\
1728 and it must have the same effective uid as the debugger.\n\
1729 When using \"attach\" with a process id, the debugger finds the\n\
1730 program running in the process, looking first in the current working\n\
1731 directory, or (if not found there) using the source file search path\n\
1732 (see the \"directory\" command). You can also use the \"file\" command\n\
1733 to specify the program, and to load its symbol table.");
1735 add_com ("detach", class_run
, detach_command
,
1736 "Detach a process or file previously attached.\n\
1737 If a process, it is no longer traced, and it continues its execution. If\n\
1738 you were debugging a file, the file is closed and gdb no longer accesses it.");
1740 add_com ("signal", class_run
, signal_command
,
1741 "Continue program giving it signal specified by the argument.\n\
1742 An argument of \"0\" means continue program without giving it a signal.");
1744 add_com ("stepi", class_run
, stepi_command
,
1745 "Step one instruction exactly.\n\
1746 Argument N means do this N times (or till program stops for another reason).");
1747 add_com_alias ("si", "stepi", class_alias
, 0);
1749 add_com ("nexti", class_run
, nexti_command
,
1750 "Step one instruction, but proceed through subroutine calls.\n\
1751 Argument N means do this N times (or till program stops for another reason).");
1752 add_com_alias ("ni", "nexti", class_alias
, 0);
1754 add_com ("finish", class_run
, finish_command
,
1755 "Execute until selected stack frame returns.\n\
1756 Upon return, the value returned is printed and put in the value history.");
1758 add_com ("next", class_run
, next_command
,
1759 "Step program, proceeding through subroutine calls.\n\
1760 Like the \"step\" command as long as subroutine calls do not happen;\n\
1761 when they do, the call is treated as one instruction.\n\
1762 Argument N means do this N times (or till program stops for another reason).");
1763 add_com_alias ("n", "next", class_run
, 1);
1765 add_com_alias ("S", "next", class_run
, 1);
1767 add_com ("step", class_run
, step_command
,
1768 "Step program until it reaches a different source line.\n\
1769 Argument N means do this N times (or till program stops for another reason).");
1770 add_com_alias ("s", "step", class_run
, 1);
1772 add_com ("until", class_run
, until_command
,
1773 "Execute until the program reaches a source line greater than the current\n\
1774 or a specified line or address or function (same args as break command).\n\
1775 Execution will also stop upon exit from the current stack frame.");
1776 add_com_alias ("u", "until", class_run
, 1);
1778 add_com ("jump", class_run
, jump_command
,
1779 "Continue program being debugged at specified line or address.\n\
1780 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1781 for an address to start at.");
1784 add_com ("go", class_run
, go_command
,
1785 "Usage: go <location>\n\
1786 Continue program being debugged, stopping at specified line or \n\
1788 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
1789 expression for an address to start at.\n\
1790 This command is a combination of tbreak and jump.");
1793 add_com_alias ("g", "go", class_run
, 1);
1795 add_com ("continue", class_run
, continue_command
,
1796 "Continue program being debugged, after signal or breakpoint.\n\
1797 If proceeding from breakpoint, a number N may be used as an argument,\n\
1798 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1799 the breakpoint won't break until the Nth time it is reached).");
1800 add_com_alias ("c", "cont", class_run
, 1);
1801 add_com_alias ("fg", "cont", class_run
, 1);
1803 add_com ("run", class_run
, run_command
,
1804 "Start debugged program. You may specify arguments to give it.\n\
1805 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1806 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1807 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1808 To cancel previous arguments and run with no arguments,\n\
1809 use \"set args\" without arguments.");
1810 add_com_alias ("r", "run", class_run
, 1);
1812 add_com ("R", class_run
, run_no_args_command
,
1813 "Start debugged program with no arguments.");
1815 add_com ("interrupt", class_run
, interrupt_target_command
,
1816 "Interrupt the execution of the debugged program.");
1818 add_info ("registers", nofp_registers_info
,
1819 "List of integer registers and their contents, for selected stack frame.\n\
1820 Register name as argument means describe only that register.");
1823 add_com ("lr", class_info
, nofp_registers_info
,
1824 "List of integer registers and their contents, for selected stack frame.\n\
1825 Register name as argument means describe only that register.");
1826 add_info ("all-registers", all_registers_info
,
1827 "List of all registers and their contents, for selected stack frame.\n\
1828 Register name as argument means describe only that register.");
1830 add_info ("program", program_info
,
1831 "Execution status of the program.");
1833 add_info ("float", float_info
,
1834 "Print the status of the floating point unit\n");
1836 inferior_args
= savestring ("", 1); /* Initially no args */
1837 inferior_environ
= make_environ ();
1838 init_environ (inferior_environ
);