* gdb.t17/callfuncs.exp: Add "return 0" to end.
[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)
398 write_register (NNPC_REGNUM, read_register (NPC_REGNUM));
399 write_register (NPC_REGNUM, read_register (PC_REGNUM));
400#endif
401 }
1304f099
JG
402
403 if (!single_inst || skip_subroutines)
404 do_cleanups(cleanups);
bd5635a1
RP
405}
406\f
407/* Continue program at specified address. */
408
409static void
410jump_command (arg, from_tty)
411 char *arg;
412 int from_tty;
413{
414 register CORE_ADDR addr;
415 struct symtabs_and_lines sals;
416 struct symtab_and_line sal;
b4fde6fa
FF
417 struct symbol *fn;
418 struct symbol *sfn;
bd5635a1
RP
419
420 ERROR_NO_INFERIOR;
421
422 if (!arg)
423 error_no_arg ("starting address");
424
425 sals = decode_line_spec_1 (arg, 1);
426 if (sals.nelts != 1)
427 {
428 error ("Unreasonable jump request");
429 }
430
431 sal = sals.sals[0];
1304f099 432 free ((PTR)sals.sals);
bd5635a1
RP
433
434 if (sal.symtab == 0 && sal.pc == 0)
435 error ("No source file has been specified.");
436
ee0613d1 437 resolve_sal_pc (&sal); /* May error out */
bd5635a1 438
b4fde6fa
FF
439 /* See if we are trying to jump to another function. */
440 fn = get_frame_function (get_current_frame ());
441 sfn = find_pc_function (sal.pc);
442 if (fn != NULL && sfn != fn)
443 {
2e4964ad
FF
444 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
445 SYMBOL_SOURCE_NAME (fn)))
b4fde6fa
FF
446 {
447 error ("Not confirmed.");
448 /* NOTREACHED */
449 }
b4fde6fa 450 }
bd5635a1 451
bd5635a1
RP
452 addr = ADDR_BITS_SET (sal.pc);
453
454 if (from_tty)
1304f099 455 printf_filtered ("Continuing at %s.\n", local_hex_string(addr));
bd5635a1
RP
456
457 clear_proceed_status ();
458 proceed (addr, 0, 0);
459}
460
461/* Continue program giving it specified signal. */
462
463static void
464signal_command (signum_exp, from_tty)
465 char *signum_exp;
466 int from_tty;
467{
468 register int signum;
469
470 dont_repeat (); /* Too dangerous. */
471 ERROR_NO_INFERIOR;
472
473 if (!signum_exp)
474 error_no_arg ("signal number");
475
de6a2704
JK
476 /* It would be even slicker to make signal names be valid expressions,
477 (the type could be "enum $signal" or some such), then the user could
478 assign them to convenience variables. */
479 signum = strtosigno (signum_exp);
480
481 if (signum == 0)
482 /* Not found as a name, try it as an expression. */
483 signum = parse_and_eval_address (signum_exp);
bd5635a1
RP
484
485 if (from_tty)
de6a2704
JK
486 {
487 char *signame = strsigno (signum);
488 printf_filtered ("Continuing with signal ");
489 if (signame == NULL || signum == 0)
490 printf_filtered ("%d.\n", signum);
491 else
492 /* Do we need to print the number as well as the name? */
493 printf_filtered ("%s (%d).\n", signame, signum);
494 }
bd5635a1
RP
495
496 clear_proceed_status ();
497 proceed (stop_pc, signum, 0);
498}
499
500/* Execute a "stack dummy", a piece of code stored in the stack
501 by the debugger to be executed in the inferior.
502
503 To call: first, do PUSH_DUMMY_FRAME.
504 Then push the contents of the dummy. It should end with a breakpoint insn.
505 Then call here, passing address at which to start the dummy.
506
507 The contents of all registers are saved before the dummy frame is popped
508 and copied into the buffer BUFFER.
509
510 The dummy's frame is automatically popped whenever that break is hit.
511 If that is the first time the program stops, run_stack_dummy
860a1754
JK
512 returns to its caller with that frame already gone and returns 0.
513 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
514 when we do hit that breakpoint). */
bd5635a1 515
ee0613d1 516/* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
bd5635a1
RP
517
518static int stack_dummy_testing = 0;
519
860a1754
JK
520int
521run_stack_dummy (addr, buffer)
bd5635a1
RP
522 CORE_ADDR addr;
523 char buffer[REGISTER_BYTES];
524{
525 /* Now proceed, having reached the desired place. */
526 clear_proceed_status ();
527 if (stack_dummy_testing & 4)
528 {
529 POP_FRAME;
37c99ddb 530 return(0);
bd5635a1
RP
531 }
532 proceed_to_finish = 1; /* We want stop_registers, please... */
533 proceed (addr, 0, 0);
534
535 if (!stop_stack_dummy)
860a1754 536 return 1;
bd5635a1
RP
537
538 /* On return, the stack dummy has been popped already. */
539
4ed3a9ea 540 memcpy (buffer, stop_registers, sizeof stop_registers);
860a1754 541 return 0;
bd5635a1
RP
542}
543\f
544/* Proceed until we reach a different source line with pc greater than
545 our current one or exit the function. We skip calls in both cases.
546
547 Note that eventually this command should probably be changed so
548 that only source lines are printed out when we hit the breakpoint
549 we set. I'm going to postpone this until after a hopeful rewrite
550 of wait_for_inferior and the proceed status code. -- randy */
551
e1ce8aa5 552/* ARGSUSED */
1304f099 553static void
bd5635a1
RP
554until_next_command (from_tty)
555 int from_tty;
556{
557 FRAME frame;
558 CORE_ADDR pc;
559 struct symbol *func;
560 struct symtab_and_line sal;
561
562 clear_proceed_status ();
563
564 frame = get_current_frame ();
565
566 /* Step until either exited from this function or greater
567 than the current line (if in symbolic section) or pc (if
568 not). */
569
570 pc = read_pc ();
571 func = find_pc_function (pc);
572
573 if (!func)
574 {
1304f099 575 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
bd5635a1 576
1304f099 577 if (msymbol == NULL)
bd5635a1
RP
578 error ("Execution is not within a known function.");
579
2e4964ad 580 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
bd5635a1
RP
581 step_range_end = pc;
582 }
583 else
584 {
585 sal = find_pc_line (pc, 0);
586
587 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
588 step_range_end = sal.end;
589 }
590
591 step_over_calls = 1;
592 step_frame_address = FRAME_FP (frame);
593
594 step_multi = 0; /* Only one call to proceed */
595
596 proceed ((CORE_ADDR) -1, -1, 1);
597}
598
1304f099 599static void
bd5635a1
RP
600until_command (arg, from_tty)
601 char *arg;
602 int from_tty;
603{
604 if (!target_has_execution)
605 error ("The program is not running.");
606 if (arg)
607 until_break_command (arg, from_tty);
608 else
609 until_next_command (from_tty);
610}
611\f
612/* "finish": Set a temporary breakpoint at the place
613 the selected frame will return to, then continue. */
614
615static void
616finish_command (arg, from_tty)
617 char *arg;
618 int from_tty;
619{
620 struct symtab_and_line sal;
621 register FRAME frame;
622 struct frame_info *fi;
623 register struct symbol *function;
1304f099
JG
624 struct breakpoint *breakpoint;
625 struct cleanup *old_chain;
bd5635a1
RP
626
627 if (arg)
628 error ("The \"finish\" command does not take any arguments.");
629 if (!target_has_execution)
630 error ("The program is not running.");
777bef06
JK
631 if (selected_frame == NULL)
632 error ("No selected frame.");
bd5635a1
RP
633
634 frame = get_prev_frame (selected_frame);
635 if (frame == 0)
636 error ("\"finish\" not meaningful in the outermost frame.");
637
638 clear_proceed_status ();
639
640 fi = get_frame_info (frame);
641 sal = find_pc_line (fi->pc, 0);
642 sal.pc = fi->pc;
1304f099
JG
643
644 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
645
646 old_chain = make_cleanup(delete_breakpoint, breakpoint);
bd5635a1
RP
647
648 /* Find the function we will return from. */
649
650 fi = get_frame_info (selected_frame);
651 function = find_pc_function (fi->pc);
652
ee0613d1
JG
653 /* Print info on the selected frame, including level number
654 but not source. */
bd5635a1
RP
655 if (from_tty)
656 {
ee0613d1
JG
657 printf_filtered ("Run till exit from ");
658 print_stack_frame (selected_frame, selected_frame_level, 0);
bd5635a1
RP
659 }
660
661 proceed_to_finish = 1; /* We want stop_registers, please... */
662 proceed ((CORE_ADDR) -1, -1, 0);
663
1304f099
JG
664 /* Did we stop at our breakpoint? */
665 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
666 && function != 0)
bd5635a1
RP
667 {
668 struct type *value_type;
669 register value val;
670 CORE_ADDR funcaddr;
671
672 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
673 if (!value_type)
674 fatal ("internal: finish_command: function has no target type");
675
676 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
677 return;
678
679 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
680
681 val = value_being_returned (value_type, stop_registers,
860a1754 682 using_struct_return (value_of_variable (function, NULL),
bd5635a1
RP
683 funcaddr,
684 value_type,
685 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
686
ee0613d1 687 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
bd5635a1 688 value_print (val, stdout, 0, Val_no_prettyprint);
ee0613d1 689 printf_filtered ("\n");
bd5635a1 690 }
1304f099 691 do_cleanups(old_chain);
bd5635a1
RP
692}
693\f
e1ce8aa5 694/* ARGSUSED */
bd5635a1
RP
695static void
696program_info (args, from_tty)
697 char *args;
698 int from_tty;
699{
700 bpstat bs = stop_bpstat;
701 int num = bpstat_num (&bs);
702
703 if (!target_has_execution)
704 {
1304f099 705 printf_filtered ("The program being debugged is not being run.\n");
bd5635a1
RP
706 return;
707 }
708
709 target_files_info ();
1304f099 710 printf_filtered ("Program stopped at %s.\n", local_hex_string(stop_pc));
bd5635a1 711 if (stop_step)
1304f099 712 printf_filtered ("It stopped after being stepped.\n");
bd5635a1
RP
713 else if (num != 0)
714 {
715 /* There may be several breakpoints in the same place, so this
716 isn't as strange as it seems. */
717 while (num != 0)
718 {
719 if (num < 0)
1304f099 720 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
bd5635a1 721 else
1304f099 722 printf_filtered ("It stopped at breakpoint %d.\n", num);
bd5635a1
RP
723 num = bpstat_num (&bs);
724 }
725 }
de6a2704
JK
726 else if (stop_signal)
727 {
bd5635a1 728#ifdef PRINT_RANDOM_SIGNAL
de6a2704 729 PRINT_RANDOM_SIGNAL (stop_signal);
bd5635a1 730#else
de6a2704
JK
731 char *signame = strsigno (stop_signal);
732 printf_filtered ("It stopped with signal ");
733 if (signame == NULL)
734 printf_filtered ("%d", stop_signal);
735 else
736 /* Do we need to print the number as well as the name? */
737 printf_filtered ("%s (%d)", signame, stop_signal);
738 printf_filtered (", %s.\n", safe_strsignal (stop_signal));
bd5635a1
RP
739#endif
740 }
741
742 if (!from_tty)
1304f099 743 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
bd5635a1
RP
744}
745\f
746static void
1304f099 747environment_info (var, from_tty)
bd5635a1 748 char *var;
1304f099 749 int from_tty;
bd5635a1
RP
750{
751 if (var)
752 {
753 register char *val = get_in_environ (inferior_environ, var);
754 if (val)
631f7a9f
JG
755 {
756 puts_filtered (var);
757 puts_filtered (" = ");
758 puts_filtered (val);
759 puts_filtered ("\n");
760 }
bd5635a1 761 else
631f7a9f
JG
762 {
763 puts_filtered ("Environment variable \"");
764 puts_filtered (var);
765 puts_filtered ("\" not defined.\n");
766 }
bd5635a1
RP
767 }
768 else
769 {
770 register char **vector = environ_vector (inferior_environ);
771 while (*vector)
631f7a9f
JG
772 {
773 puts_filtered (*vector++);
774 puts_filtered ("\n");
775 }
bd5635a1
RP
776 }
777}
778
779static void
1304f099 780set_environment_command (arg, from_tty)
bd5635a1 781 char *arg;
1304f099 782 int from_tty;
bd5635a1
RP
783{
784 register char *p, *val, *var;
785 int nullset = 0;
786
787 if (arg == 0)
788 error_no_arg ("environment variable and value");
789
790 /* Find seperation between variable name and value */
791 p = (char *) strchr (arg, '=');
792 val = (char *) strchr (arg, ' ');
793
794 if (p != 0 && val != 0)
795 {
796 /* We have both a space and an equals. If the space is before the
631f7a9f
JG
797 equals, walk forward over the spaces til we see a nonspace
798 (possibly the equals). */
bd5635a1
RP
799 if (p > val)
800 while (*val == ' ')
801 val++;
802
631f7a9f
JG
803 /* Now if the = is after the char following the spaces,
804 take the char following the spaces. */
805 if (p > val)
b5a3d2aa 806 p = val - 1;
bd5635a1
RP
807 }
808 else if (val != 0 && p == 0)
809 p = val;
810
811 if (p == arg)
812 error_no_arg ("environment variable to set");
813
814 if (p == 0 || p[1] == 0)
815 {
816 nullset = 1;
817 if (p == 0)
818 p = arg + strlen (arg); /* So that savestring below will work */
819 }
820 else
821 {
822 /* Not setting variable value to null */
823 val = p + 1;
824 while (*val == ' ' || *val == '\t')
825 val++;
826 }
827
828 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
829
830 var = savestring (arg, p - arg);
831 if (nullset)
832 {
1304f099 833 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
bd5635a1
RP
834 set_in_environ (inferior_environ, var, "");
835 }
836 else
837 set_in_environ (inferior_environ, var, val);
838 free (var);
839}
840
841static void
842unset_environment_command (var, from_tty)
843 char *var;
844 int from_tty;
845{
846 if (var == 0)
847 {
848 /* If there is no argument, delete all environment variables.
849 Ask for confirmation if reading from the terminal. */
850 if (!from_tty || query ("Delete all environment variables? "))
851 {
852 free_environ (inferior_environ);
853 inferior_environ = make_environ ();
854 }
855 }
856 else
857 unset_in_environ (inferior_environ, var);
858}
859
860/* Handle the execution path (PATH variable) */
861
a8a69e63 862static const char path_var_name[] = "PATH";
bd5635a1 863
e1ce8aa5 864/* ARGSUSED */
1304f099 865static void
bd5635a1
RP
866path_info (args, from_tty)
867 char *args;
868 int from_tty;
869{
b5a3d2aa
SG
870 puts_filtered ("Executable and object file path: ");
871 puts_filtered (get_in_environ (inferior_environ, path_var_name));
872 puts_filtered ("\n");
bd5635a1
RP
873}
874
875/* Add zero or more directories to the front of the execution path. */
876
1304f099 877static void
bd5635a1
RP
878path_command (dirname, from_tty)
879 char *dirname;
880 int from_tty;
881{
882 char *exec_path;
883
884 dont_repeat ();
885 exec_path = strsave (get_in_environ (inferior_environ, path_var_name));
e1ce8aa5 886 mod_path (dirname, &exec_path);
bd5635a1
RP
887 set_in_environ (inferior_environ, path_var_name, exec_path);
888 free (exec_path);
889 if (from_tty)
e1ce8aa5 890 path_info ((char *)NULL, from_tty);
bd5635a1
RP
891}
892\f
de6a2704
JK
893/* This routine is getting awfully cluttered with #if's. It's probably
894 time to turn this into READ_PC and define it in the tm.h file.
895 Ditto for write_pc. */
b1b4a89e 896
bd5635a1
RP
897CORE_ADDR
898read_pc ()
899{
de6a2704
JK
900#ifdef TARGET_READ_PC
901 return TARGET_READ_PC ();
b1b4a89e 902#else
bd5635a1 903 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register (PC_REGNUM));
b1b4a89e 904#endif
bd5635a1
RP
905}
906
907void
908write_pc (val)
909 CORE_ADDR val;
910{
de6a2704
JK
911#ifdef TARGET_WRITE_PC
912 TARGET_WRITE_PC (val);
913#else
bd5635a1
RP
914 write_register (PC_REGNUM, (long) val);
915#ifdef NPC_REGNUM
b1b4a89e
JK
916 write_register (NPC_REGNUM, (long) val + 4);
917#ifdef NNPC_REGNUM
918 write_register (NNPC_REGNUM, (long) val + 8);
919#endif
920#endif
bd5635a1 921#endif
bd5635a1
RP
922}
923
de6a2704
JK
924/* Cope with strage ways of getting to the stack and frame pointers */
925
926CORE_ADDR
927read_sp ()
928{
929#ifdef TARGET_READ_SP
930 return TARGET_READ_SP ();
931#else
932 return read_register (SP_REGNUM);
933#endif
934}
935
936void
937write_sp (val)
938 CORE_ADDR val;
939{
940#ifdef TARGET_WRITE_SP
941 TARGET_WRITE_SP (val);
942#else
943 write_register (SP_REGNUM, val);
944#endif
945}
946
947
948CORE_ADDR
949read_fp ()
950{
951#ifdef TARGET_READ_FP
952 return TARGET_READ_FP ();
953#else
954 return read_register (FP_REGNUM);
955#endif
956}
957
958void
959write_fp (val)
960 CORE_ADDR val;
961{
962#ifdef TARGET_WRITE_FP
963 TARGET_WRITE_FP (val);
964#else
965 write_register (FP_REGNUM, val);
966#endif
967}
968
1304f099 969const char * const reg_names[] = REGISTER_NAMES;
bd5635a1
RP
970
971/* Print out the machine register regnum. If regnum is -1,
ee0613d1
JG
972 print all registers (fpregs == 1) or all non-float registers
973 (fpregs == 0).
974
bd5635a1
RP
975 For most machines, having all_registers_info() print the
976 register(s) one per line is good enough. If a different format
ee0613d1 977 is required, (eg, for MIPS or Pyramid 90x, which both have
bd5635a1 978 lots of regs), or there is an existing convention for showing
ee0613d1 979 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
bd5635a1 980 to provide that format. */
ee0613d1 981
bd5635a1 982#if !defined (DO_REGISTERS_INFO)
ee0613d1
JG
983#define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
984static void
985do_registers_info (regnum, fpregs)
bd5635a1 986 int regnum;
ee0613d1 987 int fpregs;
bd5635a1
RP
988{
989 register int i;
990
bd5635a1
RP
991 for (i = 0; i < NUM_REGS; i++)
992 {
993 char raw_buffer[MAX_REGISTER_RAW_SIZE];
994 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
995
ee0613d1
JG
996 /* Decide between printing all regs, nonfloat regs, or specific reg. */
997 if (regnum == -1) {
998 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
999 continue;
1000 } else {
1001 if (i != regnum)
1002 continue;
1003 }
bd5635a1
RP
1004
1005 fputs_filtered (reg_names[i], stdout);
1006 print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
1007
1008 /* Get the data in raw format, then convert also to virtual format. */
1009 if (read_relative_register_raw_bytes (i, raw_buffer))
1010 {
1011 printf_filtered ("Invalid register contents\n");
1012 continue;
1013 }
1014
b5a3d2aa 1015 REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);
bd5635a1
RP
1016
1017 /* If virtual format is floating, print it that way, and in raw hex. */
1018 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT
1019 && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1020 {
1021 register int j;
1022
1023 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,
1024 stdout, 0, 1, 0, Val_pretty_default);
1025
1026 printf_filtered ("\t(raw 0x");
1027 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1028 printf_filtered ("%02x", (unsigned char)raw_buffer[j]);
1029 printf_filtered (")");
1030 }
1031
1032/* FIXME! val_print probably can handle all of these cases now... */
1033
1034 /* Else if virtual format is too long for printf,
1035 print in hex a byte at a time. */
1036 else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))
1037 {
1038 register int j;
1039 printf_filtered ("0x");
1040 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1041 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
1042 }
1043 /* Else print as integer in hex and in decimal. */
1044 else
1045 {
1046 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1047 stdout, 'x', 1, 0, Val_pretty_default);
1048 printf_filtered ("\t");
1049 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1050 stdout, 0, 1, 0, Val_pretty_default);
1051 }
1052
1053 /* The SPARC wants to print even-numbered float regs as doubles
1054 in addition to printing them as floats. */
1055#ifdef PRINT_REGISTER_HOOK
1056 PRINT_REGISTER_HOOK (i);
1057#endif
1058
1059 printf_filtered ("\n");
1060 }
1061}
1062#endif /* no DO_REGISTERS_INFO. */
1063
1064static void
ee0613d1 1065registers_info (addr_exp, fpregs)
bd5635a1 1066 char *addr_exp;
ee0613d1 1067 int fpregs;
bd5635a1
RP
1068{
1069 int regnum;
b5a3d2aa 1070 register char *end;
bd5635a1
RP
1071
1072 if (!target_has_registers)
1073 error ("The program has no registers now.");
1074
b5a3d2aa 1075 if (!addr_exp)
bd5635a1 1076 {
b5a3d2aa
SG
1077 DO_REGISTERS_INFO(-1, fpregs);
1078 return;
bd5635a1 1079 }
bd5635a1 1080
b5a3d2aa
SG
1081 do
1082 {
1083 if (addr_exp[0] == '$')
1084 addr_exp++;
1085 end = addr_exp;
1086 while (*end != '\0' && *end != ' ' && *end != '\t')
1087 ++end;
1088 for (regnum = 0; regnum < NUM_REGS; regnum++)
1089 if (!strncmp (addr_exp, reg_names[regnum], end - addr_exp)
1090 && strlen (reg_names[regnum]) == end - addr_exp)
1091 goto found;
1092 if (*addr_exp >= '0' && *addr_exp <= '9')
1093 regnum = atoi (addr_exp); /* Take a number */
1094 if (regnum >= NUM_REGS) /* Bad name, or bad number */
1095 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1096
1097found:
1098 DO_REGISTERS_INFO(regnum, fpregs);
1099
1100 addr_exp = end;
1101 while (*addr_exp == ' ' || *addr_exp == '\t')
1102 ++addr_exp;
1103 } while (*addr_exp != '\0');
ee0613d1
JG
1104}
1105
1106static void
1304f099 1107all_registers_info (addr_exp, from_tty)
ee0613d1 1108 char *addr_exp;
1304f099 1109 int from_tty;
ee0613d1
JG
1110{
1111 registers_info (addr_exp, 1);
1112}
1113
1114static void
1304f099 1115nofp_registers_info (addr_exp, from_tty)
ee0613d1 1116 char *addr_exp;
1304f099 1117 int from_tty;
ee0613d1
JG
1118{
1119 registers_info (addr_exp, 0);
bd5635a1
RP
1120}
1121\f
1122/*
1123 * TODO:
1124 * Should save/restore the tty state since it might be that the
1125 * program to be debugged was started on this tty and it wants
1126 * the tty in some state other than what we want. If it's running
1127 * on another terminal or without a terminal, then saving and
1128 * restoring the tty state is a harmless no-op.
1129 * This only needs to be done if we are attaching to a process.
1130 */
1131
1132/*
b5a3d2aa
SG
1133 attach_command --
1134 takes a program started up outside of gdb and ``attaches'' to it.
1135 This stops it cold in its tracks and allows us to start debugging it.
1136 and wait for the trace-trap that results from attaching. */
1137
bd5635a1
RP
1138void
1139attach_command (args, from_tty)
1140 char *args;
1141 int from_tty;
1142{
f266e564 1143 dont_repeat (); /* Not for the faint of heart */
b5a3d2aa
SG
1144
1145 if (target_has_execution)
1146 {
1147 if (query ("A program is being debugged already. Kill it? "))
1148 target_kill ();
1149 else
b1b4a89e 1150 error ("Not killed.");
b5a3d2aa
SG
1151 }
1152
bd5635a1 1153 target_attach (args, from_tty);
b5a3d2aa
SG
1154
1155 /* Set up the "saved terminal modes" of the inferior
1156 based on what modes we are starting it with. */
1157 target_terminal_init ();
1158
1159 /* Install inferior's terminal modes. */
1160 target_terminal_inferior ();
1161
1162 /* Set up execution context to know that we should return from
1163 wait_for_inferior as soon as the target reports a stop. */
1164 init_wait_for_inferior ();
1165 clear_proceed_status ();
1166 stop_soon_quietly = 1;
1167
1168 wait_for_inferior ();
1169
1170#ifdef SOLIB_ADD
1171 /* Add shared library symbols from the newly attached process, if any. */
1172 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
1173#endif
1174
1175 normal_stop ();
bd5635a1
RP
1176}
1177
1178/*
1179 * detach_command --
1180 * takes a program previously attached to and detaches it.
1181 * The program resumes execution and will no longer stop
1182 * on signals, etc. We better not have left any breakpoints
1183 * in the program or it'll die when it hits one. For this
1184 * to work, it may be necessary for the process to have been
1185 * previously attached. It *might* work if the program was
1186 * started via the normal ptrace (PTRACE_TRACEME).
1187 */
1188
1189static void
1190detach_command (args, from_tty)
1191 char *args;
1192 int from_tty;
1193{
f266e564 1194 dont_repeat (); /* Not for the faint of heart */
bd5635a1
RP
1195 target_detach (args, from_tty);
1196}
1197
1198/* ARGSUSED */
1199static void
1304f099 1200float_info (addr_exp, from_tty)
bd5635a1 1201 char *addr_exp;
1304f099 1202 int from_tty;
bd5635a1
RP
1203{
1204#ifdef FLOAT_INFO
1205 FLOAT_INFO;
1206#else
1304f099 1207 printf_filtered ("No floating point info available for this processor.\n");
bd5635a1
RP
1208#endif
1209}
1210\f
f266e564
JK
1211/* ARGSUSED */
1212static void
1213unset_command (args, from_tty)
1214 char *args;
1215 int from_tty;
1216{
1304f099 1217 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
f266e564
JK
1218 help_list (unsetlist, "unset ", -1, stdout);
1219}
1220
bd5635a1
RP
1221void
1222_initialize_infcmd ()
1223{
1224 struct cmd_list_element *c;
1225
1226 add_com ("tty", class_run, tty_command,
1227 "Set terminal for future runs of program being debugged.");
1228
1229 add_show_from_set
1230 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1231
1232"Set arguments to give program being debugged when it is started.\n\
1233Follow this command with any number of args, to be passed to the program.",
1234 &setlist),
1235 &showlist);
1236
1237 c = add_cmd
1238 ("environment", no_class, environment_info,
1239 "The environment to give the program, or one variable's value.\n\
1240With an argument VAR, prints the value of environment variable VAR to\n\
1241give the program being debugged. With no arguments, prints the entire\n\
1242environment to be given to the program.", &showlist);
1243 c->completer = noop_completer;
1244
f266e564
JK
1245 add_prefix_cmd ("unset", no_class, unset_command,
1246 "Complement to certain \"set\" commands",
1247 &unsetlist, "unset ", 0, &cmdlist);
1248
bd5635a1
RP
1249 c = add_cmd ("environment", class_run, unset_environment_command,
1250 "Cancel environment variable VAR for the program.\n\
1251This does not affect the program until the next \"run\" command.",
f266e564 1252 &unsetlist);
bd5635a1
RP
1253 c->completer = noop_completer;
1254
1255 c = add_cmd ("environment", class_run, set_environment_command,
1256 "Set environment variable value to give the program.\n\
1257Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1258VALUES of environment variables are uninterpreted strings.\n\
1259This does not affect the program until the next \"run\" command.",
1260 &setlist);
1261 c->completer = noop_completer;
1262
1263 add_com ("path", class_files, path_command,
1264 "Add directory DIR(s) to beginning of search path for object files.\n\
1265$cwd in the path means the current working directory.\n\
1266This path is equivalent to the $PATH shell variable. It is a list of\n\
1267directories, separated by colons. These directories are searched to find\n\
1268fully linked executable files and separately compiled object files as needed.");
1269
ee0613d1 1270 c = add_cmd ("paths", no_class, path_info,
bd5635a1
RP
1271 "Current search path for finding object files.\n\
1272$cwd in the path means the current working directory.\n\
1273This path is equivalent to the $PATH shell variable. It is a list of\n\
1274directories, separated by colons. These directories are searched to find\n\
ee0613d1
JG
1275fully linked executable files and separately compiled object files as needed.", &showlist);
1276 c->completer = noop_completer;
bd5635a1
RP
1277
1278 add_com ("attach", class_run, attach_command,
1279 "Attach to a process or file outside of GDB.\n\
1280This command attaches to another target, of the same type as your last\n\
1281`target' command (`info files' will show your target stack).\n\
1282The command may take as argument a process id or a device file.\n\
1283For a process id, you must have permission to send the process a signal,\n\
1284and it must have the same effective uid as the debugger.\n\
1285When using \"attach\", you should use the \"file\" command to specify\n\
1286the program running in the process, and to load its symbol table.");
1287
1288 add_com ("detach", class_run, detach_command,
1289 "Detach a process or file previously attached.\n\
1290If a process, it is no longer traced, and it continues its execution. If you\n\
1291were debugging a file, the file is closed and gdb no longer accesses it.");
1292
1293 add_com ("signal", class_run, signal_command,
1294 "Continue program giving it signal number SIGNUMBER.");
1295
1296 add_com ("stepi", class_run, stepi_command,
1297 "Step one instruction exactly.\n\
1298Argument N means do this N times (or till program stops for another reason).");
1299 add_com_alias ("si", "stepi", class_alias, 0);
1300
1301 add_com ("nexti", class_run, nexti_command,
1302 "Step one instruction, but proceed through subroutine calls.\n\
1303Argument N means do this N times (or till program stops for another reason).");
1304 add_com_alias ("ni", "nexti", class_alias, 0);
1305
1306 add_com ("finish", class_run, finish_command,
1307 "Execute until selected stack frame returns.\n\
1308Upon return, the value returned is printed and put in the value history.");
1309
1310 add_com ("next", class_run, next_command,
1311 "Step program, proceeding through subroutine calls.\n\
1312Like the \"step\" command as long as subroutine calls do not happen;\n\
1313when they do, the call is treated as one instruction.\n\
1314Argument N means do this N times (or till program stops for another reason).");
1315 add_com_alias ("n", "next", class_run, 1);
1316
1317 add_com ("step", class_run, step_command,
1318 "Step program until it reaches a different source line.\n\
1319Argument N means do this N times (or till program stops for another reason).");
1320 add_com_alias ("s", "step", class_run, 1);
1321
1322 add_com ("until", class_run, until_command,
1323 "Execute until the program reaches a source line greater than the current\n\
1324or a specified line or address or function (same args as break command).\n\
1325Execution will also stop upon exit from the current stack frame.");
1326 add_com_alias ("u", "until", class_run, 1);
1327
1328 add_com ("jump", class_run, jump_command,
1329 "Continue program being debugged at specified line or address.\n\
1330Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1331for an address to start at.");
1332
1333 add_com ("continue", class_run, continue_command,
1334 "Continue program being debugged, after signal or breakpoint.\n\
de6a2704
JK
1335If proceeding from breakpoint, a number N may be used as an argument,\n\
1336which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1337the breakpoint won't break until the Nth time it is reached).");
bd5635a1
RP
1338 add_com_alias ("c", "cont", class_run, 1);
1339 add_com_alias ("fg", "cont", class_run, 1);
1340
1341 add_com ("run", class_run, run_command,
1342 "Start debugged program. You may specify arguments to give it.\n\
1343Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1344Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
b4fde6fa 1345With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
bd5635a1
RP
1346To cancel previous arguments and run with no arguments,\n\
1347use \"set args\" without arguments.");
1348 add_com_alias ("r", "run", class_run, 1);
1349
ee0613d1
JG
1350 add_info ("registers", nofp_registers_info,
1351 "List of integer registers and their contents, for selected stack frame.\n\
1352Register name as argument means describe only that register.");
1353
1354 add_info ("all-registers", all_registers_info,
1355"List of all registers and their contents, for selected stack frame.\n\
bd5635a1
RP
1356Register name as argument means describe only that register.");
1357
1358 add_info ("program", program_info,
1359 "Execution status of the program.");
1360
1361 add_info ("float", float_info,
1362 "Print the status of the floating point unit\n");
1363
1364 inferior_args = savestring ("", 1); /* Initially no args */
1365 inferior_environ = make_environ ();
1366 init_environ (inferior_environ);
1367}
This page took 0.175529 seconds and 4 git commands to generate.