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