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