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>
36 continue_command PARAMS ((char *, int));
39 until_next_command PARAMS ((int));
42 until_command PARAMS ((char *, int));
45 path_info PARAMS ((char *, int));
48 path_command PARAMS ((char *, int));
51 unset_command PARAMS ((char *, int));
54 float_info PARAMS ((char *, int));
57 detach_command PARAMS ((char *, int));
60 nofp_registers_info PARAMS ((char *, int));
63 all_registers_info PARAMS ((char *, int));
66 registers_info PARAMS ((char *, int));
69 do_registers_info PARAMS ((int, int));
72 unset_environment_command PARAMS ((char *, int));
75 set_environment_command PARAMS ((char *, int));
78 environment_info PARAMS ((char *, int));
81 program_info PARAMS ((char *, int));
84 finish_command PARAMS ((char *, int));
87 signal_command PARAMS ((char *, int));
90 jump_command PARAMS ((char *, int));
93 step_1 PARAMS ((int, int, char *));
96 nexti_command PARAMS ((char *, int));
99 stepi_command PARAMS ((char *, int));
102 next_command PARAMS ((char *, int));
105 step_command PARAMS ((char *, int));
108 run_command PARAMS ((char *, int));
110 #define ERROR_NO_INFERIOR \
111 if (!target_has_execution) error ("The program is not being run.");
113 /* String containing arguments to give to the program, separated by spaces.
114 Empty string (pointer to '\0') means no args. */
116 static char *inferior_args;
118 /* File name for default use for standard in/out in the inferior. */
120 char *inferior_io_terminal;
122 /* Pid of our debugged inferior, or 0 if no inferior now.
123 Since various parts of infrun.c test this to see whether there is a program
124 being debugged it should be nonzero (currently 3 is used) for remote
129 /* Last signal that the inferior received (why it stopped). */
133 /* Address at which inferior stopped. */
137 /* Stack frame when program stopped. */
139 FRAME_ADDR stop_frame_address;
141 /* Chain containing status of breakpoint(s) that we have stopped at. */
145 /* Flag indicating that a command has proceeded the inferior past the
146 current breakpoint. */
148 int breakpoint_proceeded;
150 /* Nonzero if stopped due to a step command. */
154 /* Nonzero if stopped due to completion of a stack dummy routine. */
156 int stop_stack_dummy;
158 /* Nonzero if stopped due to a random (unexpected) signal in inferior
161 int stopped_by_random_signal;
163 /* Range to single step within.
164 If this is nonzero, respond to a single-step signal
165 by continuing to step if the pc is in this range. */
167 CORE_ADDR step_range_start; /* Inclusive */
168 CORE_ADDR step_range_end; /* Exclusive */
170 /* Stack frame address as of when stepping command was issued.
171 This is how we know when we step into a subroutine call,
172 and how to set the frame for the breakpoint used to step out. */
174 FRAME_ADDR step_frame_address;
176 /* 1 means step over all subroutine calls.
177 0 means don't step over calls (used by stepi).
178 -1 means step over calls to undebuggable functions. */
182 /* If stepping, nonzero means step count is > 1
183 so don't print frame next time inferior stops
184 if it stops due to stepping. */
188 /* Environment to use for running inferior,
189 in format described in environ.h. */
191 struct environ *inferior_environ;
196 tty_command (file, from_tty)
201 error_no_arg ("terminal name for running target process");
203 inferior_io_terminal = savestring (file, strlen (file));
207 run_command (args, from_tty)
215 /* Shouldn't this be target_has_execution? FIXME. */
219 !query ("The program being debugged has been started already.\n\
220 Start it from the beginning? "))
221 error ("Program not restarted.");
225 exec_file = (char *) get_exec_file (0);
227 /* The exec file is re-read every time we do a generic_mourn_inferior, so
228 we just have to worry about the symbol file. */
231 /* We keep symbols from add-symbol-file, on the grounds that the
232 user might want to add some symbols before running the program
233 (right?). But sometimes (dynamic loading where the user manually
234 introduces the new symbols with add-symbol-file), the code which
235 the symbols describe does not persist between runs. Currently
236 the user has to manually nuke all symbols between runs if they
237 want them to go away (PR 2207). This is probably reasonable. */
242 cmd = concat ("set args ", args, NULL);
243 make_cleanup (free, cmd);
244 execute_command (cmd, from_tty);
249 puts_filtered("Starting program: ");
251 puts_filtered(exec_file);
253 puts_filtered(inferior_args);
258 target_create_inferior (exec_file, inferior_args,
259 environ_vector (inferior_environ));
263 continue_command (proc_count_exp, from_tty)
264 char *proc_count_exp;
269 /* If have argument, set proceed count of breakpoint we stopped at. */
271 if (proc_count_exp != NULL)
273 bpstat bs = stop_bpstat;
274 int num = bpstat_num (&bs);
275 if (num == 0 && from_tty)
278 ("Not stopped at any breakpoint; argument ignored.\n");
282 set_ignore_count (num,
283 parse_and_eval_address (proc_count_exp) - 1,
285 /* set_ignore_count prints a message ending with a period.
286 So print two spaces before "Continuing.". */
288 printf_filtered (" ");
289 num = bpstat_num (&bs);
294 printf_filtered ("Continuing.\n");
296 clear_proceed_status ();
298 proceed ((CORE_ADDR) -1, -1, 0);
301 /* Step until outside of current statement. */
305 step_command (count_string, from_tty)
309 step_1 (0, 0, count_string);
312 /* Likewise, but skip over subroutine calls as if single instructions. */
316 next_command (count_string, from_tty)
320 step_1 (1, 0, count_string);
323 /* Likewise, but step only one instruction. */
327 stepi_command (count_string, from_tty)
331 step_1 (0, 1, count_string);
336 nexti_command (count_string, from_tty)
340 step_1 (1, 1, count_string);
344 step_1 (skip_subroutines, single_inst, count_string)
345 int skip_subroutines;
349 register int count = 1;
351 struct cleanup *cleanups = 0;
354 count = count_string ? parse_and_eval_address (count_string) : 1;
356 if (!single_inst || skip_subroutines) /* leave si command alone */
358 enable_longjmp_breakpoint();
359 cleanups = make_cleanup(disable_longjmp_breakpoint, 0);
362 for (; count > 0; count--)
364 clear_proceed_status ();
366 fr = get_current_frame ();
367 if (!fr) /* Avoid coredump here. Why tho? */
368 error ("No current frame");
369 step_frame_address = FRAME_FP (fr);
373 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
374 if (step_range_end == 0)
377 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
378 &step_range_end) == 0)
379 error ("Cannot find bounds of current function");
381 target_terminal_ours ();
383 Single stepping until exit from function %s, \n\
384 which has no line number information.\n", name);
390 /* Say we are stepping, but stop after one insn whatever it does. */
391 step_range_start = step_range_end = 1;
392 if (!skip_subroutines)
394 Don't step over function calls, not even to functions lacking
399 if (skip_subroutines)
402 step_multi = (count > 1);
403 proceed ((CORE_ADDR) -1, -1, 1);
407 /* FIXME: On nexti, this may have already been done (when we hit the
408 step resume break, I think). Probably this should be moved to
409 wait_for_inferior (near the top). */
410 #if defined (SHIFT_INST_REGS)
415 if (!single_inst || skip_subroutines)
416 do_cleanups(cleanups);
419 /* Continue program at specified address. */
422 jump_command (arg, from_tty)
426 register CORE_ADDR addr;
427 struct symtabs_and_lines sals;
428 struct symtab_and_line sal;
435 error_no_arg ("starting address");
437 sals = decode_line_spec_1 (arg, 1);
440 error ("Unreasonable jump request");
444 free ((PTR)sals.sals);
446 if (sal.symtab == 0 && sal.pc == 0)
447 error ("No source file has been specified.");
449 resolve_sal_pc (&sal); /* May error out */
451 /* See if we are trying to jump to another function. */
452 fn = get_frame_function (get_current_frame ());
453 sfn = find_pc_function (sal.pc);
454 if (fn != NULL && sfn != fn)
456 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
457 SYMBOL_SOURCE_NAME (fn)))
459 error ("Not confirmed.");
467 printf_filtered ("Continuing at %s.\n",
468 local_hex_string((unsigned long) addr));
470 clear_proceed_status ();
471 proceed (addr, 0, 0);
474 /* Continue program giving it specified signal. */
477 signal_command (signum_exp, from_tty)
483 dont_repeat (); /* Too dangerous. */
487 error_no_arg ("signal number");
489 /* It would be even slicker to make signal names be valid expressions,
490 (the type could be "enum $signal" or some such), then the user could
491 assign them to convenience variables. */
492 signum = strtosigno (signum_exp);
495 /* Not found as a name, try it as an expression. */
496 signum = parse_and_eval_address (signum_exp);
500 char *signame = strsigno (signum);
501 printf_filtered ("Continuing with signal ");
502 if (signame == NULL || signum == 0)
503 printf_filtered ("%d.\n", signum);
505 /* Do we need to print the number as well as the name? */
506 printf_filtered ("%s (%d).\n", signame, signum);
509 clear_proceed_status ();
510 proceed (stop_pc, signum, 0);
513 /* Call breakpoint_auto_delete on the current contents of the bpstat
514 pointed to by arg (which is really a bpstat *). */
516 breakpoint_auto_delete_contents (arg)
519 breakpoint_auto_delete (*(bpstat *)arg);
522 /* Execute a "stack dummy", a piece of code stored in the stack
523 by the debugger to be executed in the inferior.
525 To call: first, do PUSH_DUMMY_FRAME.
526 Then push the contents of the dummy. It should end with a breakpoint insn.
527 Then call here, passing address at which to start the dummy.
529 The contents of all registers are saved before the dummy frame is popped
530 and copied into the buffer BUFFER.
532 The dummy's frame is automatically popped whenever that break is hit.
533 If that is the first time the program stops, run_stack_dummy
534 returns to its caller with that frame already gone and returns 0.
535 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
536 when we do hit that breakpoint). */
538 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
540 static int stack_dummy_testing = 0;
543 run_stack_dummy (addr, buffer)
545 char buffer[REGISTER_BYTES];
547 struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
549 /* Now proceed, having reached the desired place. */
550 clear_proceed_status ();
551 if (stack_dummy_testing & 4)
556 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
558 struct breakpoint *bpt;
559 struct symtab_and_line sal;
561 #if CALL_DUMMY_LOCATION != AT_ENTRY_POINT
562 sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET;
564 sal.pc = entry_point_address ();
569 /* Set up a FRAME for the dummy frame so we can pass it to
570 set_momentary_breakpoint. We need to give the breakpoint a
571 frame in case there is only one copy of the dummy (e.g.
572 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
573 flush_cached_frames ();
574 set_current_frame (create_new_frame (read_fp (), sal.pc));
576 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
577 a breakpoint instruction. If not, the call dummy already has the
578 breakpoint instruction in it.
580 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
581 so we need to subtract the CALL_DUMMY_START_OFFSET. */
582 bpt = set_momentary_breakpoint (sal,
583 get_current_frame (),
585 bpt->disposition = delete;
587 /* If all error()s out of proceed ended up calling normal_stop (and
588 perhaps they should; it already does in the special case of error
589 out of resume()), then we wouldn't need this. */
590 make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
592 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */
594 proceed_to_finish = 1; /* We want stop_registers, please... */
595 proceed (addr, 0, 0);
597 discard_cleanups (old_cleanups);
599 if (!stop_stack_dummy)
602 /* On return, the stack dummy has been popped already. */
604 memcpy (buffer, stop_registers, sizeof stop_registers);
608 /* Proceed until we reach a different source line with pc greater than
609 our current one or exit the function. We skip calls in both cases.
611 Note that eventually this command should probably be changed so
612 that only source lines are printed out when we hit the breakpoint
613 we set. I'm going to postpone this until after a hopeful rewrite
614 of wait_for_inferior and the proceed status code. -- randy */
618 until_next_command (from_tty)
624 struct symtab_and_line sal;
626 clear_proceed_status ();
628 frame = get_current_frame ();
630 /* Step until either exited from this function or greater
631 than the current line (if in symbolic section) or pc (if
635 func = find_pc_function (pc);
639 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
642 error ("Execution is not within a known function.");
644 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
649 sal = find_pc_line (pc, 0);
651 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
652 step_range_end = sal.end;
656 step_frame_address = FRAME_FP (frame);
658 step_multi = 0; /* Only one call to proceed */
660 proceed ((CORE_ADDR) -1, -1, 1);
664 until_command (arg, from_tty)
668 if (!target_has_execution)
669 error ("The program is not running.");
671 until_break_command (arg, from_tty);
673 until_next_command (from_tty);
676 /* "finish": Set a temporary breakpoint at the place
677 the selected frame will return to, then continue. */
680 finish_command (arg, from_tty)
684 struct symtab_and_line sal;
685 register FRAME frame;
686 struct frame_info *fi;
687 register struct symbol *function;
688 struct breakpoint *breakpoint;
689 struct cleanup *old_chain;
692 error ("The \"finish\" command does not take any arguments.");
693 if (!target_has_execution)
694 error ("The program is not running.");
695 if (selected_frame == NULL)
696 error ("No selected frame.");
698 frame = get_prev_frame (selected_frame);
700 error ("\"finish\" not meaningful in the outermost frame.");
702 clear_proceed_status ();
704 fi = get_frame_info (frame);
705 sal = find_pc_line (fi->pc, 0);
708 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
710 old_chain = make_cleanup(delete_breakpoint, breakpoint);
712 /* Find the function we will return from. */
714 fi = get_frame_info (selected_frame);
715 function = find_pc_function (fi->pc);
717 /* Print info on the selected frame, including level number
721 printf_filtered ("Run till exit from ");
722 print_stack_frame (selected_frame, selected_frame_level, 0);
725 proceed_to_finish = 1; /* We want stop_registers, please... */
726 proceed ((CORE_ADDR) -1, -1, 0);
728 /* Did we stop at our breakpoint? */
729 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
732 struct type *value_type;
736 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
738 fatal ("internal: finish_command: function has no target type");
740 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
743 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
745 val = value_being_returned (value_type, stop_registers,
746 using_struct_return (value_of_variable (function, NULL),
749 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
751 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
752 value_print (val, stdout, 0, Val_no_prettyprint);
753 printf_filtered ("\n");
755 do_cleanups(old_chain);
760 program_info (args, from_tty)
764 bpstat bs = stop_bpstat;
765 int num = bpstat_num (&bs);
767 if (!target_has_execution)
769 printf_filtered ("The program being debugged is not being run.\n");
773 target_files_info ();
774 printf_filtered ("Program stopped at %s.\n",
775 local_hex_string((unsigned long) stop_pc));
777 printf_filtered ("It stopped after being stepped.\n");
780 /* There may be several breakpoints in the same place, so this
781 isn't as strange as it seems. */
785 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
787 printf_filtered ("It stopped at breakpoint %d.\n", num);
788 num = bpstat_num (&bs);
791 else if (stop_signal)
793 #ifdef PRINT_RANDOM_SIGNAL
794 PRINT_RANDOM_SIGNAL (stop_signal);
796 char *signame = strsigno (stop_signal);
797 printf_filtered ("It stopped with signal ");
799 printf_filtered ("%d", stop_signal);
801 /* Do we need to print the number as well as the name? */
802 printf_filtered ("%s (%d)", signame, stop_signal);
803 printf_filtered (", %s.\n", safe_strsignal (stop_signal));
808 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
812 environment_info (var, from_tty)
818 register char *val = get_in_environ (inferior_environ, var);
822 puts_filtered (" = ");
824 puts_filtered ("\n");
828 puts_filtered ("Environment variable \"");
830 puts_filtered ("\" not defined.\n");
835 register char **vector = environ_vector (inferior_environ);
838 puts_filtered (*vector++);
839 puts_filtered ("\n");
845 set_environment_command (arg, from_tty)
849 register char *p, *val, *var;
853 error_no_arg ("environment variable and value");
855 /* Find seperation between variable name and value */
856 p = (char *) strchr (arg, '=');
857 val = (char *) strchr (arg, ' ');
859 if (p != 0 && val != 0)
861 /* We have both a space and an equals. If the space is before the
862 equals, walk forward over the spaces til we see a nonspace
863 (possibly the equals). */
868 /* Now if the = is after the char following the spaces,
869 take the char following the spaces. */
873 else if (val != 0 && p == 0)
877 error_no_arg ("environment variable to set");
879 if (p == 0 || p[1] == 0)
883 p = arg + strlen (arg); /* So that savestring below will work */
887 /* Not setting variable value to null */
889 while (*val == ' ' || *val == '\t')
893 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
895 var = savestring (arg, p - arg);
898 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
899 set_in_environ (inferior_environ, var, "");
902 set_in_environ (inferior_environ, var, val);
907 unset_environment_command (var, from_tty)
913 /* If there is no argument, delete all environment variables.
914 Ask for confirmation if reading from the terminal. */
915 if (!from_tty || query ("Delete all environment variables? "))
917 free_environ (inferior_environ);
918 inferior_environ = make_environ ();
922 unset_in_environ (inferior_environ, var);
925 /* Handle the execution path (PATH variable) */
927 static const char path_var_name[] = "PATH";
931 path_info (args, from_tty)
935 puts_filtered ("Executable and object file path: ");
936 puts_filtered (get_in_environ (inferior_environ, path_var_name));
937 puts_filtered ("\n");
940 /* Add zero or more directories to the front of the execution path. */
943 path_command (dirname, from_tty)
950 exec_path = strsave (get_in_environ (inferior_environ, path_var_name));
951 mod_path (dirname, &exec_path);
952 set_in_environ (inferior_environ, path_var_name, exec_path);
955 path_info ((char *)NULL, from_tty);
958 /* This routine is getting awfully cluttered with #if's. It's probably
959 time to turn this into READ_PC and define it in the tm.h file.
960 Ditto for write_pc. */
965 #ifdef TARGET_READ_PC
966 return TARGET_READ_PC ();
968 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register (PC_REGNUM));
976 #ifdef TARGET_WRITE_PC
977 TARGET_WRITE_PC (val);
979 write_register (PC_REGNUM, (long) val);
981 write_register (NPC_REGNUM, (long) val + 4);
983 write_register (NNPC_REGNUM, (long) val + 8);
989 /* Cope with strage ways of getting to the stack and frame pointers */
994 #ifdef TARGET_READ_SP
995 return TARGET_READ_SP ();
997 return read_register (SP_REGNUM);
1005 #ifdef TARGET_WRITE_SP
1006 TARGET_WRITE_SP (val);
1008 write_register (SP_REGNUM, val);
1016 #ifdef TARGET_READ_FP
1017 return TARGET_READ_FP ();
1019 return read_register (FP_REGNUM);
1027 #ifdef TARGET_WRITE_FP
1028 TARGET_WRITE_FP (val);
1030 write_register (FP_REGNUM, val);
1034 const char * const reg_names[] = REGISTER_NAMES;
1036 /* Print out the machine register regnum. If regnum is -1,
1037 print all registers (fpregs == 1) or all non-float registers
1040 For most machines, having all_registers_info() print the
1041 register(s) one per line is good enough. If a different format
1042 is required, (eg, for MIPS or Pyramid 90x, which both have
1043 lots of regs), or there is an existing convention for showing
1044 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
1045 to provide that format. */
1047 #if !defined (DO_REGISTERS_INFO)
1048 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
1050 do_registers_info (regnum, fpregs)
1056 for (i = 0; i < NUM_REGS; i++)
1058 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1059 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
1061 /* Decide between printing all regs, nonfloat regs, or specific reg. */
1063 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
1070 fputs_filtered (reg_names[i], stdout);
1071 print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
1073 /* Get the data in raw format, then convert also to virtual format. */
1074 if (read_relative_register_raw_bytes (i, raw_buffer))
1076 printf_filtered ("Invalid register contents\n");
1080 REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);
1082 /* If virtual format is floating, print it that way, and in raw hex. */
1083 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT
1084 && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1088 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,
1089 stdout, 0, 1, 0, Val_pretty_default);
1091 printf_filtered ("\t(raw 0x");
1092 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1093 printf_filtered ("%02x", (unsigned char)raw_buffer[j]);
1094 printf_filtered (")");
1097 /* FIXME! val_print probably can handle all of these cases now... */
1099 /* Else if virtual format is too long for printf,
1100 print in hex a byte at a time. */
1101 else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))
1104 printf_filtered ("0x");
1105 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1106 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
1108 /* Else print as integer in hex and in decimal. */
1111 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1112 stdout, 'x', 1, 0, Val_pretty_default);
1113 printf_filtered ("\t");
1114 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1115 stdout, 0, 1, 0, Val_pretty_default);
1118 /* The SPARC wants to print even-numbered float regs as doubles
1119 in addition to printing them as floats. */
1120 #ifdef PRINT_REGISTER_HOOK
1121 PRINT_REGISTER_HOOK (i);
1124 printf_filtered ("\n");
1127 #endif /* no DO_REGISTERS_INFO. */
1130 registers_info (addr_exp, fpregs)
1137 if (!target_has_registers)
1138 error ("The program has no registers now.");
1142 DO_REGISTERS_INFO(-1, fpregs);
1148 if (addr_exp[0] == '$')
1151 while (*end != '\0' && *end != ' ' && *end != '\t')
1153 for (regnum = 0; regnum < NUM_REGS; regnum++)
1154 if (!strncmp (addr_exp, reg_names[regnum], end - addr_exp)
1155 && strlen (reg_names[regnum]) == end - addr_exp)
1157 if (*addr_exp >= '0' && *addr_exp <= '9')
1158 regnum = atoi (addr_exp); /* Take a number */
1159 if (regnum >= NUM_REGS) /* Bad name, or bad number */
1160 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1163 DO_REGISTERS_INFO(regnum, fpregs);
1166 while (*addr_exp == ' ' || *addr_exp == '\t')
1168 } while (*addr_exp != '\0');
1172 all_registers_info (addr_exp, from_tty)
1176 registers_info (addr_exp, 1);
1180 nofp_registers_info (addr_exp, from_tty)
1184 registers_info (addr_exp, 0);
1189 * Should save/restore the tty state since it might be that the
1190 * program to be debugged was started on this tty and it wants
1191 * the tty in some state other than what we want. If it's running
1192 * on another terminal or without a terminal, then saving and
1193 * restoring the tty state is a harmless no-op.
1194 * This only needs to be done if we are attaching to a process.
1199 takes a program started up outside of gdb and ``attaches'' to it.
1200 This stops it cold in its tracks and allows us to start debugging it.
1201 and wait for the trace-trap that results from attaching. */
1204 attach_command (args, from_tty)
1208 dont_repeat (); /* Not for the faint of heart */
1210 if (target_has_execution)
1212 if (query ("A program is being debugged already. Kill it? "))
1215 error ("Not killed.");
1218 target_attach (args, from_tty);
1220 /* Set up the "saved terminal modes" of the inferior
1221 based on what modes we are starting it with. */
1222 target_terminal_init ();
1224 /* Install inferior's terminal modes. */
1225 target_terminal_inferior ();
1227 /* Set up execution context to know that we should return from
1228 wait_for_inferior as soon as the target reports a stop. */
1229 init_wait_for_inferior ();
1230 clear_proceed_status ();
1231 stop_soon_quietly = 1;
1233 wait_for_inferior ();
1236 /* Add shared library symbols from the newly attached process, if any. */
1237 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
1245 * takes a program previously attached to and detaches it.
1246 * The program resumes execution and will no longer stop
1247 * on signals, etc. We better not have left any breakpoints
1248 * in the program or it'll die when it hits one. For this
1249 * to work, it may be necessary for the process to have been
1250 * previously attached. It *might* work if the program was
1251 * started via the normal ptrace (PTRACE_TRACEME).
1255 detach_command (args, from_tty)
1259 dont_repeat (); /* Not for the faint of heart */
1260 target_detach (args, from_tty);
1265 float_info (addr_exp, from_tty)
1272 printf_filtered ("No floating point info available for this processor.\n");
1278 unset_command (args, from_tty)
1282 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1283 help_list (unsetlist, "unset ", -1, stdout);
1287 _initialize_infcmd ()
1289 struct cmd_list_element *c;
1291 add_com ("tty", class_run, tty_command,
1292 "Set terminal for future runs of program being debugged.");
1295 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1297 "Set arguments to give program being debugged when it is started.\n\
1298 Follow this command with any number of args, to be passed to the program.",
1303 ("environment", no_class, environment_info,
1304 "The environment to give the program, or one variable's value.\n\
1305 With an argument VAR, prints the value of environment variable VAR to\n\
1306 give the program being debugged. With no arguments, prints the entire\n\
1307 environment to be given to the program.", &showlist);
1308 c->completer = noop_completer;
1310 add_prefix_cmd ("unset", no_class, unset_command,
1311 "Complement to certain \"set\" commands",
1312 &unsetlist, "unset ", 0, &cmdlist);
1314 c = add_cmd ("environment", class_run, unset_environment_command,
1315 "Cancel environment variable VAR for the program.\n\
1316 This does not affect the program until the next \"run\" command.",
1318 c->completer = noop_completer;
1320 c = add_cmd ("environment", class_run, set_environment_command,
1321 "Set environment variable value to give the program.\n\
1322 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1323 VALUES of environment variables are uninterpreted strings.\n\
1324 This does not affect the program until the next \"run\" command.",
1326 c->completer = noop_completer;
1328 add_com ("path", class_files, path_command,
1329 "Add directory DIR(s) to beginning of search path for object files.\n\
1330 $cwd in the path means the current working directory.\n\
1331 This path is equivalent to the $PATH shell variable. It is a list of\n\
1332 directories, separated by colons. These directories are searched to find\n\
1333 fully linked executable files and separately compiled object files as needed.");
1335 c = add_cmd ("paths", no_class, path_info,
1336 "Current search path for finding object files.\n\
1337 $cwd in the path means the current working directory.\n\
1338 This path is equivalent to the $PATH shell variable. It is a list of\n\
1339 directories, separated by colons. These directories are searched to find\n\
1340 fully linked executable files and separately compiled object files as needed.", &showlist);
1341 c->completer = noop_completer;
1343 add_com ("attach", class_run, attach_command,
1344 "Attach to a process or file outside of GDB.\n\
1345 This command attaches to another target, of the same type as your last\n\
1346 `target' command (`info files' will show your target stack).\n\
1347 The command may take as argument a process id or a device file.\n\
1348 For a process id, you must have permission to send the process a signal,\n\
1349 and it must have the same effective uid as the debugger.\n\
1350 When using \"attach\", you should use the \"file\" command to specify\n\
1351 the program running in the process, and to load its symbol table.");
1353 add_com ("detach", class_run, detach_command,
1354 "Detach a process or file previously attached.\n\
1355 If a process, it is no longer traced, and it continues its execution. If you\n\
1356 were debugging a file, the file is closed and gdb no longer accesses it.");
1358 add_com ("signal", class_run, signal_command,
1359 "Continue program giving it signal number SIGNUMBER.");
1361 add_com ("stepi", class_run, stepi_command,
1362 "Step one instruction exactly.\n\
1363 Argument N means do this N times (or till program stops for another reason).");
1364 add_com_alias ("si", "stepi", class_alias, 0);
1366 add_com ("nexti", class_run, nexti_command,
1367 "Step one instruction, but proceed through subroutine calls.\n\
1368 Argument N means do this N times (or till program stops for another reason).");
1369 add_com_alias ("ni", "nexti", class_alias, 0);
1371 add_com ("finish", class_run, finish_command,
1372 "Execute until selected stack frame returns.\n\
1373 Upon return, the value returned is printed and put in the value history.");
1375 add_com ("next", class_run, next_command,
1376 "Step program, proceeding through subroutine calls.\n\
1377 Like the \"step\" command as long as subroutine calls do not happen;\n\
1378 when they do, the call is treated as one instruction.\n\
1379 Argument N means do this N times (or till program stops for another reason).");
1380 add_com_alias ("n", "next", class_run, 1);
1382 add_com ("step", class_run, step_command,
1383 "Step program until it reaches a different source line.\n\
1384 Argument N means do this N times (or till program stops for another reason).");
1385 add_com_alias ("s", "step", class_run, 1);
1387 add_com ("until", class_run, until_command,
1388 "Execute until the program reaches a source line greater than the current\n\
1389 or a specified line or address or function (same args as break command).\n\
1390 Execution will also stop upon exit from the current stack frame.");
1391 add_com_alias ("u", "until", class_run, 1);
1393 add_com ("jump", class_run, jump_command,
1394 "Continue program being debugged at specified line or address.\n\
1395 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1396 for an address to start at.");
1398 add_com ("continue", class_run, continue_command,
1399 "Continue program being debugged, after signal or breakpoint.\n\
1400 If proceeding from breakpoint, a number N may be used as an argument,\n\
1401 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1402 the breakpoint won't break until the Nth time it is reached).");
1403 add_com_alias ("c", "cont", class_run, 1);
1404 add_com_alias ("fg", "cont", class_run, 1);
1406 add_com ("run", class_run, run_command,
1407 "Start debugged program. You may specify arguments to give it.\n\
1408 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1409 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1410 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1411 To cancel previous arguments and run with no arguments,\n\
1412 use \"set args\" without arguments.");
1413 add_com_alias ("r", "run", class_run, 1);
1415 add_info ("registers", nofp_registers_info,
1416 "List of integer registers and their contents, for selected stack frame.\n\
1417 Register name as argument means describe only that register.");
1419 add_info ("all-registers", all_registers_info,
1420 "List of all registers and their contents, for selected stack frame.\n\
1421 Register name as argument means describe only that register.");
1423 add_info ("program", program_info,
1424 "Execution status of the program.");
1426 add_info ("float", float_info,
1427 "Print the status of the floating point unit\n");
1429 inferior_args = savestring ("", 1); /* Initially no args */
1430 inferior_environ = make_environ ();
1431 init_environ (inferior_environ);