* utils.c (fprintfi_filtered): Fix comments.
[deliverable/binutils-gdb.git] / gdb / infcmd.c
CommitLineData
ee0613d1
JG
1/* Memory-access and commands for "inferior" (child) process, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
bd5635a1
RP
3
4This file is part of GDB.
5
ee0613d1 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
ee0613d1
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
ee0613d1 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
ee0613d1
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 19
1304f099 20#include "defs.h"
bd5635a1
RP
21#include <signal.h>
22#include <sys/param.h>
23#include <string.h>
bd5635a1 24#include "symtab.h"
1304f099 25#include "gdbtypes.h"
bd5635a1
RP
26#include "frame.h"
27#include "inferior.h"
28#include "environ.h"
29#include "value.h"
30#include "gdbcmd.h"
31#include "gdbcore.h"
32#include "target.h"
33
1304f099
JG
34static void
35continue_command PARAMS ((char *, int));
36
37static void
38until_next_command PARAMS ((int));
39
40static void
41until_command PARAMS ((char *, int));
42
43static void
44path_info PARAMS ((char *, int));
45
46static void
47path_command PARAMS ((char *, int));
48
49static void
50unset_command PARAMS ((char *, int));
51
52static void
53float_info PARAMS ((char *, int));
54
55static void
56detach_command PARAMS ((char *, int));
57
58static void
59nofp_registers_info PARAMS ((char *, int));
60
61static void
62all_registers_info PARAMS ((char *, int));
63
64static void
65registers_info PARAMS ((char *, int));
66
67static void
68do_registers_info PARAMS ((int, int));
69
70static void
71unset_environment_command PARAMS ((char *, int));
72
73static void
74set_environment_command PARAMS ((char *, int));
75
76static void
77environment_info PARAMS ((char *, int));
78
79static void
80program_info PARAMS ((char *, int));
81
82static void
83finish_command PARAMS ((char *, int));
84
85static void
86signal_command PARAMS ((char *, int));
87
88static void
89jump_command PARAMS ((char *, int));
90
91static void
92step_1 PARAMS ((int, int, char *));
93
94static void
95nexti_command PARAMS ((char *, int));
bd5635a1 96
1304f099
JG
97static void
98stepi_command PARAMS ((char *, int));
99
100static void
101next_command PARAMS ((char *, int));
102
103static void
104step_command PARAMS ((char *, int));
105
106static void
107run_command PARAMS ((char *, int));
bd5635a1
RP
108
109#define ERROR_NO_INFERIOR \
110 if (!target_has_execution) error ("The program is not being run.");
111
112/* String containing arguments to give to the program, separated by spaces.
113 Empty string (pointer to '\0') means no args. */
114
115static char *inferior_args;
116
117/* File name for default use for standard in/out in the inferior. */
118
119char *inferior_io_terminal;
120
121/* Pid of our debugged inferior, or 0 if no inferior now.
122 Since various parts of infrun.c test this to see whether there is a program
123 being debugged it should be nonzero (currently 3 is used) for remote
124 debugging. */
125
126int inferior_pid;
127
128/* Last signal that the inferior received (why it stopped). */
129
130int stop_signal;
131
132/* Address at which inferior stopped. */
133
134CORE_ADDR stop_pc;
135
136/* Stack frame when program stopped. */
137
138FRAME_ADDR stop_frame_address;
139
140/* Chain containing status of breakpoint(s) that we have stopped at. */
141
142bpstat stop_bpstat;
143
144/* Flag indicating that a command has proceeded the inferior past the
145 current breakpoint. */
146
147int breakpoint_proceeded;
148
149/* Nonzero if stopped due to a step command. */
150
151int stop_step;
152
153/* Nonzero if stopped due to completion of a stack dummy routine. */
154
155int stop_stack_dummy;
156
157/* Nonzero if stopped due to a random (unexpected) signal in inferior
158 process. */
159
160int stopped_by_random_signal;
161
162/* Range to single step within.
163 If this is nonzero, respond to a single-step signal
164 by continuing to step if the pc is in this range. */
165
166CORE_ADDR step_range_start; /* Inclusive */
167CORE_ADDR step_range_end; /* Exclusive */
168
169/* Stack frame address as of when stepping command was issued.
170 This is how we know when we step into a subroutine call,
171 and how to set the frame for the breakpoint used to step out. */
172
173FRAME_ADDR step_frame_address;
174
175/* 1 means step over all subroutine calls.
b5a3d2aa 176 0 means don't step over calls (used by stepi).
bd5635a1
RP
177 -1 means step over calls to undebuggable functions. */
178
179int step_over_calls;
180
181/* If stepping, nonzero means step count is > 1
182 so don't print frame next time inferior stops
183 if it stops due to stepping. */
184
185int step_multi;
186
187/* Environment to use for running inferior,
188 in format described in environ.h. */
189
190struct environ *inferior_environ;
191
bd5635a1 192\f
e1ce8aa5 193/* ARGSUSED */
bd5635a1
RP
194void
195tty_command (file, from_tty)
196 char *file;
197 int from_tty;
198{
199 if (file == 0)
200 error_no_arg ("terminal name for running target process");
201
202 inferior_io_terminal = savestring (file, strlen (file));
203}
204
205static void
206run_command (args, from_tty)
207 char *args;
208 int from_tty;
209{
210 char *exec_file;
211
212 dont_repeat ();
213
02ff0cd3 214 /* Shouldn't this be target_has_execution? FIXME. */
bd5635a1
RP
215 if (inferior_pid)
216 {
217 if (
218 !query ("The program being debugged has been started already.\n\
219Start it from the beginning? "))
220 error ("Program not restarted.");
ee0613d1 221 target_kill ();
bd5635a1
RP
222 }
223
224 exec_file = (char *) get_exec_file (0);
225
1304f099 226 /* The exec file is re-read every time we do a generic_mourn_inferior, so
bd5635a1
RP
227 we just have to worry about the symbol file. */
228 reread_symbols ();
229
230 if (args)
231 {
232 char *cmd;
ee0613d1 233 cmd = concat ("set args ", args, NULL);
bd5635a1
RP
234 make_cleanup (free, cmd);
235 execute_command (cmd, from_tty);
236 }
237
238 if (from_tty)
239 {
b5a3d2aa
SG
240 puts_filtered("Starting program: ");
241 if (exec_file)
242 puts_filtered(exec_file);
243 puts_filtered(" ");
244 puts_filtered(inferior_args);
245 puts_filtered("\n");
bd5635a1
RP
246 fflush (stdout);
247 }
248
249 target_create_inferior (exec_file, inferior_args,
250 environ_vector (inferior_environ));
251}
252\f
1304f099 253static void
bd5635a1
RP
254continue_command (proc_count_exp, from_tty)
255 char *proc_count_exp;
256 int from_tty;
257{
258 ERROR_NO_INFERIOR;
259
260 /* If have argument, set proceed count of breakpoint we stopped at. */
261
262 if (proc_count_exp != NULL)
263 {
264 bpstat bs = stop_bpstat;
265 int num = bpstat_num (&bs);
266 if (num == 0 && from_tty)
267 {
268 printf_filtered
269 ("Not stopped at any breakpoint; argument ignored.\n");
270 }
271 while (num != 0)
272 {
273 set_ignore_count (num,
274 parse_and_eval_address (proc_count_exp) - 1,
275 from_tty);
276 /* set_ignore_count prints a message ending with a period.
277 So print two spaces before "Continuing.". */
278 if (from_tty)
1304f099 279 printf_filtered (" ");
bd5635a1
RP
280 num = bpstat_num (&bs);
281 }
282 }
283
284 if (from_tty)
1304f099 285 printf_filtered ("Continuing.\n");
bd5635a1
RP
286
287 clear_proceed_status ();
288
289 proceed ((CORE_ADDR) -1, -1, 0);
290}
291\f
292/* Step until outside of current statement. */
bd5635a1 293
e1ce8aa5 294/* ARGSUSED */
bd5635a1
RP
295static void
296step_command (count_string, from_tty)
1304f099 297 char *count_string;
bd5635a1
RP
298 int from_tty;
299{
300 step_1 (0, 0, count_string);
301}
302
303/* Likewise, but skip over subroutine calls as if single instructions. */
304
e1ce8aa5 305/* ARGSUSED */
bd5635a1
RP
306static void
307next_command (count_string, from_tty)
1304f099 308 char *count_string;
bd5635a1
RP
309 int from_tty;
310{
311 step_1 (1, 0, count_string);
312}
313
314/* Likewise, but step only one instruction. */
315
e1ce8aa5 316/* ARGSUSED */
bd5635a1
RP
317static void
318stepi_command (count_string, from_tty)
1304f099 319 char *count_string;
bd5635a1
RP
320 int from_tty;
321{
322 step_1 (0, 1, count_string);
323}
324
e1ce8aa5 325/* ARGSUSED */
bd5635a1
RP
326static void
327nexti_command (count_string, from_tty)
1304f099 328 char *count_string;
bd5635a1
RP
329 int from_tty;
330{
331 step_1 (1, 1, count_string);
332}
333
334static void
335step_1 (skip_subroutines, single_inst, count_string)
336 int skip_subroutines;
337 int single_inst;
338 char *count_string;
339{
340 register int count = 1;
341 FRAME fr;
1304f099 342 struct cleanup *cleanups = 0;
bd5635a1
RP
343
344 ERROR_NO_INFERIOR;
345 count = count_string ? parse_and_eval_address (count_string) : 1;
346
1304f099
JG
347 if (!single_inst || skip_subroutines) /* leave si command alone */
348 {
349 enable_longjmp_breakpoint();
350 cleanups = make_cleanup(disable_longjmp_breakpoint, 0);
351 }
352
bd5635a1
RP
353 for (; count > 0; count--)
354 {
355 clear_proceed_status ();
356
bd5635a1
RP
357 fr = get_current_frame ();
358 if (!fr) /* Avoid coredump here. Why tho? */
359 error ("No current frame");
360 step_frame_address = FRAME_FP (fr);
361
362 if (! single_inst)
363 {
364 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
365 if (step_range_end == 0)
366 {
860a1754
JK
367 char *name;
368 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
369 &step_range_end) == 0)
370 error ("Cannot find bounds of current function");
bd5635a1 371
bd5635a1 372 target_terminal_ours ();
860a1754
JK
373 printf_filtered ("\
374Single stepping until exit from function %s, \n\
375which has no line number information.\n", name);
bd5635a1 376 fflush (stdout);
bd5635a1
RP
377 }
378 }
379 else
380 {
fe675038 381 /* Say we are stepping, but stop after one insn whatever it does. */
bd5635a1
RP
382 step_range_start = step_range_end = 1;
383 if (!skip_subroutines)
fe675038
JK
384 /* It is stepi.
385 Don't step over function calls, not even to functions lacking
386 line numbers. */
bd5635a1
RP
387 step_over_calls = 0;
388 }
389
390 if (skip_subroutines)
391 step_over_calls = 1;
392
393 step_multi = (count > 1);
394 proceed ((CORE_ADDR) -1, -1, 1);
395 if (! stop_step)
396 break;
397#if defined (SHIFT_INST_REGS)
07a5991a 398 SHIFT_INST_REGS();
bd5635a1
RP
399#endif
400 }
1304f099
JG
401
402 if (!single_inst || skip_subroutines)
403 do_cleanups(cleanups);
bd5635a1
RP
404}
405\f
406/* Continue program at specified address. */
407
408static void
409jump_command (arg, from_tty)
410 char *arg;
411 int from_tty;
412{
413 register CORE_ADDR addr;
414 struct symtabs_and_lines sals;
415 struct symtab_and_line sal;
b4fde6fa
FF
416 struct symbol *fn;
417 struct symbol *sfn;
bd5635a1
RP
418
419 ERROR_NO_INFERIOR;
420
421 if (!arg)
422 error_no_arg ("starting address");
423
424 sals = decode_line_spec_1 (arg, 1);
425 if (sals.nelts != 1)
426 {
427 error ("Unreasonable jump request");
428 }
429
430 sal = sals.sals[0];
1304f099 431 free ((PTR)sals.sals);
bd5635a1
RP
432
433 if (sal.symtab == 0 && sal.pc == 0)
434 error ("No source file has been specified.");
435
ee0613d1 436 resolve_sal_pc (&sal); /* May error out */
bd5635a1 437
b4fde6fa
FF
438 /* See if we are trying to jump to another function. */
439 fn = get_frame_function (get_current_frame ());
440 sfn = find_pc_function (sal.pc);
441 if (fn != NULL && sfn != fn)
442 {
2e4964ad
FF
443 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
444 SYMBOL_SOURCE_NAME (fn)))
b4fde6fa
FF
445 {
446 error ("Not confirmed.");
447 /* NOTREACHED */
448 }
b4fde6fa 449 }
bd5635a1 450
bd5635a1
RP
451 addr = ADDR_BITS_SET (sal.pc);
452
453 if (from_tty)
1304f099 454 printf_filtered ("Continuing at %s.\n", local_hex_string(addr));
bd5635a1
RP
455
456 clear_proceed_status ();
457 proceed (addr, 0, 0);
458}
459
460/* Continue program giving it specified signal. */
461
462static void
463signal_command (signum_exp, from_tty)
464 char *signum_exp;
465 int from_tty;
466{
467 register int signum;
468
469 dont_repeat (); /* Too dangerous. */
470 ERROR_NO_INFERIOR;
471
472 if (!signum_exp)
473 error_no_arg ("signal number");
474
de6a2704
JK
475 /* It would be even slicker to make signal names be valid expressions,
476 (the type could be "enum $signal" or some such), then the user could
477 assign them to convenience variables. */
478 signum = strtosigno (signum_exp);
479
480 if (signum == 0)
481 /* Not found as a name, try it as an expression. */
482 signum = parse_and_eval_address (signum_exp);
bd5635a1
RP
483
484 if (from_tty)
de6a2704
JK
485 {
486 char *signame = strsigno (signum);
487 printf_filtered ("Continuing with signal ");
488 if (signame == NULL || signum == 0)
489 printf_filtered ("%d.\n", signum);
490 else
491 /* Do we need to print the number as well as the name? */
492 printf_filtered ("%s (%d).\n", signame, signum);
493 }
bd5635a1
RP
494
495 clear_proceed_status ();
496 proceed (stop_pc, signum, 0);
497}
498
84d59861
JK
499/* Call breakpoint_auto_delete on the current contents of the bpstat
500 pointed to by arg (which is really a bpstat *). */
501void
502breakpoint_auto_delete_contents (arg)
503 PTR arg;
504{
505 breakpoint_auto_delete (*(bpstat *)arg);
506}
507
bd5635a1
RP
508/* Execute a "stack dummy", a piece of code stored in the stack
509 by the debugger to be executed in the inferior.
510
511 To call: first, do PUSH_DUMMY_FRAME.
512 Then push the contents of the dummy. It should end with a breakpoint insn.
513 Then call here, passing address at which to start the dummy.
514
515 The contents of all registers are saved before the dummy frame is popped
516 and copied into the buffer BUFFER.
517
518 The dummy's frame is automatically popped whenever that break is hit.
519 If that is the first time the program stops, run_stack_dummy
860a1754
JK
520 returns to its caller with that frame already gone and returns 0.
521 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
522 when we do hit that breakpoint). */
bd5635a1 523
ee0613d1 524/* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
bd5635a1
RP
525
526static int stack_dummy_testing = 0;
527
860a1754
JK
528int
529run_stack_dummy (addr, buffer)
bd5635a1
RP
530 CORE_ADDR addr;
531 char buffer[REGISTER_BYTES];
532{
84d59861
JK
533 struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
534
bd5635a1
RP
535 /* Now proceed, having reached the desired place. */
536 clear_proceed_status ();
537 if (stack_dummy_testing & 4)
538 {
539 POP_FRAME;
37c99ddb 540 return(0);
bd5635a1 541 }
84d59861
JK
542#ifdef CALL_DUMMY_BREAKPOINT_OFFSET
543 {
544 struct breakpoint *bpt;
545 struct symtab_and_line sal;
546
547 sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET;
548 sal.symtab = NULL;
549 sal.line = 0;
550
551 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
552 a breakpoint instruction. If not, the call dummy already has the
553 breakpoint instruction in it.
554
555 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
556 so we need to subtract the CALL_DUMMY_START_OFFSET. */
557 bpt = set_momentary_breakpoint (sal,
558 NULL,
559 bp_call_dummy);
560 bpt->disposition = delete;
561
562 /* If all error()s out of proceed ended up calling normal_stop (and
563 perhaps they should; it already does in the special case of error
564 out of resume()), then we wouldn't need this. */
565 make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
566 }
567#endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */
568
bd5635a1
RP
569 proceed_to_finish = 1; /* We want stop_registers, please... */
570 proceed (addr, 0, 0);
571
84d59861
JK
572 discard_cleanups (old_cleanups);
573
bd5635a1 574 if (!stop_stack_dummy)
860a1754 575 return 1;
bd5635a1
RP
576
577 /* On return, the stack dummy has been popped already. */
578
4ed3a9ea 579 memcpy (buffer, stop_registers, sizeof stop_registers);
860a1754 580 return 0;
bd5635a1
RP
581}
582\f
583/* Proceed until we reach a different source line with pc greater than
584 our current one or exit the function. We skip calls in both cases.
585
586 Note that eventually this command should probably be changed so
587 that only source lines are printed out when we hit the breakpoint
588 we set. I'm going to postpone this until after a hopeful rewrite
589 of wait_for_inferior and the proceed status code. -- randy */
590
e1ce8aa5 591/* ARGSUSED */
1304f099 592static void
bd5635a1
RP
593until_next_command (from_tty)
594 int from_tty;
595{
596 FRAME frame;
597 CORE_ADDR pc;
598 struct symbol *func;
599 struct symtab_and_line sal;
600
601 clear_proceed_status ();
602
603 frame = get_current_frame ();
604
605 /* Step until either exited from this function or greater
606 than the current line (if in symbolic section) or pc (if
607 not). */
608
609 pc = read_pc ();
610 func = find_pc_function (pc);
611
612 if (!func)
613 {
1304f099 614 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
bd5635a1 615
1304f099 616 if (msymbol == NULL)
bd5635a1
RP
617 error ("Execution is not within a known function.");
618
2e4964ad 619 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
bd5635a1
RP
620 step_range_end = pc;
621 }
622 else
623 {
624 sal = find_pc_line (pc, 0);
625
626 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
627 step_range_end = sal.end;
628 }
629
630 step_over_calls = 1;
631 step_frame_address = FRAME_FP (frame);
632
633 step_multi = 0; /* Only one call to proceed */
634
635 proceed ((CORE_ADDR) -1, -1, 1);
636}
637
1304f099 638static void
bd5635a1
RP
639until_command (arg, from_tty)
640 char *arg;
641 int from_tty;
642{
643 if (!target_has_execution)
644 error ("The program is not running.");
645 if (arg)
646 until_break_command (arg, from_tty);
647 else
648 until_next_command (from_tty);
649}
650\f
651/* "finish": Set a temporary breakpoint at the place
652 the selected frame will return to, then continue. */
653
654static void
655finish_command (arg, from_tty)
656 char *arg;
657 int from_tty;
658{
659 struct symtab_and_line sal;
660 register FRAME frame;
661 struct frame_info *fi;
662 register struct symbol *function;
1304f099
JG
663 struct breakpoint *breakpoint;
664 struct cleanup *old_chain;
bd5635a1
RP
665
666 if (arg)
667 error ("The \"finish\" command does not take any arguments.");
668 if (!target_has_execution)
669 error ("The program is not running.");
777bef06
JK
670 if (selected_frame == NULL)
671 error ("No selected frame.");
bd5635a1
RP
672
673 frame = get_prev_frame (selected_frame);
674 if (frame == 0)
675 error ("\"finish\" not meaningful in the outermost frame.");
676
677 clear_proceed_status ();
678
679 fi = get_frame_info (frame);
680 sal = find_pc_line (fi->pc, 0);
681 sal.pc = fi->pc;
1304f099
JG
682
683 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
684
685 old_chain = make_cleanup(delete_breakpoint, breakpoint);
bd5635a1
RP
686
687 /* Find the function we will return from. */
688
689 fi = get_frame_info (selected_frame);
690 function = find_pc_function (fi->pc);
691
ee0613d1
JG
692 /* Print info on the selected frame, including level number
693 but not source. */
bd5635a1
RP
694 if (from_tty)
695 {
ee0613d1
JG
696 printf_filtered ("Run till exit from ");
697 print_stack_frame (selected_frame, selected_frame_level, 0);
bd5635a1
RP
698 }
699
700 proceed_to_finish = 1; /* We want stop_registers, please... */
701 proceed ((CORE_ADDR) -1, -1, 0);
702
1304f099
JG
703 /* Did we stop at our breakpoint? */
704 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
705 && function != 0)
bd5635a1
RP
706 {
707 struct type *value_type;
708 register value val;
709 CORE_ADDR funcaddr;
710
711 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
712 if (!value_type)
713 fatal ("internal: finish_command: function has no target type");
714
715 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
716 return;
717
718 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
719
720 val = value_being_returned (value_type, stop_registers,
860a1754 721 using_struct_return (value_of_variable (function, NULL),
bd5635a1
RP
722 funcaddr,
723 value_type,
724 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
725
ee0613d1 726 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
bd5635a1 727 value_print (val, stdout, 0, Val_no_prettyprint);
ee0613d1 728 printf_filtered ("\n");
bd5635a1 729 }
1304f099 730 do_cleanups(old_chain);
bd5635a1
RP
731}
732\f
e1ce8aa5 733/* ARGSUSED */
bd5635a1
RP
734static void
735program_info (args, from_tty)
736 char *args;
737 int from_tty;
738{
739 bpstat bs = stop_bpstat;
740 int num = bpstat_num (&bs);
741
742 if (!target_has_execution)
743 {
1304f099 744 printf_filtered ("The program being debugged is not being run.\n");
bd5635a1
RP
745 return;
746 }
747
748 target_files_info ();
1304f099 749 printf_filtered ("Program stopped at %s.\n", local_hex_string(stop_pc));
bd5635a1 750 if (stop_step)
1304f099 751 printf_filtered ("It stopped after being stepped.\n");
bd5635a1
RP
752 else if (num != 0)
753 {
754 /* There may be several breakpoints in the same place, so this
755 isn't as strange as it seems. */
756 while (num != 0)
757 {
758 if (num < 0)
1304f099 759 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
bd5635a1 760 else
1304f099 761 printf_filtered ("It stopped at breakpoint %d.\n", num);
bd5635a1
RP
762 num = bpstat_num (&bs);
763 }
764 }
de6a2704
JK
765 else if (stop_signal)
766 {
bd5635a1 767#ifdef PRINT_RANDOM_SIGNAL
de6a2704 768 PRINT_RANDOM_SIGNAL (stop_signal);
bd5635a1 769#else
de6a2704
JK
770 char *signame = strsigno (stop_signal);
771 printf_filtered ("It stopped with signal ");
772 if (signame == NULL)
773 printf_filtered ("%d", stop_signal);
774 else
775 /* Do we need to print the number as well as the name? */
776 printf_filtered ("%s (%d)", signame, stop_signal);
777 printf_filtered (", %s.\n", safe_strsignal (stop_signal));
bd5635a1
RP
778#endif
779 }
780
781 if (!from_tty)
1304f099 782 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
bd5635a1
RP
783}
784\f
785static void
1304f099 786environment_info (var, from_tty)
bd5635a1 787 char *var;
1304f099 788 int from_tty;
bd5635a1
RP
789{
790 if (var)
791 {
792 register char *val = get_in_environ (inferior_environ, var);
793 if (val)
631f7a9f
JG
794 {
795 puts_filtered (var);
796 puts_filtered (" = ");
797 puts_filtered (val);
798 puts_filtered ("\n");
799 }
bd5635a1 800 else
631f7a9f
JG
801 {
802 puts_filtered ("Environment variable \"");
803 puts_filtered (var);
804 puts_filtered ("\" not defined.\n");
805 }
bd5635a1
RP
806 }
807 else
808 {
809 register char **vector = environ_vector (inferior_environ);
810 while (*vector)
631f7a9f
JG
811 {
812 puts_filtered (*vector++);
813 puts_filtered ("\n");
814 }
bd5635a1
RP
815 }
816}
817
818static void
1304f099 819set_environment_command (arg, from_tty)
bd5635a1 820 char *arg;
1304f099 821 int from_tty;
bd5635a1
RP
822{
823 register char *p, *val, *var;
824 int nullset = 0;
825
826 if (arg == 0)
827 error_no_arg ("environment variable and value");
828
829 /* Find seperation between variable name and value */
830 p = (char *) strchr (arg, '=');
831 val = (char *) strchr (arg, ' ');
832
833 if (p != 0 && val != 0)
834 {
835 /* We have both a space and an equals. If the space is before the
631f7a9f
JG
836 equals, walk forward over the spaces til we see a nonspace
837 (possibly the equals). */
bd5635a1
RP
838 if (p > val)
839 while (*val == ' ')
840 val++;
841
631f7a9f
JG
842 /* Now if the = is after the char following the spaces,
843 take the char following the spaces. */
844 if (p > val)
b5a3d2aa 845 p = val - 1;
bd5635a1
RP
846 }
847 else if (val != 0 && p == 0)
848 p = val;
849
850 if (p == arg)
851 error_no_arg ("environment variable to set");
852
853 if (p == 0 || p[1] == 0)
854 {
855 nullset = 1;
856 if (p == 0)
857 p = arg + strlen (arg); /* So that savestring below will work */
858 }
859 else
860 {
861 /* Not setting variable value to null */
862 val = p + 1;
863 while (*val == ' ' || *val == '\t')
864 val++;
865 }
866
867 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
868
869 var = savestring (arg, p - arg);
870 if (nullset)
871 {
1304f099 872 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
bd5635a1
RP
873 set_in_environ (inferior_environ, var, "");
874 }
875 else
876 set_in_environ (inferior_environ, var, val);
877 free (var);
878}
879
880static void
881unset_environment_command (var, from_tty)
882 char *var;
883 int from_tty;
884{
885 if (var == 0)
886 {
887 /* If there is no argument, delete all environment variables.
888 Ask for confirmation if reading from the terminal. */
889 if (!from_tty || query ("Delete all environment variables? "))
890 {
891 free_environ (inferior_environ);
892 inferior_environ = make_environ ();
893 }
894 }
895 else
896 unset_in_environ (inferior_environ, var);
897}
898
899/* Handle the execution path (PATH variable) */
900
a8a69e63 901static const char path_var_name[] = "PATH";
bd5635a1 902
e1ce8aa5 903/* ARGSUSED */
1304f099 904static void
bd5635a1
RP
905path_info (args, from_tty)
906 char *args;
907 int from_tty;
908{
b5a3d2aa
SG
909 puts_filtered ("Executable and object file path: ");
910 puts_filtered (get_in_environ (inferior_environ, path_var_name));
911 puts_filtered ("\n");
bd5635a1
RP
912}
913
914/* Add zero or more directories to the front of the execution path. */
915
1304f099 916static void
bd5635a1
RP
917path_command (dirname, from_tty)
918 char *dirname;
919 int from_tty;
920{
921 char *exec_path;
922
923 dont_repeat ();
924 exec_path = strsave (get_in_environ (inferior_environ, path_var_name));
e1ce8aa5 925 mod_path (dirname, &exec_path);
bd5635a1
RP
926 set_in_environ (inferior_environ, path_var_name, exec_path);
927 free (exec_path);
928 if (from_tty)
e1ce8aa5 929 path_info ((char *)NULL, from_tty);
bd5635a1
RP
930}
931\f
de6a2704
JK
932/* This routine is getting awfully cluttered with #if's. It's probably
933 time to turn this into READ_PC and define it in the tm.h file.
934 Ditto for write_pc. */
b1b4a89e 935
bd5635a1
RP
936CORE_ADDR
937read_pc ()
938{
de6a2704
JK
939#ifdef TARGET_READ_PC
940 return TARGET_READ_PC ();
b1b4a89e 941#else
bd5635a1 942 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register (PC_REGNUM));
b1b4a89e 943#endif
bd5635a1
RP
944}
945
946void
947write_pc (val)
948 CORE_ADDR val;
949{
de6a2704
JK
950#ifdef TARGET_WRITE_PC
951 TARGET_WRITE_PC (val);
952#else
bd5635a1
RP
953 write_register (PC_REGNUM, (long) val);
954#ifdef NPC_REGNUM
b1b4a89e
JK
955 write_register (NPC_REGNUM, (long) val + 4);
956#ifdef NNPC_REGNUM
957 write_register (NNPC_REGNUM, (long) val + 8);
958#endif
959#endif
bd5635a1 960#endif
bd5635a1
RP
961}
962
de6a2704
JK
963/* Cope with strage ways of getting to the stack and frame pointers */
964
965CORE_ADDR
966read_sp ()
967{
968#ifdef TARGET_READ_SP
969 return TARGET_READ_SP ();
970#else
971 return read_register (SP_REGNUM);
972#endif
973}
974
975void
976write_sp (val)
977 CORE_ADDR val;
978{
979#ifdef TARGET_WRITE_SP
980 TARGET_WRITE_SP (val);
981#else
982 write_register (SP_REGNUM, val);
983#endif
984}
985
986
987CORE_ADDR
988read_fp ()
989{
990#ifdef TARGET_READ_FP
991 return TARGET_READ_FP ();
992#else
993 return read_register (FP_REGNUM);
994#endif
995}
996
997void
998write_fp (val)
999 CORE_ADDR val;
1000{
1001#ifdef TARGET_WRITE_FP
1002 TARGET_WRITE_FP (val);
1003#else
1004 write_register (FP_REGNUM, val);
1005#endif
1006}
1007
1304f099 1008const char * const reg_names[] = REGISTER_NAMES;
bd5635a1
RP
1009
1010/* Print out the machine register regnum. If regnum is -1,
ee0613d1
JG
1011 print all registers (fpregs == 1) or all non-float registers
1012 (fpregs == 0).
1013
bd5635a1
RP
1014 For most machines, having all_registers_info() print the
1015 register(s) one per line is good enough. If a different format
ee0613d1 1016 is required, (eg, for MIPS or Pyramid 90x, which both have
bd5635a1 1017 lots of regs), or there is an existing convention for showing
ee0613d1 1018 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
bd5635a1 1019 to provide that format. */
ee0613d1 1020
bd5635a1 1021#if !defined (DO_REGISTERS_INFO)
ee0613d1
JG
1022#define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
1023static void
1024do_registers_info (regnum, fpregs)
bd5635a1 1025 int regnum;
ee0613d1 1026 int fpregs;
bd5635a1
RP
1027{
1028 register int i;
1029
bd5635a1
RP
1030 for (i = 0; i < NUM_REGS; i++)
1031 {
1032 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1033 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
1034
ee0613d1
JG
1035 /* Decide between printing all regs, nonfloat regs, or specific reg. */
1036 if (regnum == -1) {
1037 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
1038 continue;
1039 } else {
1040 if (i != regnum)
1041 continue;
1042 }
bd5635a1
RP
1043
1044 fputs_filtered (reg_names[i], stdout);
1045 print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
1046
1047 /* Get the data in raw format, then convert also to virtual format. */
1048 if (read_relative_register_raw_bytes (i, raw_buffer))
1049 {
1050 printf_filtered ("Invalid register contents\n");
1051 continue;
1052 }
1053
b5a3d2aa 1054 REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);
bd5635a1
RP
1055
1056 /* If virtual format is floating, print it that way, and in raw hex. */
1057 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT
1058 && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1059 {
1060 register int j;
1061
1062 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,
1063 stdout, 0, 1, 0, Val_pretty_default);
1064
1065 printf_filtered ("\t(raw 0x");
1066 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1067 printf_filtered ("%02x", (unsigned char)raw_buffer[j]);
1068 printf_filtered (")");
1069 }
1070
1071/* FIXME! val_print probably can handle all of these cases now... */
1072
1073 /* Else if virtual format is too long for printf,
1074 print in hex a byte at a time. */
1075 else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))
1076 {
1077 register int j;
1078 printf_filtered ("0x");
1079 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1080 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
1081 }
1082 /* Else print as integer in hex and in decimal. */
1083 else
1084 {
1085 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1086 stdout, 'x', 1, 0, Val_pretty_default);
1087 printf_filtered ("\t");
1088 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1089 stdout, 0, 1, 0, Val_pretty_default);
1090 }
1091
1092 /* The SPARC wants to print even-numbered float regs as doubles
1093 in addition to printing them as floats. */
1094#ifdef PRINT_REGISTER_HOOK
1095 PRINT_REGISTER_HOOK (i);
1096#endif
1097
1098 printf_filtered ("\n");
1099 }
1100}
1101#endif /* no DO_REGISTERS_INFO. */
1102
1103static void
ee0613d1 1104registers_info (addr_exp, fpregs)
bd5635a1 1105 char *addr_exp;
ee0613d1 1106 int fpregs;
bd5635a1
RP
1107{
1108 int regnum;
b5a3d2aa 1109 register char *end;
bd5635a1
RP
1110
1111 if (!target_has_registers)
1112 error ("The program has no registers now.");
1113
b5a3d2aa 1114 if (!addr_exp)
bd5635a1 1115 {
b5a3d2aa
SG
1116 DO_REGISTERS_INFO(-1, fpregs);
1117 return;
bd5635a1 1118 }
bd5635a1 1119
b5a3d2aa
SG
1120 do
1121 {
1122 if (addr_exp[0] == '$')
1123 addr_exp++;
1124 end = addr_exp;
1125 while (*end != '\0' && *end != ' ' && *end != '\t')
1126 ++end;
1127 for (regnum = 0; regnum < NUM_REGS; regnum++)
1128 if (!strncmp (addr_exp, reg_names[regnum], end - addr_exp)
1129 && strlen (reg_names[regnum]) == end - addr_exp)
1130 goto found;
1131 if (*addr_exp >= '0' && *addr_exp <= '9')
1132 regnum = atoi (addr_exp); /* Take a number */
1133 if (regnum >= NUM_REGS) /* Bad name, or bad number */
1134 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1135
1136found:
1137 DO_REGISTERS_INFO(regnum, fpregs);
1138
1139 addr_exp = end;
1140 while (*addr_exp == ' ' || *addr_exp == '\t')
1141 ++addr_exp;
1142 } while (*addr_exp != '\0');
ee0613d1
JG
1143}
1144
1145static void
1304f099 1146all_registers_info (addr_exp, from_tty)
ee0613d1 1147 char *addr_exp;
1304f099 1148 int from_tty;
ee0613d1
JG
1149{
1150 registers_info (addr_exp, 1);
1151}
1152
1153static void
1304f099 1154nofp_registers_info (addr_exp, from_tty)
ee0613d1 1155 char *addr_exp;
1304f099 1156 int from_tty;
ee0613d1
JG
1157{
1158 registers_info (addr_exp, 0);
bd5635a1
RP
1159}
1160\f
1161/*
1162 * TODO:
1163 * Should save/restore the tty state since it might be that the
1164 * program to be debugged was started on this tty and it wants
1165 * the tty in some state other than what we want. If it's running
1166 * on another terminal or without a terminal, then saving and
1167 * restoring the tty state is a harmless no-op.
1168 * This only needs to be done if we are attaching to a process.
1169 */
1170
1171/*
b5a3d2aa
SG
1172 attach_command --
1173 takes a program started up outside of gdb and ``attaches'' to it.
1174 This stops it cold in its tracks and allows us to start debugging it.
1175 and wait for the trace-trap that results from attaching. */
1176
bd5635a1
RP
1177void
1178attach_command (args, from_tty)
1179 char *args;
1180 int from_tty;
1181{
f266e564 1182 dont_repeat (); /* Not for the faint of heart */
b5a3d2aa
SG
1183
1184 if (target_has_execution)
1185 {
1186 if (query ("A program is being debugged already. Kill it? "))
1187 target_kill ();
1188 else
b1b4a89e 1189 error ("Not killed.");
b5a3d2aa
SG
1190 }
1191
bd5635a1 1192 target_attach (args, from_tty);
b5a3d2aa
SG
1193
1194 /* Set up the "saved terminal modes" of the inferior
1195 based on what modes we are starting it with. */
1196 target_terminal_init ();
1197
1198 /* Install inferior's terminal modes. */
1199 target_terminal_inferior ();
1200
1201 /* Set up execution context to know that we should return from
1202 wait_for_inferior as soon as the target reports a stop. */
1203 init_wait_for_inferior ();
1204 clear_proceed_status ();
1205 stop_soon_quietly = 1;
1206
1207 wait_for_inferior ();
1208
1209#ifdef SOLIB_ADD
1210 /* Add shared library symbols from the newly attached process, if any. */
1211 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
1212#endif
1213
1214 normal_stop ();
bd5635a1
RP
1215}
1216
1217/*
1218 * detach_command --
1219 * takes a program previously attached to and detaches it.
1220 * The program resumes execution and will no longer stop
1221 * on signals, etc. We better not have left any breakpoints
1222 * in the program or it'll die when it hits one. For this
1223 * to work, it may be necessary for the process to have been
1224 * previously attached. It *might* work if the program was
1225 * started via the normal ptrace (PTRACE_TRACEME).
1226 */
1227
1228static void
1229detach_command (args, from_tty)
1230 char *args;
1231 int from_tty;
1232{
f266e564 1233 dont_repeat (); /* Not for the faint of heart */
bd5635a1
RP
1234 target_detach (args, from_tty);
1235}
1236
1237/* ARGSUSED */
1238static void
1304f099 1239float_info (addr_exp, from_tty)
bd5635a1 1240 char *addr_exp;
1304f099 1241 int from_tty;
bd5635a1
RP
1242{
1243#ifdef FLOAT_INFO
1244 FLOAT_INFO;
1245#else
1304f099 1246 printf_filtered ("No floating point info available for this processor.\n");
bd5635a1
RP
1247#endif
1248}
1249\f
f266e564
JK
1250/* ARGSUSED */
1251static void
1252unset_command (args, from_tty)
1253 char *args;
1254 int from_tty;
1255{
1304f099 1256 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
f266e564
JK
1257 help_list (unsetlist, "unset ", -1, stdout);
1258}
1259
bd5635a1
RP
1260void
1261_initialize_infcmd ()
1262{
1263 struct cmd_list_element *c;
1264
1265 add_com ("tty", class_run, tty_command,
1266 "Set terminal for future runs of program being debugged.");
1267
1268 add_show_from_set
1269 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1270
1271"Set arguments to give program being debugged when it is started.\n\
1272Follow this command with any number of args, to be passed to the program.",
1273 &setlist),
1274 &showlist);
1275
1276 c = add_cmd
1277 ("environment", no_class, environment_info,
1278 "The environment to give the program, or one variable's value.\n\
1279With an argument VAR, prints the value of environment variable VAR to\n\
1280give the program being debugged. With no arguments, prints the entire\n\
1281environment to be given to the program.", &showlist);
1282 c->completer = noop_completer;
1283
f266e564
JK
1284 add_prefix_cmd ("unset", no_class, unset_command,
1285 "Complement to certain \"set\" commands",
1286 &unsetlist, "unset ", 0, &cmdlist);
1287
bd5635a1
RP
1288 c = add_cmd ("environment", class_run, unset_environment_command,
1289 "Cancel environment variable VAR for the program.\n\
1290This does not affect the program until the next \"run\" command.",
f266e564 1291 &unsetlist);
bd5635a1
RP
1292 c->completer = noop_completer;
1293
1294 c = add_cmd ("environment", class_run, set_environment_command,
1295 "Set environment variable value to give the program.\n\
1296Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1297VALUES of environment variables are uninterpreted strings.\n\
1298This does not affect the program until the next \"run\" command.",
1299 &setlist);
1300 c->completer = noop_completer;
1301
1302 add_com ("path", class_files, path_command,
1303 "Add directory DIR(s) to beginning of search path for object files.\n\
1304$cwd in the path means the current working directory.\n\
1305This path is equivalent to the $PATH shell variable. It is a list of\n\
1306directories, separated by colons. These directories are searched to find\n\
1307fully linked executable files and separately compiled object files as needed.");
1308
ee0613d1 1309 c = add_cmd ("paths", no_class, path_info,
bd5635a1
RP
1310 "Current search path for finding object files.\n\
1311$cwd in the path means the current working directory.\n\
1312This path is equivalent to the $PATH shell variable. It is a list of\n\
1313directories, separated by colons. These directories are searched to find\n\
ee0613d1
JG
1314fully linked executable files and separately compiled object files as needed.", &showlist);
1315 c->completer = noop_completer;
bd5635a1
RP
1316
1317 add_com ("attach", class_run, attach_command,
1318 "Attach to a process or file outside of GDB.\n\
1319This command attaches to another target, of the same type as your last\n\
1320`target' command (`info files' will show your target stack).\n\
1321The command may take as argument a process id or a device file.\n\
1322For a process id, you must have permission to send the process a signal,\n\
1323and it must have the same effective uid as the debugger.\n\
1324When using \"attach\", you should use the \"file\" command to specify\n\
1325the program running in the process, and to load its symbol table.");
1326
1327 add_com ("detach", class_run, detach_command,
1328 "Detach a process or file previously attached.\n\
1329If a process, it is no longer traced, and it continues its execution. If you\n\
1330were debugging a file, the file is closed and gdb no longer accesses it.");
1331
1332 add_com ("signal", class_run, signal_command,
1333 "Continue program giving it signal number SIGNUMBER.");
1334
1335 add_com ("stepi", class_run, stepi_command,
1336 "Step one instruction exactly.\n\
1337Argument N means do this N times (or till program stops for another reason).");
1338 add_com_alias ("si", "stepi", class_alias, 0);
1339
1340 add_com ("nexti", class_run, nexti_command,
1341 "Step one instruction, but proceed through subroutine calls.\n\
1342Argument N means do this N times (or till program stops for another reason).");
1343 add_com_alias ("ni", "nexti", class_alias, 0);
1344
1345 add_com ("finish", class_run, finish_command,
1346 "Execute until selected stack frame returns.\n\
1347Upon return, the value returned is printed and put in the value history.");
1348
1349 add_com ("next", class_run, next_command,
1350 "Step program, proceeding through subroutine calls.\n\
1351Like the \"step\" command as long as subroutine calls do not happen;\n\
1352when they do, the call is treated as one instruction.\n\
1353Argument N means do this N times (or till program stops for another reason).");
1354 add_com_alias ("n", "next", class_run, 1);
1355
1356 add_com ("step", class_run, step_command,
1357 "Step program until it reaches a different source line.\n\
1358Argument N means do this N times (or till program stops for another reason).");
1359 add_com_alias ("s", "step", class_run, 1);
1360
1361 add_com ("until", class_run, until_command,
1362 "Execute until the program reaches a source line greater than the current\n\
1363or a specified line or address or function (same args as break command).\n\
1364Execution will also stop upon exit from the current stack frame.");
1365 add_com_alias ("u", "until", class_run, 1);
1366
1367 add_com ("jump", class_run, jump_command,
1368 "Continue program being debugged at specified line or address.\n\
1369Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1370for an address to start at.");
1371
1372 add_com ("continue", class_run, continue_command,
1373 "Continue program being debugged, after signal or breakpoint.\n\
de6a2704
JK
1374If proceeding from breakpoint, a number N may be used as an argument,\n\
1375which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1376the breakpoint won't break until the Nth time it is reached).");
bd5635a1
RP
1377 add_com_alias ("c", "cont", class_run, 1);
1378 add_com_alias ("fg", "cont", class_run, 1);
1379
1380 add_com ("run", class_run, run_command,
1381 "Start debugged program. You may specify arguments to give it.\n\
1382Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1383Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
b4fde6fa 1384With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
bd5635a1
RP
1385To cancel previous arguments and run with no arguments,\n\
1386use \"set args\" without arguments.");
1387 add_com_alias ("r", "run", class_run, 1);
1388
ee0613d1
JG
1389 add_info ("registers", nofp_registers_info,
1390 "List of integer registers and their contents, for selected stack frame.\n\
1391Register name as argument means describe only that register.");
1392
1393 add_info ("all-registers", all_registers_info,
1394"List of all registers and their contents, for selected stack frame.\n\
bd5635a1
RP
1395Register name as argument means describe only that register.");
1396
1397 add_info ("program", program_info,
1398 "Execution status of the program.");
1399
1400 add_info ("float", float_info,
1401 "Print the status of the floating point unit\n");
1402
1403 inferior_args = savestring ("", 1); /* Initially no args */
1404 inferior_environ = make_environ ();
1405 init_environ (inferior_environ);
1406}
This page took 0.178421 seconds and 4 git commands to generate.