HPPA merge.
[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.
176 -1 means step over calls to undebuggable functions. */
177
178int step_over_calls;
179
180/* If stepping, nonzero means step count is > 1
181 so don't print frame next time inferior stops
182 if it stops due to stepping. */
183
184int step_multi;
185
186/* Environment to use for running inferior,
187 in format described in environ.h. */
188
189struct environ *inferior_environ;
190
bd5635a1 191\f
e1ce8aa5 192/* ARGSUSED */
bd5635a1
RP
193void
194tty_command (file, from_tty)
195 char *file;
196 int from_tty;
197{
198 if (file == 0)
199 error_no_arg ("terminal name for running target process");
200
201 inferior_io_terminal = savestring (file, strlen (file));
202}
203
204static void
205run_command (args, from_tty)
206 char *args;
207 int from_tty;
208{
209 char *exec_file;
210
211 dont_repeat ();
212
213 if (inferior_pid)
214 {
215 if (
216 !query ("The program being debugged has been started already.\n\
217Start it from the beginning? "))
218 error ("Program not restarted.");
ee0613d1 219 target_kill ();
bd5635a1
RP
220 }
221
222 exec_file = (char *) get_exec_file (0);
223
1304f099 224 /* The exec file is re-read every time we do a generic_mourn_inferior, so
bd5635a1
RP
225 we just have to worry about the symbol file. */
226 reread_symbols ();
227
228 if (args)
229 {
230 char *cmd;
ee0613d1 231 cmd = concat ("set args ", args, NULL);
bd5635a1
RP
232 make_cleanup (free, cmd);
233 execute_command (cmd, from_tty);
234 }
235
236 if (from_tty)
237 {
1304f099 238 printf_filtered ("Starting program: %s %s\n",
bd5635a1
RP
239 exec_file? exec_file: "", inferior_args);
240 fflush (stdout);
241 }
242
243 target_create_inferior (exec_file, inferior_args,
244 environ_vector (inferior_environ));
245}
246\f
1304f099 247static void
bd5635a1
RP
248continue_command (proc_count_exp, from_tty)
249 char *proc_count_exp;
250 int from_tty;
251{
252 ERROR_NO_INFERIOR;
253
254 /* If have argument, set proceed count of breakpoint we stopped at. */
255
256 if (proc_count_exp != NULL)
257 {
258 bpstat bs = stop_bpstat;
259 int num = bpstat_num (&bs);
260 if (num == 0 && from_tty)
261 {
262 printf_filtered
263 ("Not stopped at any breakpoint; argument ignored.\n");
264 }
265 while (num != 0)
266 {
267 set_ignore_count (num,
268 parse_and_eval_address (proc_count_exp) - 1,
269 from_tty);
270 /* set_ignore_count prints a message ending with a period.
271 So print two spaces before "Continuing.". */
272 if (from_tty)
1304f099 273 printf_filtered (" ");
bd5635a1
RP
274 num = bpstat_num (&bs);
275 }
276 }
277
278 if (from_tty)
1304f099 279 printf_filtered ("Continuing.\n");
bd5635a1
RP
280
281 clear_proceed_status ();
282
283 proceed ((CORE_ADDR) -1, -1, 0);
284}
285\f
286/* Step until outside of current statement. */
bd5635a1 287
e1ce8aa5 288/* ARGSUSED */
bd5635a1
RP
289static void
290step_command (count_string, from_tty)
1304f099 291 char *count_string;
bd5635a1
RP
292 int from_tty;
293{
294 step_1 (0, 0, count_string);
295}
296
297/* Likewise, but skip over subroutine calls as if single instructions. */
298
e1ce8aa5 299/* ARGSUSED */
bd5635a1
RP
300static void
301next_command (count_string, from_tty)
1304f099 302 char *count_string;
bd5635a1
RP
303 int from_tty;
304{
305 step_1 (1, 0, count_string);
306}
307
308/* Likewise, but step only one instruction. */
309
e1ce8aa5 310/* ARGSUSED */
bd5635a1
RP
311static void
312stepi_command (count_string, from_tty)
1304f099 313 char *count_string;
bd5635a1
RP
314 int from_tty;
315{
316 step_1 (0, 1, count_string);
317}
318
e1ce8aa5 319/* ARGSUSED */
bd5635a1
RP
320static void
321nexti_command (count_string, from_tty)
1304f099 322 char *count_string;
bd5635a1
RP
323 int from_tty;
324{
325 step_1 (1, 1, count_string);
326}
327
328static void
329step_1 (skip_subroutines, single_inst, count_string)
330 int skip_subroutines;
331 int single_inst;
332 char *count_string;
333{
334 register int count = 1;
335 FRAME fr;
1304f099 336 struct cleanup *cleanups = 0;
bd5635a1
RP
337
338 ERROR_NO_INFERIOR;
339 count = count_string ? parse_and_eval_address (count_string) : 1;
340
1304f099
JG
341 if (!single_inst || skip_subroutines) /* leave si command alone */
342 {
343 enable_longjmp_breakpoint();
344 cleanups = make_cleanup(disable_longjmp_breakpoint, 0);
345 }
346
bd5635a1
RP
347 for (; count > 0; count--)
348 {
349 clear_proceed_status ();
350
bd5635a1
RP
351 fr = get_current_frame ();
352 if (!fr) /* Avoid coredump here. Why tho? */
353 error ("No current frame");
354 step_frame_address = FRAME_FP (fr);
355
356 if (! single_inst)
357 {
358 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
359 if (step_range_end == 0)
360 {
1304f099 361 struct minimal_symbol *msymbol;
bd5635a1 362
1304f099 363 msymbol = lookup_minimal_symbol_by_pc (stop_pc);
bd5635a1 364 target_terminal_ours ();
1304f099 365 printf_filtered ("Current function has no line number information.\n");
bd5635a1
RP
366 fflush (stdout);
367
368 /* No info or after _etext ("Can't happen") */
1304f099 369 if (msymbol == NULL || (msymbol + 1) -> name == NULL)
bd5635a1
RP
370 error ("No data available on pc function.");
371
1304f099 372 printf_filtered ("Single stepping until function exit.\n");
bd5635a1
RP
373 fflush (stdout);
374
1304f099
JG
375 step_range_start = msymbol -> address;
376 step_range_end = (msymbol + 1) -> address;
bd5635a1
RP
377 }
378 }
379 else
380 {
381 /* Say we are stepping, but stop after one insn whatever it does.
382 Don't step through subroutine calls even to undebuggable
383 functions. */
384 step_range_start = step_range_end = 1;
385 if (!skip_subroutines)
386 step_over_calls = 0;
387 }
388
389 if (skip_subroutines)
390 step_over_calls = 1;
391
392 step_multi = (count > 1);
393 proceed ((CORE_ADDR) -1, -1, 1);
394 if (! stop_step)
395 break;
396#if defined (SHIFT_INST_REGS)
397 write_register (NNPC_REGNUM, read_register (NPC_REGNUM));
398 write_register (NPC_REGNUM, read_register (PC_REGNUM));
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;
416
417 ERROR_NO_INFERIOR;
418
419 if (!arg)
420 error_no_arg ("starting address");
421
422 sals = decode_line_spec_1 (arg, 1);
423 if (sals.nelts != 1)
424 {
425 error ("Unreasonable jump request");
426 }
427
428 sal = sals.sals[0];
1304f099 429 free ((PTR)sals.sals);
bd5635a1
RP
430
431 if (sal.symtab == 0 && sal.pc == 0)
432 error ("No source file has been specified.");
433
ee0613d1 434 resolve_sal_pc (&sal); /* May error out */
bd5635a1
RP
435
436 {
437 struct symbol *fn = get_frame_function (get_current_frame ());
438 struct symbol *sfn = find_pc_function (sal.pc);
439 if (fn != 0 && sfn != fn
440 && ! query ("Line %d is not in `%s'. Jump anyway? ",
441 sal.line, SYMBOL_NAME (fn)))
442 error ("Not confirmed.");
443 }
444
bd5635a1
RP
445 addr = ADDR_BITS_SET (sal.pc);
446
447 if (from_tty)
1304f099 448 printf_filtered ("Continuing at %s.\n", local_hex_string(addr));
bd5635a1
RP
449
450 clear_proceed_status ();
451 proceed (addr, 0, 0);
452}
453
454/* Continue program giving it specified signal. */
455
456static void
457signal_command (signum_exp, from_tty)
458 char *signum_exp;
459 int from_tty;
460{
461 register int signum;
462
463 dont_repeat (); /* Too dangerous. */
464 ERROR_NO_INFERIOR;
465
466 if (!signum_exp)
467 error_no_arg ("signal number");
468
469 signum = parse_and_eval_address (signum_exp);
470
471 if (from_tty)
1304f099 472 printf_filtered ("Continuing with signal %d.\n", signum);
bd5635a1
RP
473
474 clear_proceed_status ();
475 proceed (stop_pc, signum, 0);
476}
477
478/* Execute a "stack dummy", a piece of code stored in the stack
479 by the debugger to be executed in the inferior.
480
481 To call: first, do PUSH_DUMMY_FRAME.
482 Then push the contents of the dummy. It should end with a breakpoint insn.
483 Then call here, passing address at which to start the dummy.
484
485 The contents of all registers are saved before the dummy frame is popped
486 and copied into the buffer BUFFER.
487
488 The dummy's frame is automatically popped whenever that break is hit.
489 If that is the first time the program stops, run_stack_dummy
490 returns to its caller with that frame already gone.
491 Otherwise, the caller never gets returned to. */
492
ee0613d1 493/* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
bd5635a1
RP
494
495static int stack_dummy_testing = 0;
496
497void
498run_stack_dummy (addr, buffer)
499 CORE_ADDR addr;
500 char buffer[REGISTER_BYTES];
501{
502 /* Now proceed, having reached the desired place. */
503 clear_proceed_status ();
504 if (stack_dummy_testing & 4)
505 {
506 POP_FRAME;
507 return;
508 }
509 proceed_to_finish = 1; /* We want stop_registers, please... */
510 proceed (addr, 0, 0);
511
512 if (!stop_stack_dummy)
513 /* This used to say
514 "Cannot continue previously requested operation". */
515 error ("\
516The program being debugged stopped while in a function called from GDB.\n\
517The expression which contained the function call has been discarded.");
518
519 /* On return, the stack dummy has been popped already. */
520
521 bcopy (stop_registers, buffer, sizeof stop_registers);
522}
523\f
524/* Proceed until we reach a different source line with pc greater than
525 our current one or exit the function. We skip calls in both cases.
526
527 Note that eventually this command should probably be changed so
528 that only source lines are printed out when we hit the breakpoint
529 we set. I'm going to postpone this until after a hopeful rewrite
530 of wait_for_inferior and the proceed status code. -- randy */
531
e1ce8aa5 532/* ARGSUSED */
1304f099 533static void
bd5635a1
RP
534until_next_command (from_tty)
535 int from_tty;
536{
537 FRAME frame;
538 CORE_ADDR pc;
539 struct symbol *func;
540 struct symtab_and_line sal;
541
542 clear_proceed_status ();
543
544 frame = get_current_frame ();
545
546 /* Step until either exited from this function or greater
547 than the current line (if in symbolic section) or pc (if
548 not). */
549
550 pc = read_pc ();
551 func = find_pc_function (pc);
552
553 if (!func)
554 {
1304f099 555 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
bd5635a1 556
1304f099 557 if (msymbol == NULL)
bd5635a1
RP
558 error ("Execution is not within a known function.");
559
1304f099 560 step_range_start = msymbol -> address;
bd5635a1
RP
561 step_range_end = pc;
562 }
563 else
564 {
565 sal = find_pc_line (pc, 0);
566
567 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
568 step_range_end = sal.end;
569 }
570
571 step_over_calls = 1;
572 step_frame_address = FRAME_FP (frame);
573
574 step_multi = 0; /* Only one call to proceed */
575
576 proceed ((CORE_ADDR) -1, -1, 1);
577}
578
1304f099 579static void
bd5635a1
RP
580until_command (arg, from_tty)
581 char *arg;
582 int from_tty;
583{
584 if (!target_has_execution)
585 error ("The program is not running.");
586 if (arg)
587 until_break_command (arg, from_tty);
588 else
589 until_next_command (from_tty);
590}
591\f
592/* "finish": Set a temporary breakpoint at the place
593 the selected frame will return to, then continue. */
594
595static void
596finish_command (arg, from_tty)
597 char *arg;
598 int from_tty;
599{
600 struct symtab_and_line sal;
601 register FRAME frame;
602 struct frame_info *fi;
603 register struct symbol *function;
1304f099
JG
604 struct breakpoint *breakpoint;
605 struct cleanup *old_chain;
bd5635a1
RP
606
607 if (arg)
608 error ("The \"finish\" command does not take any arguments.");
609 if (!target_has_execution)
610 error ("The program is not running.");
777bef06
JK
611 if (selected_frame == NULL)
612 error ("No selected frame.");
bd5635a1
RP
613
614 frame = get_prev_frame (selected_frame);
615 if (frame == 0)
616 error ("\"finish\" not meaningful in the outermost frame.");
617
618 clear_proceed_status ();
619
620 fi = get_frame_info (frame);
621 sal = find_pc_line (fi->pc, 0);
622 sal.pc = fi->pc;
1304f099
JG
623
624 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
625
626 old_chain = make_cleanup(delete_breakpoint, breakpoint);
bd5635a1
RP
627
628 /* Find the function we will return from. */
629
630 fi = get_frame_info (selected_frame);
631 function = find_pc_function (fi->pc);
632
ee0613d1
JG
633 /* Print info on the selected frame, including level number
634 but not source. */
bd5635a1
RP
635 if (from_tty)
636 {
ee0613d1
JG
637 printf_filtered ("Run till exit from ");
638 print_stack_frame (selected_frame, selected_frame_level, 0);
bd5635a1
RP
639 }
640
641 proceed_to_finish = 1; /* We want stop_registers, please... */
642 proceed ((CORE_ADDR) -1, -1, 0);
643
1304f099
JG
644 /* Did we stop at our breakpoint? */
645 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
646 && function != 0)
bd5635a1
RP
647 {
648 struct type *value_type;
649 register value val;
650 CORE_ADDR funcaddr;
651
652 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
653 if (!value_type)
654 fatal ("internal: finish_command: function has no target type");
655
656 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
657 return;
658
659 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
660
661 val = value_being_returned (value_type, stop_registers,
662 using_struct_return (value_of_variable (function),
663 funcaddr,
664 value_type,
665 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
666
ee0613d1 667 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
bd5635a1 668 value_print (val, stdout, 0, Val_no_prettyprint);
ee0613d1 669 printf_filtered ("\n");
bd5635a1 670 }
1304f099 671 do_cleanups(old_chain);
bd5635a1
RP
672}
673\f
e1ce8aa5 674/* ARGSUSED */
bd5635a1
RP
675static void
676program_info (args, from_tty)
677 char *args;
678 int from_tty;
679{
680 bpstat bs = stop_bpstat;
681 int num = bpstat_num (&bs);
682
683 if (!target_has_execution)
684 {
1304f099 685 printf_filtered ("The program being debugged is not being run.\n");
bd5635a1
RP
686 return;
687 }
688
689 target_files_info ();
1304f099 690 printf_filtered ("Program stopped at %s.\n", local_hex_string(stop_pc));
bd5635a1 691 if (stop_step)
1304f099 692 printf_filtered ("It stopped after being stepped.\n");
bd5635a1
RP
693 else if (num != 0)
694 {
695 /* There may be several breakpoints in the same place, so this
696 isn't as strange as it seems. */
697 while (num != 0)
698 {
699 if (num < 0)
1304f099 700 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
bd5635a1 701 else
1304f099 702 printf_filtered ("It stopped at breakpoint %d.\n", num);
bd5635a1
RP
703 num = bpstat_num (&bs);
704 }
705 }
706 else if (stop_signal) {
707#ifdef PRINT_RANDOM_SIGNAL
708 PRINT_RANDOM_SIGNAL (stop_signal);
709#else
1304f099
JG
710 printf_filtered ("It stopped with signal %d (%s).\n",
711 stop_signal, safe_strsignal (stop_signal));
bd5635a1
RP
712#endif
713 }
714
715 if (!from_tty)
1304f099 716 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
bd5635a1
RP
717}
718\f
719static void
1304f099 720environment_info (var, from_tty)
bd5635a1 721 char *var;
1304f099 722 int from_tty;
bd5635a1
RP
723{
724 if (var)
725 {
726 register char *val = get_in_environ (inferior_environ, var);
727 if (val)
1304f099 728 printf_filtered ("%s = %s\n", var, val);
bd5635a1 729 else
1304f099 730 printf_filtered ("Environment variable \"%s\" not defined.\n", var);
bd5635a1
RP
731 }
732 else
733 {
734 register char **vector = environ_vector (inferior_environ);
735 while (*vector)
1304f099 736 printf_filtered ("%s\n", *vector++);
bd5635a1
RP
737 }
738}
739
740static void
1304f099 741set_environment_command (arg, from_tty)
bd5635a1 742 char *arg;
1304f099 743 int from_tty;
bd5635a1
RP
744{
745 register char *p, *val, *var;
746 int nullset = 0;
747
748 if (arg == 0)
749 error_no_arg ("environment variable and value");
750
751 /* Find seperation between variable name and value */
752 p = (char *) strchr (arg, '=');
753 val = (char *) strchr (arg, ' ');
754
755 if (p != 0 && val != 0)
756 {
757 /* We have both a space and an equals. If the space is before the
758 equals and the only thing between the two is more space, use
759 the equals */
760 if (p > val)
761 while (*val == ' ')
762 val++;
763
764 /* Take the smaller of the two. If there was space before the
765 "=", they will be the same right now. */
766 p = arg + min (p - arg, val - arg);
767 }
768 else if (val != 0 && p == 0)
769 p = val;
770
771 if (p == arg)
772 error_no_arg ("environment variable to set");
773
774 if (p == 0 || p[1] == 0)
775 {
776 nullset = 1;
777 if (p == 0)
778 p = arg + strlen (arg); /* So that savestring below will work */
779 }
780 else
781 {
782 /* Not setting variable value to null */
783 val = p + 1;
784 while (*val == ' ' || *val == '\t')
785 val++;
786 }
787
788 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
789
790 var = savestring (arg, p - arg);
791 if (nullset)
792 {
1304f099 793 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
bd5635a1
RP
794 set_in_environ (inferior_environ, var, "");
795 }
796 else
797 set_in_environ (inferior_environ, var, val);
798 free (var);
799}
800
801static void
802unset_environment_command (var, from_tty)
803 char *var;
804 int from_tty;
805{
806 if (var == 0)
807 {
808 /* If there is no argument, delete all environment variables.
809 Ask for confirmation if reading from the terminal. */
810 if (!from_tty || query ("Delete all environment variables? "))
811 {
812 free_environ (inferior_environ);
813 inferior_environ = make_environ ();
814 }
815 }
816 else
817 unset_in_environ (inferior_environ, var);
818}
819
820/* Handle the execution path (PATH variable) */
821
822const static char path_var_name[] = "PATH";
823
e1ce8aa5 824/* ARGSUSED */
1304f099 825static void
bd5635a1
RP
826path_info (args, from_tty)
827 char *args;
828 int from_tty;
829{
1304f099 830 printf_filtered ("Executable and object file path: %s\n",
bd5635a1
RP
831 get_in_environ (inferior_environ, path_var_name));
832}
833
834/* Add zero or more directories to the front of the execution path. */
835
1304f099 836static void
bd5635a1
RP
837path_command (dirname, from_tty)
838 char *dirname;
839 int from_tty;
840{
841 char *exec_path;
842
843 dont_repeat ();
844 exec_path = strsave (get_in_environ (inferior_environ, path_var_name));
e1ce8aa5 845 mod_path (dirname, &exec_path);
bd5635a1
RP
846 set_in_environ (inferior_environ, path_var_name, exec_path);
847 free (exec_path);
848 if (from_tty)
e1ce8aa5 849 path_info ((char *)NULL, from_tty);
bd5635a1
RP
850}
851\f
852CORE_ADDR
853read_pc ()
854{
855 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register (PC_REGNUM));
856}
857
858void
859write_pc (val)
860 CORE_ADDR val;
861{
862 write_register (PC_REGNUM, (long) val);
863#ifdef NPC_REGNUM
864 write_register (NPC_REGNUM, (long) val+4);
865#endif
866 pc_changed = 0;
867}
868
1304f099 869const char * const reg_names[] = REGISTER_NAMES;
bd5635a1
RP
870
871/* Print out the machine register regnum. If regnum is -1,
ee0613d1
JG
872 print all registers (fpregs == 1) or all non-float registers
873 (fpregs == 0).
874
bd5635a1
RP
875 For most machines, having all_registers_info() print the
876 register(s) one per line is good enough. If a different format
ee0613d1 877 is required, (eg, for MIPS or Pyramid 90x, which both have
bd5635a1 878 lots of regs), or there is an existing convention for showing
ee0613d1 879 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
bd5635a1 880 to provide that format. */
ee0613d1 881
bd5635a1 882#if !defined (DO_REGISTERS_INFO)
ee0613d1
JG
883#define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
884static void
885do_registers_info (regnum, fpregs)
bd5635a1 886 int regnum;
ee0613d1 887 int fpregs;
bd5635a1
RP
888{
889 register int i;
890
bd5635a1
RP
891 for (i = 0; i < NUM_REGS; i++)
892 {
893 char raw_buffer[MAX_REGISTER_RAW_SIZE];
894 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
895
ee0613d1
JG
896 /* Decide between printing all regs, nonfloat regs, or specific reg. */
897 if (regnum == -1) {
898 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
899 continue;
900 } else {
901 if (i != regnum)
902 continue;
903 }
bd5635a1
RP
904
905 fputs_filtered (reg_names[i], stdout);
906 print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
907
908 /* Get the data in raw format, then convert also to virtual format. */
909 if (read_relative_register_raw_bytes (i, raw_buffer))
910 {
911 printf_filtered ("Invalid register contents\n");
912 continue;
913 }
914
915 target_convert_to_virtual (i, raw_buffer, virtual_buffer);
916
917 /* If virtual format is floating, print it that way, and in raw hex. */
918 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT
919 && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
920 {
921 register int j;
922
923 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,
924 stdout, 0, 1, 0, Val_pretty_default);
925
926 printf_filtered ("\t(raw 0x");
927 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
928 printf_filtered ("%02x", (unsigned char)raw_buffer[j]);
929 printf_filtered (")");
930 }
931
932/* FIXME! val_print probably can handle all of these cases now... */
933
934 /* Else if virtual format is too long for printf,
935 print in hex a byte at a time. */
936 else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))
937 {
938 register int j;
939 printf_filtered ("0x");
940 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
941 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
942 }
943 /* Else print as integer in hex and in decimal. */
944 else
945 {
946 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
947 stdout, 'x', 1, 0, Val_pretty_default);
948 printf_filtered ("\t");
949 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
950 stdout, 0, 1, 0, Val_pretty_default);
951 }
952
953 /* The SPARC wants to print even-numbered float regs as doubles
954 in addition to printing them as floats. */
955#ifdef PRINT_REGISTER_HOOK
956 PRINT_REGISTER_HOOK (i);
957#endif
958
959 printf_filtered ("\n");
960 }
961}
962#endif /* no DO_REGISTERS_INFO. */
963
964static void
ee0613d1 965registers_info (addr_exp, fpregs)
bd5635a1 966 char *addr_exp;
ee0613d1 967 int fpregs;
bd5635a1
RP
968{
969 int regnum;
970
971 if (!target_has_registers)
972 error ("The program has no registers now.");
973
974 if (addr_exp)
975 {
976 if (*addr_exp >= '0' && *addr_exp <= '9')
977 regnum = atoi (addr_exp);
978 else
979 {
980 register char *p = addr_exp;
981 if (p[0] == '$')
982 p++;
983 for (regnum = 0; regnum < NUM_REGS; regnum++)
984 if (!strcmp (p, reg_names[regnum]))
985 break;
986 if (regnum == NUM_REGS)
987 error ("%s: invalid register name.", addr_exp);
988 }
989 }
990 else
991 regnum = -1;
992
ee0613d1
JG
993 DO_REGISTERS_INFO(regnum, fpregs);
994}
995
996static void
1304f099 997all_registers_info (addr_exp, from_tty)
ee0613d1 998 char *addr_exp;
1304f099 999 int from_tty;
ee0613d1
JG
1000{
1001 registers_info (addr_exp, 1);
1002}
1003
1004static void
1304f099 1005nofp_registers_info (addr_exp, from_tty)
ee0613d1 1006 char *addr_exp;
1304f099 1007 int from_tty;
ee0613d1
JG
1008{
1009 registers_info (addr_exp, 0);
bd5635a1
RP
1010}
1011\f
1012/*
1013 * TODO:
1014 * Should save/restore the tty state since it might be that the
1015 * program to be debugged was started on this tty and it wants
1016 * the tty in some state other than what we want. If it's running
1017 * on another terminal or without a terminal, then saving and
1018 * restoring the tty state is a harmless no-op.
1019 * This only needs to be done if we are attaching to a process.
1020 */
1021
1022/*
1023 * attach_command --
1024 * takes a program started up outside of gdb and ``attaches'' to it.
1025 * This stops it cold in its tracks and allows us to start tracing it.
1026 * For this to work, we must be able to send the process a
1027 * signal and we must have the same effective uid as the program.
1028 */
1029void
1030attach_command (args, from_tty)
1031 char *args;
1032 int from_tty;
1033{
f266e564 1034 dont_repeat (); /* Not for the faint of heart */
bd5635a1
RP
1035 target_attach (args, from_tty);
1036}
1037
1038/*
1039 * detach_command --
1040 * takes a program previously attached to and detaches it.
1041 * The program resumes execution and will no longer stop
1042 * on signals, etc. We better not have left any breakpoints
1043 * in the program or it'll die when it hits one. For this
1044 * to work, it may be necessary for the process to have been
1045 * previously attached. It *might* work if the program was
1046 * started via the normal ptrace (PTRACE_TRACEME).
1047 */
1048
1049static void
1050detach_command (args, from_tty)
1051 char *args;
1052 int from_tty;
1053{
f266e564 1054 dont_repeat (); /* Not for the faint of heart */
bd5635a1
RP
1055 target_detach (args, from_tty);
1056}
1057
1058/* ARGSUSED */
1059static void
1304f099 1060float_info (addr_exp, from_tty)
bd5635a1 1061 char *addr_exp;
1304f099 1062 int from_tty;
bd5635a1
RP
1063{
1064#ifdef FLOAT_INFO
1065 FLOAT_INFO;
1066#else
1304f099 1067 printf_filtered ("No floating point info available for this processor.\n");
bd5635a1
RP
1068#endif
1069}
1070\f
f266e564
JK
1071struct cmd_list_element *unsetlist = NULL;
1072
1073/* ARGSUSED */
1074static void
1075unset_command (args, from_tty)
1076 char *args;
1077 int from_tty;
1078{
1304f099 1079 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
f266e564
JK
1080 help_list (unsetlist, "unset ", -1, stdout);
1081}
1082
bd5635a1
RP
1083void
1084_initialize_infcmd ()
1085{
1086 struct cmd_list_element *c;
1087
1088 add_com ("tty", class_run, tty_command,
1089 "Set terminal for future runs of program being debugged.");
1090
1091 add_show_from_set
1092 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1093
1094"Set arguments to give program being debugged when it is started.\n\
1095Follow this command with any number of args, to be passed to the program.",
1096 &setlist),
1097 &showlist);
1098
1099 c = add_cmd
1100 ("environment", no_class, environment_info,
1101 "The environment to give the program, or one variable's value.\n\
1102With an argument VAR, prints the value of environment variable VAR to\n\
1103give the program being debugged. With no arguments, prints the entire\n\
1104environment to be given to the program.", &showlist);
1105 c->completer = noop_completer;
1106
f266e564
JK
1107 add_prefix_cmd ("unset", no_class, unset_command,
1108 "Complement to certain \"set\" commands",
1109 &unsetlist, "unset ", 0, &cmdlist);
1110
bd5635a1
RP
1111 c = add_cmd ("environment", class_run, unset_environment_command,
1112 "Cancel environment variable VAR for the program.\n\
1113This does not affect the program until the next \"run\" command.",
f266e564 1114 &unsetlist);
bd5635a1
RP
1115 c->completer = noop_completer;
1116
1117 c = add_cmd ("environment", class_run, set_environment_command,
1118 "Set environment variable value to give the program.\n\
1119Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1120VALUES of environment variables are uninterpreted strings.\n\
1121This does not affect the program until the next \"run\" command.",
1122 &setlist);
1123 c->completer = noop_completer;
1124
1125 add_com ("path", class_files, path_command,
1126 "Add directory DIR(s) to beginning of search path for object files.\n\
1127$cwd in the path means the current working directory.\n\
1128This path is equivalent to the $PATH shell variable. It is a list of\n\
1129directories, separated by colons. These directories are searched to find\n\
1130fully linked executable files and separately compiled object files as needed.");
1131
ee0613d1 1132 c = add_cmd ("paths", no_class, path_info,
bd5635a1
RP
1133 "Current search path for finding object files.\n\
1134$cwd in the path means the current working directory.\n\
1135This path is equivalent to the $PATH shell variable. It is a list of\n\
1136directories, separated by colons. These directories are searched to find\n\
ee0613d1
JG
1137fully linked executable files and separately compiled object files as needed.", &showlist);
1138 c->completer = noop_completer;
bd5635a1
RP
1139
1140 add_com ("attach", class_run, attach_command,
1141 "Attach to a process or file outside of GDB.\n\
1142This command attaches to another target, of the same type as your last\n\
1143`target' command (`info files' will show your target stack).\n\
1144The command may take as argument a process id or a device file.\n\
1145For a process id, you must have permission to send the process a signal,\n\
1146and it must have the same effective uid as the debugger.\n\
1147When using \"attach\", you should use the \"file\" command to specify\n\
1148the program running in the process, and to load its symbol table.");
1149
1150 add_com ("detach", class_run, detach_command,
1151 "Detach a process or file previously attached.\n\
1152If a process, it is no longer traced, and it continues its execution. If you\n\
1153were debugging a file, the file is closed and gdb no longer accesses it.");
1154
1155 add_com ("signal", class_run, signal_command,
1156 "Continue program giving it signal number SIGNUMBER.");
1157
1158 add_com ("stepi", class_run, stepi_command,
1159 "Step one instruction exactly.\n\
1160Argument N means do this N times (or till program stops for another reason).");
1161 add_com_alias ("si", "stepi", class_alias, 0);
1162
1163 add_com ("nexti", class_run, nexti_command,
1164 "Step one instruction, but proceed through subroutine calls.\n\
1165Argument N means do this N times (or till program stops for another reason).");
1166 add_com_alias ("ni", "nexti", class_alias, 0);
1167
1168 add_com ("finish", class_run, finish_command,
1169 "Execute until selected stack frame returns.\n\
1170Upon return, the value returned is printed and put in the value history.");
1171
1172 add_com ("next", class_run, next_command,
1173 "Step program, proceeding through subroutine calls.\n\
1174Like the \"step\" command as long as subroutine calls do not happen;\n\
1175when they do, the call is treated as one instruction.\n\
1176Argument N means do this N times (or till program stops for another reason).");
1177 add_com_alias ("n", "next", class_run, 1);
1178
1179 add_com ("step", class_run, step_command,
1180 "Step program until it reaches a different source line.\n\
1181Argument N means do this N times (or till program stops for another reason).");
1182 add_com_alias ("s", "step", class_run, 1);
1183
1184 add_com ("until", class_run, until_command,
1185 "Execute until the program reaches a source line greater than the current\n\
1186or a specified line or address or function (same args as break command).\n\
1187Execution will also stop upon exit from the current stack frame.");
1188 add_com_alias ("u", "until", class_run, 1);
1189
1190 add_com ("jump", class_run, jump_command,
1191 "Continue program being debugged at specified line or address.\n\
1192Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1193for an address to start at.");
1194
1195 add_com ("continue", class_run, continue_command,
1196 "Continue program being debugged, after signal or breakpoint.\n\
1197If proceeding from breakpoint, a number N may be used as an argument:\n\
1198then the same breakpoint won't break until the Nth time it is reached.");
1199 add_com_alias ("c", "cont", class_run, 1);
1200 add_com_alias ("fg", "cont", class_run, 1);
1201
1202 add_com ("run", class_run, run_command,
1203 "Start debugged program. You may specify arguments to give it.\n\
1204Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1205Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1206With no arguments, uses arguments last specified (with \"run\" or \"set args\".\n\
1207To cancel previous arguments and run with no arguments,\n\
1208use \"set args\" without arguments.");
1209 add_com_alias ("r", "run", class_run, 1);
1210
ee0613d1
JG
1211 add_info ("registers", nofp_registers_info,
1212 "List of integer registers and their contents, for selected stack frame.\n\
1213Register name as argument means describe only that register.");
1214
1215 add_info ("all-registers", all_registers_info,
1216"List of all registers and their contents, for selected stack frame.\n\
bd5635a1
RP
1217Register name as argument means describe only that register.");
1218
1219 add_info ("program", program_info,
1220 "Execution status of the program.");
1221
1222 add_info ("float", float_info,
1223 "Print the status of the floating point unit\n");
1224
1225 inferior_args = savestring ("", 1); /* Initially no args */
1226 inferior_environ = make_environ ();
1227 init_environ (inferior_environ);
1228}
This page took 0.194289 seconds and 4 git commands to generate.