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