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