1 /* Memory-access and commands for "inferior" process, for GDB.
2 Copyright 1986, 87, 88, 89, 91, 92, 95, 96, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
37 /* Functions exported for general use: */
39 void nofp_registers_info PARAMS ((char *, int));
41 void all_registers_info PARAMS ((char *, int));
43 void registers_info PARAMS ((char *, int));
45 /* Local functions: */
47 void continue_command PARAMS ((char *, int));
49 static void until_next_command PARAMS ((int));
51 static void until_command PARAMS ((char *, int));
53 static void path_info PARAMS ((char *, int));
55 static void path_command PARAMS ((char *, int));
57 static void unset_command PARAMS ((char *, int));
59 static void float_info PARAMS ((char *, int));
61 static void detach_command PARAMS ((char *, int));
63 #if !defined (DO_REGISTERS_INFO)
64 static void do_registers_info PARAMS ((int, int));
67 static void unset_environment_command PARAMS ((char *, int));
69 static void set_environment_command PARAMS ((char *, int));
71 static void environment_info PARAMS ((char *, int));
73 static void program_info PARAMS ((char *, int));
75 static void finish_command PARAMS ((char *, int));
77 static void signal_command PARAMS ((char *, int));
79 static void jump_command PARAMS ((char *, int));
81 static void step_1 PARAMS ((int, int, char *));
83 void nexti_command PARAMS ((char *, int));
85 void stepi_command PARAMS ((char *, int));
87 static void next_command PARAMS ((char *, int));
89 static void step_command PARAMS ((char *, int));
91 static void run_command PARAMS ((char *, int));
93 void _initialize_infcmd PARAMS ((void));
95 #define GO_USAGE "Usage: go <location>\n"
97 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
98 static void breakpoint_auto_delete_contents PARAMS ((PTR));
101 #define ERROR_NO_INFERIOR \
102 if (!target_has_execution) error ("The program is not being run.");
104 /* String containing arguments to give to the program, separated by spaces.
105 Empty string (pointer to '\0') means no args. */
107 static char *inferior_args;
109 /* File name for default use for standard in/out in the inferior. */
111 char *inferior_io_terminal;
113 /* Pid of our debugged inferior, or 0 if no inferior now.
114 Since various parts of infrun.c test this to see whether there is a program
115 being debugged it should be nonzero (currently 3 is used) for remote
120 /* Last signal that the inferior received (why it stopped). */
122 enum target_signal stop_signal;
124 /* Address at which inferior stopped. */
128 /* Chain containing status of breakpoint(s) that we have stopped at. */
132 /* Flag indicating that a command has proceeded the inferior past the
133 current breakpoint. */
135 int breakpoint_proceeded;
137 /* Nonzero if stopped due to a step command. */
141 /* Nonzero if stopped due to completion of a stack dummy routine. */
143 int stop_stack_dummy;
145 /* Nonzero if stopped due to a random (unexpected) signal in inferior
148 int stopped_by_random_signal;
150 /* Range to single step within.
151 If this is nonzero, respond to a single-step signal
152 by continuing to step if the pc is in this range. */
154 CORE_ADDR step_range_start; /* Inclusive */
155 CORE_ADDR step_range_end; /* Exclusive */
157 /* Stack frame address as of when stepping command was issued.
158 This is how we know when we step into a subroutine call,
159 and how to set the frame for the breakpoint used to step out. */
161 CORE_ADDR step_frame_address;
163 /* Our notion of the current stack pointer. */
167 /* 1 means step over all subroutine calls.
168 0 means don't step over calls (used by stepi).
169 -1 means step over calls to undebuggable functions. */
173 /* If stepping, nonzero means step count is > 1
174 so don't print frame next time inferior stops
175 if it stops due to stepping. */
179 /* Environment to use for running inferior,
180 in format described in environ.h. */
182 struct environ *inferior_environ;
187 tty_command (file, from_tty)
192 error_no_arg ("terminal name for running target process");
194 inferior_io_terminal = savestring (file, strlen (file));
198 run_command (args, from_tty)
206 if (inferior_pid != 0 && target_has_execution)
209 !query ("The program being debugged has been started already.\n\
210 Start it from the beginning? "))
211 error ("Program not restarted.");
213 #if defined(SOLIB_RESTART)
216 init_wait_for_inferior ();
219 clear_breakpoint_hit_counts ();
221 exec_file = (char *) get_exec_file (0);
223 /* Purge old solib objfiles. */
224 objfile_purge_solibs ();
226 do_run_cleanups (NULL);
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));
265 run_no_args_command (args, from_tty)
269 execute_command("set args", from_tty);
270 run_command((char *)NULL, from_tty);
275 continue_command (proc_count_exp, from_tty)
276 char *proc_count_exp;
281 /* If have argument, set proceed count of breakpoint we stopped at. */
283 if (proc_count_exp != NULL)
285 bpstat bs = stop_bpstat;
286 int num = bpstat_num (&bs);
287 if (num == 0 && from_tty)
290 ("Not stopped at any breakpoint; argument ignored.\n");
294 set_ignore_count (num,
295 parse_and_eval_address (proc_count_exp) - 1,
297 /* set_ignore_count prints a message ending with a period.
298 So print two spaces before "Continuing.". */
300 printf_filtered (" ");
301 num = bpstat_num (&bs);
306 printf_filtered ("Continuing.\n");
308 clear_proceed_status ();
310 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
313 /* Step until outside of current statement. */
317 step_command (count_string, from_tty)
321 step_1 (0, 0, count_string);
324 /* Likewise, but skip over subroutine calls as if single instructions. */
328 next_command (count_string, from_tty)
332 step_1 (1, 0, count_string);
335 /* Likewise, but step only one instruction. */
339 stepi_command (count_string, from_tty)
343 step_1 (0, 1, count_string);
348 nexti_command (count_string, from_tty)
352 step_1 (1, 1, count_string);
356 step_1 (skip_subroutines, single_inst, count_string)
357 int skip_subroutines;
361 register int count = 1;
362 struct frame_info *frame;
363 struct cleanup *cleanups = 0;
366 count = count_string ? parse_and_eval_address (count_string) : 1;
368 if (!single_inst || skip_subroutines) /* leave si command alone */
370 enable_longjmp_breakpoint();
371 cleanups = make_cleanup ((make_cleanup_func) disable_longjmp_breakpoint,
375 for (; count > 0; count--)
377 clear_proceed_status ();
379 frame = get_current_frame ();
380 if (!frame) /* Avoid coredump here. Why tho? */
381 error ("No current frame");
382 step_frame_address = FRAME_FP (frame);
383 step_sp = read_sp ();
387 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
388 if (step_range_end == 0)
391 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
392 &step_range_end) == 0)
393 error ("Cannot find bounds of current function");
395 target_terminal_ours ();
397 Single stepping until exit from function %s, \n\
398 which has no line number information.\n", name);
403 /* Say we are stepping, but stop after one insn whatever it does. */
404 step_range_start = step_range_end = 1;
405 if (!skip_subroutines)
407 Don't step over function calls, not even to functions lacking
412 if (skip_subroutines)
415 step_multi = (count > 1);
416 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
420 /* FIXME: On nexti, this may have already been done (when we hit the
421 step resume break, I think). Probably this should be moved to
422 wait_for_inferior (near the top). */
423 #if defined (SHIFT_INST_REGS)
428 if (!single_inst || skip_subroutines)
429 do_cleanups(cleanups);
432 /* Continue program at specified address. */
435 jump_command (arg, from_tty)
439 register CORE_ADDR addr;
440 struct symtabs_and_lines sals;
441 struct symtab_and_line sal;
448 error_no_arg ("starting address");
450 sals = decode_line_spec_1 (arg, 1);
453 error ("Unreasonable jump request");
457 free ((PTR)sals.sals);
459 if (sal.symtab == 0 && sal.pc == 0)
460 error ("No source file has been specified.");
462 resolve_sal_pc (&sal); /* May error out */
464 /* See if we are trying to jump to another function. */
465 fn = get_frame_function (get_current_frame ());
466 sfn = find_pc_function (sal.pc);
467 if (fn != NULL && sfn != fn)
469 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
470 SYMBOL_SOURCE_NAME (fn)))
472 error ("Not confirmed.");
479 fixup_symbol_section (sfn, 0);
480 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
481 !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
483 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
485 error ("Not confirmed.");
496 printf_filtered ("Continuing at ");
497 print_address_numeric (addr, 1, gdb_stdout);
498 printf_filtered (".\n");
501 clear_proceed_status ();
502 proceed (addr, TARGET_SIGNAL_0, 0);
506 /* Go to line or address in current procedure */
508 go_command(line_no, from_tty)
512 if (line_no == (char *)NULL || !*line_no)
513 printf_filtered(GO_USAGE);
516 tbreak_command(line_no, from_tty);
517 jump_command(line_no, from_tty);
522 /* Continue program giving it specified signal. */
525 signal_command (signum_exp, from_tty)
529 enum target_signal oursig;
531 dont_repeat (); /* Too dangerous. */
535 error_no_arg ("signal number");
537 /* It would be even slicker to make signal names be valid expressions,
538 (the type could be "enum $signal" or some such), then the user could
539 assign them to convenience variables. */
540 oursig = target_signal_from_name (signum_exp);
542 if (oursig == TARGET_SIGNAL_UNKNOWN)
544 /* No, try numeric. */
545 int num = parse_and_eval_address (signum_exp);
548 oursig = TARGET_SIGNAL_0;
550 oursig = target_signal_from_command (num);
555 if (oursig == TARGET_SIGNAL_0)
556 printf_filtered ("Continuing with no signal.\n");
558 printf_filtered ("Continuing with signal %s.\n",
559 target_signal_to_name (oursig));
562 clear_proceed_status ();
563 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
564 FIXME: Neither should "signal foo" but when I tried passing
565 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
566 tried to track down yet. */
567 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
570 /* Call breakpoint_auto_delete on the current contents of the bpstat
571 pointed to by arg (which is really a bpstat *). */
573 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
576 breakpoint_auto_delete_contents (arg)
579 breakpoint_auto_delete (*(bpstat *)arg);
582 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET */
584 /* Execute a "stack dummy", a piece of code stored in the stack
585 by the debugger to be executed in the inferior.
587 To call: first, do PUSH_DUMMY_FRAME.
588 Then push the contents of the dummy. It should end with a breakpoint insn.
589 Then call here, passing address at which to start the dummy.
591 The contents of all registers are saved before the dummy frame is popped
592 and copied into the buffer BUFFER.
594 The dummy's frame is automatically popped whenever that break is hit.
595 If that is the first time the program stops, run_stack_dummy
596 returns to its caller with that frame already gone and returns 0.
597 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
598 when we do hit that breakpoint). */
600 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
602 static int stack_dummy_testing = 0;
605 run_stack_dummy (addr, buffer)
607 char buffer[REGISTER_BYTES];
609 struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
611 /* Now proceed, having reached the desired place. */
612 clear_proceed_status ();
613 if (stack_dummy_testing & 4)
618 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
620 struct breakpoint *bpt;
621 struct symtab_and_line sal;
623 INIT_SAL (&sal); /* initialize to zeroes */
624 #if CALL_DUMMY_LOCATION != AT_ENTRY_POINT
625 sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET;
627 sal.pc = CALL_DUMMY_ADDRESS ();
629 sal.section = find_pc_overlay (sal.pc);
631 /* Set up a FRAME for the dummy frame so we can pass it to
632 set_momentary_breakpoint. We need to give the breakpoint a
633 frame in case there is only one copy of the dummy (e.g.
634 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
635 flush_cached_frames ();
636 set_current_frame (create_new_frame (read_fp (), sal.pc));
638 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
639 a breakpoint instruction. If not, the call dummy already has the
640 breakpoint instruction in it.
642 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
643 so we need to subtract the CALL_DUMMY_START_OFFSET. */
644 bpt = set_momentary_breakpoint (sal,
645 get_current_frame (),
647 bpt->disposition = del;
649 /* If all error()s out of proceed ended up calling normal_stop (and
650 perhaps they should; it already does in the special case of error
651 out of resume()), then we wouldn't need this. */
652 make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
654 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */
656 disable_watchpoints_before_interactive_call_start ();
657 proceed_to_finish = 1; /* We want stop_registers, please... */
658 proceed (addr, TARGET_SIGNAL_0, 0);
659 enable_watchpoints_after_interactive_call_stop ();
661 discard_cleanups (old_cleanups);
663 if (!stop_stack_dummy)
666 /* On return, the stack dummy has been popped already. */
668 memcpy (buffer, stop_registers, sizeof stop_registers);
672 /* Proceed until we reach a different source line with pc greater than
673 our current one or exit the function. We skip calls in both cases.
675 Note that eventually this command should probably be changed so
676 that only source lines are printed out when we hit the breakpoint
677 we set. This may involve changes to wait_for_inferior and the
678 proceed status code. */
682 until_next_command (from_tty)
685 struct frame_info *frame;
688 struct symtab_and_line sal;
690 clear_proceed_status ();
692 frame = get_current_frame ();
694 /* Step until either exited from this function or greater
695 than the current line (if in symbolic section) or pc (if
699 func = find_pc_function (pc);
703 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
706 error ("Execution is not within a known function.");
708 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
713 sal = find_pc_line (pc, 0);
715 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
716 step_range_end = sal.end;
720 step_frame_address = FRAME_FP (frame);
721 step_sp = read_sp ();
723 step_multi = 0; /* Only one call to proceed */
725 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
729 until_command (arg, from_tty)
733 if (!target_has_execution)
734 error ("The program is not running.");
736 until_break_command (arg, from_tty);
738 until_next_command (from_tty);
741 /* "finish": Set a temporary breakpoint at the place
742 the selected frame will return to, then continue. */
745 finish_command (arg, from_tty)
749 struct symtab_and_line sal;
750 register struct frame_info *frame;
751 register struct symbol *function;
752 struct breakpoint *breakpoint;
753 struct cleanup *old_chain;
756 error ("The \"finish\" command does not take any arguments.");
757 if (!target_has_execution)
758 error ("The program is not running.");
759 if (selected_frame == NULL)
760 error ("No selected frame.");
762 frame = get_prev_frame (selected_frame);
764 error ("\"finish\" not meaningful in the outermost frame.");
766 clear_proceed_status ();
768 sal = find_pc_line (frame->pc, 0);
771 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
773 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
775 /* Find the function we will return from. */
777 function = find_pc_function (selected_frame->pc);
779 /* Print info on the selected frame, including level number
783 printf_filtered ("Run till exit from ");
784 print_stack_frame (selected_frame, selected_frame_level, 0);
787 proceed_to_finish = 1; /* We want stop_registers, please... */
788 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
790 /* Did we stop at our breakpoint? */
791 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
794 struct type *value_type;
795 register value_ptr val;
799 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
801 fatal ("internal: finish_command: function has no target type");
803 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
806 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
808 struct_return = using_struct_return (value_of_variable (function, NULL),
811 check_typedef (value_type),
812 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function)));
816 val = value_being_returned (value_type, stop_registers, struct_return);
817 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
818 value_print (val, gdb_stdout, 0, Val_no_prettyprint);
819 printf_filtered ("\n");
823 /* elz: we cannot determine the contents of the structure because
824 it is on the stack, and we don't know where, since we did not
825 initiate the call, as opposed to the call_function_by_hand case */
826 #ifdef VALUE_RETURNED_FROM_STACK
828 printf_filtered ("Value returned has type: %s.", TYPE_NAME (value_type));
829 printf_filtered (" Cannot determine contents\n");
831 val = value_being_returned (value_type, stop_registers, struct_return);
832 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
833 value_print (val, gdb_stdout, 0, Val_no_prettyprint);
834 printf_filtered ("\n");
839 do_cleanups(old_chain);
844 program_info (args, from_tty)
848 bpstat bs = stop_bpstat;
849 int num = bpstat_num (&bs);
851 if (!target_has_execution)
853 printf_filtered ("The program being debugged is not being run.\n");
857 target_files_info ();
858 printf_filtered ("Program stopped at %s.\n",
859 local_hex_string((unsigned long) stop_pc));
861 printf_filtered ("It stopped after being stepped.\n");
864 /* There may be several breakpoints in the same place, so this
865 isn't as strange as it seems. */
869 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
871 printf_filtered ("It stopped at breakpoint %d.\n", num);
872 num = bpstat_num (&bs);
875 else if (stop_signal != TARGET_SIGNAL_0)
877 printf_filtered ("It stopped with signal %s, %s.\n",
878 target_signal_to_name (stop_signal),
879 target_signal_to_string (stop_signal));
883 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
887 environment_info (var, from_tty)
893 register char *val = get_in_environ (inferior_environ, var);
897 puts_filtered (" = ");
899 puts_filtered ("\n");
903 puts_filtered ("Environment variable \"");
905 puts_filtered ("\" not defined.\n");
910 register char **vector = environ_vector (inferior_environ);
913 puts_filtered (*vector++);
914 puts_filtered ("\n");
920 set_environment_command (arg, from_tty)
924 register char *p, *val, *var;
928 error_no_arg ("environment variable and value");
930 /* Find seperation between variable name and value */
931 p = (char *) strchr (arg, '=');
932 val = (char *) strchr (arg, ' ');
934 if (p != 0 && val != 0)
936 /* We have both a space and an equals. If the space is before the
937 equals, walk forward over the spaces til we see a nonspace
938 (possibly the equals). */
943 /* Now if the = is after the char following the spaces,
944 take the char following the spaces. */
948 else if (val != 0 && p == 0)
952 error_no_arg ("environment variable to set");
954 if (p == 0 || p[1] == 0)
958 p = arg + strlen (arg); /* So that savestring below will work */
962 /* Not setting variable value to null */
964 while (*val == ' ' || *val == '\t')
968 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
970 var = savestring (arg, p - arg);
973 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
974 set_in_environ (inferior_environ, var, "");
977 set_in_environ (inferior_environ, var, val);
982 unset_environment_command (var, from_tty)
988 /* If there is no argument, delete all environment variables.
989 Ask for confirmation if reading from the terminal. */
990 if (!from_tty || query ("Delete all environment variables? "))
992 free_environ (inferior_environ);
993 inferior_environ = make_environ ();
997 unset_in_environ (inferior_environ, var);
1000 /* Handle the execution path (PATH variable) */
1002 static const char path_var_name[] = "PATH";
1006 path_info (args, from_tty)
1010 puts_filtered ("Executable and object file path: ");
1011 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1012 puts_filtered ("\n");
1015 /* Add zero or more directories to the front of the execution path. */
1018 path_command (dirname, from_tty)
1025 env = get_in_environ (inferior_environ, path_var_name);
1026 /* Can be null if path is not set */
1029 exec_path = strsave (env);
1030 mod_path (dirname, &exec_path);
1031 set_in_environ (inferior_environ, path_var_name, exec_path);
1034 path_info ((char *)NULL, from_tty);
1038 #ifdef REGISTER_NAMES
1039 char *gdb_register_names[] = REGISTER_NAMES;
1041 /* Print out the machine register regnum. If regnum is -1,
1042 print all registers (fpregs == 1) or all non-float registers
1045 For most machines, having all_registers_info() print the
1046 register(s) one per line is good enough. If a different format
1047 is required, (eg, for MIPS or Pyramid 90x, which both have
1048 lots of regs), or there is an existing convention for showing
1049 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
1050 to provide that format. */
1052 #if !defined (DO_REGISTERS_INFO)
1054 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
1057 do_registers_info (regnum, fpregs)
1062 int numregs = ARCH_NUM_REGS;
1064 for (i = 0; i < numregs; i++)
1066 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1067 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
1069 /* Decide between printing all regs, nonfloat regs, or specific reg. */
1071 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
1078 /* If the register name is empty, it is undefined for this
1079 processor, so don't display anything. */
1080 if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0')
1083 fputs_filtered (REGISTER_NAME (i), gdb_stdout);
1084 print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), gdb_stdout);
1086 /* Get the data in raw format. */
1087 if (read_relative_register_raw_bytes (i, raw_buffer))
1089 printf_filtered ("*value not available*\n");
1093 /* Convert raw data to virtual format if necessary. */
1094 #ifdef REGISTER_CONVERTIBLE
1095 if (REGISTER_CONVERTIBLE (i))
1097 REGISTER_CONVERT_TO_VIRTUAL (i, REGISTER_VIRTUAL_TYPE (i),
1098 raw_buffer, virtual_buffer);
1102 memcpy (virtual_buffer, raw_buffer,
1103 REGISTER_VIRTUAL_SIZE (i));
1105 /* If virtual format is floating, print it that way, and in raw hex. */
1106 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT)
1110 #ifdef INVALID_FLOAT
1111 if (INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1112 printf_filtered ("<invalid float>");
1115 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1116 gdb_stdout, 0, 1, 0, Val_pretty_default);
1118 printf_filtered ("\t(raw 0x");
1119 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1121 register int idx = TARGET_BYTE_ORDER == BIG_ENDIAN ? j
1122 : REGISTER_RAW_SIZE (i) - 1 - j;
1123 printf_filtered ("%02x", (unsigned char)raw_buffer[idx]);
1125 printf_filtered (")");
1128 /* FIXME! val_print probably can handle all of these cases now... */
1130 /* Else if virtual format is too long for printf,
1131 print in hex a byte at a time. */
1132 else if (REGISTER_VIRTUAL_SIZE (i) > (int) sizeof (long))
1135 printf_filtered ("0x");
1136 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1137 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
1139 /* Else print as integer in hex and in decimal. */
1142 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1143 gdb_stdout, 'x', 1, 0, Val_pretty_default);
1144 printf_filtered ("\t");
1145 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1146 gdb_stdout, 0, 1, 0, Val_pretty_default);
1149 /* The SPARC wants to print even-numbered float regs as doubles
1150 in addition to printing them as floats. */
1151 #ifdef PRINT_REGISTER_HOOK
1152 PRINT_REGISTER_HOOK (i);
1155 printf_filtered ("\n");
1158 #endif /* no DO_REGISTERS_INFO. */
1160 extern int target_map_name_to_register PARAMS ((char *, int));
1163 registers_info (addr_exp, fpregs)
1167 int regnum, numregs;
1170 if (!target_has_registers)
1171 error ("The program has no registers now.");
1172 if (selected_frame == NULL)
1173 error ("No selected frame.");
1177 DO_REGISTERS_INFO(-1, fpregs);
1183 if (addr_exp[0] == '$')
1186 while (*end != '\0' && *end != ' ' && *end != '\t')
1188 numregs = ARCH_NUM_REGS;
1190 regnum = target_map_name_to_register (addr_exp, end - addr_exp);
1196 if (*addr_exp >= '0' && *addr_exp <= '9')
1197 regnum = atoi (addr_exp); /* Take a number */
1198 if (regnum >= numregs) /* Bad name, or bad number */
1199 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1202 DO_REGISTERS_INFO(regnum, fpregs);
1205 while (*addr_exp == ' ' || *addr_exp == '\t')
1207 } while (*addr_exp != '\0');
1211 all_registers_info (addr_exp, from_tty)
1215 registers_info (addr_exp, 1);
1219 nofp_registers_info (addr_exp, from_tty)
1223 registers_info (addr_exp, 0);
1229 * Should save/restore the tty state since it might be that the
1230 * program to be debugged was started on this tty and it wants
1231 * the tty in some state other than what we want. If it's running
1232 * on another terminal or without a terminal, then saving and
1233 * restoring the tty state is a harmless no-op.
1234 * This only needs to be done if we are attaching to a process.
1239 takes a program started up outside of gdb and ``attaches'' to it.
1240 This stops it cold in its tracks and allows us to start debugging it.
1241 and wait for the trace-trap that results from attaching. */
1244 attach_command (args, from_tty)
1249 extern int auto_solib_add;
1253 char * full_exec_path = NULL;
1255 dont_repeat (); /* Not for the faint of heart */
1257 if (target_has_execution)
1259 if (query ("A program is being debugged already. Kill it? "))
1262 error ("Not killed.");
1265 target_attach (args, from_tty);
1267 /* Set up the "saved terminal modes" of the inferior
1268 based on what modes we are starting it with. */
1269 target_terminal_init ();
1271 /* Install inferior's terminal modes. */
1272 target_terminal_inferior ();
1274 /* Set up execution context to know that we should return from
1275 wait_for_inferior as soon as the target reports a stop. */
1276 init_wait_for_inferior ();
1277 clear_proceed_status ();
1278 stop_soon_quietly = 1;
1280 /* No traps are generated when attaching to inferior under Mach 3
1282 #ifndef ATTACH_NO_WAIT
1283 wait_for_inferior ();
1287 * If no exec file is yet known, try to determine it from the
1290 exec_file = (char *) get_exec_file (0);
1292 exec_file = target_pid_to_exec_file (inferior_pid);
1294 /* It's possible we don't have a full path, but rather just a
1295 filename. Some targets, such as HP-UX, don't provide the
1298 Attempt to qualify the filename against the source path.
1299 (If that fails, we'll just fall back on the original
1300 filename. Not much more we can do...)
1302 if (!source_full_path_of (exec_file, &full_exec_path))
1303 full_exec_path = savestring (exec_file, strlen (exec_file));
1305 exec_file_attach (full_exec_path, from_tty);
1306 symbol_file_command (full_exec_path, from_tty);
1313 /* Add shared library symbols from the newly attached process, if any. */
1314 SOLIB_ADD ((char *)0, from_tty, ¤t_target);
1315 re_enable_breakpoints_in_shlibs ();
1319 /* Take any necessary post-attaching actions for this platform.
1321 target_post_attach (inferior_pid);
1328 * takes a program previously attached to and detaches it.
1329 * The program resumes execution and will no longer stop
1330 * on signals, etc. We better not have left any breakpoints
1331 * in the program or it'll die when it hits one. For this
1332 * to work, it may be necessary for the process to have been
1333 * previously attached. It *might* work if the program was
1334 * started via the normal ptrace (PTRACE_TRACEME).
1338 detach_command (args, from_tty)
1342 dont_repeat (); /* Not for the faint of heart */
1343 target_detach (args, from_tty);
1344 #if defined(SOLIB_RESTART)
1351 float_info (addr_exp, from_tty)
1358 printf_filtered ("No floating point info available for this processor.\n");
1364 unset_command (args, from_tty)
1368 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1369 help_list (unsetlist, "unset ", -1, gdb_stdout);
1373 _initialize_infcmd ()
1375 struct cmd_list_element *c;
1377 add_com ("tty", class_run, tty_command,
1378 "Set terminal for future runs of program being debugged.");
1381 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1383 "Set argument list to give program being debugged when it is started.\n\
1384 Follow this command with any number of args, to be passed to the program.",
1389 ("environment", no_class, environment_info,
1390 "The environment to give the program, or one variable's value.\n\
1391 With an argument VAR, prints the value of environment variable VAR to\n\
1392 give the program being debugged. With no arguments, prints the entire\n\
1393 environment to be given to the program.", &showlist);
1394 c->completer = noop_completer;
1396 add_prefix_cmd ("unset", no_class, unset_command,
1397 "Complement to certain \"set\" commands",
1398 &unsetlist, "unset ", 0, &cmdlist);
1400 c = add_cmd ("environment", class_run, unset_environment_command,
1401 "Cancel environment variable VAR for the program.\n\
1402 This does not affect the program until the next \"run\" command.",
1404 c->completer = noop_completer;
1406 c = add_cmd ("environment", class_run, set_environment_command,
1407 "Set environment variable value to give the program.\n\
1408 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1409 VALUES of environment variables are uninterpreted strings.\n\
1410 This does not affect the program until the next \"run\" command.",
1412 c->completer = noop_completer;
1414 add_com ("path", class_files, path_command,
1415 "Add directory DIR(s) to beginning of search path for object files.\n\
1416 $cwd in the path means the current working directory.\n\
1417 This path is equivalent to the $PATH shell variable. It is a list of\n\
1418 directories, separated by colons. These directories are searched to find\n\
1419 fully linked executable files and separately compiled object files as needed.");
1421 c = add_cmd ("paths", no_class, path_info,
1422 "Current search path for finding object files.\n\
1423 $cwd in the path means the current working directory.\n\
1424 This path is equivalent to the $PATH shell variable. It is a list of\n\
1425 directories, separated by colons. These directories are searched to find\n\
1426 fully linked executable files and separately compiled object files as needed.", &showlist);
1427 c->completer = noop_completer;
1429 add_com ("attach", class_run, attach_command,
1430 "Attach to a process or file outside of GDB.\n\
1431 This command attaches to another target, of the same type as your last\n\
1432 \"target\" command (\"info files\" will show your target stack).\n\
1433 The command may take as argument a process id or a device file.\n\
1434 For a process id, you must have permission to send the process a signal,\n\
1435 and it must have the same effective uid as the debugger.\n\
1436 When using \"attach\" with a process id, the debugger finds the\n\
1437 program running in the process, looking first in the current working\n\
1438 directory, or (if not found there) using the source file search path\n\
1439 (see the \"directory\" command). You can also use the \"file\" command\n\
1440 to specify the program, and to load its symbol table.");
1442 add_com ("detach", class_run, detach_command,
1443 "Detach a process or file previously attached.\n\
1444 If a process, it is no longer traced, and it continues its execution. If you\n\
1445 were debugging a file, the file is closed and gdb no longer accesses it.");
1447 add_com ("signal", class_run, signal_command,
1448 "Continue program giving it signal specified by the argument.\n\
1449 An argument of \"0\" means continue program without giving it a signal.");
1451 add_com ("stepi", class_run, stepi_command,
1452 "Step one instruction exactly.\n\
1453 Argument N means do this N times (or till program stops for another reason).");
1454 add_com_alias ("si", "stepi", class_alias, 0);
1456 add_com ("nexti", class_run, nexti_command,
1457 "Step one instruction, but proceed through subroutine calls.\n\
1458 Argument N means do this N times (or till program stops for another reason).");
1459 add_com_alias ("ni", "nexti", class_alias, 0);
1461 add_com ("finish", class_run, finish_command,
1462 "Execute until selected stack frame returns.\n\
1463 Upon return, the value returned is printed and put in the value history.");
1465 add_com ("next", class_run, next_command,
1466 "Step program, proceeding through subroutine calls.\n\
1467 Like the \"step\" command as long as subroutine calls do not happen;\n\
1468 when they do, the call is treated as one instruction.\n\
1469 Argument N means do this N times (or till program stops for another reason).");
1470 add_com_alias ("n", "next", class_run, 1);
1472 add_com_alias("S", "next", class_run, 1);
1474 add_com ("step", class_run, step_command,
1475 "Step program until it reaches a different source line.\n\
1476 Argument N means do this N times (or till program stops for another reason).");
1477 add_com_alias ("s", "step", class_run, 1);
1479 add_com ("until", class_run, until_command,
1480 "Execute until the program reaches a source line greater than the current\n\
1481 or a specified line or address or function (same args as break command).\n\
1482 Execution will also stop upon exit from the current stack frame.");
1483 add_com_alias ("u", "until", class_run, 1);
1485 add_com ("jump", class_run, jump_command,
1486 "Continue program being debugged at specified line or address.\n\
1487 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1488 for an address to start at.");
1490 add_com ("go", class_run, go_command,
1491 "Usage: go <location>\n\
1492 Continue program being debugged, stopping at specified line or \n\
1494 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
1495 expression for an address to start at.\n\
1496 This command is a combination of tbreak and jump.");
1498 add_com_alias("g", "g", class_run, 1);
1500 add_com ("continue", class_run, continue_command,
1501 "Continue program being debugged, after signal or breakpoint.\n\
1502 If proceeding from breakpoint, a number N may be used as an argument,\n\
1503 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1504 the breakpoint won't break until the Nth time it is reached).");
1505 add_com_alias ("c", "cont", class_run, 1);
1506 add_com_alias ("fg", "cont", class_run, 1);
1508 add_com ("run", class_run, run_command,
1509 "Start debugged program. You may specify arguments to give it.\n\
1510 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1511 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1512 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1513 To cancel previous arguments and run with no arguments,\n\
1514 use \"set args\" without arguments.");
1515 add_com_alias ("r", "run", class_run, 1);
1517 add_com ("R", class_run, run_no_args_command,
1518 "Start debugged program with no arguments.");
1520 add_info ("registers", nofp_registers_info,
1521 "List of integer registers and their contents, for selected stack frame.\n\
1522 Register name as argument means describe only that register.");
1525 add_com("lr", class_info, nofp_registers_info,
1526 "List of integer registers and their contents, for selected stack frame.\n\
1527 Register name as argument means describe only that register.");
1528 add_info ("all-registers", all_registers_info,
1529 "List of all registers and their contents, for selected stack frame.\n\
1530 Register name as argument means describe only that register.");
1532 add_info ("program", program_info,
1533 "Execution status of the program.");
1535 add_info ("float", float_info,
1536 "Print the status of the floating point unit\n");
1538 inferior_args = savestring ("", 1); /* Initially no args */
1539 inferior_environ = make_environ ();
1540 init_environ (inferior_environ);