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