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