1 /* Memory-access and commands for "inferior" process, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1995, 1996 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include <sys/param.h>
23 #include "gdb_string.h"
35 static void continue_command
PARAMS ((char *, int));
37 static void until_next_command
PARAMS ((int));
39 static void until_command
PARAMS ((char *, int));
41 static void path_info
PARAMS ((char *, int));
43 static void path_command
PARAMS ((char *, int));
45 static void unset_command
PARAMS ((char *, int));
47 static void float_info
PARAMS ((char *, int));
49 static void detach_command
PARAMS ((char *, int));
51 static void nofp_registers_info
PARAMS ((char *, int));
53 static void all_registers_info
PARAMS ((char *, int));
55 static void registers_info
PARAMS ((char *, int));
57 static void do_registers_info
PARAMS ((int, int));
59 static void unset_environment_command
PARAMS ((char *, int));
61 static void set_environment_command
PARAMS ((char *, int));
63 static void environment_info
PARAMS ((char *, int));
65 static void program_info
PARAMS ((char *, int));
67 static void finish_command
PARAMS ((char *, int));
69 static void signal_command
PARAMS ((char *, int));
71 static void jump_command
PARAMS ((char *, int));
73 static void step_1
PARAMS ((int, int, char *));
75 static void nexti_command
PARAMS ((char *, int));
77 static void stepi_command
PARAMS ((char *, int));
79 static void next_command
PARAMS ((char *, int));
81 static void step_command
PARAMS ((char *, int));
83 static void run_command
PARAMS ((char *, int));
85 static void breakpoint_auto_delete_contents
PARAMS ((PTR
));
87 #define ERROR_NO_INFERIOR \
88 if (!target_has_execution) error ("The program is not being run.");
90 /* String containing arguments to give to the program, separated by spaces.
91 Empty string (pointer to '\0') means no args. */
93 static char *inferior_args
;
95 /* File name for default use for standard in/out in the inferior. */
97 char *inferior_io_terminal
;
99 /* Pid of our debugged inferior, or 0 if no inferior now.
100 Since various parts of infrun.c test this to see whether there is a program
101 being debugged it should be nonzero (currently 3 is used) for remote
106 /* Last signal that the inferior received (why it stopped). */
108 enum target_signal stop_signal
;
110 /* Address at which inferior stopped. */
114 /* Chain containing status of breakpoint(s) that we have stopped at. */
118 /* Flag indicating that a command has proceeded the inferior past the
119 current breakpoint. */
121 int breakpoint_proceeded
;
123 /* Nonzero if stopped due to a step command. */
127 /* Nonzero if stopped due to completion of a stack dummy routine. */
129 int stop_stack_dummy
;
131 /* Nonzero if stopped due to a random (unexpected) signal in inferior
134 int stopped_by_random_signal
;
136 /* Range to single step within.
137 If this is nonzero, respond to a single-step signal
138 by continuing to step if the pc is in this range. */
140 CORE_ADDR step_range_start
; /* Inclusive */
141 CORE_ADDR step_range_end
; /* Exclusive */
143 /* Stack frame address as of when stepping command was issued.
144 This is how we know when we step into a subroutine call,
145 and how to set the frame for the breakpoint used to step out. */
147 CORE_ADDR step_frame_address
;
149 /* Our notion of the current stack pointer. */
153 /* 1 means step over all subroutine calls.
154 0 means don't step over calls (used by stepi).
155 -1 means step over calls to undebuggable functions. */
159 /* If stepping, nonzero means step count is > 1
160 so don't print frame next time inferior stops
161 if it stops due to stepping. */
165 /* Environment to use for running inferior,
166 in format described in environ.h. */
168 struct environ
*inferior_environ
;
173 tty_command (file
, from_tty
)
178 error_no_arg ("terminal name for running target process");
180 inferior_io_terminal
= savestring (file
, strlen (file
));
184 run_command (args
, from_tty
)
192 if (inferior_pid
!= 0 && target_has_execution
)
195 !query ("The program being debugged has been started already.\n\
196 Start it from the beginning? "))
197 error ("Program not restarted.");
201 clear_breakpoint_hit_counts ();
203 exec_file
= (char *) get_exec_file (0);
205 /* The exec file is re-read every time we do a generic_mourn_inferior, so
206 we just have to worry about the symbol file. */
209 /* We keep symbols from add-symbol-file, on the grounds that the
210 user might want to add some symbols before running the program
211 (right?). But sometimes (dynamic loading where the user manually
212 introduces the new symbols with add-symbol-file), the code which
213 the symbols describe does not persist between runs. Currently
214 the user has to manually nuke all symbols between runs if they
215 want them to go away (PR 2207). This is probably reasonable. */
220 cmd
= concat ("set args ", args
, NULL
);
221 make_cleanup (free
, cmd
);
222 execute_command (cmd
, from_tty
);
227 puts_filtered("Starting program: ");
229 puts_filtered(exec_file
);
231 puts_filtered(inferior_args
);
233 gdb_flush (gdb_stdout
);
236 target_create_inferior (exec_file
, inferior_args
,
237 environ_vector (inferior_environ
));
241 continue_command (proc_count_exp
, from_tty
)
242 char *proc_count_exp
;
247 /* If have argument, set proceed count of breakpoint we stopped at. */
249 if (proc_count_exp
!= NULL
)
251 bpstat bs
= stop_bpstat
;
252 int num
= bpstat_num (&bs
);
253 if (num
== 0 && from_tty
)
256 ("Not stopped at any breakpoint; argument ignored.\n");
260 set_ignore_count (num
,
261 parse_and_eval_address (proc_count_exp
) - 1,
263 /* set_ignore_count prints a message ending with a period.
264 So print two spaces before "Continuing.". */
266 printf_filtered (" ");
267 num
= bpstat_num (&bs
);
272 printf_filtered ("Continuing.\n");
274 clear_proceed_status ();
276 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
279 /* Step until outside of current statement. */
283 step_command (count_string
, from_tty
)
287 step_1 (0, 0, count_string
);
290 /* Likewise, but skip over subroutine calls as if single instructions. */
294 next_command (count_string
, from_tty
)
298 step_1 (1, 0, count_string
);
301 /* Likewise, but step only one instruction. */
305 stepi_command (count_string
, from_tty
)
309 step_1 (0, 1, count_string
);
314 nexti_command (count_string
, from_tty
)
318 step_1 (1, 1, count_string
);
322 step_1 (skip_subroutines
, single_inst
, count_string
)
323 int skip_subroutines
;
327 register int count
= 1;
328 struct frame_info
*frame
;
329 struct cleanup
*cleanups
= 0;
332 count
= count_string
? parse_and_eval_address (count_string
) : 1;
334 if (!single_inst
|| skip_subroutines
) /* leave si command alone */
336 enable_longjmp_breakpoint();
337 cleanups
= make_cleanup(disable_longjmp_breakpoint
, 0);
340 for (; count
> 0; count
--)
342 clear_proceed_status ();
344 frame
= get_current_frame ();
345 if (!frame
) /* Avoid coredump here. Why tho? */
346 error ("No current frame");
347 step_frame_address
= FRAME_FP (frame
);
348 step_sp
= read_sp ();
352 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
353 if (step_range_end
== 0)
356 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
357 &step_range_end
) == 0)
358 error ("Cannot find bounds of current function");
360 target_terminal_ours ();
362 Single stepping until exit from function %s, \n\
363 which has no line number information.\n", name
);
368 /* Say we are stepping, but stop after one insn whatever it does. */
369 step_range_start
= step_range_end
= 1;
370 if (!skip_subroutines
)
372 Don't step over function calls, not even to functions lacking
377 if (skip_subroutines
)
380 step_multi
= (count
> 1);
381 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
385 /* FIXME: On nexti, this may have already been done (when we hit the
386 step resume break, I think). Probably this should be moved to
387 wait_for_inferior (near the top). */
388 #if defined (SHIFT_INST_REGS)
393 if (!single_inst
|| skip_subroutines
)
394 do_cleanups(cleanups
);
397 /* Continue program at specified address. */
400 jump_command (arg
, from_tty
)
404 register CORE_ADDR addr
;
405 struct symtabs_and_lines sals
;
406 struct symtab_and_line sal
;
413 error_no_arg ("starting address");
415 sals
= decode_line_spec_1 (arg
, 1);
418 error ("Unreasonable jump request");
422 free ((PTR
)sals
.sals
);
424 if (sal
.symtab
== 0 && sal
.pc
== 0)
425 error ("No source file has been specified.");
427 resolve_sal_pc (&sal
); /* May error out */
429 /* See if we are trying to jump to another function. */
430 fn
= get_frame_function (get_current_frame ());
431 sfn
= find_pc_function (sal
.pc
);
432 if (fn
!= NULL
&& sfn
!= fn
)
434 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal
.line
,
435 SYMBOL_SOURCE_NAME (fn
)))
437 error ("Not confirmed.");
446 printf_filtered ("Continuing at ");
447 print_address_numeric (addr
, 1, gdb_stdout
);
448 printf_filtered (".\n");
451 clear_proceed_status ();
452 proceed (addr
, TARGET_SIGNAL_0
, 0);
455 /* Continue program giving it specified signal. */
458 signal_command (signum_exp
, from_tty
)
462 enum target_signal oursig
;
464 dont_repeat (); /* Too dangerous. */
468 error_no_arg ("signal number");
470 /* It would be even slicker to make signal names be valid expressions,
471 (the type could be "enum $signal" or some such), then the user could
472 assign them to convenience variables. */
473 oursig
= target_signal_from_name (signum_exp
);
475 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
477 /* No, try numeric. */
478 int num
= parse_and_eval_address (signum_exp
);
481 oursig
= TARGET_SIGNAL_0
;
483 oursig
= target_signal_from_command (num
);
488 if (oursig
== TARGET_SIGNAL_0
)
489 printf_filtered ("Continuing with no signal.\n");
491 printf_filtered ("Continuing with signal %s.\n",
492 target_signal_to_name (oursig
));
495 clear_proceed_status ();
496 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
497 FIXME: Neither should "signal foo" but when I tried passing
498 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
499 tried to track down yet. */
500 proceed (oursig
== TARGET_SIGNAL_0
? (CORE_ADDR
) -1 : stop_pc
, oursig
, 0);
503 /* Call breakpoint_auto_delete on the current contents of the bpstat
504 pointed to by arg (which is really a bpstat *). */
507 breakpoint_auto_delete_contents (arg
)
510 breakpoint_auto_delete (*(bpstat
*)arg
);
513 /* Execute a "stack dummy", a piece of code stored in the stack
514 by the debugger to be executed in the inferior.
516 To call: first, do PUSH_DUMMY_FRAME.
517 Then push the contents of the dummy. It should end with a breakpoint insn.
518 Then call here, passing address at which to start the dummy.
520 The contents of all registers are saved before the dummy frame is popped
521 and copied into the buffer BUFFER.
523 The dummy's frame is automatically popped whenever that break is hit.
524 If that is the first time the program stops, run_stack_dummy
525 returns to its caller with that frame already gone and returns 0.
526 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
527 when we do hit that breakpoint). */
529 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
531 static int stack_dummy_testing
= 0;
534 run_stack_dummy (addr
, buffer
)
536 char buffer
[REGISTER_BYTES
];
538 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, 0);
540 /* Now proceed, having reached the desired place. */
541 clear_proceed_status ();
542 if (stack_dummy_testing
& 4)
547 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
549 struct breakpoint
*bpt
;
550 struct symtab_and_line sal
;
552 #if CALL_DUMMY_LOCATION != AT_ENTRY_POINT
553 sal
.pc
= addr
- CALL_DUMMY_START_OFFSET
+ CALL_DUMMY_BREAKPOINT_OFFSET
;
555 sal
.pc
= CALL_DUMMY_ADDRESS ();
560 /* Set up a FRAME for the dummy frame so we can pass it to
561 set_momentary_breakpoint. We need to give the breakpoint a
562 frame in case there is only one copy of the dummy (e.g.
563 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
564 flush_cached_frames ();
565 set_current_frame (create_new_frame (read_fp (), sal
.pc
));
567 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
568 a breakpoint instruction. If not, the call dummy already has the
569 breakpoint instruction in it.
571 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
572 so we need to subtract the CALL_DUMMY_START_OFFSET. */
573 bpt
= set_momentary_breakpoint (sal
,
574 get_current_frame (),
576 bpt
->disposition
= del
;
578 /* If all error()s out of proceed ended up calling normal_stop (and
579 perhaps they should; it already does in the special case of error
580 out of resume()), then we wouldn't need this. */
581 make_cleanup (breakpoint_auto_delete_contents
, &stop_bpstat
);
583 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */
585 proceed_to_finish
= 1; /* We want stop_registers, please... */
586 proceed (addr
, TARGET_SIGNAL_0
, 0);
588 discard_cleanups (old_cleanups
);
590 if (!stop_stack_dummy
)
593 /* On return, the stack dummy has been popped already. */
595 memcpy (buffer
, stop_registers
, sizeof stop_registers
);
599 /* Proceed until we reach a different source line with pc greater than
600 our current one or exit the function. We skip calls in both cases.
602 Note that eventually this command should probably be changed so
603 that only source lines are printed out when we hit the breakpoint
604 we set. This may involve changes to wait_for_inferior and the
605 proceed status code. */
609 until_next_command (from_tty
)
612 struct frame_info
*frame
;
615 struct symtab_and_line sal
;
617 clear_proceed_status ();
619 frame
= get_current_frame ();
621 /* Step until either exited from this function or greater
622 than the current line (if in symbolic section) or pc (if
626 func
= find_pc_function (pc
);
630 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
633 error ("Execution is not within a known function.");
635 step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
640 sal
= find_pc_line (pc
, 0);
642 step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
643 step_range_end
= sal
.end
;
647 step_frame_address
= FRAME_FP (frame
);
648 step_sp
= read_sp ();
650 step_multi
= 0; /* Only one call to proceed */
652 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
656 until_command (arg
, from_tty
)
660 if (!target_has_execution
)
661 error ("The program is not running.");
663 until_break_command (arg
, from_tty
);
665 until_next_command (from_tty
);
668 /* "finish": Set a temporary breakpoint at the place
669 the selected frame will return to, then continue. */
672 finish_command (arg
, from_tty
)
676 struct symtab_and_line sal
;
677 register struct frame_info
*frame
;
678 register struct symbol
*function
;
679 struct breakpoint
*breakpoint
;
680 struct cleanup
*old_chain
;
683 error ("The \"finish\" command does not take any arguments.");
684 if (!target_has_execution
)
685 error ("The program is not running.");
686 if (selected_frame
== NULL
)
687 error ("No selected frame.");
689 frame
= get_prev_frame (selected_frame
);
691 error ("\"finish\" not meaningful in the outermost frame.");
693 clear_proceed_status ();
695 sal
= find_pc_line (frame
->pc
, 0);
698 breakpoint
= set_momentary_breakpoint (sal
, frame
, bp_finish
);
700 old_chain
= make_cleanup(delete_breakpoint
, breakpoint
);
702 /* Find the function we will return from. */
704 function
= find_pc_function (selected_frame
->pc
);
706 /* Print info on the selected frame, including level number
710 printf_filtered ("Run till exit from ");
711 print_stack_frame (selected_frame
, selected_frame_level
, 0);
714 proceed_to_finish
= 1; /* We want stop_registers, please... */
715 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
717 /* Did we stop at our breakpoint? */
718 if (bpstat_find_breakpoint(stop_bpstat
, breakpoint
) != NULL
721 struct type
*value_type
;
722 register value_ptr val
;
725 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
727 fatal ("internal: finish_command: function has no target type");
729 if (TYPE_CODE (value_type
) == TYPE_CODE_VOID
)
732 funcaddr
= BLOCK_START (SYMBOL_BLOCK_VALUE (function
));
734 val
= value_being_returned (value_type
, stop_registers
,
735 using_struct_return (value_of_variable (function
, NULL
),
737 check_typedef (value_type
),
738 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function
))));
740 printf_filtered ("Value returned is $%d = ", record_latest_value (val
));
741 value_print (val
, gdb_stdout
, 0, Val_no_prettyprint
);
742 printf_filtered ("\n");
744 do_cleanups(old_chain
);
749 program_info (args
, from_tty
)
753 bpstat bs
= stop_bpstat
;
754 int num
= bpstat_num (&bs
);
756 if (!target_has_execution
)
758 printf_filtered ("The program being debugged is not being run.\n");
762 target_files_info ();
763 printf_filtered ("Program stopped at %s.\n",
764 local_hex_string((unsigned long) stop_pc
));
766 printf_filtered ("It stopped after being stepped.\n");
769 /* There may be several breakpoints in the same place, so this
770 isn't as strange as it seems. */
774 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
776 printf_filtered ("It stopped at breakpoint %d.\n", num
);
777 num
= bpstat_num (&bs
);
780 else if (stop_signal
!= TARGET_SIGNAL_0
)
782 printf_filtered ("It stopped with signal %s, %s.\n",
783 target_signal_to_name (stop_signal
),
784 target_signal_to_string (stop_signal
));
788 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
792 environment_info (var
, from_tty
)
798 register char *val
= get_in_environ (inferior_environ
, var
);
802 puts_filtered (" = ");
804 puts_filtered ("\n");
808 puts_filtered ("Environment variable \"");
810 puts_filtered ("\" not defined.\n");
815 register char **vector
= environ_vector (inferior_environ
);
818 puts_filtered (*vector
++);
819 puts_filtered ("\n");
825 set_environment_command (arg
, from_tty
)
829 register char *p
, *val
, *var
;
833 error_no_arg ("environment variable and value");
835 /* Find seperation between variable name and value */
836 p
= (char *) strchr (arg
, '=');
837 val
= (char *) strchr (arg
, ' ');
839 if (p
!= 0 && val
!= 0)
841 /* We have both a space and an equals. If the space is before the
842 equals, walk forward over the spaces til we see a nonspace
843 (possibly the equals). */
848 /* Now if the = is after the char following the spaces,
849 take the char following the spaces. */
853 else if (val
!= 0 && p
== 0)
857 error_no_arg ("environment variable to set");
859 if (p
== 0 || p
[1] == 0)
863 p
= arg
+ strlen (arg
); /* So that savestring below will work */
867 /* Not setting variable value to null */
869 while (*val
== ' ' || *val
== '\t')
873 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t')) p
--;
875 var
= savestring (arg
, p
- arg
);
878 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var
);
879 set_in_environ (inferior_environ
, var
, "");
882 set_in_environ (inferior_environ
, var
, val
);
887 unset_environment_command (var
, from_tty
)
893 /* If there is no argument, delete all environment variables.
894 Ask for confirmation if reading from the terminal. */
895 if (!from_tty
|| query ("Delete all environment variables? "))
897 free_environ (inferior_environ
);
898 inferior_environ
= make_environ ();
902 unset_in_environ (inferior_environ
, var
);
905 /* Handle the execution path (PATH variable) */
907 static const char path_var_name
[] = "PATH";
911 path_info (args
, from_tty
)
915 puts_filtered ("Executable and object file path: ");
916 puts_filtered (get_in_environ (inferior_environ
, path_var_name
));
917 puts_filtered ("\n");
920 /* Add zero or more directories to the front of the execution path. */
923 path_command (dirname
, from_tty
)
930 env
= get_in_environ (inferior_environ
, path_var_name
);
931 /* Can be null if path is not set */
934 exec_path
= strsave (env
);
935 mod_path (dirname
, &exec_path
);
936 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
939 path_info ((char *)NULL
, from_tty
);
942 /* The array of register names. */
944 char *reg_names
[] = REGISTER_NAMES
;
946 /* Print out the machine register regnum. If regnum is -1,
947 print all registers (fpregs == 1) or all non-float registers
950 For most machines, having all_registers_info() print the
951 register(s) one per line is good enough. If a different format
952 is required, (eg, for MIPS or Pyramid 90x, which both have
953 lots of regs), or there is an existing convention for showing
954 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
955 to provide that format. */
957 #if !defined (DO_REGISTERS_INFO)
959 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
962 do_registers_info (regnum
, fpregs
)
967 int numregs
= ARCH_NUM_REGS
;
969 for (i
= 0; i
< numregs
; i
++)
971 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
972 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
974 /* Decide between printing all regs, nonfloat regs, or specific reg. */
976 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i
)) == TYPE_CODE_FLT
&& !fpregs
)
983 /* If the register name is empty, it is undefined for this
984 processor, so don't display anything. */
985 if (reg_names
[i
] == NULL
|| *(reg_names
[i
]) == '\0')
988 fputs_filtered (reg_names
[i
], gdb_stdout
);
989 print_spaces_filtered (15 - strlen (reg_names
[i
]), gdb_stdout
);
991 /* Get the data in raw format. */
992 if (read_relative_register_raw_bytes (i
, raw_buffer
))
994 printf_filtered ("Invalid register contents\n");
998 /* Convert raw data to virtual format if necessary. */
999 #ifdef REGISTER_CONVERTIBLE
1000 if (REGISTER_CONVERTIBLE (i
))
1002 REGISTER_CONVERT_TO_VIRTUAL (i
, REGISTER_VIRTUAL_TYPE (i
),
1003 raw_buffer
, virtual_buffer
);
1007 memcpy (virtual_buffer
, raw_buffer
,
1008 REGISTER_VIRTUAL_SIZE (i
));
1010 /* If virtual format is floating, print it that way, and in raw hex. */
1011 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i
)) == TYPE_CODE_FLT
)
1015 #ifdef INVALID_FLOAT
1016 if (INVALID_FLOAT (virtual_buffer
, REGISTER_VIRTUAL_SIZE (i
)))
1017 printf_filtered ("<invalid float>");
1020 val_print (REGISTER_VIRTUAL_TYPE (i
), virtual_buffer
, 0,
1021 gdb_stdout
, 0, 1, 0, Val_pretty_default
);
1023 printf_filtered ("\t(raw 0x");
1024 for (j
= 0; j
< REGISTER_RAW_SIZE (i
); j
++)
1026 register int idx
= TARGET_BYTE_ORDER
== BIG_ENDIAN
? j
1027 : REGISTER_RAW_SIZE (i
) - 1 - j
;
1028 printf_filtered ("%02x", (unsigned char)raw_buffer
[idx
]);
1030 printf_filtered (")");
1033 /* FIXME! val_print probably can handle all of these cases now... */
1035 /* Else if virtual format is too long for printf,
1036 print in hex a byte at a time. */
1037 else if (REGISTER_VIRTUAL_SIZE (i
) > (int) sizeof (long))
1040 printf_filtered ("0x");
1041 for (j
= 0; j
< REGISTER_VIRTUAL_SIZE (i
); j
++)
1042 printf_filtered ("%02x", (unsigned char)virtual_buffer
[j
]);
1044 /* Else print as integer in hex and in decimal. */
1047 val_print (REGISTER_VIRTUAL_TYPE (i
), raw_buffer
, 0,
1048 gdb_stdout
, 'x', 1, 0, Val_pretty_default
);
1049 printf_filtered ("\t");
1050 val_print (REGISTER_VIRTUAL_TYPE (i
), raw_buffer
, 0,
1051 gdb_stdout
, 0, 1, 0, Val_pretty_default
);
1054 /* The SPARC wants to print even-numbered float regs as doubles
1055 in addition to printing them as floats. */
1056 #ifdef PRINT_REGISTER_HOOK
1057 PRINT_REGISTER_HOOK (i
);
1060 printf_filtered ("\n");
1063 #endif /* no DO_REGISTERS_INFO. */
1066 registers_info (addr_exp
, fpregs
)
1070 int regnum
, numregs
;
1073 if (!target_has_registers
)
1074 error ("The program has no registers now.");
1075 if (selected_frame
== NULL
)
1076 error ("No selected frame.");
1080 DO_REGISTERS_INFO(-1, fpregs
);
1086 if (addr_exp
[0] == '$')
1089 while (*end
!= '\0' && *end
!= ' ' && *end
!= '\t')
1091 numregs
= ARCH_NUM_REGS
;
1092 for (regnum
= 0; regnum
< numregs
; regnum
++)
1093 if (!strncmp (addr_exp
, reg_names
[regnum
], end
- addr_exp
)
1094 && strlen (reg_names
[regnum
]) == end
- addr_exp
)
1096 if (*addr_exp
>= '0' && *addr_exp
<= '9')
1097 regnum
= atoi (addr_exp
); /* Take a number */
1098 if (regnum
>= numregs
) /* Bad name, or bad number */
1099 error ("%.*s: invalid register", end
- addr_exp
, addr_exp
);
1102 DO_REGISTERS_INFO(regnum
, fpregs
);
1105 while (*addr_exp
== ' ' || *addr_exp
== '\t')
1107 } while (*addr_exp
!= '\0');
1111 all_registers_info (addr_exp
, from_tty
)
1115 registers_info (addr_exp
, 1);
1119 nofp_registers_info (addr_exp
, from_tty
)
1123 registers_info (addr_exp
, 0);
1128 * Should save/restore the tty state since it might be that the
1129 * program to be debugged was started on this tty and it wants
1130 * the tty in some state other than what we want. If it's running
1131 * on another terminal or without a terminal, then saving and
1132 * restoring the tty state is a harmless no-op.
1133 * This only needs to be done if we are attaching to a process.
1138 takes a program started up outside of gdb and ``attaches'' to it.
1139 This stops it cold in its tracks and allows us to start debugging it.
1140 and wait for the trace-trap that results from attaching. */
1143 attach_command (args
, from_tty
)
1148 extern int auto_solib_add
;
1151 dont_repeat (); /* Not for the faint of heart */
1153 if (target_has_execution
)
1155 if (query ("A program is being debugged already. Kill it? "))
1158 error ("Not killed.");
1161 target_attach (args
, from_tty
);
1163 /* Set up the "saved terminal modes" of the inferior
1164 based on what modes we are starting it with. */
1165 target_terminal_init ();
1167 /* Install inferior's terminal modes. */
1168 target_terminal_inferior ();
1170 /* Set up execution context to know that we should return from
1171 wait_for_inferior as soon as the target reports a stop. */
1172 init_wait_for_inferior ();
1173 clear_proceed_status ();
1174 stop_soon_quietly
= 1;
1176 /* No traps are generated when attaching to inferior under Mach 3
1178 #ifndef ATTACH_NO_WAIT
1179 wait_for_inferior ();
1185 /* Add shared library symbols from the newly attached process, if any. */
1186 SOLIB_ADD ((char *)0, from_tty
, (struct target_ops
*)0);
1187 re_enable_breakpoints_in_shlibs ();
1196 * takes a program previously attached to and detaches it.
1197 * The program resumes execution and will no longer stop
1198 * on signals, etc. We better not have left any breakpoints
1199 * in the program or it'll die when it hits one. For this
1200 * to work, it may be necessary for the process to have been
1201 * previously attached. It *might* work if the program was
1202 * started via the normal ptrace (PTRACE_TRACEME).
1206 detach_command (args
, from_tty
)
1210 dont_repeat (); /* Not for the faint of heart */
1211 target_detach (args
, from_tty
);
1216 float_info (addr_exp
, from_tty
)
1223 printf_filtered ("No floating point info available for this processor.\n");
1229 unset_command (args
, from_tty
)
1233 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1234 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
1238 _initialize_infcmd ()
1240 struct cmd_list_element
*c
;
1242 add_com ("tty", class_run
, tty_command
,
1243 "Set terminal for future runs of program being debugged.");
1246 (add_set_cmd ("args", class_run
, var_string_noescape
, (char *)&inferior_args
,
1248 "Set arguments to give program being debugged when it is started.\n\
1249 Follow this command with any number of args, to be passed to the program.",
1254 ("environment", no_class
, environment_info
,
1255 "The environment to give the program, or one variable's value.\n\
1256 With an argument VAR, prints the value of environment variable VAR to\n\
1257 give the program being debugged. With no arguments, prints the entire\n\
1258 environment to be given to the program.", &showlist
);
1259 c
->completer
= noop_completer
;
1261 add_prefix_cmd ("unset", no_class
, unset_command
,
1262 "Complement to certain \"set\" commands",
1263 &unsetlist
, "unset ", 0, &cmdlist
);
1265 c
= add_cmd ("environment", class_run
, unset_environment_command
,
1266 "Cancel environment variable VAR for the program.\n\
1267 This does not affect the program until the next \"run\" command.",
1269 c
->completer
= noop_completer
;
1271 c
= add_cmd ("environment", class_run
, set_environment_command
,
1272 "Set environment variable value to give the program.\n\
1273 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1274 VALUES of environment variables are uninterpreted strings.\n\
1275 This does not affect the program until the next \"run\" command.",
1277 c
->completer
= noop_completer
;
1279 add_com ("path", class_files
, path_command
,
1280 "Add directory DIR(s) to beginning of search path for object files.\n\
1281 $cwd in the path means the current working directory.\n\
1282 This path is equivalent to the $PATH shell variable. It is a list of\n\
1283 directories, separated by colons. These directories are searched to find\n\
1284 fully linked executable files and separately compiled object files as needed.");
1286 c
= add_cmd ("paths", no_class
, path_info
,
1287 "Current search path for finding object files.\n\
1288 $cwd in the path means the current working directory.\n\
1289 This path is equivalent to the $PATH shell variable. It is a list of\n\
1290 directories, separated by colons. These directories are searched to find\n\
1291 fully linked executable files and separately compiled object files as needed.", &showlist
);
1292 c
->completer
= noop_completer
;
1294 add_com ("attach", class_run
, attach_command
,
1295 "Attach to a process or file outside of GDB.\n\
1296 This command attaches to another target, of the same type as your last\n\
1297 `target' command (`info files' will show your target stack).\n\
1298 The command may take as argument a process id or a device file.\n\
1299 For a process id, you must have permission to send the process a signal,\n\
1300 and it must have the same effective uid as the debugger.\n\
1301 When using \"attach\", you should use the \"file\" command to specify\n\
1302 the program running in the process, and to load its symbol table.");
1304 add_com ("detach", class_run
, detach_command
,
1305 "Detach a process or file previously attached.\n\
1306 If a process, it is no longer traced, and it continues its execution. If you\n\
1307 were debugging a file, the file is closed and gdb no longer accesses it.");
1309 add_com ("signal", class_run
, signal_command
,
1310 "Continue program giving it signal specified by the argument.\n\
1311 An argument of \"0\" means continue program without giving it a signal.");
1313 add_com ("stepi", class_run
, stepi_command
,
1314 "Step one instruction exactly.\n\
1315 Argument N means do this N times (or till program stops for another reason).");
1316 add_com_alias ("si", "stepi", class_alias
, 0);
1318 add_com ("nexti", class_run
, nexti_command
,
1319 "Step one instruction, but proceed through subroutine calls.\n\
1320 Argument N means do this N times (or till program stops for another reason).");
1321 add_com_alias ("ni", "nexti", class_alias
, 0);
1323 add_com ("finish", class_run
, finish_command
,
1324 "Execute until selected stack frame returns.\n\
1325 Upon return, the value returned is printed and put in the value history.");
1327 add_com ("next", class_run
, next_command
,
1328 "Step program, proceeding through subroutine calls.\n\
1329 Like the \"step\" command as long as subroutine calls do not happen;\n\
1330 when they do, the call is treated as one instruction.\n\
1331 Argument N means do this N times (or till program stops for another reason).");
1332 add_com_alias ("n", "next", class_run
, 1);
1334 add_com ("step", class_run
, step_command
,
1335 "Step program until it reaches a different source line.\n\
1336 Argument N means do this N times (or till program stops for another reason).");
1337 add_com_alias ("s", "step", class_run
, 1);
1339 add_com ("until", class_run
, until_command
,
1340 "Execute until the program reaches a source line greater than the current\n\
1341 or a specified line or address or function (same args as break command).\n\
1342 Execution will also stop upon exit from the current stack frame.");
1343 add_com_alias ("u", "until", class_run
, 1);
1345 add_com ("jump", class_run
, jump_command
,
1346 "Continue program being debugged at specified line or address.\n\
1347 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1348 for an address to start at.");
1350 add_com ("continue", class_run
, continue_command
,
1351 "Continue program being debugged, after signal or breakpoint.\n\
1352 If proceeding from breakpoint, a number N may be used as an argument,\n\
1353 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1354 the breakpoint won't break until the Nth time it is reached).");
1355 add_com_alias ("c", "cont", class_run
, 1);
1356 add_com_alias ("fg", "cont", class_run
, 1);
1358 add_com ("run", class_run
, run_command
,
1359 "Start debugged program. You may specify arguments to give it.\n\
1360 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1361 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1362 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1363 To cancel previous arguments and run with no arguments,\n\
1364 use \"set args\" without arguments.");
1365 add_com_alias ("r", "run", class_run
, 1);
1367 add_info ("registers", nofp_registers_info
,
1368 "List of integer registers and their contents, for selected stack frame.\n\
1369 Register name as argument means describe only that register.");
1371 add_info ("all-registers", all_registers_info
,
1372 "List of all registers and their contents, for selected stack frame.\n\
1373 Register name as argument means describe only that register.");
1375 add_info ("program", program_info
,
1376 "Execution status of the program.");
1378 add_info ("float", float_info
,
1379 "Print the status of the floating point unit\n");
1381 inferior_args
= savestring ("", 1); /* Initially no args */
1382 inferior_environ
= make_environ ();
1383 init_environ (inferior_environ
);