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