Add switches to control AIX multlibs
[deliverable/binutils-gdb.git] / gdb / stack.c
CommitLineData
bd5635a1 1/* Print and select stack frames for GDB, the GNU debugger.
d0e0eca2 2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995
1a494973 3 Free Software Foundation, Inc.
bd5635a1
RP
4
5This file is part of GDB.
6
cadbb07a 7This program is free software; you can redistribute it and/or modify
bd5635a1 8it under the terms of the GNU General Public License as published by
cadbb07a
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
bd5635a1 11
cadbb07a 12This program is distributed in the hope that it will be useful,
bd5635a1
RP
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
cadbb07a 18along with this program; if not, write to the Free Software
d0e0eca2
FF
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
bd5635a1 21
bd5635a1 22#include "defs.h"
d0e0eca2 23#include "gdb_string.h"
b4fde6fa 24#include "value.h"
bd5635a1 25#include "symtab.h"
b4fde6fa
FF
26#include "gdbtypes.h"
27#include "expression.h"
28#include "language.h"
bd5635a1
RP
29#include "frame.h"
30#include "gdbcmd.h"
bd5635a1
RP
31#include "gdbcore.h"
32#include "target.h"
33#include "breakpoint.h"
b4fde6fa 34#include "demangle.h"
df2a1bd7 35#include "inferior.h"
1a494973 36#include "annotate.h"
b4fde6fa 37
1a494973 38static void return_command PARAMS ((char *, int));
b4fde6fa 39
1a494973 40static void down_command PARAMS ((char *, int));
b4fde6fa 41
1a494973 42static void down_silently_command PARAMS ((char *, int));
b4fde6fa 43
1a494973 44static void up_command PARAMS ((char *, int));
b4fde6fa 45
1a494973 46static void up_silently_command PARAMS ((char *, int));
b4fde6fa 47
1a494973 48static void frame_command PARAMS ((char *, int));
b4fde6fa 49
1a494973 50static void select_frame_command PARAMS ((char *, int));
b4fde6fa 51
1a494973 52static void args_info PARAMS ((char *, int));
b4fde6fa 53
1a494973 54static void print_frame_arg_vars PARAMS ((struct frame_info *, GDB_FILE *));
b4fde6fa 55
1a494973 56static void catch_info PARAMS ((char *, int));
b4fde6fa 57
1a494973 58static void locals_info PARAMS ((char *, int));
b4fde6fa 59
1a494973
C
60static void print_frame_label_vars PARAMS ((struct frame_info *, int,
61 GDB_FILE *));
b4fde6fa 62
1a494973 63static void print_frame_local_vars PARAMS ((struct frame_info *, GDB_FILE *));
b4fde6fa 64
1a494973
C
65static int print_block_frame_labels PARAMS ((struct block *, int *,
66 GDB_FILE *));
b4fde6fa 67
1a494973
C
68static int print_block_frame_locals PARAMS ((struct block *,
69 struct frame_info *,
70 GDB_FILE *));
b4fde6fa 71
1a494973 72static void backtrace_command PARAMS ((char *, int));
b4fde6fa 73
1a494973 74static struct frame_info *parse_frame_specification PARAMS ((char *));
b4fde6fa 75
1a494973 76static void frame_info PARAMS ((char *, int));
bd5635a1
RP
77
78extern int addressprint; /* Print addresses, or stay symbolic only? */
79extern int info_verbose; /* Verbosity of symbol reading msgs */
d8ce1326 80extern int lines_to_list; /* # of lines "list" command shows by default */
bd5635a1 81
b4fde6fa 82/* The "selected" stack frame is used by default for local and arg access.
bd5635a1
RP
83 May be zero, for no selected frame. */
84
1a494973 85struct frame_info *selected_frame;
bd5635a1
RP
86
87/* Level of the selected frame:
88 0 for innermost, 1 for its caller, ...
89 or -1 for frame specified by address with no defined level. */
90
91int selected_frame_level;
92
d24c0599
JK
93/* Zero means do things normally; we are interacting directly with the
94 user. One means print the full filename and linenumber when a
95 frame is printed, and do so in a format emacs18/emacs19.22 can
96 parse. Two means print similar annotations, but in many more
97 cases and in a slightly different syntax. */
bd5635a1 98
d24c0599 99int annotation_level = 0;
bd5635a1 100
bd5635a1 101\f
199b2450
TL
102struct print_stack_frame_args {
103 struct frame_info *fi;
104 int level;
105 int source;
106 int args;
107};
108
109static int print_stack_frame_stub PARAMS ((char *));
110
111/* Pass the args the way catch_errors wants them. */
112static int
113print_stack_frame_stub (args)
114 char *args;
115{
116 struct print_stack_frame_args *p = (struct print_stack_frame_args *)args;
1a494973 117
199b2450
TL
118 print_frame_info (p->fi, p->level, p->source, p->args);
119 return 0;
120}
121
1a494973 122/* Print a stack frame briefly. FRAME_INFI should be the frame info
bd5635a1
RP
123 and LEVEL should be its level in the stack (or -1 for level not defined).
124 This prints the level, the function executing, the arguments,
125 and the file name and line number.
126 If the pc is not at the beginning of the source line,
127 the actual pc is printed at the beginning.
128
129 If SOURCE is 1, print the source line as well.
130 If SOURCE is -1, print ONLY the source line. */
131
cadbb07a 132void
1a494973
C
133print_stack_frame (fi, level, source)
134 struct frame_info *fi;
bd5635a1
RP
135 int level;
136 int source;
137{
199b2450 138 struct print_stack_frame_args args;
bd5635a1 139
1a494973 140 args.fi = fi;
199b2450
TL
141 args.level = level;
142 args.source = source;
143 args.args = 1;
bd5635a1 144
199b2450 145 catch_errors (print_stack_frame_stub, (char *)&args, "", RETURN_MASK_ERROR);
bd5635a1
RP
146}
147
c94e7e75
JK
148struct print_args_args {
149 struct symbol *func;
150 struct frame_info *fi;
151};
152
153static int print_args_stub PARAMS ((char *));
154
155/* Pass the args the way catch_errors wants them. */
1a494973 156
c94e7e75
JK
157static int
158print_args_stub (args)
159 char *args;
160{
161 int numargs;
162 struct print_args_args *p = (struct print_args_args *)args;
1a494973 163
c94e7e75 164 FRAME_NUM_ARGS (numargs, (p->fi));
199b2450 165 print_frame_args (p->func, p->fi, numargs, gdb_stdout);
c94e7e75
JK
166 return 0;
167}
168
1a494973
C
169/* LEVEL is the level of the frame, or -1 if it is the innermost frame
170 but we don't want to print the level. */
171
bd5635a1
RP
172void
173print_frame_info (fi, level, source, args)
174 struct frame_info *fi;
175 register int level;
176 int source;
177 int args;
178{
179 struct symtab_and_line sal;
180 struct symbol *func;
181 register char *funname = 0;
bd5d07d9 182 enum language funlang = language_unknown;
1a494973
C
183
184#if 0
dff84871
PS
185 char buf[MAX_REGISTER_RAW_SIZE];
186 CORE_ADDR sp;
187
05052b63
JK
188 /* On the 68k, this spends too much time in m68k_find_saved_regs. */
189
dff84871
PS
190 /* Get the value of SP_REGNUM relative to the frame. */
191 get_saved_register (buf, (int *)NULL, (CORE_ADDR *)NULL,
192 FRAME_INFO_ID (fi), SP_REGNUM, (enum lval_type *)NULL);
193 sp = extract_address (buf, REGISTER_RAW_SIZE (SP_REGNUM));
194
195 /* This is not a perfect test, because if a function alloca's some
196 memory, puts some code there, and then jumps into it, then the test
78cab901
JK
197 will succeed even though there is no call dummy. Probably best is
198 to check for a bp_call_dummy breakpoint. */
dff84871 199 if (PC_IN_CALL_DUMMY (fi->pc, sp, fi->frame))
05052b63
JK
200#else
201 if (frame_in_dummy (fi))
202#endif
df2a1bd7 203 {
1a494973
C
204 annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
205
df2a1bd7
JK
206 /* Do this regardless of SOURCE because we don't have any source
207 to list for this frame. */
208 if (level >= 0)
209 printf_filtered ("#%-2d ", level);
1a494973 210 annotate_function_call ();
df2a1bd7 211 printf_filtered ("<function called from gdb>\n");
1a494973 212 annotate_frame_end ();
df2a1bd7
JK
213 return;
214 }
cee86be3
JK
215 if (fi->signal_handler_caller)
216 {
1a494973
C
217 annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
218
cee86be3
JK
219 /* Do this regardless of SOURCE because we don't have any source
220 to list for this frame. */
221 if (level >= 0)
222 printf_filtered ("#%-2d ", level);
1a494973 223 annotate_signal_handler_caller ();
cee86be3 224 printf_filtered ("<signal handler called>\n");
1a494973 225 annotate_frame_end ();
cee86be3
JK
226 return;
227 }
b4fde6fa 228
46c28185
RP
229 /* If fi is not the innermost frame, that normally means that fi->pc
230 points to *after* the call instruction, and we want to get the line
231 containing the call, never the next line. But if the next frame is
f1de67d3
PS
232 a signal_handler_caller or a dummy frame, then the next frame was
233 not entered as the result of a call, and we want to get the line
234 containing fi->pc. */
46c28185
RP
235 sal =
236 find_pc_line (fi->pc,
f1de67d3
PS
237 fi->next != NULL
238 && !fi->next->signal_handler_caller
239 && !frame_in_dummy (fi->next));
46c28185 240
bd5635a1
RP
241 func = find_pc_function (fi->pc);
242 if (func)
243 {
244 /* In certain pathological cases, the symtabs give the wrong
245 function (when we are in the first function in a file which
246 is compiled without debugging symbols, the previous function
247 is compiled with debugging symbols, and the "foo.o" symbol
248 that is supposed to tell us where the file with debugging symbols
249 ends has been truncated by ar because it is longer than 15
dff84871
PS
250 characters). This also occurs if the user uses asm() to create
251 a function but not stabs for it (in a file compiled -g).
bd5635a1 252
b4fde6fa 253 So look in the minimal symbol tables as well, and if it comes
bd5635a1 254 up with a larger address for the function use that instead.
b4fde6fa 255 I don't think this can ever cause any problems; there shouldn't
dff84871
PS
256 be any minimal symbols in the middle of a function; if this is
257 ever changed many parts of GDB will need to be changed (and we'll
258 create a find_pc_minimal_function or some such). */
b4fde6fa
FF
259
260 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
261 if (msymbol != NULL
bd5d07d9 262 && (SYMBOL_VALUE_ADDRESS (msymbol)
bd5635a1
RP
263 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
264 {
d24c0599
JK
265#if 0
266 /* There is no particular reason to think the line number
267 information is wrong. Someone might have just put in
268 a label with asm() but left the line numbers alone. */
bd5635a1
RP
269 /* In this case we have no way of knowing the source file
270 and line number, so don't print them. */
271 sal.symtab = 0;
d24c0599 272#endif
bd5635a1
RP
273 /* We also don't know anything about the function besides
274 its address and name. */
275 func = 0;
bd5d07d9
FF
276 funname = SYMBOL_NAME (msymbol);
277 funlang = SYMBOL_LANGUAGE (msymbol);
bd5635a1
RP
278 }
279 else
bd5d07d9
FF
280 {
281 funname = SYMBOL_NAME (func);
282 funlang = SYMBOL_LANGUAGE (func);
283 }
bd5635a1
RP
284 }
285 else
286 {
b4fde6fa
FF
287 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
288 if (msymbol != NULL)
bd5d07d9
FF
289 {
290 funname = SYMBOL_NAME (msymbol);
291 funlang = SYMBOL_LANGUAGE (msymbol);
292 }
bd5635a1
RP
293 }
294
295 if (source >= 0 || !sal.symtab)
296 {
1a494973
C
297 annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
298
bd5635a1
RP
299 if (level >= 0)
300 printf_filtered ("#%-2d ", level);
301 if (addressprint)
302 if (fi->pc != sal.pc || !sal.symtab)
833e0d94 303 {
1a494973 304 annotate_frame_address ();
d24c0599 305 print_address_numeric (fi->pc, 1, gdb_stdout);
1a494973 306 annotate_frame_address_end ();
833e0d94
JK
307 printf_filtered (" in ");
308 }
1a494973 309 annotate_frame_function_name ();
199b2450 310 fprintf_symbol_filtered (gdb_stdout, funname ? funname : "??", funlang,
05052b63 311 DMGL_ANSI);
bd5635a1 312 wrap_here (" ");
1a494973 313 annotate_frame_args ();
199b2450 314 fputs_filtered (" (", gdb_stdout);
bd5635a1
RP
315 if (args)
316 {
c94e7e75
JK
317 struct print_args_args args;
318 args.fi = fi;
319 args.func = func;
23a8e291 320 catch_errors (print_args_stub, (char *)&args, "", RETURN_MASK_ERROR);
bd5635a1
RP
321 }
322 printf_filtered (")");
323 if (sal.symtab && sal.symtab->filename)
324 {
1a494973 325 annotate_frame_source_begin ();
bd5635a1 326 wrap_here (" ");
1a494973
C
327 printf_filtered (" at ");
328 annotate_frame_source_file ();
329 printf_filtered ("%s", sal.symtab->filename);
330 annotate_frame_source_file_end ();
331 printf_filtered (":");
332 annotate_frame_source_line ();
333 printf_filtered ("%d", sal.line);
334 annotate_frame_source_end ();
bd5635a1 335 }
b4fde6fa
FF
336
337#ifdef PC_LOAD_SEGMENT
338 /* If we couldn't print out function name but if can figure out what
339 load segment this pc value is from, at least print out some info
340 about its load segment. */
1a494973
C
341 if (!funname)
342 {
343 annotate_frame_where ();
344 wrap_here (" ");
345 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc));
346 }
d0e0eca2
FF
347#endif
348#ifdef PC_SOLIB
349 if (!funname)
350 {
351 char *lib = PC_SOLIB (fi->pc);
352 if (lib)
353 {
354 annotate_frame_where ();
355 wrap_here (" ");
356 printf_filtered (" from %s", lib);
357 }
358 }
b4fde6fa 359#endif
bd5635a1
RP
360 printf_filtered ("\n");
361 }
362
363 if ((source != 0) && sal.symtab)
364 {
365 int done = 0;
366 int mid_statement = source < 0 && fi->pc != sal.pc;
d24c0599 367 if (annotation_level)
c94e7e75
JK
368 done = identify_source_line (sal.symtab, sal.line, mid_statement,
369 fi->pc);
bd5635a1
RP
370 if (!done)
371 {
372 if (addressprint && mid_statement)
833e0d94 373 {
d24c0599 374 print_address_numeric (fi->pc, 1, gdb_stdout);
833e0d94
JK
375 printf_filtered ("\t");
376 }
1a494973
C
377 if (print_frame_info_listing_hook)
378 print_frame_info_listing_hook (sal.symtab, sal.line, sal.line + 1, 0);
379 else
380 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
bd5635a1 381 }
cadbb07a 382 current_source_line = max (sal.line - lines_to_list/2, 1);
bd5635a1
RP
383 }
384 if (source != 0)
385 set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
386
1a494973
C
387 annotate_frame_end ();
388
199b2450 389 gdb_flush (gdb_stdout);
bd5635a1
RP
390}
391
1a494973
C
392/* Read a frame specification in whatever the appropriate format is.
393 Call error() if the specification is in any way invalid (i.e.
394 this function never returns NULL). */
395
396static struct frame_info *
bd5635a1
RP
397parse_frame_specification (frame_exp)
398 char *frame_exp;
399{
400 int numargs = 0;
bd5d07d9 401#define MAXARGS 4
78cab901 402 CORE_ADDR args[MAXARGS];
bd5635a1
RP
403
404 if (frame_exp)
405 {
406 char *addr_string, *p;
407 struct cleanup *tmp_cleanup;
408
409 while (*frame_exp == ' ') frame_exp++;
bd5635a1 410
bd5d07d9 411 while (*frame_exp)
bd5635a1 412 {
bd5d07d9
FF
413 if (numargs > MAXARGS)
414 error ("Too many args in frame specification");
415 /* Parse an argument. */
416 for (p = frame_exp; *p && *p != ' '; p++)
417 ;
bd5635a1
RP
418 addr_string = savestring(frame_exp, p - frame_exp);
419
420 {
421 tmp_cleanup = make_cleanup (free, addr_string);
bd5d07d9 422 args[numargs++] = parse_and_eval_address (addr_string);
bd5635a1
RP
423 do_cleanups (tmp_cleanup);
424 }
425
bd5d07d9 426 /* Skip spaces, move to possible next arg. */
bd5635a1 427 while (*p == ' ') p++;
bd5d07d9 428 frame_exp = p;
bd5635a1
RP
429 }
430 }
431
432 switch (numargs)
433 {
434 case 0:
777bef06
JK
435 if (selected_frame == NULL)
436 error ("No selected frame.");
bd5635a1
RP
437 return selected_frame;
438 /* NOTREACHED */
439 case 1:
440 {
bd5d07d9 441 int level = args[0];
1a494973
C
442 struct frame_info *fid =
443 find_relative_frame (get_current_frame (), &level);
444 struct frame_info *tfid;
bd5635a1
RP
445
446 if (level == 0)
447 /* find_relative_frame was successful */
448 return fid;
449
d24c0599
JK
450 /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications
451 take at least 2 addresses. It is important to detect this case
452 here so that "frame 100" does not give a confusing error message
453 like "frame specification requires two addresses". This of course
454 does not solve the "frame 100" problem for machines on which
455 a frame specification can be made with one address. To solve
456 that, we need a new syntax for a specifying a frame by address.
457 I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for
458 two args, etc.), but people might think that is too much typing,
459 so I guess *0x23,0x45 would be a possible alternative (commas
460 really should be used instead of spaces to delimit; using spaces
461 normally works in an expression). */
462#ifdef SETUP_ARBITRARY_FRAME
463 error ("No frame %d", args[0]);
464#endif
465
bd5635a1
RP
466 /* If (s)he specifies the frame with an address, he deserves what
467 (s)he gets. Still, give the highest one that matches. */
468
469 for (fid = get_current_frame ();
1a494973 470 fid && fid->frame != args[0];
bd5635a1
RP
471 fid = get_prev_frame (fid))
472 ;
473
474 if (fid)
475 while ((tfid = get_prev_frame (fid)) &&
1a494973 476 (tfid->frame == args[0]))
bd5635a1
RP
477 fid = tfid;
478
bd5d07d9 479 /* We couldn't identify the frame as an existing frame, but
d24c0599 480 perhaps we can create one with a single argument. */
bd5635a1 481 }
bd5d07d9
FF
482
483 default:
484#ifdef SETUP_ARBITRARY_FRAME
485 return SETUP_ARBITRARY_FRAME (numargs, args);
bd5635a1 486#else
bd5d07d9
FF
487 /* Usual case. Do it here rather than have everyone supply
488 a SETUP_ARBITRARY_FRAME that does this. */
489 if (numargs == 1)
490 return create_new_frame (args[0], 0);
491 error ("Too many args in frame specification");
bd5635a1
RP
492#endif
493 /* NOTREACHED */
494 }
bd5635a1
RP
495 /* NOTREACHED */
496}
497
498/* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
499 that if it is unsure about the answer, it returns 0
500 instead of guessing (this happens on the VAX and i960, for example).
501
502 On most machines, we never have to guess about the args address,
503 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
504#if !defined (FRAME_ARGS_ADDRESS_CORRECT)
505#define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
506#endif
507
508/* Print verbosely the selected frame or the frame at address ADDR.
509 This means absolutely all information in the frame is printed. */
510
511static void
b4fde6fa 512frame_info (addr_exp, from_tty)
bd5635a1 513 char *addr_exp;
b4fde6fa 514 int from_tty;
bd5635a1 515{
bd5635a1
RP
516 struct frame_info *fi;
517 struct frame_saved_regs fsr;
518 struct symtab_and_line sal;
519 struct symbol *func;
89e0bbcd 520 struct symtab *s;
1a494973
C
521 struct frame_info *calling_frame_info;
522 int i, count, numregs;
bd5635a1 523 char *funname = 0;
bd5d07d9 524 enum language funlang = language_unknown;
bd5635a1
RP
525
526 if (!target_has_stack)
6fe90fc8 527 error ("No stack.");
bd5635a1 528
1a494973
C
529 fi = parse_frame_specification (addr_exp);
530 if (fi == NULL)
bd5635a1
RP
531 error ("Invalid frame specified.");
532
dff84871 533 sal = find_pc_line (fi->pc,
f1de67d3
PS
534 fi->next != NULL
535 && !fi->next->signal_handler_caller
536 && !frame_in_dummy (fi->next));
1a494973 537 func = get_frame_function (fi);
89e0bbcd 538 s = find_pc_symtab(fi->pc);
bd5635a1 539 if (func)
bd5d07d9
FF
540 {
541 funname = SYMBOL_NAME (func);
542 funlang = SYMBOL_LANGUAGE (func);
543 }
bd5635a1
RP
544 else
545 {
b4fde6fa
FF
546 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
547 if (msymbol != NULL)
bd5d07d9
FF
548 {
549 funname = SYMBOL_NAME (msymbol);
550 funlang = SYMBOL_LANGUAGE (msymbol);
551 }
bd5635a1 552 }
1a494973 553 calling_frame_info = get_prev_frame (fi);
bd5635a1 554
833e0d94
JK
555 if (!addr_exp && selected_frame_level >= 0)
556 {
5e678752 557 printf_filtered ("Stack level %d, frame at ", selected_frame_level);
1a494973 558 print_address_numeric (fi->frame, 1, gdb_stdout);
833e0d94
JK
559 printf_filtered (":\n");
560 }
561 else
562 {
563 printf_filtered ("Stack frame at ");
1a494973 564 print_address_numeric (fi->frame, 1, gdb_stdout);
833e0d94
JK
565 printf_filtered (":\n");
566 }
1a494973 567 printf_filtered (" %s = ", reg_names[PC_REGNUM]);
d24c0599 568 print_address_numeric (fi->pc, 1, gdb_stdout);
bd5635a1
RP
569
570 wrap_here (" ");
571 if (funname)
b0077123
JG
572 {
573 printf_filtered (" in ");
199b2450 574 fprintf_symbol_filtered (gdb_stdout, funname, funlang,
5e81259d 575 DMGL_ANSI | DMGL_PARAMS);
b0077123 576 }
bd5635a1
RP
577 wrap_here (" ");
578 if (sal.symtab)
579 printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
580 puts_filtered ("; ");
581 wrap_here (" ");
833e0d94 582 printf_filtered ("saved %s ", reg_names[PC_REGNUM]);
1a494973 583 print_address_numeric (FRAME_SAVED_PC (fi), 1, gdb_stdout);
833e0d94 584 printf_filtered ("\n");
b4fde6fa
FF
585
586 {
587 int frameless = 0;
588#ifdef FRAMELESS_FUNCTION_INVOCATION
589 FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
590#endif
591 if (frameless)
592 printf_filtered (" (FRAMELESS),");
593 }
594
1a494973 595 if (calling_frame_info)
833e0d94
JK
596 {
597 printf_filtered (" called by frame at ");
1a494973 598 print_address_numeric (calling_frame_info->frame, 1, gdb_stdout);
833e0d94 599 }
1a494973 600 if (fi->next && calling_frame_info)
bd5635a1
RP
601 puts_filtered (",");
602 wrap_here (" ");
23a8e291 603 if (fi->next)
833e0d94
JK
604 {
605 printf_filtered (" caller of frame at ");
d24c0599 606 print_address_numeric (fi->next->frame, 1, gdb_stdout);
833e0d94 607 }
1a494973 608 if (fi->next || calling_frame_info)
bd5635a1 609 puts_filtered ("\n");
89e0bbcd 610 if (s)
833e0d94 611 printf_filtered (" source language %s.\n", language_str (s->language));
bd5635a1 612
bd5d07d9
FF
613#ifdef PRINT_EXTRA_FRAME_INFO
614 PRINT_EXTRA_FRAME_INFO (fi);
615#endif
616
bd5635a1
RP
617 {
618 /* Address of the argument list for this frame, or 0. */
619 CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
620 /* Number of args for this frame, or -1 if unknown. */
621 int numargs;
622
623 if (arg_list == 0)
833e0d94 624 printf_filtered (" Arglist at unknown address.\n");
bd5635a1
RP
625 else
626 {
833e0d94 627 printf_filtered (" Arglist at ");
d24c0599 628 print_address_numeric (arg_list, 1, gdb_stdout);
833e0d94 629 printf_filtered (",");
bd5635a1
RP
630
631 FRAME_NUM_ARGS (numargs, fi);
632 if (numargs < 0)
633 puts_filtered (" args: ");
634 else if (numargs == 0)
635 puts_filtered (" no args.");
636 else if (numargs == 1)
637 puts_filtered (" 1 arg: ");
638 else
639 printf_filtered (" %d args: ", numargs);
199b2450 640 print_frame_args (func, fi, numargs, gdb_stdout);
bd5635a1
RP
641 puts_filtered ("\n");
642 }
643 }
b4fde6fa
FF
644 {
645 /* Address of the local variables for this frame, or 0. */
646 CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
647
648 if (arg_list == 0)
833e0d94 649 printf_filtered (" Locals at unknown address,");
b4fde6fa 650 else
833e0d94
JK
651 {
652 printf_filtered (" Locals at ");
d24c0599 653 print_address_numeric (arg_list, 1, gdb_stdout);
833e0d94
JK
654 printf_filtered (",");
655 }
b4fde6fa 656 }
bd5635a1
RP
657
658#if defined (FRAME_FIND_SAVED_REGS)
659 get_frame_saved_regs (fi, &fsr);
660 /* The sp is special; what's returned isn't the save address, but
661 actually the value of the previous frame's sp. */
833e0d94 662 printf_filtered (" Previous frame's sp is ");
d24c0599 663 print_address_numeric (fsr.regs[SP_REGNUM], 1, gdb_stdout);
833e0d94 664 printf_filtered ("\n");
bd5635a1 665 count = 0;
1a494973
C
666 numregs = ARCH_NUM_REGS;
667 for (i = 0; i < numregs; i++)
bd5635a1
RP
668 if (fsr.regs[i] && i != SP_REGNUM)
669 {
670 if (count == 0)
671 puts_filtered (" Saved registers:\n ");
672 else
673 puts_filtered (",");
674 wrap_here (" ");
833e0d94 675 printf_filtered (" %s at ", reg_names[i]);
d24c0599 676 print_address_numeric (fsr.regs[i], 1, gdb_stdout);
bd5635a1
RP
677 count++;
678 }
679 if (count)
680 puts_filtered ("\n");
f1de67d3 681#else /* Have FRAME_FIND_SAVED_REGS. */
1a494973
C
682 /* We could get some information about saved registers by calling
683 get_saved_register on each register. Which info goes with which frame
684 is necessarily lost, however, and I suspect that the users don't care
685 whether they get the info. */
f1de67d3 686 puts_filtered ("\n");
bd5635a1
RP
687#endif /* Have FRAME_FIND_SAVED_REGS. */
688}
689
690#if 0
691/* Set a limit on the number of frames printed by default in a
692 backtrace. */
693
694static int backtrace_limit;
695
696static void
697set_backtrace_limit_command (count_exp, from_tty)
698 char *count_exp;
699 int from_tty;
700{
701 int count = parse_and_eval_address (count_exp);
702
703 if (count < 0)
704 error ("Negative argument not meaningful as backtrace limit.");
705
706 backtrace_limit = count;
707}
708
709static void
710backtrace_limit_info (arg, from_tty)
711 char *arg;
712 int from_tty;
713{
714 if (arg)
715 error ("\"Info backtrace-limit\" takes no arguments.");
716
199b2450 717 printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit);
bd5635a1
RP
718}
719#endif
720
721/* Print briefly all stack frames or just the innermost COUNT frames. */
722
723static void
724backtrace_command (count_exp, from_tty)
725 char *count_exp;
726 int from_tty;
727{
728 struct frame_info *fi;
729 register int count;
bd5635a1 730 register int i;
1a494973 731 register struct frame_info *trailing;
bd5635a1
RP
732 register int trailing_level;
733
777bef06
JK
734 if (!target_has_stack)
735 error ("No stack.");
736
bd5635a1
RP
737 /* The following code must do two things. First, it must
738 set the variable TRAILING to the frame from which we should start
739 printing. Second, it must set the variable count to the number
740 of frames which we should print, or -1 if all of them. */
741 trailing = get_current_frame ();
742 trailing_level = 0;
743 if (count_exp)
744 {
745 count = parse_and_eval_address (count_exp);
746 if (count < 0)
747 {
1a494973 748 struct frame_info *current;
bd5635a1
RP
749
750 count = -count;
751
752 current = trailing;
753 while (current && count--)
754 {
755 QUIT;
756 current = get_prev_frame (current);
757 }
758
759 /* Will stop when CURRENT reaches the top of the stack. TRAILING
760 will be COUNT below it. */
761 while (current)
762 {
763 QUIT;
764 trailing = get_prev_frame (trailing);
765 current = get_prev_frame (current);
766 trailing_level++;
767 }
768
769 count = -1;
770 }
771 }
772 else
773 count = -1;
774
775 if (info_verbose)
776 {
777 struct partial_symtab *ps;
778
779 /* Read in symbols for all of the frames. Need to do this in
780 a separate pass so that "Reading in symbols for xxx" messages
781 don't screw up the appearance of the backtrace. Also
782 if people have strong opinions against reading symbols for
783 backtrace this may have to be an option. */
784 i = count;
1a494973
C
785 for (fi = trailing;
786 fi != NULL && i--;
787 fi = get_prev_frame (fi))
bd5635a1
RP
788 {
789 QUIT;
bd5635a1
RP
790 ps = find_pc_psymtab (fi->pc);
791 if (ps)
3de61d8c 792 PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */
bd5635a1
RP
793 }
794 }
795
1a494973
C
796 for (i = 0, fi = trailing;
797 fi && count--;
798 i++, fi = get_prev_frame (fi))
bd5635a1
RP
799 {
800 QUIT;
199b2450
TL
801
802 /* Don't use print_stack_frame; if an error() occurs it probably
803 means further attempts to backtrace would fail (on the other
804 hand, perhaps the code does or could be fixed to make sure
805 the frame->prev field gets set to NULL in that case). */
bd5635a1
RP
806 print_frame_info (fi, trailing_level + i, 0, 1);
807 }
808
809 /* If we've stopped before the end, mention that. */
1a494973 810 if (fi && from_tty)
bd5635a1
RP
811 printf_filtered ("(More stack frames follow...)\n");
812}
813\f
814/* Print the local variables of a block B active in FRAME.
815 Return 1 if any variables were printed; 0 otherwise. */
816
817static int
1a494973 818print_block_frame_locals (b, fi, stream)
bd5635a1 819 struct block *b;
1a494973 820 register struct frame_info *fi;
199b2450 821 register GDB_FILE *stream;
bd5635a1
RP
822{
823 int nsyms;
824 register int i;
825 register struct symbol *sym;
826 register int values_printed = 0;
827
828 nsyms = BLOCK_NSYMS (b);
829
830 for (i = 0; i < nsyms; i++)
831 {
832 sym = BLOCK_SYM (b, i);
f1de67d3 833 switch (SYMBOL_CLASS (sym))
bd5635a1 834 {
f1de67d3
PS
835 case LOC_LOCAL:
836 case LOC_REGISTER:
837 case LOC_STATIC:
838 case LOC_BASEREG:
bd5635a1 839 values_printed = 1;
bd5d07d9 840 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
bd5635a1 841 fputs_filtered (" = ", stream);
1a494973 842 print_variable_value (sym, fi, stream);
bd5635a1 843 fprintf_filtered (stream, "\n");
f1de67d3
PS
844 break;
845
846 default:
847 /* Ignore symbols which are not locals. */
848 break;
bd5635a1
RP
849 }
850 }
851 return values_printed;
852}
853
cadbb07a 854/* Same, but print labels. */
bd5635a1
RP
855
856static int
cadbb07a 857print_block_frame_labels (b, have_default, stream)
bd5635a1 858 struct block *b;
bd5635a1 859 int *have_default;
199b2450 860 register GDB_FILE *stream;
bd5635a1
RP
861{
862 int nsyms;
863 register int i;
864 register struct symbol *sym;
865 register int values_printed = 0;
866
867 nsyms = BLOCK_NSYMS (b);
868
869 for (i = 0; i < nsyms; i++)
870 {
871 sym = BLOCK_SYM (b, i);
bd5d07d9 872 if (STREQ (SYMBOL_NAME (sym), "default"))
bd5635a1
RP
873 {
874 if (*have_default)
875 continue;
876 *have_default = 1;
877 }
878 if (SYMBOL_CLASS (sym) == LOC_LABEL)
879 {
880 struct symtab_and_line sal;
881 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
882 values_printed = 1;
bd5d07d9 883 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
bd5635a1 884 if (addressprint)
833e0d94
JK
885 {
886 fprintf_filtered (stream, " ");
d24c0599 887 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, stream);
833e0d94 888 }
bd5635a1
RP
889 fprintf_filtered (stream, " in file %s, line %d\n",
890 sal.symtab->filename, sal.line);
bd5635a1
RP
891 }
892 }
893 return values_printed;
894}
895
896/* Print on STREAM all the local variables in frame FRAME,
897 including all the blocks active in that frame
898 at its current pc.
899
900 Returns 1 if the job was done,
901 or 0 if nothing was printed because we have no info
902 on the function running in FRAME. */
903
c4668207 904static void
1a494973
C
905print_frame_local_vars (fi, stream)
906 register struct frame_info *fi;
199b2450 907 register GDB_FILE *stream;
bd5635a1 908{
1a494973 909 register struct block *block = get_frame_block (fi);
bd5635a1
RP
910 register int values_printed = 0;
911
912 if (block == 0)
913 {
914 fprintf_filtered (stream, "No symbol table info available.\n");
c4668207 915 return;
bd5635a1
RP
916 }
917
918 while (block != 0)
919 {
1a494973 920 if (print_block_frame_locals (block, fi, stream))
bd5635a1
RP
921 values_printed = 1;
922 /* After handling the function's top-level block, stop.
923 Don't continue to its superblock, the block of
924 per-file symbols. */
925 if (BLOCK_FUNCTION (block))
926 break;
927 block = BLOCK_SUPERBLOCK (block);
928 }
929
930 if (!values_printed)
931 {
932 fprintf_filtered (stream, "No locals.\n");
bd5635a1 933 }
bd5635a1
RP
934}
935
936/* Same, but print labels. */
937
c4668207 938static void
1a494973
C
939print_frame_label_vars (fi, this_level_only, stream)
940 register struct frame_info *fi;
bd5635a1 941 int this_level_only;
199b2450 942 register GDB_FILE *stream;
bd5635a1 943{
bd5635a1 944 register struct blockvector *bl;
1a494973 945 register struct block *block = get_frame_block (fi);
bd5635a1
RP
946 register int values_printed = 0;
947 int index, have_default = 0;
948 char *blocks_printed;
bd5635a1
RP
949 CORE_ADDR pc = fi->pc;
950
951 if (block == 0)
952 {
953 fprintf_filtered (stream, "No symbol table info available.\n");
c4668207 954 return;
bd5635a1
RP
955 }
956
957 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
958 blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
3de61d8c 959 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
bd5635a1
RP
960
961 while (block != 0)
962 {
963 CORE_ADDR end = BLOCK_END (block) - 4;
964 int last_index;
965
966 if (bl != blockvector_for_pc (end, &index))
967 error ("blockvector blotch");
968 if (BLOCKVECTOR_BLOCK (bl, index) != block)
969 error ("blockvector botch");
970 last_index = BLOCKVECTOR_NBLOCKS (bl);
971 index += 1;
972
973 /* Don't print out blocks that have gone by. */
974 while (index < last_index
975 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
976 index++;
977
978 while (index < last_index
979 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
980 {
981 if (blocks_printed[index] == 0)
982 {
cadbb07a 983 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
bd5635a1
RP
984 values_printed = 1;
985 blocks_printed[index] = 1;
986 }
987 index++;
988 }
989 if (have_default)
c4668207 990 return;
bd5635a1 991 if (values_printed && this_level_only)
c4668207 992 return;
bd5635a1
RP
993
994 /* After handling the function's top-level block, stop.
995 Don't continue to its superblock, the block of
996 per-file symbols. */
997 if (BLOCK_FUNCTION (block))
998 break;
999 block = BLOCK_SUPERBLOCK (block);
1000 }
1001
1002 if (!values_printed && !this_level_only)
1003 {
1004 fprintf_filtered (stream, "No catches.\n");
bd5635a1 1005 }
bd5635a1
RP
1006}
1007
e1ce8aa5 1008/* ARGSUSED */
bd5635a1
RP
1009static void
1010locals_info (args, from_tty)
1011 char *args;
1012 int from_tty;
1013{
cadbb07a
JG
1014 if (!selected_frame)
1015 error ("No frame selected.");
199b2450 1016 print_frame_local_vars (selected_frame, gdb_stdout);
bd5635a1
RP
1017}
1018
1019static void
b4fde6fa
FF
1020catch_info (ignore, from_tty)
1021 char *ignore;
1022 int from_tty;
bd5635a1 1023{
cadbb07a
JG
1024 if (!selected_frame)
1025 error ("No frame selected.");
199b2450 1026 print_frame_label_vars (selected_frame, 0, gdb_stdout);
bd5635a1
RP
1027}
1028
c4668207 1029static void
1a494973
C
1030print_frame_arg_vars (fi, stream)
1031 register struct frame_info *fi;
199b2450 1032 register GDB_FILE *stream;
bd5635a1 1033{
1a494973 1034 struct symbol *func = get_frame_function (fi);
bd5635a1
RP
1035 register struct block *b;
1036 int nsyms;
1037 register int i;
1038 register struct symbol *sym, *sym2;
1039 register int values_printed = 0;
1040
1041 if (func == 0)
1042 {
1043 fprintf_filtered (stream, "No symbol table info available.\n");
c4668207 1044 return;
bd5635a1
RP
1045 }
1046
1047 b = SYMBOL_BLOCK_VALUE (func);
1048 nsyms = BLOCK_NSYMS (b);
1049
1050 for (i = 0; i < nsyms; i++)
1051 {
1052 sym = BLOCK_SYM (b, i);
46c28185 1053 switch (SYMBOL_CLASS (sym))
bd5635a1 1054 {
46c28185
RP
1055 case LOC_ARG:
1056 case LOC_LOCAL_ARG:
1057 case LOC_REF_ARG:
1058 case LOC_REGPARM:
1059 case LOC_REGPARM_ADDR:
1060 case LOC_BASEREG_ARG:
bd5635a1 1061 values_printed = 1;
bd5d07d9 1062 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
bd5635a1 1063 fputs_filtered (" = ", stream);
31258e4f
JK
1064
1065 /* We have to look up the symbol because arguments can have
1066 two entries (one a parameter, one a local) and the one we
1067 want is the local, which lookup_symbol will find for us.
1068 This includes gcc1 (not gcc2) on the sparc when passing a
1069 small structure and gcc2 when the argument type is float
1070 and it is passed as a double and converted to float by
1071 the prologue (in the latter case the type of the LOC_ARG
1072 symbol is double and the type of the LOC_LOCAL symbol is
6fe90fc8
JK
1073 float). There are also LOC_ARG/LOC_REGISTER pairs which
1074 are not combined in symbol-reading. */
31258e4f 1075
bd5635a1
RP
1076 sym2 = lookup_symbol (SYMBOL_NAME (sym),
1077 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1a494973 1078 print_variable_value (sym2, fi, stream);
bd5635a1 1079 fprintf_filtered (stream, "\n");
46c28185
RP
1080 break;
1081
1082 default:
1083 /* Don't worry about things which aren't arguments. */
1084 break;
bd5635a1
RP
1085 }
1086 }
1087
1088 if (!values_printed)
1089 {
1090 fprintf_filtered (stream, "No arguments.\n");
bd5635a1 1091 }
bd5635a1
RP
1092}
1093
1094static void
b4fde6fa
FF
1095args_info (ignore, from_tty)
1096 char *ignore;
1097 int from_tty;
bd5635a1 1098{
cadbb07a
JG
1099 if (!selected_frame)
1100 error ("No frame selected.");
199b2450 1101 print_frame_arg_vars (selected_frame, gdb_stdout);
bd5635a1
RP
1102}
1103\f
1a494973 1104/* Select frame FI, and note that its stack level is LEVEL.
bd5635a1
RP
1105 LEVEL may be -1 if an actual level number is not known. */
1106
1107void
1a494973
C
1108select_frame (fi, level)
1109 struct frame_info *fi;
bd5635a1
RP
1110 int level;
1111{
89e0bbcd
JG
1112 register struct symtab *s;
1113
1a494973 1114 selected_frame = fi;
bd5635a1 1115 selected_frame_level = level;
89e0bbcd
JG
1116
1117 /* Ensure that symbols for this frame are read in. Also, determine the
1118 source language of this frame, and switch to it if desired. */
1a494973 1119 if (fi)
89e0bbcd 1120 {
1a494973 1121 s = find_pc_symtab (fi->pc);
89e0bbcd 1122 if (s
91ec58ee 1123 && s->language != current_language->la_language
89e0bbcd
JG
1124 && s->language != language_unknown
1125 && language_mode == language_mode_auto) {
1126 set_language(s->language);
1127 }
1128 }
bd5635a1
RP
1129}
1130
777bef06
JK
1131/* Store the selected frame and its level into *FRAMEP and *LEVELP.
1132 If there is no selected frame, *FRAMEP is set to NULL. */
bd5635a1
RP
1133
1134void
1135record_selected_frame (frameaddrp, levelp)
1a494973 1136 CORE_ADDR *frameaddrp;
bd5635a1
RP
1137 int *levelp;
1138{
1a494973 1139 *frameaddrp = selected_frame ? selected_frame->frame : 0;
bd5635a1
RP
1140 *levelp = selected_frame_level;
1141}
1142
1143/* Return the symbol-block in which the selected frame is executing.
1144 Can return zero under various legitimate circumstances. */
1145
1146struct block *
1147get_selected_block ()
1148{
1149 if (!target_has_stack)
1150 return 0;
1151
1152 if (!selected_frame)
1153 return get_current_block ();
1154 return get_frame_block (selected_frame);
1155}
1156
1157/* Find a frame a certain number of levels away from FRAME.
1158 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1159 Positive means go to earlier frames (up); negative, the reverse.
1160 The int that contains the number of levels is counted toward
1161 zero as the frames for those levels are found.
1162 If the top or bottom frame is reached, that frame is returned,
1163 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1164 how much farther the original request asked to go. */
1165
1a494973 1166struct frame_info *
bd5635a1 1167find_relative_frame (frame, level_offset_ptr)
1a494973
C
1168 register struct frame_info *frame;
1169 register int *level_offset_ptr;
bd5635a1 1170{
1a494973
C
1171 register struct frame_info *prev;
1172 register struct frame_info *frame1;
bd5635a1
RP
1173
1174 /* Going up is simple: just do get_prev_frame enough times
1175 or until initial frame is reached. */
1176 while (*level_offset_ptr > 0)
1177 {
1178 prev = get_prev_frame (frame);
1179 if (prev == 0)
1180 break;
1181 (*level_offset_ptr)--;
1182 frame = prev;
1183 }
d8ce1326 1184 /* Going down is just as simple. */
bd5635a1
RP
1185 if (*level_offset_ptr < 0)
1186 {
cadbb07a
JG
1187 while (*level_offset_ptr < 0) {
1188 frame1 = get_next_frame (frame);
1189 if (!frame1)
1190 break;
1191 frame = frame1;
1192 (*level_offset_ptr)++;
1193 }
bd5635a1
RP
1194 }
1195 return frame;
1196}
1197
c4668207 1198/* The "select_frame" command. With no arg, NOP.
bd5635a1
RP
1199 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1200 valid level. Otherwise, treat level_exp as an address expression
b0077123 1201 and select it. See parse_frame_specification for more info on proper
bd5635a1
RP
1202 frame expressions. */
1203
c4668207 1204/* ARGSUSED */
bd5635a1 1205static void
c4668207 1206select_frame_command (level_exp, from_tty)
bd5635a1
RP
1207 char *level_exp;
1208 int from_tty;
1209{
1a494973 1210 register struct frame_info *frame, *frame1;
bd5635a1
RP
1211 unsigned int level = 0;
1212
1213 if (!target_has_stack)
1214 error ("No stack.");
1215
1216 frame = parse_frame_specification (level_exp);
1217
cadbb07a
JG
1218 /* Try to figure out what level this frame is. But if there is
1219 no current stack, don't error out -- let the user set one. */
1220 frame1 = 0;
1221 if (get_current_frame()) {
1222 for (frame1 = get_prev_frame (0);
1223 frame1 && frame1 != frame;
1224 frame1 = get_prev_frame (frame1))
1225 level++;
1226 }
bd5635a1
RP
1227
1228 if (!frame1)
1229 level = 0;
1230
1231 select_frame (frame, level);
b0077123 1232}
bd5635a1 1233
b0077123 1234/* The "frame" command. With no arg, print selected frame briefly.
c4668207 1235 With arg, behaves like select_frame and then prints the selected
b0077123 1236 frame. */
bd5635a1 1237
b0077123
JG
1238static void
1239frame_command (level_exp, from_tty)
1240 char *level_exp;
1241 int from_tty;
1242{
c4668207 1243 select_frame_command (level_exp, from_tty);
bd5635a1
RP
1244 print_stack_frame (selected_frame, selected_frame_level, 1);
1245}
1246
1247/* Select the frame up one or COUNT stack levels
1248 from the previously selected frame, and print it briefly. */
1249
e1ce8aa5 1250/* ARGSUSED */
bd5635a1
RP
1251static void
1252up_silently_command (count_exp, from_tty)
1253 char *count_exp;
1254 int from_tty;
1255{
1a494973 1256 register struct frame_info *fi;
bd5635a1
RP
1257 int count = 1, count1;
1258 if (count_exp)
1259 count = parse_and_eval_address (count_exp);
1260 count1 = count;
1261
0f552c5f 1262 if (target_has_stack == 0 || selected_frame == 0)
bd5635a1
RP
1263 error ("No stack.");
1264
1a494973 1265 fi = find_relative_frame (selected_frame, &count1);
bd5635a1
RP
1266 if (count1 != 0 && count_exp == 0)
1267 error ("Initial frame selected; you cannot go up.");
1a494973 1268 select_frame (fi, selected_frame_level + count - count1);
bd5635a1
RP
1269}
1270
1271static void
1272up_command (count_exp, from_tty)
1273 char *count_exp;
1274 int from_tty;
1275{
1276 up_silently_command (count_exp, from_tty);
1277 print_stack_frame (selected_frame, selected_frame_level, 1);
1278}
1279
1280/* Select the frame down one or COUNT stack levels
1281 from the previously selected frame, and print it briefly. */
1282
e1ce8aa5 1283/* ARGSUSED */
bd5635a1
RP
1284static void
1285down_silently_command (count_exp, from_tty)
1286 char *count_exp;
1287 int from_tty;
1288{
1a494973 1289 register struct frame_info *frame;
bd5635a1
RP
1290 int count = -1, count1;
1291 if (count_exp)
1292 count = - parse_and_eval_address (count_exp);
1293 count1 = count;
1294
0f552c5f 1295 if (target_has_stack == 0 || selected_frame == 0)
89e0bbcd
JG
1296 error ("No stack.");
1297
bd5635a1
RP
1298 frame = find_relative_frame (selected_frame, &count1);
1299 if (count1 != 0 && count_exp == 0)
4f983400
JK
1300 {
1301
1302 /* We only do this if count_exp is not specified. That way "down"
1303 means to really go down (and let me know if that is
1304 impossible), but "down 9999" can be used to mean go all the way
1305 down without getting an error. */
1306
1307 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1308 }
1309
bd5635a1
RP
1310 select_frame (frame, selected_frame_level + count - count1);
1311}
1312
1313
1314static void
1315down_command (count_exp, from_tty)
1316 char *count_exp;
1317 int from_tty;
1318{
1319 down_silently_command (count_exp, from_tty);
1320 print_stack_frame (selected_frame, selected_frame_level, 1);
1321}
1322\f
1323static void
1324return_command (retval_exp, from_tty)
1325 char *retval_exp;
1326 int from_tty;
1327{
777bef06 1328 struct symbol *thisfun;
1a494973 1329 CORE_ADDR selected_frame_addr;
777bef06 1330 CORE_ADDR selected_frame_pc;
1a494973 1331 struct frame_info *frame;
d24c0599 1332 value_ptr return_value = NULL;
bd5635a1 1333
777bef06
JK
1334 if (selected_frame == NULL)
1335 error ("No selected frame.");
1336 thisfun = get_frame_function (selected_frame);
1337 selected_frame_addr = FRAME_FP (selected_frame);
1a494973 1338 selected_frame_pc = selected_frame->pc;
777bef06 1339
78cab901 1340 /* Compute the return value (if any -- possibly getting errors here). */
0f552c5f
JG
1341
1342 if (retval_exp)
1343 {
1a494973
C
1344 struct type *return_type = NULL;
1345
0f552c5f 1346 return_value = parse_and_eval (retval_exp);
78cab901 1347
1a494973
C
1348 /* Cast return value to the return type of the function. */
1349 if (thisfun != NULL)
1350 return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
1351 if (return_type == NULL)
1352 return_type = builtin_type_int;
1353 return_value = value_cast (return_type, return_value);
1354
78cab901
JK
1355 /* Make sure we have fully evaluated it, since
1356 it might live in the stack frame we're about to pop. */
1357 if (VALUE_LAZY (return_value))
1358 value_fetch_lazy (return_value);
0f552c5f
JG
1359 }
1360
bd5635a1
RP
1361 /* If interactive, require confirmation. */
1362
1363 if (from_tty)
1364 {
1365 if (thisfun != 0)
1366 {
bd5d07d9 1367 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
b4fde6fa
FF
1368 {
1369 error ("Not confirmed.");
1370 /* NOTREACHED */
1371 }
bd5635a1
RP
1372 }
1373 else
1374 if (!query ("Make selected stack frame return now? "))
1375 error ("Not confirmed.");
1376 }
1377
1378 /* Do the real work. Pop until the specified frame is current. We
1379 use this method because the selected_frame is not valid after
1380 a POP_FRAME. The pc comparison makes this work even if the
1381 selected frame shares its fp with another frame. */
1382
1a494973
C
1383 while (selected_frame_addr != (frame = get_current_frame())->frame
1384 || selected_frame_pc != frame->pc)
bd5635a1
RP
1385 POP_FRAME;
1386
1387 /* Then pop that frame. */
1388
1389 POP_FRAME;
1390
1391 /* Compute the return value (if any) and store in the place
1392 for return values. */
1393
1394 if (retval_exp)
0f552c5f 1395 set_return_value (return_value);
bd5635a1
RP
1396
1397 /* If interactive, print the frame that is now current. */
1398
1399 if (from_tty)
1400 frame_command ("0", 1);
d0e0eca2
FF
1401 else
1402 select_frame_command ("0", 0);
bd5635a1 1403}
89e0bbcd 1404
1a494973
C
1405/* Gets the language of the current frame. */
1406
89e0bbcd
JG
1407enum language
1408get_frame_language()
1409{
1a494973
C
1410 register struct symtab *s;
1411 enum language flang; /* The language of the current frame */
89e0bbcd 1412
1a494973
C
1413 if (selected_frame)
1414 {
1415 s = find_pc_symtab(selected_frame->pc);
1416 if (s)
1417 flang = s->language;
89e0bbcd 1418 else
1a494973
C
1419 flang = language_unknown;
1420 }
1421 else
1422 flang = language_unknown;
89e0bbcd 1423
1a494973 1424 return flang;
89e0bbcd 1425}
bd5635a1
RP
1426\f
1427void
1428_initialize_stack ()
1429{
1430#if 0
1431 backtrace_limit = 30;
1432#endif
1433
1434 add_com ("return", class_stack, return_command,
1435 "Make selected stack frame return to its caller.\n\
1436Control remains in the debugger, but when you continue\n\
1437execution will resume in the frame above the one now selected.\n\
1438If an argument is given, it is an expression for the value to return.");
1439
1440 add_com ("up", class_stack, up_command,
1441 "Select and print stack frame that called this one.\n\
1442An argument says how many frames up to go.");
1443 add_com ("up-silently", class_support, up_silently_command,
1444 "Same as the `up' command, but does not print anything.\n\
1445This is useful in command scripts.");
1446
1447 add_com ("down", class_stack, down_command,
1448 "Select and print stack frame called by this one.\n\
1449An argument says how many frames down to go.");
1450 add_com_alias ("do", "down", class_stack, 1);
3de61d8c 1451 add_com_alias ("dow", "down", class_stack, 1);
bd5635a1
RP
1452 add_com ("down-silently", class_support, down_silently_command,
1453 "Same as the `down' command, but does not print anything.\n\
1454This is useful in command scripts.");
1455
1456 add_com ("frame", class_stack, frame_command,
1457 "Select and print a stack frame.\n\
1458With no argument, print the selected stack frame. (See also \"info frame\").\n\
1459An argument specifies the frame to select.\n\
1460It can be a stack frame number or the address of the frame.\n\
1461With argument, nothing is printed if input is coming from\n\
1462a command file or a user-defined command.");
1463
1464 add_com_alias ("f", "frame", class_stack, 1);
1465
c4668207 1466 add_com ("select-frame", class_stack, select_frame_command,
b0077123
JG
1467 "Select a stack frame without printing anything.\n\
1468An argument specifies the frame to select.\n\
1469It can be a stack frame number or the address of the frame.\n");
1470
bd5635a1
RP
1471 add_com ("backtrace", class_stack, backtrace_command,
1472 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1473With a negative argument, print outermost -COUNT frames.");
1474 add_com_alias ("bt", "backtrace", class_stack, 0);
1475 add_com_alias ("where", "backtrace", class_alias, 0);
1476 add_info ("stack", backtrace_command,
1477 "Backtrace of the stack, or innermost COUNT frames.");
1478 add_info_alias ("s", "stack", 1);
1479 add_info ("frame", frame_info,
1480 "All about selected stack frame, or frame at ADDR.");
1481 add_info_alias ("f", "frame", 1);
1482 add_info ("locals", locals_info,
1483 "Local variables of current stack frame.");
1484 add_info ("args", args_info,
1485 "Argument variables of current stack frame.");
1486 add_info ("catch", catch_info,
1487 "Exceptions that can be caught in the current stack frame.");
1488
1489#if 0
1490 add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
1491 "Specify maximum number of frames for \"backtrace\" to print by default.",
1492 &setlist);
1493 add_info ("backtrace-limit", backtrace_limit_info,
1494 "The maximum number of frames for \"backtrace\" to print by default.");
1495#endif
1496}
This page took 0.34609 seconds and 4 git commands to generate.