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