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