1999-01-19 Fernando Nasser <fnasser@totem.to.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / stack.c
CommitLineData
bd5635a1 1/* Print and select stack frames for GDB, the GNU debugger.
9ddf9aa9 2 Copyright 1986, 87, 89, 91, 92, 93, 94, 95, 96, 1998
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
65b07ddc 21#include <ctype.h>
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"
9ddf9aa9
AC
37#include "symfile.h"
38#include "objfiles.h"
39
40/* Prototypes for exported functions. */
41
42void args_info PARAMS ((char *, int));
43
44void locals_info PARAMS ((char *, int));
45
46void (*selected_frame_level_changed_hook) PARAMS ((int));
47
48void _initialize_stack PARAMS ((void));
49
50/* Prototypes for local functions. */
b4fde6fa 51
1a494973 52static void return_command PARAMS ((char *, int));
b4fde6fa 53
1a494973 54static void down_command PARAMS ((char *, int));
b4fde6fa 55
65b07ddc
DT
56static void down_silently_base PARAMS ((char *));
57
1a494973 58static void down_silently_command PARAMS ((char *, int));
b4fde6fa 59
1a494973 60static void up_command PARAMS ((char *, int));
b4fde6fa 61
65b07ddc
DT
62static void up_silently_base PARAMS ((char *));
63
1a494973 64static void up_silently_command PARAMS ((char *, int));
b4fde6fa 65
65b07ddc 66void frame_command PARAMS ((char *, int));
b4fde6fa 67
1a494973 68static void select_frame_command PARAMS ((char *, int));
b4fde6fa 69
1a494973 70static void print_frame_arg_vars PARAMS ((struct frame_info *, GDB_FILE *));
b4fde6fa 71
1a494973 72static void catch_info PARAMS ((char *, int));
b4fde6fa 73
65b07ddc
DT
74static void args_plus_locals_info PARAMS ((char *, int));
75
76static void print_frame_label_vars PARAMS ((struct frame_info *,
77 int,
1a494973 78 GDB_FILE *));
b4fde6fa 79
65b07ddc
DT
80static void print_frame_local_vars PARAMS ((struct frame_info *,
81 int,
82 GDB_FILE *));
b4fde6fa 83
1a494973
C
84static int print_block_frame_labels PARAMS ((struct block *, int *,
85 GDB_FILE *));
b4fde6fa 86
1a494973
C
87static int print_block_frame_locals PARAMS ((struct block *,
88 struct frame_info *,
65b07ddc 89 int,
1a494973 90 GDB_FILE *));
b4fde6fa 91
65b07ddc
DT
92static void print_frame_info_base PARAMS ((struct frame_info *, int, int, int));
93
94static void print_stack_frame_base PARAMS ((struct frame_info *, int, int));
95
1a494973 96static void backtrace_command PARAMS ((char *, int));
b4fde6fa 97
65b07ddc 98struct frame_info *parse_frame_specification PARAMS ((char *));
b4fde6fa 99
1a494973 100static void frame_info PARAMS ((char *, int));
bd5635a1
RP
101
102extern int addressprint; /* Print addresses, or stay symbolic only? */
103extern int info_verbose; /* Verbosity of symbol reading msgs */
d8ce1326 104extern int lines_to_list; /* # of lines "list" command shows by default */
bd5635a1 105
b4fde6fa 106/* The "selected" stack frame is used by default for local and arg access.
bd5635a1
RP
107 May be zero, for no selected frame. */
108
1a494973 109struct frame_info *selected_frame;
bd5635a1
RP
110
111/* Level of the selected frame:
112 0 for innermost, 1 for its caller, ...
113 or -1 for frame specified by address with no defined level. */
114
115int selected_frame_level;
116
d24c0599
JK
117/* Zero means do things normally; we are interacting directly with the
118 user. One means print the full filename and linenumber when a
119 frame is printed, and do so in a format emacs18/emacs19.22 can
120 parse. Two means print similar annotations, but in many more
121 cases and in a slightly different syntax. */
bd5635a1 122
d24c0599 123int annotation_level = 0;
bd5635a1 124
bd5635a1 125\f
199b2450
TL
126struct print_stack_frame_args {
127 struct frame_info *fi;
128 int level;
129 int source;
130 int args;
131};
132
65b07ddc 133static int print_stack_frame_base_stub PARAMS ((char *));
199b2450 134
65b07ddc
DT
135/* Show and print the frame arguments.
136 Pass the args the way catch_errors wants them. */
199b2450 137static int
65b07ddc 138show_and_print_stack_frame_stub (args)
199b2450
TL
139 char *args;
140{
141 struct print_stack_frame_args *p = (struct print_stack_frame_args *)args;
1a494973 142
65b07ddc
DT
143 /* Reversed order of these so tuiDo() doesn't occur
144 * in the middle of "Breakpoint 1 ... [location]" printing = RT
145 */
146 if (tui_version)
147 print_frame_info_base (p->fi, p->level, p->source, p->args);
199b2450 148 print_frame_info (p->fi, p->level, p->source, p->args);
65b07ddc
DT
149
150 return 0;
151}
152
153/* Show or print the frame arguments.
154 Pass the args the way catch_errors wants them. */
155static int
156print_stack_frame_stub (args)
157 char *args;
158{
159 struct print_stack_frame_args *p = (struct print_stack_frame_args *)args;
160
161 if (tui_version)
162 print_frame_info (p->fi, p->level, p->source, p->args);
163 else
164 print_frame_info_base (p->fi, p->level, p->source, p->args);
165 return 0;
166}
167
168/* Print a stack frame briefly. FRAME_INFI should be the frame info
169 and LEVEL should be its level in the stack (or -1 for level not defined).
170
171/* Pass the args the way catch_errors wants them. */
172static int
173print_stack_frame_base_stub (args)
174 char *args;
175{
176 struct print_stack_frame_args *p = (struct print_stack_frame_args *)args;
177
178 print_frame_info_base (p->fi, p->level, p->source, p->args);
179 return 0;
180}
181
182/* print the frame arguments to the terminal.
183 Pass the args the way catch_errors wants them. */
184static int
185print_only_stack_frame_stub (args)
186 char *args;
187{
188 struct print_stack_frame_args *p = (struct print_stack_frame_args *)args;
189
190 print_frame_info_base (p->fi, p->level, p->source, p->args);
199b2450
TL
191 return 0;
192}
193
1a494973 194/* Print a stack frame briefly. FRAME_INFI should be the frame info
bd5635a1
RP
195 and LEVEL should be its level in the stack (or -1 for level not defined).
196 This prints the level, the function executing, the arguments,
197 and the file name and line number.
198 If the pc is not at the beginning of the source line,
199 the actual pc is printed at the beginning.
200
201 If SOURCE is 1, print the source line as well.
202 If SOURCE is -1, print ONLY the source line. */
203
65b07ddc
DT
204static void
205print_stack_frame_base (fi, level, source)
206 struct frame_info *fi;
207 int level;
208 int source;
209{
210 struct print_stack_frame_args args;
211
212 args.fi = fi;
213 args.level = level;
214 args.source = source;
215 args.args = 1;
216
217 catch_errors (print_stack_frame_stub, (char *)&args, "", RETURN_MASK_ALL);
218}
219
220/* Show and print a stack frame briefly. FRAME_INFI should be the frame info
221 and LEVEL should be its level in the stack (or -1 for level not defined).
222 This prints the level, the function executing, the arguments,
223 and the file name and line number.
224 If the pc is not at the beginning of the source line,
225 the actual pc is printed at the beginning.
226
227 If SOURCE is 1, print the source line as well.
228 If SOURCE is -1, print ONLY the source line. */
229
230void
231show_and_print_stack_frame (fi, level, source)
232 struct frame_info *fi;
233 int level;
234 int source;
235{
236 struct print_stack_frame_args args;
237
238 args.fi = fi;
239 args.level = level;
240 args.source = source;
241 args.args = 1;
242
243 catch_errors (show_and_print_stack_frame_stub, (char *)&args, "", RETURN_MASK_ALL);
244}
245
246
247/* Show or print a stack frame briefly. FRAME_INFI should be the frame info
248 and LEVEL should be its level in the stack (or -1 for level not defined).
249 This prints the level, the function executing, the arguments,
250 and the file name and line number.
251 If the pc is not at the beginning of the source line,
252 the actual pc is printed at the beginning.
253
254 If SOURCE is 1, print the source line as well.
255 If SOURCE is -1, print ONLY the source line. */
256
cadbb07a 257void
1a494973
C
258print_stack_frame (fi, level, source)
259 struct frame_info *fi;
bd5635a1
RP
260 int level;
261 int source;
262{
199b2450 263 struct print_stack_frame_args args;
bd5635a1 264
1a494973 265 args.fi = fi;
199b2450
TL
266 args.level = level;
267 args.source = source;
268 args.args = 1;
bd5635a1 269
9ddf9aa9 270 catch_errors (print_stack_frame_stub, (char *)&args, "", RETURN_MASK_ALL);
bd5635a1
RP
271}
272
65b07ddc
DT
273/* Print a stack frame briefly. FRAME_INFI should be the frame info
274 and LEVEL should be its level in the stack (or -1 for level not defined).
275 This prints the level, the function executing, the arguments,
276 and the file name and line number.
277 If the pc is not at the beginning of the source line,
278 the actual pc is printed at the beginning.
279
280 If SOURCE is 1, print the source line as well.
281 If SOURCE is -1, print ONLY the source line. */
282
283void
284print_only_stack_frame (fi, level, source)
285 struct frame_info *fi;
286 int level;
287 int source;
288{
289 struct print_stack_frame_args args;
290
291 args.fi = fi;
292 args.level = level;
293 args.source = source;
294 args.args = 1;
295
296 catch_errors (print_only_stack_frame_stub,
297 (char *)&args, "", RETURN_MASK_ALL);
298}
299
c94e7e75
JK
300struct print_args_args {
301 struct symbol *func;
302 struct frame_info *fi;
303};
304
305static int print_args_stub PARAMS ((char *));
306
307/* Pass the args the way catch_errors wants them. */
1a494973 308
c94e7e75
JK
309static int
310print_args_stub (args)
311 char *args;
312{
313 int numargs;
314 struct print_args_args *p = (struct print_args_args *)args;
1a494973 315
c94e7e75 316 FRAME_NUM_ARGS (numargs, (p->fi));
199b2450 317 print_frame_args (p->func, p->fi, numargs, gdb_stdout);
c94e7e75
JK
318 return 0;
319}
320
65b07ddc
DT
321/* Print information about a frame for frame "fi" at level "level".
322 * Used in "where" output, also used to emit breakpoint or step messages.
323 * LEVEL is the level of the frame, or -1 if it is the innermost frame
324 * but we don't want to print the level.
325 * The meaning of the SOURCE argument is:
326 * -1: Print only source line
327 * 0: Print only location
328 * 1: Print location and source line
329 */
1a494973 330
65b07ddc
DT
331static void
332print_frame_info_base (fi, level, source, args)
bd5635a1 333 struct frame_info *fi;
65b07ddc 334 int level;
bd5635a1
RP
335 int source;
336 int args;
337{
338 struct symtab_and_line sal;
339 struct symbol *func;
340 register char *funname = 0;
bd5d07d9 341 enum language funlang = language_unknown;
1a494973
C
342
343#if 0
dff84871
PS
344 char buf[MAX_REGISTER_RAW_SIZE];
345 CORE_ADDR sp;
346
05052b63
JK
347 /* On the 68k, this spends too much time in m68k_find_saved_regs. */
348
dff84871
PS
349 /* Get the value of SP_REGNUM relative to the frame. */
350 get_saved_register (buf, (int *)NULL, (CORE_ADDR *)NULL,
351 FRAME_INFO_ID (fi), SP_REGNUM, (enum lval_type *)NULL);
352 sp = extract_address (buf, REGISTER_RAW_SIZE (SP_REGNUM));
353
354 /* This is not a perfect test, because if a function alloca's some
355 memory, puts some code there, and then jumps into it, then the test
78cab901
JK
356 will succeed even though there is no call dummy. Probably best is
357 to check for a bp_call_dummy breakpoint. */
dff84871 358 if (PC_IN_CALL_DUMMY (fi->pc, sp, fi->frame))
05052b63
JK
359#else
360 if (frame_in_dummy (fi))
361#endif
df2a1bd7 362 {
1a494973
C
363 annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
364
df2a1bd7
JK
365 /* Do this regardless of SOURCE because we don't have any source
366 to list for this frame. */
367 if (level >= 0)
368 printf_filtered ("#%-2d ", level);
1a494973 369 annotate_function_call ();
df2a1bd7 370 printf_filtered ("<function called from gdb>\n");
1a494973 371 annotate_frame_end ();
df2a1bd7
JK
372 return;
373 }
cee86be3
JK
374 if (fi->signal_handler_caller)
375 {
1a494973
C
376 annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
377
cee86be3
JK
378 /* Do this regardless of SOURCE because we don't have any source
379 to list for this frame. */
380 if (level >= 0)
381 printf_filtered ("#%-2d ", level);
1a494973 382 annotate_signal_handler_caller ();
cee86be3 383 printf_filtered ("<signal handler called>\n");
1a494973 384 annotate_frame_end ();
cee86be3
JK
385 return;
386 }
b4fde6fa 387
46c28185
RP
388 /* If fi is not the innermost frame, that normally means that fi->pc
389 points to *after* the call instruction, and we want to get the line
390 containing the call, never the next line. But if the next frame is
f1de67d3
PS
391 a signal_handler_caller or a dummy frame, then the next frame was
392 not entered as the result of a call, and we want to get the line
393 containing fi->pc. */
46c28185
RP
394 sal =
395 find_pc_line (fi->pc,
f1de67d3
PS
396 fi->next != NULL
397 && !fi->next->signal_handler_caller
398 && !frame_in_dummy (fi->next));
46c28185 399
bd5635a1
RP
400 func = find_pc_function (fi->pc);
401 if (func)
402 {
403 /* In certain pathological cases, the symtabs give the wrong
404 function (when we are in the first function in a file which
405 is compiled without debugging symbols, the previous function
406 is compiled with debugging symbols, and the "foo.o" symbol
407 that is supposed to tell us where the file with debugging symbols
408 ends has been truncated by ar because it is longer than 15
dff84871
PS
409 characters). This also occurs if the user uses asm() to create
410 a function but not stabs for it (in a file compiled -g).
bd5635a1 411
b4fde6fa 412 So look in the minimal symbol tables as well, and if it comes
bd5635a1 413 up with a larger address for the function use that instead.
b4fde6fa 414 I don't think this can ever cause any problems; there shouldn't
dff84871
PS
415 be any minimal symbols in the middle of a function; if this is
416 ever changed many parts of GDB will need to be changed (and we'll
417 create a find_pc_minimal_function or some such). */
b4fde6fa
FF
418
419 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
420 if (msymbol != NULL
bd5d07d9 421 && (SYMBOL_VALUE_ADDRESS (msymbol)
bd5635a1
RP
422 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
423 {
d24c0599
JK
424#if 0
425 /* There is no particular reason to think the line number
426 information is wrong. Someone might have just put in
427 a label with asm() but left the line numbers alone. */
bd5635a1
RP
428 /* In this case we have no way of knowing the source file
429 and line number, so don't print them. */
430 sal.symtab = 0;
d24c0599 431#endif
bd5635a1
RP
432 /* We also don't know anything about the function besides
433 its address and name. */
434 func = 0;
bd5d07d9
FF
435 funname = SYMBOL_NAME (msymbol);
436 funlang = SYMBOL_LANGUAGE (msymbol);
bd5635a1
RP
437 }
438 else
bd5d07d9 439 {
65b07ddc
DT
440 /* I'd like to use SYMBOL_SOURCE_NAME() here, to display
441 * the demangled name that we already have stored in
442 * the symbol table, but we stored a version with
443 * DMGL_PARAMS turned on, and here we don't want
444 * to display parameters. So call the demangler again,
445 * with DMGL_ANSI only. RT
446 * (Yes, I know that printf_symbol_filtered() will
447 * again try to demangle the name on the fly, but
448 * the issue is that if cplus_demangle() fails here,
449 * it'll fail there too. So we want to catch the failure
450 * ("demangled==NULL" case below) here, while we still
451 * have our hands on the function symbol.)
452 */
453 char * demangled;
bd5d07d9
FF
454 funname = SYMBOL_NAME (func);
455 funlang = SYMBOL_LANGUAGE (func);
65b07ddc
DT
456 if (funlang == language_cplus) {
457 demangled = cplus_demangle (funname, DMGL_ANSI);
458 if (demangled == NULL)
459 /* If the demangler fails, try the demangled name
460 * from the symbol table. This'll have parameters,
461 * but that's preferable to diplaying a mangled name.
462 */
463 funname = SYMBOL_SOURCE_NAME (func);
464 }
bd5d07d9 465 }
bd5635a1
RP
466 }
467 else
468 {
9ddf9aa9 469 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
b4fde6fa 470 if (msymbol != NULL)
bd5d07d9
FF
471 {
472 funname = SYMBOL_NAME (msymbol);
473 funlang = SYMBOL_LANGUAGE (msymbol);
474 }
bd5635a1
RP
475 }
476
477 if (source >= 0 || !sal.symtab)
478 {
1a494973
C
479 annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
480
bd5635a1
RP
481 if (level >= 0)
482 printf_filtered ("#%-2d ", level);
483 if (addressprint)
484 if (fi->pc != sal.pc || !sal.symtab)
833e0d94 485 {
1a494973 486 annotate_frame_address ();
d24c0599 487 print_address_numeric (fi->pc, 1, gdb_stdout);
1a494973 488 annotate_frame_address_end ();
833e0d94
JK
489 printf_filtered (" in ");
490 }
1a494973 491 annotate_frame_function_name ();
199b2450 492 fprintf_symbol_filtered (gdb_stdout, funname ? funname : "??", funlang,
05052b63 493 DMGL_ANSI);
bd5635a1 494 wrap_here (" ");
1a494973 495 annotate_frame_args ();
199b2450 496 fputs_filtered (" (", gdb_stdout);
bd5635a1
RP
497 if (args)
498 {
c94e7e75
JK
499 struct print_args_args args;
500 args.fi = fi;
501 args.func = func;
9ddf9aa9
AC
502 catch_errors (print_args_stub, (char *)&args, "", RETURN_MASK_ALL);
503 QUIT;
bd5635a1
RP
504 }
505 printf_filtered (")");
506 if (sal.symtab && sal.symtab->filename)
507 {
1a494973 508 annotate_frame_source_begin ();
bd5635a1 509 wrap_here (" ");
1a494973
C
510 printf_filtered (" at ");
511 annotate_frame_source_file ();
512 printf_filtered ("%s", sal.symtab->filename);
513 annotate_frame_source_file_end ();
514 printf_filtered (":");
515 annotate_frame_source_line ();
516 printf_filtered ("%d", sal.line);
517 annotate_frame_source_end ();
bd5635a1 518 }
b4fde6fa
FF
519
520#ifdef PC_LOAD_SEGMENT
521 /* If we couldn't print out function name but if can figure out what
522 load segment this pc value is from, at least print out some info
523 about its load segment. */
1a494973
C
524 if (!funname)
525 {
526 annotate_frame_where ();
527 wrap_here (" ");
528 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc));
529 }
d0e0eca2
FF
530#endif
531#ifdef PC_SOLIB
65b07ddc 532 if (!funname || (!sal.symtab || !sal.symtab->filename))
d0e0eca2
FF
533 {
534 char *lib = PC_SOLIB (fi->pc);
535 if (lib)
536 {
537 annotate_frame_where ();
538 wrap_here (" ");
539 printf_filtered (" from %s", lib);
540 }
541 }
b4fde6fa 542#endif
bd5635a1
RP
543 printf_filtered ("\n");
544 }
545
546 if ((source != 0) && sal.symtab)
547 {
548 int done = 0;
549 int mid_statement = source < 0 && fi->pc != sal.pc;
d24c0599 550 if (annotation_level)
c94e7e75
JK
551 done = identify_source_line (sal.symtab, sal.line, mid_statement,
552 fi->pc);
bd5635a1
RP
553 if (!done)
554 {
65b07ddc 555 if (addressprint && mid_statement && !tui_version)
833e0d94 556 {
d24c0599 557 print_address_numeric (fi->pc, 1, gdb_stdout);
833e0d94
JK
558 printf_filtered ("\t");
559 }
1a494973
C
560 if (print_frame_info_listing_hook)
561 print_frame_info_listing_hook (sal.symtab, sal.line, sal.line + 1, 0);
65b07ddc 562 else if (!tui_version)
1a494973 563 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
bd5635a1 564 }
cadbb07a 565 current_source_line = max (sal.line - lines_to_list/2, 1);
bd5635a1
RP
566 }
567 if (source != 0)
568 set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
569
1a494973
C
570 annotate_frame_end ();
571
199b2450 572 gdb_flush (gdb_stdout);
bd5635a1 573}
65b07ddc
DT
574\f
575
576void
577stack_publish_stopped_with_no_frame()
578{
579 TUIDO(((TuiOpaqueFuncPtr)tuiUpdateOnEnd));
580
581 return;
582}
bd5635a1 583
65b07ddc
DT
584/* Show or print the frame info. If this is the tui, it will be shown in
585 the source display */
586void
587print_frame_info(fi, level, source, args)
588 struct frame_info *fi;
589 register int level;
590 int source;
591 int args;
592{
593 if (!tui_version)
594 print_frame_info_base(fi, level, source, args);
595 else
596 {
597 if (fi && (frame_in_dummy(fi) || fi->signal_handler_caller))
598 print_frame_info_base(fi, level, source, args);
599 else
600 {
601 TUIDO(((TuiOpaqueFuncPtr)tui_vShowFrameInfo, fi));
602 }
603 }
604}
605
606/* Show the frame info. If this is the tui, it will be shown in
607 the source display otherwise, nothing is done */
608void
609show_stack_frame(fi)
610 struct frame_info *fi;
611{
612 TUIDO(((TuiOpaqueFuncPtr)tui_vShowFrameInfo, fi));
613}
614
615\f
1a494973
C
616/* Read a frame specification in whatever the appropriate format is.
617 Call error() if the specification is in any way invalid (i.e.
618 this function never returns NULL). */
619
65b07ddc 620struct frame_info *
bd5635a1
RP
621parse_frame_specification (frame_exp)
622 char *frame_exp;
623{
624 int numargs = 0;
bd5d07d9 625#define MAXARGS 4
78cab901 626 CORE_ADDR args[MAXARGS];
bd5635a1
RP
627
628 if (frame_exp)
629 {
630 char *addr_string, *p;
631 struct cleanup *tmp_cleanup;
632
633 while (*frame_exp == ' ') frame_exp++;
bd5635a1 634
bd5d07d9 635 while (*frame_exp)
bd5635a1 636 {
bd5d07d9
FF
637 if (numargs > MAXARGS)
638 error ("Too many args in frame specification");
639 /* Parse an argument. */
640 for (p = frame_exp; *p && *p != ' '; p++)
641 ;
bd5635a1
RP
642 addr_string = savestring(frame_exp, p - frame_exp);
643
644 {
645 tmp_cleanup = make_cleanup (free, addr_string);
bd5d07d9 646 args[numargs++] = parse_and_eval_address (addr_string);
bd5635a1
RP
647 do_cleanups (tmp_cleanup);
648 }
649
bd5d07d9 650 /* Skip spaces, move to possible next arg. */
bd5635a1 651 while (*p == ' ') p++;
bd5d07d9 652 frame_exp = p;
bd5635a1
RP
653 }
654 }
655
656 switch (numargs)
657 {
658 case 0:
777bef06
JK
659 if (selected_frame == NULL)
660 error ("No selected frame.");
bd5635a1
RP
661 return selected_frame;
662 /* NOTREACHED */
663 case 1:
664 {
bd5d07d9 665 int level = args[0];
1a494973
C
666 struct frame_info *fid =
667 find_relative_frame (get_current_frame (), &level);
668 struct frame_info *tfid;
bd5635a1
RP
669
670 if (level == 0)
671 /* find_relative_frame was successful */
672 return fid;
673
d24c0599
JK
674 /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications
675 take at least 2 addresses. It is important to detect this case
676 here so that "frame 100" does not give a confusing error message
677 like "frame specification requires two addresses". This of course
678 does not solve the "frame 100" problem for machines on which
679 a frame specification can be made with one address. To solve
680 that, we need a new syntax for a specifying a frame by address.
681 I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for
682 two args, etc.), but people might think that is too much typing,
683 so I guess *0x23,0x45 would be a possible alternative (commas
684 really should be used instead of spaces to delimit; using spaces
685 normally works in an expression). */
686#ifdef SETUP_ARBITRARY_FRAME
687 error ("No frame %d", args[0]);
688#endif
689
bd5635a1
RP
690 /* If (s)he specifies the frame with an address, he deserves what
691 (s)he gets. Still, give the highest one that matches. */
692
693 for (fid = get_current_frame ();
1a494973 694 fid && fid->frame != args[0];
bd5635a1
RP
695 fid = get_prev_frame (fid))
696 ;
697
698 if (fid)
699 while ((tfid = get_prev_frame (fid)) &&
1a494973 700 (tfid->frame == args[0]))
bd5635a1
RP
701 fid = tfid;
702
bd5d07d9 703 /* We couldn't identify the frame as an existing frame, but
d24c0599 704 perhaps we can create one with a single argument. */
bd5635a1 705 }
bd5d07d9
FF
706
707 default:
708#ifdef SETUP_ARBITRARY_FRAME
709 return SETUP_ARBITRARY_FRAME (numargs, args);
bd5635a1 710#else
bd5d07d9
FF
711 /* Usual case. Do it here rather than have everyone supply
712 a SETUP_ARBITRARY_FRAME that does this. */
713 if (numargs == 1)
714 return create_new_frame (args[0], 0);
715 error ("Too many args in frame specification");
bd5635a1
RP
716#endif
717 /* NOTREACHED */
718 }
bd5635a1
RP
719 /* NOTREACHED */
720}
721
722/* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
723 that if it is unsure about the answer, it returns 0
724 instead of guessing (this happens on the VAX and i960, for example).
725
726 On most machines, we never have to guess about the args address,
727 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
728#if !defined (FRAME_ARGS_ADDRESS_CORRECT)
729#define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
730#endif
731
732/* Print verbosely the selected frame or the frame at address ADDR.
733 This means absolutely all information in the frame is printed. */
734
735static void
b4fde6fa 736frame_info (addr_exp, from_tty)
bd5635a1 737 char *addr_exp;
b4fde6fa 738 int from_tty;
bd5635a1 739{
bd5635a1 740 struct frame_info *fi;
bd5635a1
RP
741 struct symtab_and_line sal;
742 struct symbol *func;
89e0bbcd 743 struct symtab *s;
1a494973
C
744 struct frame_info *calling_frame_info;
745 int i, count, numregs;
bd5635a1 746 char *funname = 0;
bd5d07d9 747 enum language funlang = language_unknown;
bd5635a1
RP
748
749 if (!target_has_stack)
6fe90fc8 750 error ("No stack.");
bd5635a1 751
1a494973
C
752 fi = parse_frame_specification (addr_exp);
753 if (fi == NULL)
bd5635a1
RP
754 error ("Invalid frame specified.");
755
dff84871 756 sal = find_pc_line (fi->pc,
f1de67d3
PS
757 fi->next != NULL
758 && !fi->next->signal_handler_caller
759 && !frame_in_dummy (fi->next));
1a494973 760 func = get_frame_function (fi);
89e0bbcd 761 s = find_pc_symtab(fi->pc);
bd5635a1 762 if (func)
bd5d07d9 763 {
65b07ddc
DT
764 /* I'd like to use SYMBOL_SOURCE_NAME() here, to display
765 * the demangled name that we already have stored in
766 * the symbol table, but we stored a version with
767 * DMGL_PARAMS turned on, and here we don't want
768 * to display parameters. So call the demangler again,
769 * with DMGL_ANSI only. RT
770 * (Yes, I know that printf_symbol_filtered() will
771 * again try to demangle the name on the fly, but
772 * the issue is that if cplus_demangle() fails here,
773 * it'll fail there too. So we want to catch the failure
774 * ("demangled==NULL" case below) here, while we still
775 * have our hands on the function symbol.)
776 */
777 char * demangled;
778 funname = SYMBOL_NAME (func);
779 funlang = SYMBOL_LANGUAGE (func);
780 if (funlang == language_cplus)
781 {
782 demangled = cplus_demangle (funname, DMGL_ANSI);
783 /* If the demangler fails, try the demangled name
784 * from the symbol table. This'll have parameters,
785 * but that's preferable to diplaying a mangled name.
786 */
787 if (demangled == NULL)
788 funname = SYMBOL_SOURCE_NAME (func);
789 }
bd5d07d9 790 }
bd5635a1
RP
791 else
792 {
b4fde6fa
FF
793 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
794 if (msymbol != NULL)
bd5d07d9
FF
795 {
796 funname = SYMBOL_NAME (msymbol);
797 funlang = SYMBOL_LANGUAGE (msymbol);
798 }
bd5635a1 799 }
1a494973 800 calling_frame_info = get_prev_frame (fi);
bd5635a1 801
833e0d94
JK
802 if (!addr_exp && selected_frame_level >= 0)
803 {
5e678752 804 printf_filtered ("Stack level %d, frame at ", selected_frame_level);
1a494973 805 print_address_numeric (fi->frame, 1, gdb_stdout);
833e0d94
JK
806 printf_filtered (":\n");
807 }
808 else
809 {
810 printf_filtered ("Stack frame at ");
1a494973 811 print_address_numeric (fi->frame, 1, gdb_stdout);
833e0d94
JK
812 printf_filtered (":\n");
813 }
9ddf9aa9 814 printf_filtered (" %s = ", REGISTER_NAME (PC_REGNUM));
d24c0599 815 print_address_numeric (fi->pc, 1, gdb_stdout);
bd5635a1
RP
816
817 wrap_here (" ");
818 if (funname)
b0077123
JG
819 {
820 printf_filtered (" in ");
199b2450 821 fprintf_symbol_filtered (gdb_stdout, funname, funlang,
5e81259d 822 DMGL_ANSI | DMGL_PARAMS);
b0077123 823 }
bd5635a1
RP
824 wrap_here (" ");
825 if (sal.symtab)
826 printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
827 puts_filtered ("; ");
828 wrap_here (" ");
9ddf9aa9 829 printf_filtered ("saved %s ", REGISTER_NAME (PC_REGNUM));
1a494973 830 print_address_numeric (FRAME_SAVED_PC (fi), 1, gdb_stdout);
833e0d94 831 printf_filtered ("\n");
b4fde6fa
FF
832
833 {
834 int frameless = 0;
835#ifdef FRAMELESS_FUNCTION_INVOCATION
836 FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
837#endif
838 if (frameless)
839 printf_filtered (" (FRAMELESS),");
840 }
841
1a494973 842 if (calling_frame_info)
833e0d94
JK
843 {
844 printf_filtered (" called by frame at ");
1a494973 845 print_address_numeric (calling_frame_info->frame, 1, gdb_stdout);
833e0d94 846 }
1a494973 847 if (fi->next && calling_frame_info)
bd5635a1
RP
848 puts_filtered (",");
849 wrap_here (" ");
23a8e291 850 if (fi->next)
833e0d94
JK
851 {
852 printf_filtered (" caller of frame at ");
d24c0599 853 print_address_numeric (fi->next->frame, 1, gdb_stdout);
833e0d94 854 }
1a494973 855 if (fi->next || calling_frame_info)
bd5635a1 856 puts_filtered ("\n");
89e0bbcd 857 if (s)
833e0d94 858 printf_filtered (" source language %s.\n", language_str (s->language));
bd5635a1 859
bd5d07d9
FF
860#ifdef PRINT_EXTRA_FRAME_INFO
861 PRINT_EXTRA_FRAME_INFO (fi);
862#endif
863
bd5635a1
RP
864 {
865 /* Address of the argument list for this frame, or 0. */
866 CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
867 /* Number of args for this frame, or -1 if unknown. */
868 int numargs;
869
870 if (arg_list == 0)
833e0d94 871 printf_filtered (" Arglist at unknown address.\n");
bd5635a1
RP
872 else
873 {
833e0d94 874 printf_filtered (" Arglist at ");
d24c0599 875 print_address_numeric (arg_list, 1, gdb_stdout);
833e0d94 876 printf_filtered (",");
bd5635a1
RP
877
878 FRAME_NUM_ARGS (numargs, fi);
879 if (numargs < 0)
880 puts_filtered (" args: ");
881 else if (numargs == 0)
882 puts_filtered (" no args.");
883 else if (numargs == 1)
884 puts_filtered (" 1 arg: ");
885 else
886 printf_filtered (" %d args: ", numargs);
199b2450 887 print_frame_args (func, fi, numargs, gdb_stdout);
bd5635a1
RP
888 puts_filtered ("\n");
889 }
890 }
b4fde6fa
FF
891 {
892 /* Address of the local variables for this frame, or 0. */
893 CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
894
895 if (arg_list == 0)
833e0d94 896 printf_filtered (" Locals at unknown address,");
b4fde6fa 897 else
833e0d94
JK
898 {
899 printf_filtered (" Locals at ");
d24c0599 900 print_address_numeric (arg_list, 1, gdb_stdout);
833e0d94
JK
901 printf_filtered (",");
902 }
b4fde6fa 903 }
bd5635a1 904
65b07ddc
DT
905 FRAME_INIT_SAVED_REGS (fi);
906 if (fi->saved_regs != NULL)
907 {
908 /* The sp is special; what's returned isn't the save address, but
909 actually the value of the previous frame's sp. */
910 printf_filtered (" Previous frame's sp is ");
911 print_address_numeric (fi->saved_regs[SP_REGNUM], 1, gdb_stdout);
912 printf_filtered ("\n");
913 count = 0;
914 numregs = ARCH_NUM_REGS;
915 for (i = 0; i < numregs; i++)
916 if (fi->saved_regs[i] && i != SP_REGNUM)
917 {
918 if (count == 0)
919 puts_filtered (" Saved registers:\n ");
920 else
921 puts_filtered (",");
922 wrap_here (" ");
923 printf_filtered (" %s at ", REGISTER_NAME (i));
924 print_address_numeric (fi->saved_regs[i], 1, gdb_stdout);
925 count++;
926 }
927 if (count)
928 puts_filtered ("\n");
929 }
930 else
931 {
932 /* We could get some information about saved registers by
933 calling get_saved_register on each register. Which info goes
934 with which frame is necessarily lost, however, and I suspect
935 that the users don't care whether they get the info. */
936 puts_filtered ("\n");
937 }
bd5635a1
RP
938}
939
940#if 0
941/* Set a limit on the number of frames printed by default in a
942 backtrace. */
943
944static int backtrace_limit;
945
946static void
947set_backtrace_limit_command (count_exp, from_tty)
948 char *count_exp;
949 int from_tty;
950{
951 int count = parse_and_eval_address (count_exp);
952
953 if (count < 0)
954 error ("Negative argument not meaningful as backtrace limit.");
955
956 backtrace_limit = count;
957}
958
959static void
960backtrace_limit_info (arg, from_tty)
961 char *arg;
962 int from_tty;
963{
964 if (arg)
965 error ("\"Info backtrace-limit\" takes no arguments.");
966
199b2450 967 printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit);
bd5635a1
RP
968}
969#endif
970
971/* Print briefly all stack frames or just the innermost COUNT frames. */
972
973static void
65b07ddc 974backtrace_command_1 (count_exp, show_locals, from_tty)
bd5635a1 975 char *count_exp;
65b07ddc 976 int show_locals;
bd5635a1
RP
977 int from_tty;
978{
979 struct frame_info *fi;
980 register int count;
bd5635a1 981 register int i;
1a494973 982 register struct frame_info *trailing;
bd5635a1
RP
983 register int trailing_level;
984
777bef06
JK
985 if (!target_has_stack)
986 error ("No stack.");
987
bd5635a1
RP
988 /* The following code must do two things. First, it must
989 set the variable TRAILING to the frame from which we should start
990 printing. Second, it must set the variable count to the number
991 of frames which we should print, or -1 if all of them. */
992 trailing = get_current_frame ();
993 trailing_level = 0;
994 if (count_exp)
995 {
996 count = parse_and_eval_address (count_exp);
997 if (count < 0)
998 {
1a494973 999 struct frame_info *current;
bd5635a1
RP
1000
1001 count = -count;
1002
1003 current = trailing;
1004 while (current && count--)
1005 {
1006 QUIT;
1007 current = get_prev_frame (current);
1008 }
1009
1010 /* Will stop when CURRENT reaches the top of the stack. TRAILING
1011 will be COUNT below it. */
1012 while (current)
1013 {
1014 QUIT;
1015 trailing = get_prev_frame (trailing);
1016 current = get_prev_frame (current);
1017 trailing_level++;
1018 }
1019
1020 count = -1;
1021 }
1022 }
1023 else
1024 count = -1;
1025
1026 if (info_verbose)
1027 {
1028 struct partial_symtab *ps;
1029
1030 /* Read in symbols for all of the frames. Need to do this in
1031 a separate pass so that "Reading in symbols for xxx" messages
1032 don't screw up the appearance of the backtrace. Also
1033 if people have strong opinions against reading symbols for
1034 backtrace this may have to be an option. */
1035 i = count;
1a494973
C
1036 for (fi = trailing;
1037 fi != NULL && i--;
1038 fi = get_prev_frame (fi))
bd5635a1
RP
1039 {
1040 QUIT;
bd5635a1
RP
1041 ps = find_pc_psymtab (fi->pc);
1042 if (ps)
3de61d8c 1043 PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */
bd5635a1
RP
1044 }
1045 }
1046
1a494973
C
1047 for (i = 0, fi = trailing;
1048 fi && count--;
1049 i++, fi = get_prev_frame (fi))
bd5635a1
RP
1050 {
1051 QUIT;
199b2450
TL
1052
1053 /* Don't use print_stack_frame; if an error() occurs it probably
1054 means further attempts to backtrace would fail (on the other
1055 hand, perhaps the code does or could be fixed to make sure
1056 the frame->prev field gets set to NULL in that case). */
65b07ddc
DT
1057 print_frame_info_base (fi, trailing_level + i, 0, 1);
1058 if (show_locals)
1059 print_frame_local_vars(fi, 1, gdb_stdout);
bd5635a1
RP
1060 }
1061
1062 /* If we've stopped before the end, mention that. */
1a494973 1063 if (fi && from_tty)
bd5635a1
RP
1064 printf_filtered ("(More stack frames follow...)\n");
1065}
65b07ddc
DT
1066
1067static void
1068backtrace_command (arg, from_tty)
1069 char *arg;
1070 int from_tty;
1071{
1072 struct cleanup *old_chain = (struct cleanup *)NULL;
1073 char **argv = (char **)NULL;
1074 int argIndicatingFullTrace = (-1), totArgLen = 0, argc = 0;
1075 char *argPtr = arg;
1076
1077 if (arg != (char *)NULL)
1078 {
1079 int i;
1080
1081 argv = buildargv(arg);
1082 old_chain = make_cleanup(freeargv, (char *)argv);
1083 argc = 0;
1084 for (i = 0; (argv[i] != (char *)NULL); i++)
1085 {
1086 int j;
1087
1088 for (j = 0; (j < strlen(argv[i])); j++)
1089 argv[i][j] = tolower(argv[i][j]);
1090
1091 if (argIndicatingFullTrace < 0 && subsetCompare(argv[i], "full"))
1092 argIndicatingFullTrace = argc;
1093 else
1094 {
1095 argc++;
1096 totArgLen += strlen(argv[i]);
1097 }
1098 }
1099 totArgLen += argc;
1100 if (argIndicatingFullTrace >= 0)
1101 {
1102 if (totArgLen > 0)
1103 {
1104 argPtr = (char *)xmalloc(totArgLen + 1);
1105 if (!argPtr)
1106 nomem(0);
1107 else
1108 {
1109 memset(argPtr, 0, totArgLen + 1);
1110 for (i = 0; (i < (argc + 1)); i++)
1111 {
1112 if (i != argIndicatingFullTrace)
1113 {
1114 strcat(argPtr, argv[i]);
1115 strcat(argPtr, " ");
1116 }
1117 }
1118 }
1119 }
1120 else
1121 argPtr = (char *)NULL;
1122 }
1123 }
1124
1125 backtrace_command_1 (argPtr, (argIndicatingFullTrace >= 0), from_tty);
1126
1127 if (argIndicatingFullTrace >= 0 && totArgLen > 0)
1128 free(argPtr);
1129
1130 if (old_chain)
1131 do_cleanups(old_chain);
1132}
1133
1134static void
1135backtrace_full_command (arg, from_tty)
1136 char *arg;
1137 int from_tty;
1138{
1139 backtrace_command_1 (arg, 1, from_tty);
1140}
1141
bd5635a1
RP
1142\f
1143/* Print the local variables of a block B active in FRAME.
1144 Return 1 if any variables were printed; 0 otherwise. */
1145
1146static int
65b07ddc 1147print_block_frame_locals (b, fi, num_tabs, stream)
bd5635a1 1148 struct block *b;
1a494973 1149 register struct frame_info *fi;
65b07ddc 1150 int num_tabs;
199b2450 1151 register GDB_FILE *stream;
bd5635a1
RP
1152{
1153 int nsyms;
65b07ddc 1154 register int i, j;
bd5635a1
RP
1155 register struct symbol *sym;
1156 register int values_printed = 0;
1157
1158 nsyms = BLOCK_NSYMS (b);
1159
1160 for (i = 0; i < nsyms; i++)
1161 {
1162 sym = BLOCK_SYM (b, i);
f1de67d3 1163 switch (SYMBOL_CLASS (sym))
bd5635a1 1164 {
f1de67d3
PS
1165 case LOC_LOCAL:
1166 case LOC_REGISTER:
1167 case LOC_STATIC:
1168 case LOC_BASEREG:
bd5635a1 1169 values_printed = 1;
65b07ddc
DT
1170 for (j = 0; j < num_tabs; j++)
1171 fputs_filtered("\t", stream);
bd5d07d9 1172 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
bd5635a1 1173 fputs_filtered (" = ", stream);
1a494973 1174 print_variable_value (sym, fi, stream);
bd5635a1 1175 fprintf_filtered (stream, "\n");
f1de67d3
PS
1176 break;
1177
1178 default:
1179 /* Ignore symbols which are not locals. */
1180 break;
bd5635a1
RP
1181 }
1182 }
1183 return values_printed;
1184}
1185
cadbb07a 1186/* Same, but print labels. */
bd5635a1
RP
1187
1188static int
cadbb07a 1189print_block_frame_labels (b, have_default, stream)
bd5635a1 1190 struct block *b;
bd5635a1 1191 int *have_default;
199b2450 1192 register GDB_FILE *stream;
bd5635a1
RP
1193{
1194 int nsyms;
1195 register int i;
1196 register struct symbol *sym;
1197 register int values_printed = 0;
1198
1199 nsyms = BLOCK_NSYMS (b);
1200
1201 for (i = 0; i < nsyms; i++)
1202 {
1203 sym = BLOCK_SYM (b, i);
bd5d07d9 1204 if (STREQ (SYMBOL_NAME (sym), "default"))
bd5635a1
RP
1205 {
1206 if (*have_default)
1207 continue;
1208 *have_default = 1;
1209 }
1210 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1211 {
1212 struct symtab_and_line sal;
1213 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1214 values_printed = 1;
bd5d07d9 1215 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
bd5635a1 1216 if (addressprint)
833e0d94
JK
1217 {
1218 fprintf_filtered (stream, " ");
d24c0599 1219 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, stream);
833e0d94 1220 }
bd5635a1
RP
1221 fprintf_filtered (stream, " in file %s, line %d\n",
1222 sal.symtab->filename, sal.line);
bd5635a1
RP
1223 }
1224 }
1225 return values_printed;
1226}
1227
1228/* Print on STREAM all the local variables in frame FRAME,
1229 including all the blocks active in that frame
1230 at its current pc.
1231
1232 Returns 1 if the job was done,
1233 or 0 if nothing was printed because we have no info
1234 on the function running in FRAME. */
1235
c4668207 1236static void
65b07ddc 1237print_frame_local_vars (fi, num_tabs, stream)
1a494973 1238 register struct frame_info *fi;
65b07ddc 1239 register int num_tabs;
199b2450 1240 register GDB_FILE *stream;
bd5635a1 1241{
1a494973 1242 register struct block *block = get_frame_block (fi);
bd5635a1
RP
1243 register int values_printed = 0;
1244
1245 if (block == 0)
1246 {
1247 fprintf_filtered (stream, "No symbol table info available.\n");
c4668207 1248 return;
bd5635a1
RP
1249 }
1250
1251 while (block != 0)
1252 {
65b07ddc 1253 if (print_block_frame_locals (block, fi, num_tabs, stream))
bd5635a1
RP
1254 values_printed = 1;
1255 /* After handling the function's top-level block, stop.
1256 Don't continue to its superblock, the block of
1257 per-file symbols. */
1258 if (BLOCK_FUNCTION (block))
1259 break;
1260 block = BLOCK_SUPERBLOCK (block);
1261 }
1262
1263 if (!values_printed)
1264 {
1265 fprintf_filtered (stream, "No locals.\n");
bd5635a1 1266 }
bd5635a1
RP
1267}
1268
1269/* Same, but print labels. */
1270
c4668207 1271static void
1a494973
C
1272print_frame_label_vars (fi, this_level_only, stream)
1273 register struct frame_info *fi;
bd5635a1 1274 int this_level_only;
199b2450 1275 register GDB_FILE *stream;
bd5635a1 1276{
bd5635a1 1277 register struct blockvector *bl;
1a494973 1278 register struct block *block = get_frame_block (fi);
bd5635a1
RP
1279 register int values_printed = 0;
1280 int index, have_default = 0;
1281 char *blocks_printed;
bd5635a1
RP
1282 CORE_ADDR pc = fi->pc;
1283
1284 if (block == 0)
1285 {
1286 fprintf_filtered (stream, "No symbol table info available.\n");
c4668207 1287 return;
bd5635a1
RP
1288 }
1289
1290 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1291 blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
3de61d8c 1292 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
bd5635a1
RP
1293
1294 while (block != 0)
1295 {
1296 CORE_ADDR end = BLOCK_END (block) - 4;
1297 int last_index;
1298
1299 if (bl != blockvector_for_pc (end, &index))
1300 error ("blockvector blotch");
1301 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1302 error ("blockvector botch");
1303 last_index = BLOCKVECTOR_NBLOCKS (bl);
1304 index += 1;
1305
1306 /* Don't print out blocks that have gone by. */
1307 while (index < last_index
1308 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1309 index++;
1310
1311 while (index < last_index
1312 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1313 {
1314 if (blocks_printed[index] == 0)
1315 {
cadbb07a 1316 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
bd5635a1
RP
1317 values_printed = 1;
1318 blocks_printed[index] = 1;
1319 }
1320 index++;
1321 }
1322 if (have_default)
c4668207 1323 return;
bd5635a1 1324 if (values_printed && this_level_only)
c4668207 1325 return;
bd5635a1
RP
1326
1327 /* After handling the function's top-level block, stop.
1328 Don't continue to its superblock, the block of
1329 per-file symbols. */
1330 if (BLOCK_FUNCTION (block))
1331 break;
1332 block = BLOCK_SUPERBLOCK (block);
1333 }
1334
1335 if (!values_printed && !this_level_only)
1336 {
1337 fprintf_filtered (stream, "No catches.\n");
bd5635a1 1338 }
bd5635a1
RP
1339}
1340
e1ce8aa5 1341/* ARGSUSED */
9ddf9aa9 1342void
bd5635a1
RP
1343locals_info (args, from_tty)
1344 char *args;
1345 int from_tty;
1346{
cadbb07a
JG
1347 if (!selected_frame)
1348 error ("No frame selected.");
65b07ddc 1349 print_frame_local_vars (selected_frame, 0, gdb_stdout);
bd5635a1
RP
1350}
1351
1352static void
b4fde6fa
FF
1353catch_info (ignore, from_tty)
1354 char *ignore;
1355 int from_tty;
bd5635a1 1356{
65b07ddc
DT
1357 struct symtab_and_line * sal;
1358
1359 /* Check for target support for exception handling */
1360 sal = target_enable_exception_callback (EX_EVENT_CATCH, 1);
1361 if (sal)
1362 {
1363 /* Currently not handling this */
1364 /* Ideally, here we should interact with the C++ runtime
1365 system to find the list of active handlers, etc. */
1366 fprintf_filtered (gdb_stdout, "Info catch not supported with this target/compiler combination.\n");
1367#if 0
cadbb07a
JG
1368 if (!selected_frame)
1369 error ("No frame selected.");
65b07ddc
DT
1370#endif
1371 }
1372 else
1373 {
1374 /* Assume g++ compiled code -- old v 4.16 behaviour */
1375 if (!selected_frame)
1376 error ("No frame selected.");
1377
1378 print_frame_label_vars (selected_frame, 0, gdb_stdout);
1379 }
bd5635a1
RP
1380}
1381
c4668207 1382static void
1a494973
C
1383print_frame_arg_vars (fi, stream)
1384 register struct frame_info *fi;
199b2450 1385 register GDB_FILE *stream;
bd5635a1 1386{
1a494973 1387 struct symbol *func = get_frame_function (fi);
bd5635a1
RP
1388 register struct block *b;
1389 int nsyms;
1390 register int i;
1391 register struct symbol *sym, *sym2;
1392 register int values_printed = 0;
1393
1394 if (func == 0)
1395 {
1396 fprintf_filtered (stream, "No symbol table info available.\n");
c4668207 1397 return;
bd5635a1
RP
1398 }
1399
1400 b = SYMBOL_BLOCK_VALUE (func);
1401 nsyms = BLOCK_NSYMS (b);
1402
1403 for (i = 0; i < nsyms; i++)
1404 {
1405 sym = BLOCK_SYM (b, i);
46c28185 1406 switch (SYMBOL_CLASS (sym))
bd5635a1 1407 {
46c28185
RP
1408 case LOC_ARG:
1409 case LOC_LOCAL_ARG:
1410 case LOC_REF_ARG:
1411 case LOC_REGPARM:
1412 case LOC_REGPARM_ADDR:
1413 case LOC_BASEREG_ARG:
bd5635a1 1414 values_printed = 1;
bd5d07d9 1415 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
bd5635a1 1416 fputs_filtered (" = ", stream);
31258e4f
JK
1417
1418 /* We have to look up the symbol because arguments can have
1419 two entries (one a parameter, one a local) and the one we
1420 want is the local, which lookup_symbol will find for us.
1421 This includes gcc1 (not gcc2) on the sparc when passing a
1422 small structure and gcc2 when the argument type is float
1423 and it is passed as a double and converted to float by
1424 the prologue (in the latter case the type of the LOC_ARG
1425 symbol is double and the type of the LOC_LOCAL symbol is
6fe90fc8
JK
1426 float). There are also LOC_ARG/LOC_REGISTER pairs which
1427 are not combined in symbol-reading. */
31258e4f 1428
bd5635a1
RP
1429 sym2 = lookup_symbol (SYMBOL_NAME (sym),
1430 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1a494973 1431 print_variable_value (sym2, fi, stream);
bd5635a1 1432 fprintf_filtered (stream, "\n");
46c28185
RP
1433 break;
1434
1435 default:
1436 /* Don't worry about things which aren't arguments. */
1437 break;
bd5635a1
RP
1438 }
1439 }
1440
1441 if (!values_printed)
1442 {
1443 fprintf_filtered (stream, "No arguments.\n");
bd5635a1 1444 }
bd5635a1
RP
1445}
1446
9ddf9aa9 1447void
b4fde6fa
FF
1448args_info (ignore, from_tty)
1449 char *ignore;
1450 int from_tty;
bd5635a1 1451{
cadbb07a
JG
1452 if (!selected_frame)
1453 error ("No frame selected.");
199b2450 1454 print_frame_arg_vars (selected_frame, gdb_stdout);
bd5635a1 1455}
9ddf9aa9 1456
65b07ddc
DT
1457
1458static void
1459args_plus_locals_info(ignore, from_tty)
1460 char *ignore;
1461 int from_tty;
1462{
1463 args_info(ignore, from_tty);
1464 locals_info(ignore, from_tty);
1465}
1466
bd5635a1 1467\f
1a494973 1468/* Select frame FI, and note that its stack level is LEVEL.
bd5635a1
RP
1469 LEVEL may be -1 if an actual level number is not known. */
1470
1471void
1a494973
C
1472select_frame (fi, level)
1473 struct frame_info *fi;
bd5635a1
RP
1474 int level;
1475{
89e0bbcd
JG
1476 register struct symtab *s;
1477
1a494973 1478 selected_frame = fi;
bd5635a1 1479 selected_frame_level = level;
9ddf9aa9
AC
1480 if (selected_frame_level_changed_hook)
1481 selected_frame_level_changed_hook (level);
89e0bbcd
JG
1482
1483 /* Ensure that symbols for this frame are read in. Also, determine the
1484 source language of this frame, and switch to it if desired. */
1a494973 1485 if (fi)
89e0bbcd 1486 {
1a494973 1487 s = find_pc_symtab (fi->pc);
89e0bbcd 1488 if (s
91ec58ee 1489 && s->language != current_language->la_language
89e0bbcd
JG
1490 && s->language != language_unknown
1491 && language_mode == language_mode_auto) {
1492 set_language(s->language);
1493 }
65b07ddc
DT
1494 /* elz: this if here fixes the problem with the pc not being displayed
1495 in the tui asm layout, with no debug symbols. The value of s
1496 would be 0 here, and select_source_symtab would abort the
1497 command by calling the 'error' function*/
1498 if (s)
1499 {
1500 TUIDO(((TuiOpaqueFuncPtr)tui_vSelectSourceSymtab, s));
1501 }
89e0bbcd 1502 }
bd5635a1
RP
1503}
1504
65b07ddc
DT
1505\f
1506/* Select frame FI, noting that its stack level is LEVEL. Also print
1507 the stack frame and show the source if this is the tui version. */
1508void
1509select_and_print_frame(fi, level)
1510 struct frame_info *fi;
1511 int level;
1512{
1513 select_frame(fi, level);
1514 if (fi)
1515 {
1516 print_stack_frame(fi, level, 1);
1517 TUIDO(((TuiOpaqueFuncPtr)tui_vCheckDataValues, fi));
1518 }
1519}
1520
1521\f
1522/* Select frame FI, noting that its stack level is LEVEL. Be silent if
1523 not the TUI */
1524void
1525select_and_maybe_print_frame(fi, level)
1526 struct frame_info *fi;
1527 int level;
1528{
1529 if (!tui_version)
1530 select_frame(fi, level);
1531 else
1532 select_and_print_frame(fi, level);
1533}
1534
1535
777bef06
JK
1536/* Store the selected frame and its level into *FRAMEP and *LEVELP.
1537 If there is no selected frame, *FRAMEP is set to NULL. */
bd5635a1
RP
1538
1539void
1540record_selected_frame (frameaddrp, levelp)
1a494973 1541 CORE_ADDR *frameaddrp;
bd5635a1
RP
1542 int *levelp;
1543{
1a494973 1544 *frameaddrp = selected_frame ? selected_frame->frame : 0;
bd5635a1
RP
1545 *levelp = selected_frame_level;
1546}
1547
1548/* Return the symbol-block in which the selected frame is executing.
1549 Can return zero under various legitimate circumstances. */
1550
1551struct block *
1552get_selected_block ()
1553{
1554 if (!target_has_stack)
1555 return 0;
1556
1557 if (!selected_frame)
1558 return get_current_block ();
1559 return get_frame_block (selected_frame);
1560}
1561
1562/* Find a frame a certain number of levels away from FRAME.
1563 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1564 Positive means go to earlier frames (up); negative, the reverse.
1565 The int that contains the number of levels is counted toward
1566 zero as the frames for those levels are found.
1567 If the top or bottom frame is reached, that frame is returned,
1568 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1569 how much farther the original request asked to go. */
1570
1a494973 1571struct frame_info *
bd5635a1 1572find_relative_frame (frame, level_offset_ptr)
1a494973
C
1573 register struct frame_info *frame;
1574 register int *level_offset_ptr;
bd5635a1 1575{
1a494973
C
1576 register struct frame_info *prev;
1577 register struct frame_info *frame1;
bd5635a1
RP
1578
1579 /* Going up is simple: just do get_prev_frame enough times
1580 or until initial frame is reached. */
1581 while (*level_offset_ptr > 0)
1582 {
1583 prev = get_prev_frame (frame);
1584 if (prev == 0)
1585 break;
1586 (*level_offset_ptr)--;
1587 frame = prev;
1588 }
d8ce1326 1589 /* Going down is just as simple. */
bd5635a1
RP
1590 if (*level_offset_ptr < 0)
1591 {
cadbb07a
JG
1592 while (*level_offset_ptr < 0) {
1593 frame1 = get_next_frame (frame);
1594 if (!frame1)
1595 break;
1596 frame = frame1;
1597 (*level_offset_ptr)++;
1598 }
bd5635a1
RP
1599 }
1600 return frame;
1601}
1602
c4668207 1603/* The "select_frame" command. With no arg, NOP.
bd5635a1
RP
1604 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1605 valid level. Otherwise, treat level_exp as an address expression
b0077123 1606 and select it. See parse_frame_specification for more info on proper
bd5635a1
RP
1607 frame expressions. */
1608
c4668207 1609/* ARGSUSED */
bd5635a1 1610static void
c4668207 1611select_frame_command (level_exp, from_tty)
bd5635a1
RP
1612 char *level_exp;
1613 int from_tty;
1614{
1a494973 1615 register struct frame_info *frame, *frame1;
bd5635a1
RP
1616 unsigned int level = 0;
1617
1618 if (!target_has_stack)
1619 error ("No stack.");
1620
1621 frame = parse_frame_specification (level_exp);
1622
cadbb07a
JG
1623 /* Try to figure out what level this frame is. But if there is
1624 no current stack, don't error out -- let the user set one. */
1625 frame1 = 0;
1626 if (get_current_frame()) {
1627 for (frame1 = get_prev_frame (0);
1628 frame1 && frame1 != frame;
1629 frame1 = get_prev_frame (frame1))
1630 level++;
1631 }
bd5635a1
RP
1632
1633 if (!frame1)
1634 level = 0;
1635
1636 select_frame (frame, level);
b0077123 1637}
bd5635a1 1638
b0077123 1639/* The "frame" command. With no arg, print selected frame briefly.
c4668207 1640 With arg, behaves like select_frame and then prints the selected
b0077123 1641 frame. */
bd5635a1 1642
65b07ddc 1643void
b0077123
JG
1644frame_command (level_exp, from_tty)
1645 char *level_exp;
1646 int from_tty;
1647{
c4668207 1648 select_frame_command (level_exp, from_tty);
65b07ddc 1649 show_and_print_stack_frame (selected_frame, selected_frame_level, 1);
bd5635a1
RP
1650}
1651
65b07ddc
DT
1652/* The XDB Compatibility command to print the current frame. */
1653
1654void
1655current_frame_command (level_exp, from_tty)
1656 char *level_exp;
1657 int from_tty;
1658{
1659 if (target_has_stack == 0 || selected_frame == 0)
1660 error ("No stack.");
1661 print_only_stack_frame (selected_frame, selected_frame_level, 1);
1662 }
1663
bd5635a1
RP
1664/* Select the frame up one or COUNT stack levels
1665 from the previously selected frame, and print it briefly. */
1666
e1ce8aa5 1667/* ARGSUSED */
bd5635a1 1668static void
65b07ddc 1669up_silently_base (count_exp)
bd5635a1 1670 char *count_exp;
bd5635a1 1671{
1a494973 1672 register struct frame_info *fi;
bd5635a1
RP
1673 int count = 1, count1;
1674 if (count_exp)
1675 count = parse_and_eval_address (count_exp);
1676 count1 = count;
1677
0f552c5f 1678 if (target_has_stack == 0 || selected_frame == 0)
bd5635a1
RP
1679 error ("No stack.");
1680
1a494973 1681 fi = find_relative_frame (selected_frame, &count1);
bd5635a1
RP
1682 if (count1 != 0 && count_exp == 0)
1683 error ("Initial frame selected; you cannot go up.");
1a494973 1684 select_frame (fi, selected_frame_level + count - count1);
bd5635a1
RP
1685}
1686
65b07ddc
DT
1687static void
1688up_silently_command (count_exp, from_tty)
1689 char *count_exp;
1690 int from_tty;
1691{
1692 up_silently_base(count_exp);
1693 if (tui_version)
1694 print_stack_frame (selected_frame, selected_frame_level, 1);
1695}
1696
bd5635a1
RP
1697static void
1698up_command (count_exp, from_tty)
1699 char *count_exp;
1700 int from_tty;
1701{
65b07ddc
DT
1702 up_silently_base (count_exp);
1703 show_and_print_stack_frame (selected_frame, selected_frame_level, 1);
bd5635a1
RP
1704}
1705
1706/* Select the frame down one or COUNT stack levels
1707 from the previously selected frame, and print it briefly. */
1708
e1ce8aa5 1709/* ARGSUSED */
bd5635a1 1710static void
65b07ddc 1711down_silently_base (count_exp)
bd5635a1 1712 char *count_exp;
bd5635a1 1713{
1a494973 1714 register struct frame_info *frame;
bd5635a1
RP
1715 int count = -1, count1;
1716 if (count_exp)
1717 count = - parse_and_eval_address (count_exp);
1718 count1 = count;
1719
0f552c5f 1720 if (target_has_stack == 0 || selected_frame == 0)
89e0bbcd
JG
1721 error ("No stack.");
1722
bd5635a1
RP
1723 frame = find_relative_frame (selected_frame, &count1);
1724 if (count1 != 0 && count_exp == 0)
4f983400
JK
1725 {
1726
1727 /* We only do this if count_exp is not specified. That way "down"
1728 means to really go down (and let me know if that is
1729 impossible), but "down 9999" can be used to mean go all the way
1730 down without getting an error. */
1731
1732 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1733 }
1734
bd5635a1
RP
1735 select_frame (frame, selected_frame_level + count - count1);
1736}
1737
65b07ddc
DT
1738/* ARGSUSED */
1739static void
1740down_silently_command (count_exp, from_tty)
1741 char *count_exp;
1742 int from_tty;
1743{
1744 down_silently_base (count_exp);
1745 if (tui_version)
1746 print_stack_frame (selected_frame, selected_frame_level, 1);
1747}
bd5635a1
RP
1748
1749static void
1750down_command (count_exp, from_tty)
1751 char *count_exp;
1752 int from_tty;
1753{
65b07ddc
DT
1754 down_silently_base (count_exp);
1755 show_and_print_stack_frame (selected_frame, selected_frame_level, 1);
bd5635a1
RP
1756}
1757\f
1758static void
1759return_command (retval_exp, from_tty)
1760 char *retval_exp;
1761 int from_tty;
1762{
777bef06 1763 struct symbol *thisfun;
1a494973 1764 CORE_ADDR selected_frame_addr;
777bef06 1765 CORE_ADDR selected_frame_pc;
1a494973 1766 struct frame_info *frame;
d24c0599 1767 value_ptr return_value = NULL;
bd5635a1 1768
777bef06
JK
1769 if (selected_frame == NULL)
1770 error ("No selected frame.");
1771 thisfun = get_frame_function (selected_frame);
1772 selected_frame_addr = FRAME_FP (selected_frame);
1a494973 1773 selected_frame_pc = selected_frame->pc;
777bef06 1774
78cab901 1775 /* Compute the return value (if any -- possibly getting errors here). */
0f552c5f
JG
1776
1777 if (retval_exp)
1778 {
1a494973
C
1779 struct type *return_type = NULL;
1780
0f552c5f 1781 return_value = parse_and_eval (retval_exp);
78cab901 1782
1a494973
C
1783 /* Cast return value to the return type of the function. */
1784 if (thisfun != NULL)
1785 return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
1786 if (return_type == NULL)
1787 return_type = builtin_type_int;
1788 return_value = value_cast (return_type, return_value);
1789
78cab901
JK
1790 /* Make sure we have fully evaluated it, since
1791 it might live in the stack frame we're about to pop. */
1792 if (VALUE_LAZY (return_value))
1793 value_fetch_lazy (return_value);
0f552c5f
JG
1794 }
1795
bd5635a1
RP
1796 /* If interactive, require confirmation. */
1797
1798 if (from_tty)
1799 {
1800 if (thisfun != 0)
1801 {
bd5d07d9 1802 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
b4fde6fa
FF
1803 {
1804 error ("Not confirmed.");
1805 /* NOTREACHED */
1806 }
bd5635a1
RP
1807 }
1808 else
1809 if (!query ("Make selected stack frame return now? "))
1810 error ("Not confirmed.");
1811 }
1812
1813 /* Do the real work. Pop until the specified frame is current. We
1814 use this method because the selected_frame is not valid after
1815 a POP_FRAME. The pc comparison makes this work even if the
1816 selected frame shares its fp with another frame. */
1817
1a494973
C
1818 while (selected_frame_addr != (frame = get_current_frame())->frame
1819 || selected_frame_pc != frame->pc)
bd5635a1
RP
1820 POP_FRAME;
1821
1822 /* Then pop that frame. */
1823
1824 POP_FRAME;
1825
1826 /* Compute the return value (if any) and store in the place
1827 for return values. */
1828
1829 if (retval_exp)
0f552c5f 1830 set_return_value (return_value);
bd5635a1
RP
1831
1832 /* If interactive, print the frame that is now current. */
1833
1834 if (from_tty)
1835 frame_command ("0", 1);
d0e0eca2
FF
1836 else
1837 select_frame_command ("0", 0);
bd5635a1 1838}
89e0bbcd 1839
65b07ddc
DT
1840/* Sets the scope to input function name, provided that the
1841 function is within the current stack frame */
4cffc916 1842struct function_bounds
65b07ddc
DT
1843{
1844 CORE_ADDR low, high;
1845};
1846
1847static void
1848func_command (arg, from_tty)
1849 char *arg;
1850 int from_tty;
1851{
1852 if (arg != (char *)NULL)
1853 {
1854 struct frame_info *fp;
1855 int found = 0;
1856 struct symtabs_and_lines sals;
1857 int i;
1858 int level = 1;
1859 struct function_bounds *funcBounds = (struct function_bounds *)NULL;
1860
1861 fp = parse_frame_specification("0");
1862 sals = decode_line_spec(arg, 1);
1863 funcBounds = (struct function_bounds *)xmalloc(
1864 sizeof(struct function_bounds) * sals.nelts);
1865 for (i = 0; (i < sals.nelts && !found); i++)
1866 {
1867 if (sals.sals[i].pc == (CORE_ADDR)0 ||
1868 find_pc_partial_function(sals.sals[i].pc,
1869 (char **)NULL,
1870 &funcBounds[i].low,
1871 &funcBounds[i].high) == 0)
1872 {
1873 funcBounds[i].low =
1874 funcBounds[i].high = (CORE_ADDR)NULL;
1875 }
1876 }
1877
1878 do
1879 {
1880 for (i = 0; (i < sals.nelts && !found); i++)
1881 found = (fp->pc >= funcBounds[i].low &&
1882 fp->pc < funcBounds[i].high);
1883 if (!found)
1884 {
1885 level = 1;
1886 fp = find_relative_frame(fp, &level);
1887 }
1888 } while (!found && level == 0);
1889
1890 if (funcBounds)
1891 free(funcBounds);
1892
1893 if (!found)
1894 printf_filtered("'%s' not within current stack frame.\n", arg);
1895 else if (fp != selected_frame) /* set the stack frame here! */
1896 select_and_print_frame(fp);
1897 }
1898}
1899
1a494973
C
1900/* Gets the language of the current frame. */
1901
89e0bbcd
JG
1902enum language
1903get_frame_language()
1904{
1a494973
C
1905 register struct symtab *s;
1906 enum language flang; /* The language of the current frame */
89e0bbcd 1907
1a494973
C
1908 if (selected_frame)
1909 {
1910 s = find_pc_symtab(selected_frame->pc);
1911 if (s)
1912 flang = s->language;
89e0bbcd 1913 else
1a494973
C
1914 flang = language_unknown;
1915 }
1916 else
1917 flang = language_unknown;
89e0bbcd 1918
1a494973 1919 return flang;
89e0bbcd 1920}
bd5635a1
RP
1921\f
1922void
1923_initialize_stack ()
1924{
1925#if 0
1926 backtrace_limit = 30;
1927#endif
1928
1929 add_com ("return", class_stack, return_command,
1930 "Make selected stack frame return to its caller.\n\
1931Control remains in the debugger, but when you continue\n\
1932execution will resume in the frame above the one now selected.\n\
1933If an argument is given, it is an expression for the value to return.");
1934
1935 add_com ("up", class_stack, up_command,
1936 "Select and print stack frame that called this one.\n\
1937An argument says how many frames up to go.");
1938 add_com ("up-silently", class_support, up_silently_command,
1939 "Same as the `up' command, but does not print anything.\n\
1940This is useful in command scripts.");
1941
1942 add_com ("down", class_stack, down_command,
1943 "Select and print stack frame called by this one.\n\
1944An argument says how many frames down to go.");
1945 add_com_alias ("do", "down", class_stack, 1);
3de61d8c 1946 add_com_alias ("dow", "down", class_stack, 1);
bd5635a1
RP
1947 add_com ("down-silently", class_support, down_silently_command,
1948 "Same as the `down' command, but does not print anything.\n\
1949This is useful in command scripts.");
1950
1951 add_com ("frame", class_stack, frame_command,
1952 "Select and print a stack frame.\n\
1953With no argument, print the selected stack frame. (See also \"info frame\").\n\
1954An argument specifies the frame to select.\n\
1955It can be a stack frame number or the address of the frame.\n\
1956With argument, nothing is printed if input is coming from\n\
1957a command file or a user-defined command.");
1958
1959 add_com_alias ("f", "frame", class_stack, 1);
1960
65b07ddc
DT
1961 if (xdb_commands)
1962 {
1963 add_com("L", class_stack, current_frame_command,
1964 "Print the current stack frame.\n");
1965 add_com_alias ("V", "frame", class_stack, 1);
1966 }
c4668207 1967 add_com ("select-frame", class_stack, select_frame_command,
b0077123
JG
1968 "Select a stack frame without printing anything.\n\
1969An argument specifies the frame to select.\n\
1970It can be a stack frame number or the address of the frame.\n");
1971
bd5635a1
RP
1972 add_com ("backtrace", class_stack, backtrace_command,
1973 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
65b07ddc
DT
1974With a negative argument, print outermost -COUNT frames.\n\
1975Use of the 'full' qualifier also prints the values of the local variables.\n");
bd5635a1 1976 add_com_alias ("bt", "backtrace", class_stack, 0);
65b07ddc
DT
1977 if (xdb_commands)
1978 {
1979 add_com_alias ("t", "backtrace", class_stack, 0);
1980 add_com ("T", class_stack, backtrace_full_command,
1981 "Print backtrace of all stack frames, or innermost COUNT frames \n\
1982and the values of the local variables.\n\
1983With a negative argument, print outermost -COUNT frames.\n\
1984Usage: T <count>\n");
1985 }
1986
bd5635a1
RP
1987 add_com_alias ("where", "backtrace", class_alias, 0);
1988 add_info ("stack", backtrace_command,
1989 "Backtrace of the stack, or innermost COUNT frames.");
1990 add_info_alias ("s", "stack", 1);
1991 add_info ("frame", frame_info,
1992 "All about selected stack frame, or frame at ADDR.");
1993 add_info_alias ("f", "frame", 1);
1994 add_info ("locals", locals_info,
1995 "Local variables of current stack frame.");
1996 add_info ("args", args_info,
1997 "Argument variables of current stack frame.");
65b07ddc
DT
1998 if (xdb_commands)
1999 add_com("l", class_info, args_plus_locals_info,
2000 "Argument and local variables of current stack frame.");
2001
2002 if (dbx_commands)
2003 add_com("func", class_stack, func_command,
2004 "Select the stack frame that contains <func>.\nUsage: func <name>\n");
2005
bd5635a1
RP
2006 add_info ("catch", catch_info,
2007 "Exceptions that can be caught in the current stack frame.");
2008
2009#if 0
2010 add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
2011 "Specify maximum number of frames for \"backtrace\" to print by default.",
2012 &setlist);
2013 add_info ("backtrace-limit", backtrace_limit_info,
2014 "The maximum number of frames for \"backtrace\" to print by default.");
2015#endif
2016}
This page took 0.650073 seconds and 4 git commands to generate.