1 /* Memory-access and commands for "inferior" (child) process, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include <sys/param.h>
35 continue_command
PARAMS ((char *, int));
38 until_next_command
PARAMS ((int));
41 until_command
PARAMS ((char *, int));
44 path_info
PARAMS ((char *, int));
47 path_command
PARAMS ((char *, int));
50 unset_command
PARAMS ((char *, int));
53 float_info
PARAMS ((char *, int));
56 detach_command
PARAMS ((char *, int));
59 nofp_registers_info
PARAMS ((char *, int));
62 all_registers_info
PARAMS ((char *, int));
65 registers_info
PARAMS ((char *, int));
68 do_registers_info
PARAMS ((int, int));
71 unset_environment_command
PARAMS ((char *, int));
74 set_environment_command
PARAMS ((char *, int));
77 environment_info
PARAMS ((char *, int));
80 program_info
PARAMS ((char *, int));
83 finish_command
PARAMS ((char *, int));
86 signal_command
PARAMS ((char *, int));
89 jump_command
PARAMS ((char *, int));
92 step_1
PARAMS ((int, int, char *));
95 nexti_command
PARAMS ((char *, int));
98 stepi_command
PARAMS ((char *, int));
101 next_command
PARAMS ((char *, int));
104 step_command
PARAMS ((char *, int));
107 run_command
PARAMS ((char *, int));
109 #define ERROR_NO_INFERIOR \
110 if (!target_has_execution) error ("The program is not being run.");
112 /* String containing arguments to give to the program, separated by spaces.
113 Empty string (pointer to '\0') means no args. */
115 static char *inferior_args
;
117 /* File name for default use for standard in/out in the inferior. */
119 char *inferior_io_terminal
;
121 /* Pid of our debugged inferior, or 0 if no inferior now.
122 Since various parts of infrun.c test this to see whether there is a program
123 being debugged it should be nonzero (currently 3 is used) for remote
128 /* Last signal that the inferior received (why it stopped). */
132 /* Address at which inferior stopped. */
136 /* Stack frame when program stopped. */
138 FRAME_ADDR stop_frame_address
;
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 FRAME_ADDR step_frame_address
;
175 /* 1 means step over all subroutine calls.
176 0 means don't step over calls (used by stepi).
177 -1 means step over calls to undebuggable functions. */
181 /* If stepping, nonzero means step count is > 1
182 so don't print frame next time inferior stops
183 if it stops due to stepping. */
187 /* Environment to use for running inferior,
188 in format described in environ.h. */
190 struct environ
*inferior_environ
;
195 tty_command (file
, from_tty
)
200 error_no_arg ("terminal name for running target process");
202 inferior_io_terminal
= savestring (file
, strlen (file
));
206 run_command (args
, from_tty
)
217 !query ("The program being debugged has been started already.\n\
218 Start it from the beginning? "))
219 error ("Program not restarted.");
223 exec_file
= (char *) get_exec_file (0);
225 /* The exec file is re-read every time we do a generic_mourn_inferior, so
226 we just have to worry about the symbol file. */
232 cmd
= concat ("set args ", args
, NULL
);
233 make_cleanup (free
, cmd
);
234 execute_command (cmd
, from_tty
);
239 puts_filtered("Starting program: ");
241 puts_filtered(exec_file
);
243 puts_filtered(inferior_args
);
248 target_create_inferior (exec_file
, inferior_args
,
249 environ_vector (inferior_environ
));
253 continue_command (proc_count_exp
, from_tty
)
254 char *proc_count_exp
;
259 /* If have argument, set proceed count of breakpoint we stopped at. */
261 if (proc_count_exp
!= NULL
)
263 bpstat bs
= stop_bpstat
;
264 int num
= bpstat_num (&bs
);
265 if (num
== 0 && from_tty
)
268 ("Not stopped at any breakpoint; argument ignored.\n");
272 set_ignore_count (num
,
273 parse_and_eval_address (proc_count_exp
) - 1,
275 /* set_ignore_count prints a message ending with a period.
276 So print two spaces before "Continuing.". */
278 printf_filtered (" ");
279 num
= bpstat_num (&bs
);
284 printf_filtered ("Continuing.\n");
286 clear_proceed_status ();
288 proceed ((CORE_ADDR
) -1, -1, 0);
291 /* Step until outside of current statement. */
295 step_command (count_string
, from_tty
)
299 step_1 (0, 0, count_string
);
302 /* Likewise, but skip over subroutine calls as if single instructions. */
306 next_command (count_string
, from_tty
)
310 step_1 (1, 0, count_string
);
313 /* Likewise, but step only one instruction. */
317 stepi_command (count_string
, from_tty
)
321 step_1 (0, 1, count_string
);
326 nexti_command (count_string
, from_tty
)
330 step_1 (1, 1, count_string
);
334 step_1 (skip_subroutines
, single_inst
, count_string
)
335 int skip_subroutines
;
339 register int count
= 1;
341 struct cleanup
*cleanups
= 0;
344 count
= count_string
? parse_and_eval_address (count_string
) : 1;
346 if (!single_inst
|| skip_subroutines
) /* leave si command alone */
348 enable_longjmp_breakpoint();
349 cleanups
= make_cleanup(disable_longjmp_breakpoint
, 0);
352 for (; count
> 0; count
--)
354 clear_proceed_status ();
356 fr
= get_current_frame ();
357 if (!fr
) /* Avoid coredump here. Why tho? */
358 error ("No current frame");
359 step_frame_address
= FRAME_FP (fr
);
363 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
364 if (step_range_end
== 0)
366 struct minimal_symbol
*msymbol
;
368 /* FIXME: This should be using containing_function_bounds or a
369 cleaned-up version thereof, to deal with things like the
370 end of the text segment. */
372 msymbol
= lookup_minimal_symbol_by_pc (stop_pc
);
373 target_terminal_ours ();
374 printf_filtered ("Current function has no line number information.\n");
377 if (msymbol
== NULL
|| SYMBOL_NAME (msymbol
+ 1) == NULL
)
379 /* If sigtramp is in the u area, check for it. */
380 #if defined SIGTRAMP_START
381 if (IN_SIGTRAMP (stop_pc
, (char *)NULL
))
383 step_range_start
= SIGTRAMP_START
;
384 step_range_end
= SIGTRAMP_END
;
388 error ("Cannot find bounds of current function.");
392 step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
393 step_range_end
= SYMBOL_VALUE_ADDRESS (msymbol
+ 1);
396 printf_filtered ("Single stepping until function exit.\n");
402 /* Say we are stepping, but stop after one insn whatever it does.
403 Don't step through subroutine calls even to undebuggable
405 step_range_start
= step_range_end
= 1;
406 if (!skip_subroutines
)
410 if (skip_subroutines
)
413 step_multi
= (count
> 1);
414 proceed ((CORE_ADDR
) -1, -1, 1);
417 #if defined (SHIFT_INST_REGS)
418 write_register (NNPC_REGNUM
, read_register (NPC_REGNUM
));
419 write_register (NPC_REGNUM
, read_register (PC_REGNUM
));
423 if (!single_inst
|| skip_subroutines
)
424 do_cleanups(cleanups
);
427 /* Continue program at specified address. */
430 jump_command (arg
, from_tty
)
434 register CORE_ADDR addr
;
435 struct symtabs_and_lines sals
;
436 struct symtab_and_line sal
;
443 error_no_arg ("starting address");
445 sals
= decode_line_spec_1 (arg
, 1);
448 error ("Unreasonable jump request");
452 free ((PTR
)sals
.sals
);
454 if (sal
.symtab
== 0 && sal
.pc
== 0)
455 error ("No source file has been specified.");
457 resolve_sal_pc (&sal
); /* May error out */
459 /* See if we are trying to jump to another function. */
460 fn
= get_frame_function (get_current_frame ());
461 sfn
= find_pc_function (sal
.pc
);
462 if (fn
!= NULL
&& sfn
!= fn
)
464 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal
.line
,
465 SYMBOL_SOURCE_NAME (fn
)))
467 error ("Not confirmed.");
472 addr
= ADDR_BITS_SET (sal
.pc
);
475 printf_filtered ("Continuing at %s.\n", local_hex_string(addr
));
477 clear_proceed_status ();
478 proceed (addr
, 0, 0);
481 /* Continue program giving it specified signal. */
484 signal_command (signum_exp
, from_tty
)
490 dont_repeat (); /* Too dangerous. */
494 error_no_arg ("signal number");
496 /* It would be even slicker to make signal names be valid expressions,
497 (the type could be "enum $signal" or some such), then the user could
498 assign them to convenience variables. */
499 signum
= strtosigno (signum_exp
);
502 /* Not found as a name, try it as an expression. */
503 signum
= parse_and_eval_address (signum_exp
);
507 char *signame
= strsigno (signum
);
508 printf_filtered ("Continuing with signal ");
509 if (signame
== NULL
|| signum
== 0)
510 printf_filtered ("%d.\n", signum
);
512 /* Do we need to print the number as well as the name? */
513 printf_filtered ("%s (%d).\n", signame
, signum
);
516 clear_proceed_status ();
517 proceed (stop_pc
, signum
, 0);
520 /* Execute a "stack dummy", a piece of code stored in the stack
521 by the debugger to be executed in the inferior.
523 To call: first, do PUSH_DUMMY_FRAME.
524 Then push the contents of the dummy. It should end with a breakpoint insn.
525 Then call here, passing address at which to start the dummy.
527 The contents of all registers are saved before the dummy frame is popped
528 and copied into the buffer BUFFER.
530 The dummy's frame is automatically popped whenever that break is hit.
531 If that is the first time the program stops, run_stack_dummy
532 returns to its caller with that frame already gone.
533 Otherwise, the caller never gets returned to.
535 NAME is a string to print to identify the function which we are calling.
536 It is not guaranteed to be the name of a function, it could be something
537 like "at 0x4370" if a name can't be found for the function. */
539 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
541 static int stack_dummy_testing
= 0;
544 run_stack_dummy (name
, addr
, buffer
)
547 char buffer
[REGISTER_BYTES
];
549 /* Now proceed, having reached the desired place. */
550 clear_proceed_status ();
551 if (stack_dummy_testing
& 4)
556 proceed_to_finish
= 1; /* We want stop_registers, please... */
557 proceed (addr
, 0, 0);
559 if (!stop_stack_dummy
)
561 "The expression which contained the function call has been discarded."
562 It is a hard concept to explain in a few words. Ideally, GDB would
563 be able to resume evaluation of the expression when the function
564 finally is done executing. Perhaps someday this will be implemented
565 (it would not be easy). */
567 The program being debugged stopped while in a function called from GDB.\n\
568 When the function (%s) is done executing, GDB will silently\n\
569 stop (instead of continuing to evaluate the expression containing\n\
570 the function call).", name
);
572 /* On return, the stack dummy has been popped already. */
574 memcpy (buffer
, stop_registers
, sizeof stop_registers
);
577 /* Proceed until we reach a different source line with pc greater than
578 our current one or exit the function. We skip calls in both cases.
580 Note that eventually this command should probably be changed so
581 that only source lines are printed out when we hit the breakpoint
582 we set. I'm going to postpone this until after a hopeful rewrite
583 of wait_for_inferior and the proceed status code. -- randy */
587 until_next_command (from_tty
)
593 struct symtab_and_line sal
;
595 clear_proceed_status ();
597 frame
= get_current_frame ();
599 /* Step until either exited from this function or greater
600 than the current line (if in symbolic section) or pc (if
604 func
= find_pc_function (pc
);
608 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
611 error ("Execution is not within a known function.");
613 step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
618 sal
= find_pc_line (pc
, 0);
620 step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
621 step_range_end
= sal
.end
;
625 step_frame_address
= FRAME_FP (frame
);
627 step_multi
= 0; /* Only one call to proceed */
629 proceed ((CORE_ADDR
) -1, -1, 1);
633 until_command (arg
, from_tty
)
637 if (!target_has_execution
)
638 error ("The program is not running.");
640 until_break_command (arg
, from_tty
);
642 until_next_command (from_tty
);
645 /* "finish": Set a temporary breakpoint at the place
646 the selected frame will return to, then continue. */
649 finish_command (arg
, from_tty
)
653 struct symtab_and_line sal
;
654 register FRAME frame
;
655 struct frame_info
*fi
;
656 register struct symbol
*function
;
657 struct breakpoint
*breakpoint
;
658 struct cleanup
*old_chain
;
661 error ("The \"finish\" command does not take any arguments.");
662 if (!target_has_execution
)
663 error ("The program is not running.");
664 if (selected_frame
== NULL
)
665 error ("No selected frame.");
667 frame
= get_prev_frame (selected_frame
);
669 error ("\"finish\" not meaningful in the outermost frame.");
671 clear_proceed_status ();
673 fi
= get_frame_info (frame
);
674 sal
= find_pc_line (fi
->pc
, 0);
677 breakpoint
= set_momentary_breakpoint (sal
, frame
, bp_finish
);
679 old_chain
= make_cleanup(delete_breakpoint
, breakpoint
);
681 /* Find the function we will return from. */
683 fi
= get_frame_info (selected_frame
);
684 function
= find_pc_function (fi
->pc
);
686 /* Print info on the selected frame, including level number
690 printf_filtered ("Run till exit from ");
691 print_stack_frame (selected_frame
, selected_frame_level
, 0);
694 proceed_to_finish
= 1; /* We want stop_registers, please... */
695 proceed ((CORE_ADDR
) -1, -1, 0);
697 /* Did we stop at our breakpoint? */
698 if (bpstat_find_breakpoint(stop_bpstat
, breakpoint
) != NULL
701 struct type
*value_type
;
705 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
707 fatal ("internal: finish_command: function has no target type");
709 if (TYPE_CODE (value_type
) == TYPE_CODE_VOID
)
712 funcaddr
= BLOCK_START (SYMBOL_BLOCK_VALUE (function
));
714 val
= value_being_returned (value_type
, stop_registers
,
715 using_struct_return (value_of_variable (function
),
718 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function
))));
720 printf_filtered ("Value returned is $%d = ", record_latest_value (val
));
721 value_print (val
, stdout
, 0, Val_no_prettyprint
);
722 printf_filtered ("\n");
724 do_cleanups(old_chain
);
729 program_info (args
, from_tty
)
733 bpstat bs
= stop_bpstat
;
734 int num
= bpstat_num (&bs
);
736 if (!target_has_execution
)
738 printf_filtered ("The program being debugged is not being run.\n");
742 target_files_info ();
743 printf_filtered ("Program stopped at %s.\n", local_hex_string(stop_pc
));
745 printf_filtered ("It stopped after being stepped.\n");
748 /* There may be several breakpoints in the same place, so this
749 isn't as strange as it seems. */
753 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
755 printf_filtered ("It stopped at breakpoint %d.\n", num
);
756 num
= bpstat_num (&bs
);
759 else if (stop_signal
)
761 #ifdef PRINT_RANDOM_SIGNAL
762 PRINT_RANDOM_SIGNAL (stop_signal
);
764 char *signame
= strsigno (stop_signal
);
765 printf_filtered ("It stopped with signal ");
767 printf_filtered ("%d", stop_signal
);
769 /* Do we need to print the number as well as the name? */
770 printf_filtered ("%s (%d)", signame
, stop_signal
);
771 printf_filtered (", %s.\n", safe_strsignal (stop_signal
));
776 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
780 environment_info (var
, from_tty
)
786 register char *val
= get_in_environ (inferior_environ
, var
);
790 puts_filtered (" = ");
792 puts_filtered ("\n");
796 puts_filtered ("Environment variable \"");
798 puts_filtered ("\" not defined.\n");
803 register char **vector
= environ_vector (inferior_environ
);
806 puts_filtered (*vector
++);
807 puts_filtered ("\n");
813 set_environment_command (arg
, from_tty
)
817 register char *p
, *val
, *var
;
821 error_no_arg ("environment variable and value");
823 /* Find seperation between variable name and value */
824 p
= (char *) strchr (arg
, '=');
825 val
= (char *) strchr (arg
, ' ');
827 if (p
!= 0 && val
!= 0)
829 /* We have both a space and an equals. If the space is before the
830 equals, walk forward over the spaces til we see a nonspace
831 (possibly the equals). */
836 /* Now if the = is after the char following the spaces,
837 take the char following the spaces. */
841 else if (val
!= 0 && p
== 0)
845 error_no_arg ("environment variable to set");
847 if (p
== 0 || p
[1] == 0)
851 p
= arg
+ strlen (arg
); /* So that savestring below will work */
855 /* Not setting variable value to null */
857 while (*val
== ' ' || *val
== '\t')
861 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t')) p
--;
863 var
= savestring (arg
, p
- arg
);
866 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var
);
867 set_in_environ (inferior_environ
, var
, "");
870 set_in_environ (inferior_environ
, var
, val
);
875 unset_environment_command (var
, from_tty
)
881 /* If there is no argument, delete all environment variables.
882 Ask for confirmation if reading from the terminal. */
883 if (!from_tty
|| query ("Delete all environment variables? "))
885 free_environ (inferior_environ
);
886 inferior_environ
= make_environ ();
890 unset_in_environ (inferior_environ
, var
);
893 /* Handle the execution path (PATH variable) */
895 static const char path_var_name
[] = "PATH";
899 path_info (args
, from_tty
)
903 puts_filtered ("Executable and object file path: ");
904 puts_filtered (get_in_environ (inferior_environ
, path_var_name
));
905 puts_filtered ("\n");
908 /* Add zero or more directories to the front of the execution path. */
911 path_command (dirname
, from_tty
)
918 exec_path
= strsave (get_in_environ (inferior_environ
, path_var_name
));
919 mod_path (dirname
, &exec_path
);
920 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
923 path_info ((char *)NULL
, from_tty
);
926 /* This routine is getting awfully cluttered with #if's. It's probably
927 time to turn this into READ_PC and define it in the tm.h file.
928 Ditto for write_pc. */
933 #ifdef GDB_TARGET_IS_HPPA
934 int flags
= read_register(FLAGS_REGNUM
);
937 return read_register(31) & ~0x3; /* User PC is here when in sys call */
938 return read_register (PC_REGNUM
) & ~0x3;
940 #ifdef TARGET_READ_PC
941 return TARGET_READ_PC ();
943 return ADDR_BITS_REMOVE ((CORE_ADDR
) read_register (PC_REGNUM
));
952 #ifdef TARGET_WRITE_PC
953 TARGET_WRITE_PC (val
);
955 write_register (PC_REGNUM
, (long) val
);
957 write_register (NPC_REGNUM
, (long) val
+ 4);
959 write_register (NNPC_REGNUM
, (long) val
+ 8);
966 /* Cope with strage ways of getting to the stack and frame pointers */
971 #ifdef TARGET_READ_SP
972 return TARGET_READ_SP ();
974 return read_register (SP_REGNUM
);
982 #ifdef TARGET_WRITE_SP
983 TARGET_WRITE_SP (val
);
985 write_register (SP_REGNUM
, val
);
993 #ifdef TARGET_READ_FP
994 return TARGET_READ_FP ();
996 return read_register (FP_REGNUM
);
1004 #ifdef TARGET_WRITE_FP
1005 TARGET_WRITE_FP (val
);
1007 write_register (FP_REGNUM
, val
);
1011 const char * const reg_names
[] = REGISTER_NAMES
;
1013 /* Print out the machine register regnum. If regnum is -1,
1014 print all registers (fpregs == 1) or all non-float registers
1017 For most machines, having all_registers_info() print the
1018 register(s) one per line is good enough. If a different format
1019 is required, (eg, for MIPS or Pyramid 90x, which both have
1020 lots of regs), or there is an existing convention for showing
1021 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
1022 to provide that format. */
1024 #if !defined (DO_REGISTERS_INFO)
1025 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
1027 do_registers_info (regnum
, fpregs
)
1033 for (i
= 0; i
< NUM_REGS
; i
++)
1035 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1036 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
1038 /* Decide between printing all regs, nonfloat regs, or specific reg. */
1040 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i
)) == TYPE_CODE_FLT
&& !fpregs
)
1047 fputs_filtered (reg_names
[i
], stdout
);
1048 print_spaces_filtered (15 - strlen (reg_names
[i
]), stdout
);
1050 /* Get the data in raw format, then convert also to virtual format. */
1051 if (read_relative_register_raw_bytes (i
, raw_buffer
))
1053 printf_filtered ("Invalid register contents\n");
1057 REGISTER_CONVERT_TO_VIRTUAL (i
, raw_buffer
, virtual_buffer
);
1059 /* If virtual format is floating, print it that way, and in raw hex. */
1060 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i
)) == TYPE_CODE_FLT
1061 && ! INVALID_FLOAT (virtual_buffer
, REGISTER_VIRTUAL_SIZE (i
)))
1065 val_print (REGISTER_VIRTUAL_TYPE (i
), virtual_buffer
, 0,
1066 stdout
, 0, 1, 0, Val_pretty_default
);
1068 printf_filtered ("\t(raw 0x");
1069 for (j
= 0; j
< REGISTER_RAW_SIZE (i
); j
++)
1070 printf_filtered ("%02x", (unsigned char)raw_buffer
[j
]);
1071 printf_filtered (")");
1074 /* FIXME! val_print probably can handle all of these cases now... */
1076 /* Else if virtual format is too long for printf,
1077 print in hex a byte at a time. */
1078 else if (REGISTER_VIRTUAL_SIZE (i
) > sizeof (long))
1081 printf_filtered ("0x");
1082 for (j
= 0; j
< REGISTER_VIRTUAL_SIZE (i
); j
++)
1083 printf_filtered ("%02x", (unsigned char)virtual_buffer
[j
]);
1085 /* Else print as integer in hex and in decimal. */
1088 val_print (REGISTER_VIRTUAL_TYPE (i
), raw_buffer
, 0,
1089 stdout
, 'x', 1, 0, Val_pretty_default
);
1090 printf_filtered ("\t");
1091 val_print (REGISTER_VIRTUAL_TYPE (i
), raw_buffer
, 0,
1092 stdout
, 0, 1, 0, Val_pretty_default
);
1095 /* The SPARC wants to print even-numbered float regs as doubles
1096 in addition to printing them as floats. */
1097 #ifdef PRINT_REGISTER_HOOK
1098 PRINT_REGISTER_HOOK (i
);
1101 printf_filtered ("\n");
1104 #endif /* no DO_REGISTERS_INFO. */
1107 registers_info (addr_exp
, fpregs
)
1114 if (!target_has_registers
)
1115 error ("The program has no registers now.");
1119 DO_REGISTERS_INFO(-1, fpregs
);
1125 if (addr_exp
[0] == '$')
1128 while (*end
!= '\0' && *end
!= ' ' && *end
!= '\t')
1130 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
1131 if (!strncmp (addr_exp
, reg_names
[regnum
], end
- addr_exp
)
1132 && strlen (reg_names
[regnum
]) == end
- addr_exp
)
1134 if (*addr_exp
>= '0' && *addr_exp
<= '9')
1135 regnum
= atoi (addr_exp
); /* Take a number */
1136 if (regnum
>= NUM_REGS
) /* Bad name, or bad number */
1137 error ("%.*s: invalid register", end
- addr_exp
, addr_exp
);
1140 DO_REGISTERS_INFO(regnum
, fpregs
);
1143 while (*addr_exp
== ' ' || *addr_exp
== '\t')
1145 } while (*addr_exp
!= '\0');
1149 all_registers_info (addr_exp
, from_tty
)
1153 registers_info (addr_exp
, 1);
1157 nofp_registers_info (addr_exp
, from_tty
)
1161 registers_info (addr_exp
, 0);
1166 * Should save/restore the tty state since it might be that the
1167 * program to be debugged was started on this tty and it wants
1168 * the tty in some state other than what we want. If it's running
1169 * on another terminal or without a terminal, then saving and
1170 * restoring the tty state is a harmless no-op.
1171 * This only needs to be done if we are attaching to a process.
1176 takes a program started up outside of gdb and ``attaches'' to it.
1177 This stops it cold in its tracks and allows us to start debugging it.
1178 and wait for the trace-trap that results from attaching. */
1181 attach_command (args
, from_tty
)
1185 dont_repeat (); /* Not for the faint of heart */
1187 if (target_has_execution
)
1189 if (query ("A program is being debugged already. Kill it? "))
1192 error ("Not killed.");
1195 target_attach (args
, from_tty
);
1197 /* Set up the "saved terminal modes" of the inferior
1198 based on what modes we are starting it with. */
1199 target_terminal_init ();
1201 /* Install inferior's terminal modes. */
1202 target_terminal_inferior ();
1204 /* Set up execution context to know that we should return from
1205 wait_for_inferior as soon as the target reports a stop. */
1206 init_wait_for_inferior ();
1207 clear_proceed_status ();
1208 stop_soon_quietly
= 1;
1210 wait_for_inferior ();
1213 /* Add shared library symbols from the newly attached process, if any. */
1214 SOLIB_ADD ((char *)0, from_tty
, (struct target_ops
*)0);
1222 * takes a program previously attached to and detaches it.
1223 * The program resumes execution and will no longer stop
1224 * on signals, etc. We better not have left any breakpoints
1225 * in the program or it'll die when it hits one. For this
1226 * to work, it may be necessary for the process to have been
1227 * previously attached. It *might* work if the program was
1228 * started via the normal ptrace (PTRACE_TRACEME).
1232 detach_command (args
, from_tty
)
1236 dont_repeat (); /* Not for the faint of heart */
1237 target_detach (args
, from_tty
);
1242 float_info (addr_exp
, from_tty
)
1249 printf_filtered ("No floating point info available for this processor.\n");
1255 unset_command (args
, from_tty
)
1259 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1260 help_list (unsetlist
, "unset ", -1, stdout
);
1264 _initialize_infcmd ()
1266 struct cmd_list_element
*c
;
1268 add_com ("tty", class_run
, tty_command
,
1269 "Set terminal for future runs of program being debugged.");
1272 (add_set_cmd ("args", class_run
, var_string_noescape
, (char *)&inferior_args
,
1274 "Set arguments to give program being debugged when it is started.\n\
1275 Follow this command with any number of args, to be passed to the program.",
1280 ("environment", no_class
, environment_info
,
1281 "The environment to give the program, or one variable's value.\n\
1282 With an argument VAR, prints the value of environment variable VAR to\n\
1283 give the program being debugged. With no arguments, prints the entire\n\
1284 environment to be given to the program.", &showlist
);
1285 c
->completer
= noop_completer
;
1287 add_prefix_cmd ("unset", no_class
, unset_command
,
1288 "Complement to certain \"set\" commands",
1289 &unsetlist
, "unset ", 0, &cmdlist
);
1291 c
= add_cmd ("environment", class_run
, unset_environment_command
,
1292 "Cancel environment variable VAR for the program.\n\
1293 This does not affect the program until the next \"run\" command.",
1295 c
->completer
= noop_completer
;
1297 c
= add_cmd ("environment", class_run
, set_environment_command
,
1298 "Set environment variable value to give the program.\n\
1299 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1300 VALUES of environment variables are uninterpreted strings.\n\
1301 This does not affect the program until the next \"run\" command.",
1303 c
->completer
= noop_completer
;
1305 add_com ("path", class_files
, path_command
,
1306 "Add directory DIR(s) to beginning of search path for object files.\n\
1307 $cwd in the path means the current working directory.\n\
1308 This path is equivalent to the $PATH shell variable. It is a list of\n\
1309 directories, separated by colons. These directories are searched to find\n\
1310 fully linked executable files and separately compiled object files as needed.");
1312 c
= add_cmd ("paths", no_class
, path_info
,
1313 "Current search path for finding object files.\n\
1314 $cwd in the path means the current working directory.\n\
1315 This path is equivalent to the $PATH shell variable. It is a list of\n\
1316 directories, separated by colons. These directories are searched to find\n\
1317 fully linked executable files and separately compiled object files as needed.", &showlist
);
1318 c
->completer
= noop_completer
;
1320 add_com ("attach", class_run
, attach_command
,
1321 "Attach to a process or file outside of GDB.\n\
1322 This command attaches to another target, of the same type as your last\n\
1323 `target' command (`info files' will show your target stack).\n\
1324 The command may take as argument a process id or a device file.\n\
1325 For a process id, you must have permission to send the process a signal,\n\
1326 and it must have the same effective uid as the debugger.\n\
1327 When using \"attach\", you should use the \"file\" command to specify\n\
1328 the program running in the process, and to load its symbol table.");
1330 add_com ("detach", class_run
, detach_command
,
1331 "Detach a process or file previously attached.\n\
1332 If a process, it is no longer traced, and it continues its execution. If you\n\
1333 were debugging a file, the file is closed and gdb no longer accesses it.");
1335 add_com ("signal", class_run
, signal_command
,
1336 "Continue program giving it signal number SIGNUMBER.");
1338 add_com ("stepi", class_run
, stepi_command
,
1339 "Step one instruction exactly.\n\
1340 Argument N means do this N times (or till program stops for another reason).");
1341 add_com_alias ("si", "stepi", class_alias
, 0);
1343 add_com ("nexti", class_run
, nexti_command
,
1344 "Step one instruction, but proceed through subroutine calls.\n\
1345 Argument N means do this N times (or till program stops for another reason).");
1346 add_com_alias ("ni", "nexti", class_alias
, 0);
1348 add_com ("finish", class_run
, finish_command
,
1349 "Execute until selected stack frame returns.\n\
1350 Upon return, the value returned is printed and put in the value history.");
1352 add_com ("next", class_run
, next_command
,
1353 "Step program, proceeding through subroutine calls.\n\
1354 Like the \"step\" command as long as subroutine calls do not happen;\n\
1355 when they do, the call is treated as one instruction.\n\
1356 Argument N means do this N times (or till program stops for another reason).");
1357 add_com_alias ("n", "next", class_run
, 1);
1359 add_com ("step", class_run
, step_command
,
1360 "Step program until it reaches a different source line.\n\
1361 Argument N means do this N times (or till program stops for another reason).");
1362 add_com_alias ("s", "step", class_run
, 1);
1364 add_com ("until", class_run
, until_command
,
1365 "Execute until the program reaches a source line greater than the current\n\
1366 or a specified line or address or function (same args as break command).\n\
1367 Execution will also stop upon exit from the current stack frame.");
1368 add_com_alias ("u", "until", class_run
, 1);
1370 add_com ("jump", class_run
, jump_command
,
1371 "Continue program being debugged at specified line or address.\n\
1372 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1373 for an address to start at.");
1375 add_com ("continue", class_run
, continue_command
,
1376 "Continue program being debugged, after signal or breakpoint.\n\
1377 If proceeding from breakpoint, a number N may be used as an argument,\n\
1378 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1379 the breakpoint won't break until the Nth time it is reached).");
1380 add_com_alias ("c", "cont", class_run
, 1);
1381 add_com_alias ("fg", "cont", class_run
, 1);
1383 add_com ("run", class_run
, run_command
,
1384 "Start debugged program. You may specify arguments to give it.\n\
1385 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1386 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1387 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1388 To cancel previous arguments and run with no arguments,\n\
1389 use \"set args\" without arguments.");
1390 add_com_alias ("r", "run", class_run
, 1);
1392 add_info ("registers", nofp_registers_info
,
1393 "List of integer registers and their contents, for selected stack frame.\n\
1394 Register name as argument means describe only that register.");
1396 add_info ("all-registers", all_registers_info
,
1397 "List of all registers and their contents, for selected stack frame.\n\
1398 Register name as argument means describe only that register.");
1400 add_info ("program", program_info
,
1401 "Execution status of the program.");
1403 add_info ("float", float_info
,
1404 "Print the status of the floating point unit\n");
1406 inferior_args
= savestring ("", 1); /* Initially no args */
1407 inferior_environ
= make_environ ();
1408 init_environ (inferior_environ
);