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)
214 /* Shouldn't this be target_has_execution? FIXME. */
218 !query ("The program being debugged has been started already.\n\
219 Start it from the beginning? "))
220 error ("Program not restarted.");
224 exec_file = (char *) get_exec_file (0);
226 /* The exec file is re-read every time we do a generic_mourn_inferior, so
227 we just have to worry about the symbol file. */
233 cmd = concat ("set args ", args, NULL);
234 make_cleanup (free, cmd);
235 execute_command (cmd, from_tty);
240 puts_filtered("Starting program: ");
242 puts_filtered(exec_file);
244 puts_filtered(inferior_args);
249 target_create_inferior (exec_file, inferior_args,
250 environ_vector (inferior_environ));
254 continue_command (proc_count_exp, from_tty)
255 char *proc_count_exp;
260 /* If have argument, set proceed count of breakpoint we stopped at. */
262 if (proc_count_exp != NULL)
264 bpstat bs = stop_bpstat;
265 int num = bpstat_num (&bs);
266 if (num == 0 && from_tty)
269 ("Not stopped at any breakpoint; argument ignored.\n");
273 set_ignore_count (num,
274 parse_and_eval_address (proc_count_exp) - 1,
276 /* set_ignore_count prints a message ending with a period.
277 So print two spaces before "Continuing.". */
279 printf_filtered (" ");
280 num = bpstat_num (&bs);
285 printf_filtered ("Continuing.\n");
287 clear_proceed_status ();
289 proceed ((CORE_ADDR) -1, -1, 0);
292 /* Step until outside of current statement. */
296 step_command (count_string, from_tty)
300 step_1 (0, 0, count_string);
303 /* Likewise, but skip over subroutine calls as if single instructions. */
307 next_command (count_string, from_tty)
311 step_1 (1, 0, count_string);
314 /* Likewise, but step only one instruction. */
318 stepi_command (count_string, from_tty)
322 step_1 (0, 1, count_string);
327 nexti_command (count_string, from_tty)
331 step_1 (1, 1, count_string);
335 step_1 (skip_subroutines, single_inst, count_string)
336 int skip_subroutines;
340 register int count = 1;
342 struct cleanup *cleanups = 0;
345 count = count_string ? parse_and_eval_address (count_string) : 1;
347 if (!single_inst || skip_subroutines) /* leave si command alone */
349 enable_longjmp_breakpoint();
350 cleanups = make_cleanup(disable_longjmp_breakpoint, 0);
353 for (; count > 0; count--)
355 clear_proceed_status ();
357 fr = get_current_frame ();
358 if (!fr) /* Avoid coredump here. Why tho? */
359 error ("No current frame");
360 step_frame_address = FRAME_FP (fr);
364 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
365 if (step_range_end == 0)
368 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
369 &step_range_end) == 0)
370 error ("Cannot find bounds of current function");
372 target_terminal_ours ();
374 Single stepping until exit from function %s, \n\
375 which has no line number information.\n", name);
381 /* Say we are stepping, but stop after one insn whatever it does. */
382 step_range_start = step_range_end = 1;
383 if (!skip_subroutines)
385 Don't step over function calls, not even to functions lacking
390 if (skip_subroutines)
393 step_multi = (count > 1);
394 proceed ((CORE_ADDR) -1, -1, 1);
398 /* FIXME: On nexti, this may have already been done (when we hit the
399 step resume break, I think). Probably this should be moved to
400 wait_for_inferior (near the top). */
401 #if defined (SHIFT_INST_REGS)
406 if (!single_inst || skip_subroutines)
407 do_cleanups(cleanups);
410 /* Continue program at specified address. */
413 jump_command (arg, from_tty)
417 register CORE_ADDR addr;
418 struct symtabs_and_lines sals;
419 struct symtab_and_line sal;
426 error_no_arg ("starting address");
428 sals = decode_line_spec_1 (arg, 1);
431 error ("Unreasonable jump request");
435 free ((PTR)sals.sals);
437 if (sal.symtab == 0 && sal.pc == 0)
438 error ("No source file has been specified.");
440 resolve_sal_pc (&sal); /* May error out */
442 /* See if we are trying to jump to another function. */
443 fn = get_frame_function (get_current_frame ());
444 sfn = find_pc_function (sal.pc);
445 if (fn != NULL && sfn != fn)
447 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
448 SYMBOL_SOURCE_NAME (fn)))
450 error ("Not confirmed.");
458 printf_filtered ("Continuing at %s.\n",
459 local_hex_string((unsigned long) addr));
461 clear_proceed_status ();
462 proceed (addr, 0, 0);
465 /* Continue program giving it specified signal. */
468 signal_command (signum_exp, from_tty)
474 dont_repeat (); /* Too dangerous. */
478 error_no_arg ("signal number");
480 /* It would be even slicker to make signal names be valid expressions,
481 (the type could be "enum $signal" or some such), then the user could
482 assign them to convenience variables. */
483 signum = strtosigno (signum_exp);
486 /* Not found as a name, try it as an expression. */
487 signum = parse_and_eval_address (signum_exp);
491 char *signame = strsigno (signum);
492 printf_filtered ("Continuing with signal ");
493 if (signame == NULL || signum == 0)
494 printf_filtered ("%d.\n", signum);
496 /* Do we need to print the number as well as the name? */
497 printf_filtered ("%s (%d).\n", signame, signum);
500 clear_proceed_status ();
501 proceed (stop_pc, signum, 0);
504 /* Call breakpoint_auto_delete on the current contents of the bpstat
505 pointed to by arg (which is really a bpstat *). */
507 breakpoint_auto_delete_contents (arg)
510 breakpoint_auto_delete (*(bpstat *)arg);
513 /* Execute a "stack dummy", a piece of code stored in the stack
514 by the debugger to be executed in the inferior.
516 To call: first, do PUSH_DUMMY_FRAME.
517 Then push the contents of the dummy. It should end with a breakpoint insn.
518 Then call here, passing address at which to start the dummy.
520 The contents of all registers are saved before the dummy frame is popped
521 and copied into the buffer BUFFER.
523 The dummy's frame is automatically popped whenever that break is hit.
524 If that is the first time the program stops, run_stack_dummy
525 returns to its caller with that frame already gone and returns 0.
526 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
527 when we do hit that breakpoint). */
529 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
531 static int stack_dummy_testing = 0;
534 run_stack_dummy (addr, buffer)
536 char buffer[REGISTER_BYTES];
538 struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
540 /* Now proceed, having reached the desired place. */
541 clear_proceed_status ();
542 if (stack_dummy_testing & 4)
547 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
549 struct breakpoint *bpt;
550 struct symtab_and_line sal;
552 sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET;
556 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
557 a breakpoint instruction. If not, the call dummy already has the
558 breakpoint instruction in it.
560 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
561 so we need to subtract the CALL_DUMMY_START_OFFSET. */
562 bpt = set_momentary_breakpoint (sal,
565 bpt->disposition = delete;
567 /* If all error()s out of proceed ended up calling normal_stop (and
568 perhaps they should; it already does in the special case of error
569 out of resume()), then we wouldn't need this. */
570 make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
572 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */
574 proceed_to_finish = 1; /* We want stop_registers, please... */
575 proceed (addr, 0, 0);
577 discard_cleanups (old_cleanups);
579 if (!stop_stack_dummy)
582 /* On return, the stack dummy has been popped already. */
584 memcpy (buffer, stop_registers, sizeof stop_registers);
588 /* Proceed until we reach a different source line with pc greater than
589 our current one or exit the function. We skip calls in both cases.
591 Note that eventually this command should probably be changed so
592 that only source lines are printed out when we hit the breakpoint
593 we set. I'm going to postpone this until after a hopeful rewrite
594 of wait_for_inferior and the proceed status code. -- randy */
598 until_next_command (from_tty)
604 struct symtab_and_line sal;
606 clear_proceed_status ();
608 frame = get_current_frame ();
610 /* Step until either exited from this function or greater
611 than the current line (if in symbolic section) or pc (if
615 func = find_pc_function (pc);
619 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
622 error ("Execution is not within a known function.");
624 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
629 sal = find_pc_line (pc, 0);
631 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
632 step_range_end = sal.end;
636 step_frame_address = FRAME_FP (frame);
638 step_multi = 0; /* Only one call to proceed */
640 proceed ((CORE_ADDR) -1, -1, 1);
644 until_command (arg, from_tty)
648 if (!target_has_execution)
649 error ("The program is not running.");
651 until_break_command (arg, from_tty);
653 until_next_command (from_tty);
656 /* "finish": Set a temporary breakpoint at the place
657 the selected frame will return to, then continue. */
660 finish_command (arg, from_tty)
664 struct symtab_and_line sal;
665 register FRAME frame;
666 struct frame_info *fi;
667 register struct symbol *function;
668 struct breakpoint *breakpoint;
669 struct cleanup *old_chain;
672 error ("The \"finish\" command does not take any arguments.");
673 if (!target_has_execution)
674 error ("The program is not running.");
675 if (selected_frame == NULL)
676 error ("No selected frame.");
678 frame = get_prev_frame (selected_frame);
680 error ("\"finish\" not meaningful in the outermost frame.");
682 clear_proceed_status ();
684 fi = get_frame_info (frame);
685 sal = find_pc_line (fi->pc, 0);
688 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
690 old_chain = make_cleanup(delete_breakpoint, breakpoint);
692 /* Find the function we will return from. */
694 fi = get_frame_info (selected_frame);
695 function = find_pc_function (fi->pc);
697 /* Print info on the selected frame, including level number
701 printf_filtered ("Run till exit from ");
702 print_stack_frame (selected_frame, selected_frame_level, 0);
705 proceed_to_finish = 1; /* We want stop_registers, please... */
706 proceed ((CORE_ADDR) -1, -1, 0);
708 /* Did we stop at our breakpoint? */
709 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
712 struct type *value_type;
716 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
718 fatal ("internal: finish_command: function has no target type");
720 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
723 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
725 val = value_being_returned (value_type, stop_registers,
726 using_struct_return (value_of_variable (function, NULL),
729 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
731 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
732 value_print (val, stdout, 0, Val_no_prettyprint);
733 printf_filtered ("\n");
735 do_cleanups(old_chain);
740 program_info (args, from_tty)
744 bpstat bs = stop_bpstat;
745 int num = bpstat_num (&bs);
747 if (!target_has_execution)
749 printf_filtered ("The program being debugged is not being run.\n");
753 target_files_info ();
754 printf_filtered ("Program stopped at %s.\n",
755 local_hex_string((unsigned long) stop_pc));
757 printf_filtered ("It stopped after being stepped.\n");
760 /* There may be several breakpoints in the same place, so this
761 isn't as strange as it seems. */
765 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
767 printf_filtered ("It stopped at breakpoint %d.\n", num);
768 num = bpstat_num (&bs);
771 else if (stop_signal)
773 #ifdef PRINT_RANDOM_SIGNAL
774 PRINT_RANDOM_SIGNAL (stop_signal);
776 char *signame = strsigno (stop_signal);
777 printf_filtered ("It stopped with signal ");
779 printf_filtered ("%d", stop_signal);
781 /* Do we need to print the number as well as the name? */
782 printf_filtered ("%s (%d)", signame, stop_signal);
783 printf_filtered (", %s.\n", safe_strsignal (stop_signal));
788 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
792 environment_info (var, from_tty)
798 register char *val = get_in_environ (inferior_environ, var);
802 puts_filtered (" = ");
804 puts_filtered ("\n");
808 puts_filtered ("Environment variable \"");
810 puts_filtered ("\" not defined.\n");
815 register char **vector = environ_vector (inferior_environ);
818 puts_filtered (*vector++);
819 puts_filtered ("\n");
825 set_environment_command (arg, from_tty)
829 register char *p, *val, *var;
833 error_no_arg ("environment variable and value");
835 /* Find seperation between variable name and value */
836 p = (char *) strchr (arg, '=');
837 val = (char *) strchr (arg, ' ');
839 if (p != 0 && val != 0)
841 /* We have both a space and an equals. If the space is before the
842 equals, walk forward over the spaces til we see a nonspace
843 (possibly the equals). */
848 /* Now if the = is after the char following the spaces,
849 take the char following the spaces. */
853 else if (val != 0 && p == 0)
857 error_no_arg ("environment variable to set");
859 if (p == 0 || p[1] == 0)
863 p = arg + strlen (arg); /* So that savestring below will work */
867 /* Not setting variable value to null */
869 while (*val == ' ' || *val == '\t')
873 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
875 var = savestring (arg, p - arg);
878 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
879 set_in_environ (inferior_environ, var, "");
882 set_in_environ (inferior_environ, var, val);
887 unset_environment_command (var, from_tty)
893 /* If there is no argument, delete all environment variables.
894 Ask for confirmation if reading from the terminal. */
895 if (!from_tty || query ("Delete all environment variables? "))
897 free_environ (inferior_environ);
898 inferior_environ = make_environ ();
902 unset_in_environ (inferior_environ, var);
905 /* Handle the execution path (PATH variable) */
907 static const char path_var_name[] = "PATH";
911 path_info (args, from_tty)
915 puts_filtered ("Executable and object file path: ");
916 puts_filtered (get_in_environ (inferior_environ, path_var_name));
917 puts_filtered ("\n");
920 /* Add zero or more directories to the front of the execution path. */
923 path_command (dirname, from_tty)
930 exec_path = strsave (get_in_environ (inferior_environ, path_var_name));
931 mod_path (dirname, &exec_path);
932 set_in_environ (inferior_environ, path_var_name, exec_path);
935 path_info ((char *)NULL, from_tty);
938 /* This routine is getting awfully cluttered with #if's. It's probably
939 time to turn this into READ_PC and define it in the tm.h file.
940 Ditto for write_pc. */
945 #ifdef TARGET_READ_PC
946 return TARGET_READ_PC ();
948 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register (PC_REGNUM));
956 #ifdef TARGET_WRITE_PC
957 TARGET_WRITE_PC (val);
959 write_register (PC_REGNUM, (long) val);
961 write_register (NPC_REGNUM, (long) val + 4);
963 write_register (NNPC_REGNUM, (long) val + 8);
969 /* Cope with strage ways of getting to the stack and frame pointers */
974 #ifdef TARGET_READ_SP
975 return TARGET_READ_SP ();
977 return read_register (SP_REGNUM);
985 #ifdef TARGET_WRITE_SP
986 TARGET_WRITE_SP (val);
988 write_register (SP_REGNUM, val);
996 #ifdef TARGET_READ_FP
997 return TARGET_READ_FP ();
999 return read_register (FP_REGNUM);
1007 #ifdef TARGET_WRITE_FP
1008 TARGET_WRITE_FP (val);
1010 write_register (FP_REGNUM, val);
1014 const char * const reg_names[] = REGISTER_NAMES;
1016 /* Print out the machine register regnum. If regnum is -1,
1017 print all registers (fpregs == 1) or all non-float registers
1020 For most machines, having all_registers_info() print the
1021 register(s) one per line is good enough. If a different format
1022 is required, (eg, for MIPS or Pyramid 90x, which both have
1023 lots of regs), or there is an existing convention for showing
1024 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
1025 to provide that format. */
1027 #if !defined (DO_REGISTERS_INFO)
1028 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
1030 do_registers_info (regnum, fpregs)
1036 for (i = 0; i < NUM_REGS; i++)
1038 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1039 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
1041 /* Decide between printing all regs, nonfloat regs, or specific reg. */
1043 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
1050 fputs_filtered (reg_names[i], stdout);
1051 print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
1053 /* Get the data in raw format, then convert also to virtual format. */
1054 if (read_relative_register_raw_bytes (i, raw_buffer))
1056 printf_filtered ("Invalid register contents\n");
1060 REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);
1062 /* If virtual format is floating, print it that way, and in raw hex. */
1063 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT
1064 && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1068 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,
1069 stdout, 0, 1, 0, Val_pretty_default);
1071 printf_filtered ("\t(raw 0x");
1072 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1073 printf_filtered ("%02x", (unsigned char)raw_buffer[j]);
1074 printf_filtered (")");
1077 /* FIXME! val_print probably can handle all of these cases now... */
1079 /* Else if virtual format is too long for printf,
1080 print in hex a byte at a time. */
1081 else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))
1084 printf_filtered ("0x");
1085 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1086 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
1088 /* Else print as integer in hex and in decimal. */
1091 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1092 stdout, 'x', 1, 0, Val_pretty_default);
1093 printf_filtered ("\t");
1094 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1095 stdout, 0, 1, 0, Val_pretty_default);
1098 /* The SPARC wants to print even-numbered float regs as doubles
1099 in addition to printing them as floats. */
1100 #ifdef PRINT_REGISTER_HOOK
1101 PRINT_REGISTER_HOOK (i);
1104 printf_filtered ("\n");
1107 #endif /* no DO_REGISTERS_INFO. */
1110 registers_info (addr_exp, fpregs)
1117 if (!target_has_registers)
1118 error ("The program has no registers now.");
1122 DO_REGISTERS_INFO(-1, fpregs);
1128 if (addr_exp[0] == '$')
1131 while (*end != '\0' && *end != ' ' && *end != '\t')
1133 for (regnum = 0; regnum < NUM_REGS; regnum++)
1134 if (!strncmp (addr_exp, reg_names[regnum], end - addr_exp)
1135 && strlen (reg_names[regnum]) == end - addr_exp)
1137 if (*addr_exp >= '0' && *addr_exp <= '9')
1138 regnum = atoi (addr_exp); /* Take a number */
1139 if (regnum >= NUM_REGS) /* Bad name, or bad number */
1140 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1143 DO_REGISTERS_INFO(regnum, fpregs);
1146 while (*addr_exp == ' ' || *addr_exp == '\t')
1148 } while (*addr_exp != '\0');
1152 all_registers_info (addr_exp, from_tty)
1156 registers_info (addr_exp, 1);
1160 nofp_registers_info (addr_exp, from_tty)
1164 registers_info (addr_exp, 0);
1169 * Should save/restore the tty state since it might be that the
1170 * program to be debugged was started on this tty and it wants
1171 * the tty in some state other than what we want. If it's running
1172 * on another terminal or without a terminal, then saving and
1173 * restoring the tty state is a harmless no-op.
1174 * This only needs to be done if we are attaching to a process.
1179 takes a program started up outside of gdb and ``attaches'' to it.
1180 This stops it cold in its tracks and allows us to start debugging it.
1181 and wait for the trace-trap that results from attaching. */
1184 attach_command (args, from_tty)
1188 dont_repeat (); /* Not for the faint of heart */
1190 if (target_has_execution)
1192 if (query ("A program is being debugged already. Kill it? "))
1195 error ("Not killed.");
1198 target_attach (args, from_tty);
1200 /* Set up the "saved terminal modes" of the inferior
1201 based on what modes we are starting it with. */
1202 target_terminal_init ();
1204 /* Install inferior's terminal modes. */
1205 target_terminal_inferior ();
1207 /* Set up execution context to know that we should return from
1208 wait_for_inferior as soon as the target reports a stop. */
1209 init_wait_for_inferior ();
1210 clear_proceed_status ();
1211 stop_soon_quietly = 1;
1213 wait_for_inferior ();
1216 /* Add shared library symbols from the newly attached process, if any. */
1217 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
1225 * takes a program previously attached to and detaches it.
1226 * The program resumes execution and will no longer stop
1227 * on signals, etc. We better not have left any breakpoints
1228 * in the program or it'll die when it hits one. For this
1229 * to work, it may be necessary for the process to have been
1230 * previously attached. It *might* work if the program was
1231 * started via the normal ptrace (PTRACE_TRACEME).
1235 detach_command (args, from_tty)
1239 dont_repeat (); /* Not for the faint of heart */
1240 target_detach (args, from_tty);
1245 float_info (addr_exp, from_tty)
1252 printf_filtered ("No floating point info available for this processor.\n");
1258 unset_command (args, from_tty)
1262 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1263 help_list (unsetlist, "unset ", -1, stdout);
1267 _initialize_infcmd ()
1269 struct cmd_list_element *c;
1271 add_com ("tty", class_run, tty_command,
1272 "Set terminal for future runs of program being debugged.");
1275 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1277 "Set arguments to give program being debugged when it is started.\n\
1278 Follow this command with any number of args, to be passed to the program.",
1283 ("environment", no_class, environment_info,
1284 "The environment to give the program, or one variable's value.\n\
1285 With an argument VAR, prints the value of environment variable VAR to\n\
1286 give the program being debugged. With no arguments, prints the entire\n\
1287 environment to be given to the program.", &showlist);
1288 c->completer = noop_completer;
1290 add_prefix_cmd ("unset", no_class, unset_command,
1291 "Complement to certain \"set\" commands",
1292 &unsetlist, "unset ", 0, &cmdlist);
1294 c = add_cmd ("environment", class_run, unset_environment_command,
1295 "Cancel environment variable VAR for the program.\n\
1296 This does not affect the program until the next \"run\" command.",
1298 c->completer = noop_completer;
1300 c = add_cmd ("environment", class_run, set_environment_command,
1301 "Set environment variable value to give the program.\n\
1302 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1303 VALUES of environment variables are uninterpreted strings.\n\
1304 This does not affect the program until the next \"run\" command.",
1306 c->completer = noop_completer;
1308 add_com ("path", class_files, path_command,
1309 "Add directory DIR(s) to beginning of search path for object files.\n\
1310 $cwd in the path means the current working directory.\n\
1311 This path is equivalent to the $PATH shell variable. It is a list of\n\
1312 directories, separated by colons. These directories are searched to find\n\
1313 fully linked executable files and separately compiled object files as needed.");
1315 c = add_cmd ("paths", no_class, path_info,
1316 "Current search path for finding object files.\n\
1317 $cwd in the path means the current working directory.\n\
1318 This path is equivalent to the $PATH shell variable. It is a list of\n\
1319 directories, separated by colons. These directories are searched to find\n\
1320 fully linked executable files and separately compiled object files as needed.", &showlist);
1321 c->completer = noop_completer;
1323 add_com ("attach", class_run, attach_command,
1324 "Attach to a process or file outside of GDB.\n\
1325 This command attaches to another target, of the same type as your last\n\
1326 `target' command (`info files' will show your target stack).\n\
1327 The command may take as argument a process id or a device file.\n\
1328 For a process id, you must have permission to send the process a signal,\n\
1329 and it must have the same effective uid as the debugger.\n\
1330 When using \"attach\", you should use the \"file\" command to specify\n\
1331 the program running in the process, and to load its symbol table.");
1333 add_com ("detach", class_run, detach_command,
1334 "Detach a process or file previously attached.\n\
1335 If a process, it is no longer traced, and it continues its execution. If you\n\
1336 were debugging a file, the file is closed and gdb no longer accesses it.");
1338 add_com ("signal", class_run, signal_command,
1339 "Continue program giving it signal number SIGNUMBER.");
1341 add_com ("stepi", class_run, stepi_command,
1342 "Step one instruction exactly.\n\
1343 Argument N means do this N times (or till program stops for another reason).");
1344 add_com_alias ("si", "stepi", class_alias, 0);
1346 add_com ("nexti", class_run, nexti_command,
1347 "Step one instruction, but proceed through subroutine calls.\n\
1348 Argument N means do this N times (or till program stops for another reason).");
1349 add_com_alias ("ni", "nexti", class_alias, 0);
1351 add_com ("finish", class_run, finish_command,
1352 "Execute until selected stack frame returns.\n\
1353 Upon return, the value returned is printed and put in the value history.");
1355 add_com ("next", class_run, next_command,
1356 "Step program, proceeding through subroutine calls.\n\
1357 Like the \"step\" command as long as subroutine calls do not happen;\n\
1358 when they do, the call is treated as one instruction.\n\
1359 Argument N means do this N times (or till program stops for another reason).");
1360 add_com_alias ("n", "next", class_run, 1);
1362 add_com ("step", class_run, step_command,
1363 "Step program until it reaches a different source line.\n\
1364 Argument N means do this N times (or till program stops for another reason).");
1365 add_com_alias ("s", "step", class_run, 1);
1367 add_com ("until", class_run, until_command,
1368 "Execute until the program reaches a source line greater than the current\n\
1369 or a specified line or address or function (same args as break command).\n\
1370 Execution will also stop upon exit from the current stack frame.");
1371 add_com_alias ("u", "until", class_run, 1);
1373 add_com ("jump", class_run, jump_command,
1374 "Continue program being debugged at specified line or address.\n\
1375 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1376 for an address to start at.");
1378 add_com ("continue", class_run, continue_command,
1379 "Continue program being debugged, after signal or breakpoint.\n\
1380 If proceeding from breakpoint, a number N may be used as an argument,\n\
1381 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1382 the breakpoint won't break until the Nth time it is reached).");
1383 add_com_alias ("c", "cont", class_run, 1);
1384 add_com_alias ("fg", "cont", class_run, 1);
1386 add_com ("run", class_run, run_command,
1387 "Start debugged program. You may specify arguments to give it.\n\
1388 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1389 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1390 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1391 To cancel previous arguments and run with no arguments,\n\
1392 use \"set args\" without arguments.");
1393 add_com_alias ("r", "run", class_run, 1);
1395 add_info ("registers", nofp_registers_info,
1396 "List of integer registers and their contents, for selected stack frame.\n\
1397 Register name as argument means describe only that register.");
1399 add_info ("all-registers", all_registers_info,
1400 "List of all registers and their contents, for selected stack frame.\n\
1401 Register name as argument means describe only that register.");
1403 add_info ("program", program_info,
1404 "Execution status of the program.");
1406 add_info ("float", float_info,
1407 "Print the status of the floating point unit\n");
1409 inferior_args = savestring ("", 1); /* Initially no args */
1410 inferior_environ = make_environ ();
1411 init_environ (inferior_environ);