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