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