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