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). */
131 enum target_signal stop_signal;
133 /* Address at which inferior stopped. */
137 /* Chain containing status of breakpoint(s) that we have stopped at. */
141 /* Flag indicating that a command has proceeded the inferior past the
142 current breakpoint. */
144 int breakpoint_proceeded;
146 /* Nonzero if stopped due to a step command. */
150 /* Nonzero if stopped due to completion of a stack dummy routine. */
152 int stop_stack_dummy;
154 /* Nonzero if stopped due to a random (unexpected) signal in inferior
157 int stopped_by_random_signal;
159 /* Range to single step within.
160 If this is nonzero, respond to a single-step signal
161 by continuing to step if the pc is in this range. */
163 CORE_ADDR step_range_start; /* Inclusive */
164 CORE_ADDR step_range_end; /* Exclusive */
166 /* Stack frame address as of when stepping command was issued.
167 This is how we know when we step into a subroutine call,
168 and how to set the frame for the breakpoint used to step out. */
170 FRAME_ADDR step_frame_address;
172 /* Our notion of the current stack pointer. */
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)
218 !query ("The program being debugged has been started already.\n\
219 Start it from the beginning? "))
220 error ("Program not restarted.");
224 clear_breakpoint_hit_counts ();
226 exec_file = (char *) get_exec_file (0);
228 /* The exec file is re-read every time we do a generic_mourn_inferior, so
229 we just have to worry about the symbol file. */
232 /* We keep symbols from add-symbol-file, on the grounds that the
233 user might want to add some symbols before running the program
234 (right?). But sometimes (dynamic loading where the user manually
235 introduces the new symbols with add-symbol-file), the code which
236 the symbols describe does not persist between runs. Currently
237 the user has to manually nuke all symbols between runs if they
238 want them to go away (PR 2207). This is probably reasonable. */
243 cmd = concat ("set args ", args, NULL);
244 make_cleanup (free, cmd);
245 execute_command (cmd, from_tty);
250 puts_filtered("Starting program: ");
252 puts_filtered(exec_file);
254 puts_filtered(inferior_args);
256 gdb_flush (gdb_stdout);
259 target_create_inferior (exec_file, inferior_args,
260 environ_vector (inferior_environ));
264 continue_command (proc_count_exp, from_tty)
265 char *proc_count_exp;
270 /* If have argument, set proceed count of breakpoint we stopped at. */
272 if (proc_count_exp != NULL)
274 bpstat bs = stop_bpstat;
275 int num = bpstat_num (&bs);
276 if (num == 0 && from_tty)
279 ("Not stopped at any breakpoint; argument ignored.\n");
283 set_ignore_count (num,
284 parse_and_eval_address (proc_count_exp) - 1,
286 /* set_ignore_count prints a message ending with a period.
287 So print two spaces before "Continuing.". */
289 printf_filtered (" ");
290 num = bpstat_num (&bs);
295 printf_filtered ("Continuing.\n");
297 clear_proceed_status ();
299 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
302 /* Step until outside of current statement. */
306 step_command (count_string, from_tty)
310 step_1 (0, 0, count_string);
313 /* Likewise, but skip over subroutine calls as if single instructions. */
317 next_command (count_string, from_tty)
321 step_1 (1, 0, count_string);
324 /* Likewise, but step only one instruction. */
328 stepi_command (count_string, from_tty)
332 step_1 (0, 1, count_string);
337 nexti_command (count_string, from_tty)
341 step_1 (1, 1, count_string);
345 step_1 (skip_subroutines, single_inst, count_string)
346 int skip_subroutines;
350 register int count = 1;
352 struct cleanup *cleanups = 0;
355 count = count_string ? parse_and_eval_address (count_string) : 1;
357 if (!single_inst || skip_subroutines) /* leave si command alone */
359 enable_longjmp_breakpoint();
360 cleanups = make_cleanup(disable_longjmp_breakpoint, 0);
363 for (; count > 0; count--)
365 clear_proceed_status ();
367 fr = get_current_frame ();
368 if (!fr) /* Avoid coredump here. Why tho? */
369 error ("No current frame");
370 step_frame_address = FRAME_FP (fr);
371 step_sp = read_sp ();
375 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
376 if (step_range_end == 0)
379 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
380 &step_range_end) == 0)
381 error ("Cannot find bounds of current function");
383 target_terminal_ours ();
385 Single stepping until exit from function %s, \n\
386 which has no line number information.\n", name);
387 gdb_flush (gdb_stdout);
392 /* Say we are stepping, but stop after one insn whatever it does. */
393 step_range_start = step_range_end = 1;
394 if (!skip_subroutines)
396 Don't step over function calls, not even to functions lacking
401 if (skip_subroutines)
404 step_multi = (count > 1);
405 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
409 /* FIXME: On nexti, this may have already been done (when we hit the
410 step resume break, I think). Probably this should be moved to
411 wait_for_inferior (near the top). */
412 #if defined (SHIFT_INST_REGS)
417 if (!single_inst || skip_subroutines)
418 do_cleanups(cleanups);
421 /* Continue program at specified address. */
424 jump_command (arg, from_tty)
428 register CORE_ADDR addr;
429 struct symtabs_and_lines sals;
430 struct symtab_and_line sal;
437 error_no_arg ("starting address");
439 sals = decode_line_spec_1 (arg, 1);
442 error ("Unreasonable jump request");
446 free ((PTR)sals.sals);
448 if (sal.symtab == 0 && sal.pc == 0)
449 error ("No source file has been specified.");
451 resolve_sal_pc (&sal); /* May error out */
453 /* See if we are trying to jump to another function. */
454 fn = get_frame_function (get_current_frame ());
455 sfn = find_pc_function (sal.pc);
456 if (fn != NULL && sfn != fn)
458 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
459 SYMBOL_SOURCE_NAME (fn)))
461 error ("Not confirmed.");
470 printf_filtered ("Continuing at ");
471 print_address_numeric (addr, 1, gdb_stdout);
472 printf_filtered (".\n");
475 clear_proceed_status ();
476 proceed (addr, TARGET_SIGNAL_0, 0);
479 /* Continue program giving it specified signal. */
482 signal_command (signum_exp, from_tty)
486 enum target_signal oursig;
488 dont_repeat (); /* Too dangerous. */
492 error_no_arg ("signal number");
494 /* It would be even slicker to make signal names be valid expressions,
495 (the type could be "enum $signal" or some such), then the user could
496 assign them to convenience variables. */
497 oursig = target_signal_from_name (signum_exp);
499 if (oursig == TARGET_SIGNAL_UNKNOWN)
501 /* Not found as a name, try it as an expression. */
502 /* The numeric signal refers to our own internal signal numbering
503 from target.h, not to host/target signal number. This is a
504 feature; users really should be using symbolic names anyway,
505 and the common ones like SIGHUP, SIGINT, SIGALRM, etc. will
506 work right anyway. */
507 int signum = parse_and_eval_address (signum_exp);
509 || signum >= (int)TARGET_SIGNAL_LAST
510 || signum == (int)TARGET_SIGNAL_UNKNOWN
511 || signum == (int)TARGET_SIGNAL_DEFAULT)
512 error ("Invalid signal number %d.", signum);
518 if (oursig == TARGET_SIGNAL_0)
519 printf_filtered ("Continuing with no signal.\n");
521 printf_filtered ("Continuing with signal %s.\n",
522 target_signal_to_name (oursig));
525 clear_proceed_status ();
526 proceed (stop_pc, oursig, 0);
529 /* Call breakpoint_auto_delete on the current contents of the bpstat
530 pointed to by arg (which is really a bpstat *). */
532 breakpoint_auto_delete_contents (arg)
535 breakpoint_auto_delete (*(bpstat *)arg);
538 /* Execute a "stack dummy", a piece of code stored in the stack
539 by the debugger to be executed in the inferior.
541 To call: first, do PUSH_DUMMY_FRAME.
542 Then push the contents of the dummy. It should end with a breakpoint insn.
543 Then call here, passing address at which to start the dummy.
545 The contents of all registers are saved before the dummy frame is popped
546 and copied into the buffer BUFFER.
548 The dummy's frame is automatically popped whenever that break is hit.
549 If that is the first time the program stops, run_stack_dummy
550 returns to its caller with that frame already gone and returns 0.
551 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
552 when we do hit that breakpoint). */
554 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
556 static int stack_dummy_testing = 0;
559 run_stack_dummy (addr, buffer)
561 char buffer[REGISTER_BYTES];
563 struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
565 /* Now proceed, having reached the desired place. */
566 clear_proceed_status ();
567 if (stack_dummy_testing & 4)
572 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
574 struct breakpoint *bpt;
575 struct symtab_and_line sal;
577 #if CALL_DUMMY_LOCATION != AT_ENTRY_POINT
578 sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET;
580 sal.pc = CALL_DUMMY_ADDRESS ();
585 /* Set up a FRAME for the dummy frame so we can pass it to
586 set_momentary_breakpoint. We need to give the breakpoint a
587 frame in case there is only one copy of the dummy (e.g.
588 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
589 flush_cached_frames ();
591 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
592 a breakpoint instruction. If not, the call dummy already has the
593 breakpoint instruction in it.
595 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
596 so we need to subtract the CALL_DUMMY_START_OFFSET. */
597 bpt = set_momentary_breakpoint (sal,
598 get_current_frame (),
600 bpt->disposition = delete;
602 /* If all error()s out of proceed ended up calling normal_stop (and
603 perhaps they should; it already does in the special case of error
604 out of resume()), then we wouldn't need this. */
605 make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
607 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */
609 proceed_to_finish = 1; /* We want stop_registers, please... */
610 proceed (addr, TARGET_SIGNAL_0, 0);
612 discard_cleanups (old_cleanups);
614 if (!stop_stack_dummy)
617 /* On return, the stack dummy has been popped already. */
619 memcpy (buffer, stop_registers, sizeof stop_registers);
623 /* Proceed until we reach a different source line with pc greater than
624 our current one or exit the function. We skip calls in both cases.
626 Note that eventually this command should probably be changed so
627 that only source lines are printed out when we hit the breakpoint
628 we set. This may involve changes to wait_for_inferior and the
629 proceed status code. */
633 until_next_command (from_tty)
639 struct symtab_and_line sal;
641 clear_proceed_status ();
643 frame = get_current_frame ();
645 /* Step until either exited from this function or greater
646 than the current line (if in symbolic section) or pc (if
650 func = find_pc_function (pc);
654 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
657 error ("Execution is not within a known function.");
659 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
664 sal = find_pc_line (pc, 0);
666 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
667 step_range_end = sal.end;
671 step_frame_address = FRAME_FP (frame);
672 step_sp = read_sp ();
674 step_multi = 0; /* Only one call to proceed */
676 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
680 until_command (arg, from_tty)
684 if (!target_has_execution)
685 error ("The program is not running.");
687 until_break_command (arg, from_tty);
689 until_next_command (from_tty);
692 /* "finish": Set a temporary breakpoint at the place
693 the selected frame will return to, then continue. */
696 finish_command (arg, from_tty)
700 struct symtab_and_line sal;
701 register FRAME frame;
702 struct frame_info *fi;
703 register struct symbol *function;
704 struct breakpoint *breakpoint;
705 struct cleanup *old_chain;
708 error ("The \"finish\" command does not take any arguments.");
709 if (!target_has_execution)
710 error ("The program is not running.");
711 if (selected_frame == NULL)
712 error ("No selected frame.");
714 frame = get_prev_frame (selected_frame);
716 error ("\"finish\" not meaningful in the outermost frame.");
718 clear_proceed_status ();
720 fi = get_frame_info (frame);
721 sal = find_pc_line (fi->pc, 0);
724 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
726 old_chain = make_cleanup(delete_breakpoint, breakpoint);
728 /* Find the function we will return from. */
730 fi = get_frame_info (selected_frame);
731 function = find_pc_function (fi->pc);
733 /* Print info on the selected frame, including level number
737 printf_filtered ("Run till exit from ");
738 print_stack_frame (selected_frame, selected_frame_level, 0);
741 proceed_to_finish = 1; /* We want stop_registers, please... */
742 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
744 /* Did we stop at our breakpoint? */
745 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
748 struct type *value_type;
749 register value_ptr val;
752 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
754 fatal ("internal: finish_command: function has no target type");
756 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
759 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
761 val = value_being_returned (value_type, stop_registers,
762 using_struct_return (value_of_variable (function, NULL),
765 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
767 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
768 value_print (val, gdb_stdout, 0, Val_no_prettyprint);
769 printf_filtered ("\n");
771 do_cleanups(old_chain);
776 program_info (args, from_tty)
780 bpstat bs = stop_bpstat;
781 int num = bpstat_num (&bs);
783 if (!target_has_execution)
785 printf_filtered ("The program being debugged is not being run.\n");
789 target_files_info ();
790 printf_filtered ("Program stopped at %s.\n",
791 local_hex_string((unsigned long) stop_pc));
793 printf_filtered ("It stopped after being stepped.\n");
796 /* There may be several breakpoints in the same place, so this
797 isn't as strange as it seems. */
801 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
803 printf_filtered ("It stopped at breakpoint %d.\n", num);
804 num = bpstat_num (&bs);
807 else if (stop_signal != TARGET_SIGNAL_0)
809 printf_filtered ("It stopped with signal %s, %s.\n",
810 target_signal_to_name (stop_signal),
811 target_signal_to_string (stop_signal));
815 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
819 environment_info (var, from_tty)
825 register char *val = get_in_environ (inferior_environ, var);
829 puts_filtered (" = ");
831 puts_filtered ("\n");
835 puts_filtered ("Environment variable \"");
837 puts_filtered ("\" not defined.\n");
842 register char **vector = environ_vector (inferior_environ);
845 puts_filtered (*vector++);
846 puts_filtered ("\n");
852 set_environment_command (arg, from_tty)
856 register char *p, *val, *var;
860 error_no_arg ("environment variable and value");
862 /* Find seperation between variable name and value */
863 p = (char *) strchr (arg, '=');
864 val = (char *) strchr (arg, ' ');
866 if (p != 0 && val != 0)
868 /* We have both a space and an equals. If the space is before the
869 equals, walk forward over the spaces til we see a nonspace
870 (possibly the equals). */
875 /* Now if the = is after the char following the spaces,
876 take the char following the spaces. */
880 else if (val != 0 && p == 0)
884 error_no_arg ("environment variable to set");
886 if (p == 0 || p[1] == 0)
890 p = arg + strlen (arg); /* So that savestring below will work */
894 /* Not setting variable value to null */
896 while (*val == ' ' || *val == '\t')
900 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
902 var = savestring (arg, p - arg);
905 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
906 set_in_environ (inferior_environ, var, "");
909 set_in_environ (inferior_environ, var, val);
914 unset_environment_command (var, from_tty)
920 /* If there is no argument, delete all environment variables.
921 Ask for confirmation if reading from the terminal. */
922 if (!from_tty || query ("Delete all environment variables? "))
924 free_environ (inferior_environ);
925 inferior_environ = make_environ ();
929 unset_in_environ (inferior_environ, var);
932 /* Handle the execution path (PATH variable) */
934 static const char path_var_name[] = "PATH";
938 path_info (args, from_tty)
942 puts_filtered ("Executable and object file path: ");
943 puts_filtered (get_in_environ (inferior_environ, path_var_name));
944 puts_filtered ("\n");
947 /* Add zero or more directories to the front of the execution path. */
950 path_command (dirname, from_tty)
957 exec_path = strsave (get_in_environ (inferior_environ, path_var_name));
958 mod_path (dirname, &exec_path);
959 set_in_environ (inferior_environ, path_var_name, exec_path);
962 path_info ((char *)NULL, from_tty);
965 const char * const reg_names[] = REGISTER_NAMES;
967 /* Print out the machine register regnum. If regnum is -1,
968 print all registers (fpregs == 1) or all non-float registers
971 For most machines, having all_registers_info() print the
972 register(s) one per line is good enough. If a different format
973 is required, (eg, for MIPS or Pyramid 90x, which both have
974 lots of regs), or there is an existing convention for showing
975 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
976 to provide that format. */
978 #if !defined (DO_REGISTERS_INFO)
980 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
983 do_registers_info (regnum, fpregs)
988 int numregs = ARCH_NUM_REGS;
990 for (i = 0; i < numregs; i++)
992 char raw_buffer[MAX_REGISTER_RAW_SIZE];
993 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
995 /* Decide between printing all regs, nonfloat regs, or specific reg. */
997 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
1004 fputs_filtered (reg_names[i], gdb_stdout);
1005 print_spaces_filtered (15 - strlen (reg_names[i]), gdb_stdout);
1007 /* Get the data in raw format. */
1008 if (read_relative_register_raw_bytes (i, raw_buffer))
1010 printf_filtered ("Invalid register contents\n");
1014 /* Convert raw data to virtual format if necessary. */
1015 #ifdef REGISTER_CONVERTIBLE
1016 if (REGISTER_CONVERTIBLE (i))
1018 REGISTER_CONVERT_TO_VIRTUAL (i, REGISTER_VIRTUAL_TYPE (i),
1019 raw_buffer, virtual_buffer);
1023 memcpy (virtual_buffer, raw_buffer,
1024 REGISTER_VIRTUAL_SIZE (i));
1026 /* If virtual format is floating, print it that way, and in raw hex. */
1027 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT)
1031 #ifdef INVALID_FLOAT
1032 if (INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1033 printf_filtered ("<invalid float>");
1036 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,
1037 gdb_stdout, 0, 1, 0, Val_pretty_default);
1039 printf_filtered ("\t(raw 0x");
1040 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1041 printf_filtered ("%02x", (unsigned char)raw_buffer[j]);
1042 printf_filtered (")");
1045 /* FIXME! val_print probably can handle all of these cases now... */
1047 /* Else if virtual format is too long for printf,
1048 print in hex a byte at a time. */
1049 else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))
1052 printf_filtered ("0x");
1053 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1054 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
1056 /* Else print as integer in hex and in decimal. */
1059 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1060 gdb_stdout, 'x', 1, 0, Val_pretty_default);
1061 printf_filtered ("\t");
1062 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1063 gdb_stdout, 0, 1, 0, Val_pretty_default);
1066 /* The SPARC wants to print even-numbered float regs as doubles
1067 in addition to printing them as floats. */
1068 #ifdef PRINT_REGISTER_HOOK
1069 PRINT_REGISTER_HOOK (i);
1072 printf_filtered ("\n");
1075 #endif /* no DO_REGISTERS_INFO. */
1078 registers_info (addr_exp, fpregs)
1082 int regnum, numregs;
1085 if (!target_has_registers)
1086 error ("The program has no registers now.");
1090 DO_REGISTERS_INFO(-1, fpregs);
1096 if (addr_exp[0] == '$')
1099 while (*end != '\0' && *end != ' ' && *end != '\t')
1101 numregs = ARCH_NUM_REGS;
1102 for (regnum = 0; regnum < numregs; regnum++)
1103 if (!strncmp (addr_exp, reg_names[regnum], end - addr_exp)
1104 && strlen (reg_names[regnum]) == end - addr_exp)
1106 if (*addr_exp >= '0' && *addr_exp <= '9')
1107 regnum = atoi (addr_exp); /* Take a number */
1108 if (regnum >= numregs) /* Bad name, or bad number */
1109 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1112 DO_REGISTERS_INFO(regnum, fpregs);
1115 while (*addr_exp == ' ' || *addr_exp == '\t')
1117 } while (*addr_exp != '\0');
1121 all_registers_info (addr_exp, from_tty)
1125 registers_info (addr_exp, 1);
1129 nofp_registers_info (addr_exp, from_tty)
1133 registers_info (addr_exp, 0);
1138 * Should save/restore the tty state since it might be that the
1139 * program to be debugged was started on this tty and it wants
1140 * the tty in some state other than what we want. If it's running
1141 * on another terminal or without a terminal, then saving and
1142 * restoring the tty state is a harmless no-op.
1143 * This only needs to be done if we are attaching to a process.
1148 takes a program started up outside of gdb and ``attaches'' to it.
1149 This stops it cold in its tracks and allows us to start debugging it.
1150 and wait for the trace-trap that results from attaching. */
1153 attach_command (args, from_tty)
1157 dont_repeat (); /* Not for the faint of heart */
1159 if (target_has_execution)
1161 if (query ("A program is being debugged already. Kill it? "))
1164 error ("Not killed.");
1167 target_attach (args, from_tty);
1169 /* Set up the "saved terminal modes" of the inferior
1170 based on what modes we are starting it with. */
1171 target_terminal_init ();
1173 /* Install inferior's terminal modes. */
1174 target_terminal_inferior ();
1176 /* Set up execution context to know that we should return from
1177 wait_for_inferior as soon as the target reports a stop. */
1178 init_wait_for_inferior ();
1179 clear_proceed_status ();
1180 stop_soon_quietly = 1;
1183 /* Mach 3 does not generate any traps when attaching to inferior,
1184 and to set up frames we can do this. */
1186 wait_for_inferior ();
1190 /* Add shared library symbols from the newly attached process, if any. */
1191 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
1199 * takes a program previously attached to and detaches it.
1200 * The program resumes execution and will no longer stop
1201 * on signals, etc. We better not have left any breakpoints
1202 * in the program or it'll die when it hits one. For this
1203 * to work, it may be necessary for the process to have been
1204 * previously attached. It *might* work if the program was
1205 * started via the normal ptrace (PTRACE_TRACEME).
1209 detach_command (args, from_tty)
1213 dont_repeat (); /* Not for the faint of heart */
1214 target_detach (args, from_tty);
1219 float_info (addr_exp, from_tty)
1226 printf_filtered ("No floating point info available for this processor.\n");
1232 unset_command (args, from_tty)
1236 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1237 help_list (unsetlist, "unset ", -1, gdb_stdout);
1241 _initialize_infcmd ()
1243 struct cmd_list_element *c;
1245 add_com ("tty", class_run, tty_command,
1246 "Set terminal for future runs of program being debugged.");
1249 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1251 "Set arguments to give program being debugged when it is started.\n\
1252 Follow this command with any number of args, to be passed to the program.",
1257 ("environment", no_class, environment_info,
1258 "The environment to give the program, or one variable's value.\n\
1259 With an argument VAR, prints the value of environment variable VAR to\n\
1260 give the program being debugged. With no arguments, prints the entire\n\
1261 environment to be given to the program.", &showlist);
1262 c->completer = noop_completer;
1264 add_prefix_cmd ("unset", no_class, unset_command,
1265 "Complement to certain \"set\" commands",
1266 &unsetlist, "unset ", 0, &cmdlist);
1268 c = add_cmd ("environment", class_run, unset_environment_command,
1269 "Cancel environment variable VAR for the program.\n\
1270 This does not affect the program until the next \"run\" command.",
1272 c->completer = noop_completer;
1274 c = add_cmd ("environment", class_run, set_environment_command,
1275 "Set environment variable value to give the program.\n\
1276 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1277 VALUES of environment variables are uninterpreted strings.\n\
1278 This does not affect the program until the next \"run\" command.",
1280 c->completer = noop_completer;
1282 add_com ("path", class_files, path_command,
1283 "Add directory DIR(s) to beginning of search path for object files.\n\
1284 $cwd in the path means the current working directory.\n\
1285 This path is equivalent to the $PATH shell variable. It is a list of\n\
1286 directories, separated by colons. These directories are searched to find\n\
1287 fully linked executable files and separately compiled object files as needed.");
1289 c = add_cmd ("paths", no_class, path_info,
1290 "Current search path for finding object files.\n\
1291 $cwd in the path means the current working directory.\n\
1292 This path is equivalent to the $PATH shell variable. It is a list of\n\
1293 directories, separated by colons. These directories are searched to find\n\
1294 fully linked executable files and separately compiled object files as needed.", &showlist);
1295 c->completer = noop_completer;
1297 add_com ("attach", class_run, attach_command,
1298 "Attach to a process or file outside of GDB.\n\
1299 This command attaches to another target, of the same type as your last\n\
1300 `target' command (`info files' will show your target stack).\n\
1301 The command may take as argument a process id or a device file.\n\
1302 For a process id, you must have permission to send the process a signal,\n\
1303 and it must have the same effective uid as the debugger.\n\
1304 When using \"attach\", you should use the \"file\" command to specify\n\
1305 the program running in the process, and to load its symbol table.");
1307 add_com ("detach", class_run, detach_command,
1308 "Detach a process or file previously attached.\n\
1309 If a process, it is no longer traced, and it continues its execution. If you\n\
1310 were debugging a file, the file is closed and gdb no longer accesses it.");
1312 add_com ("signal", class_run, signal_command,
1313 "Continue program giving it signal number SIGNUMBER.");
1315 add_com ("stepi", class_run, stepi_command,
1316 "Step one instruction exactly.\n\
1317 Argument N means do this N times (or till program stops for another reason).");
1318 add_com_alias ("si", "stepi", class_alias, 0);
1320 add_com ("nexti", class_run, nexti_command,
1321 "Step one instruction, but proceed through subroutine calls.\n\
1322 Argument N means do this N times (or till program stops for another reason).");
1323 add_com_alias ("ni", "nexti", class_alias, 0);
1325 add_com ("finish", class_run, finish_command,
1326 "Execute until selected stack frame returns.\n\
1327 Upon return, the value returned is printed and put in the value history.");
1329 add_com ("next", class_run, next_command,
1330 "Step program, proceeding through subroutine calls.\n\
1331 Like the \"step\" command as long as subroutine calls do not happen;\n\
1332 when they do, the call is treated as one instruction.\n\
1333 Argument N means do this N times (or till program stops for another reason).");
1334 add_com_alias ("n", "next", class_run, 1);
1336 add_com ("step", class_run, step_command,
1337 "Step program until it reaches a different source line.\n\
1338 Argument N means do this N times (or till program stops for another reason).");
1339 add_com_alias ("s", "step", class_run, 1);
1341 add_com ("until", class_run, until_command,
1342 "Execute until the program reaches a source line greater than the current\n\
1343 or a specified line or address or function (same args as break command).\n\
1344 Execution will also stop upon exit from the current stack frame.");
1345 add_com_alias ("u", "until", class_run, 1);
1347 add_com ("jump", class_run, jump_command,
1348 "Continue program being debugged at specified line or address.\n\
1349 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1350 for an address to start at.");
1352 add_com ("continue", class_run, continue_command,
1353 "Continue program being debugged, after signal or breakpoint.\n\
1354 If proceeding from breakpoint, a number N may be used as an argument,\n\
1355 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1356 the breakpoint won't break until the Nth time it is reached).");
1357 add_com_alias ("c", "cont", class_run, 1);
1358 add_com_alias ("fg", "cont", class_run, 1);
1360 add_com ("run", class_run, run_command,
1361 "Start debugged program. You may specify arguments to give it.\n\
1362 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1363 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1364 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1365 To cancel previous arguments and run with no arguments,\n\
1366 use \"set args\" without arguments.");
1367 add_com_alias ("r", "run", class_run, 1);
1369 add_info ("registers", nofp_registers_info,
1370 "List of integer registers and their contents, for selected stack frame.\n\
1371 Register name as argument means describe only that register.");
1373 add_info ("all-registers", all_registers_info,
1374 "List of all registers and their contents, for selected stack frame.\n\
1375 Register name as argument means describe only that register.");
1377 add_info ("program", program_info,
1378 "Execution status of the program.");
1380 add_info ("float", float_info,
1381 "Print the status of the floating point unit\n");
1383 inferior_args = savestring ("", 1); /* Initially no args */
1384 inferior_environ = make_environ ();
1385 init_environ (inferior_environ);