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