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