]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Print and select stack frames for GDB, the GNU debugger. |
bd5d07d9 | 2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
cadbb07a | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
cadbb07a JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
cadbb07a | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
cadbb07a JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 | 19 | |
bd5635a1 | 20 | #include "defs.h" |
b4fde6fa | 21 | #include "value.h" |
bd5635a1 | 22 | #include "symtab.h" |
b4fde6fa FF |
23 | #include "gdbtypes.h" |
24 | #include "expression.h" | |
25 | #include "language.h" | |
bd5635a1 RP |
26 | #include "frame.h" |
27 | #include "gdbcmd.h" | |
bd5635a1 RP |
28 | #include "gdbcore.h" |
29 | #include "target.h" | |
30 | #include "breakpoint.h" | |
b4fde6fa | 31 | #include "demangle.h" |
df2a1bd7 | 32 | #include "inferior.h" |
b4fde6fa FF |
33 | |
34 | static void | |
35 | return_command PARAMS ((char *, int)); | |
36 | ||
37 | static void | |
38 | down_command PARAMS ((char *, int)); | |
39 | ||
40 | static void | |
41 | down_silently_command PARAMS ((char *, int)); | |
42 | ||
43 | static void | |
44 | up_command PARAMS ((char *, int)); | |
45 | ||
46 | static void | |
47 | up_silently_command PARAMS ((char *, int)); | |
48 | ||
49 | static void | |
50 | frame_command PARAMS ((char *, int)); | |
51 | ||
52 | static void | |
53 | select_frame_command PARAMS ((char *, int)); | |
54 | ||
55 | static void | |
56 | args_info PARAMS ((char *, int)); | |
57 | ||
58 | static void | |
199b2450 | 59 | print_frame_arg_vars PARAMS ((FRAME, GDB_FILE *)); |
b4fde6fa FF |
60 | |
61 | static void | |
62 | catch_info PARAMS ((char *, int)); | |
63 | ||
64 | static void | |
65 | locals_info PARAMS ((char *, int)); | |
66 | ||
67 | static void | |
199b2450 | 68 | print_frame_label_vars PARAMS ((FRAME, int, GDB_FILE *)); |
b4fde6fa FF |
69 | |
70 | static void | |
199b2450 | 71 | print_frame_local_vars PARAMS ((FRAME, GDB_FILE *)); |
b4fde6fa FF |
72 | |
73 | static int | |
199b2450 | 74 | print_block_frame_labels PARAMS ((struct block *, int *, GDB_FILE *)); |
b4fde6fa FF |
75 | |
76 | static int | |
199b2450 | 77 | print_block_frame_locals PARAMS ((struct block *, FRAME, GDB_FILE *)); |
b4fde6fa FF |
78 | |
79 | static void | |
80 | backtrace_command PARAMS ((char *, int)); | |
81 | ||
82 | static FRAME | |
83 | parse_frame_specification PARAMS ((char *)); | |
84 | ||
85 | static void | |
86 | frame_info PARAMS ((char *, int)); | |
87 | ||
bd5635a1 RP |
88 | |
89 | extern int addressprint; /* Print addresses, or stay symbolic only? */ | |
90 | extern int info_verbose; /* Verbosity of symbol reading msgs */ | |
d8ce1326 | 91 | extern int lines_to_list; /* # of lines "list" command shows by default */ |
bd5635a1 | 92 | |
b4fde6fa | 93 | /* The "selected" stack frame is used by default for local and arg access. |
bd5635a1 RP |
94 | May be zero, for no selected frame. */ |
95 | ||
96 | FRAME selected_frame; | |
97 | ||
98 | /* Level of the selected frame: | |
99 | 0 for innermost, 1 for its caller, ... | |
100 | or -1 for frame specified by address with no defined level. */ | |
101 | ||
102 | int selected_frame_level; | |
103 | ||
d24c0599 JK |
104 | /* Zero means do things normally; we are interacting directly with the |
105 | user. One means print the full filename and linenumber when a | |
106 | frame is printed, and do so in a format emacs18/emacs19.22 can | |
107 | parse. Two means print similar annotations, but in many more | |
108 | cases and in a slightly different syntax. */ | |
bd5635a1 | 109 | |
d24c0599 | 110 | int annotation_level = 0; |
bd5635a1 | 111 | |
bd5635a1 | 112 | \f |
199b2450 TL |
113 | struct print_stack_frame_args { |
114 | struct frame_info *fi; | |
115 | int level; | |
116 | int source; | |
117 | int args; | |
118 | }; | |
119 | ||
120 | static int print_stack_frame_stub PARAMS ((char *)); | |
121 | ||
122 | /* Pass the args the way catch_errors wants them. */ | |
123 | static int | |
124 | print_stack_frame_stub (args) | |
125 | char *args; | |
126 | { | |
127 | struct print_stack_frame_args *p = (struct print_stack_frame_args *)args; | |
128 | print_frame_info (p->fi, p->level, p->source, p->args); | |
129 | return 0; | |
130 | } | |
131 | ||
bd5635a1 RP |
132 | /* Print a stack frame briefly. FRAME should be the frame id |
133 | and LEVEL should be its level in the stack (or -1 for level not defined). | |
134 | This prints the level, the function executing, the arguments, | |
135 | and the file name and line number. | |
136 | If the pc is not at the beginning of the source line, | |
137 | the actual pc is printed at the beginning. | |
138 | ||
139 | If SOURCE is 1, print the source line as well. | |
140 | If SOURCE is -1, print ONLY the source line. */ | |
141 | ||
cadbb07a | 142 | void |
bd5635a1 RP |
143 | print_stack_frame (frame, level, source) |
144 | FRAME frame; | |
145 | int level; | |
146 | int source; | |
147 | { | |
199b2450 | 148 | struct print_stack_frame_args args; |
bd5635a1 | 149 | |
199b2450 TL |
150 | args.fi = get_frame_info (frame); |
151 | args.level = level; | |
152 | args.source = source; | |
153 | args.args = 1; | |
bd5635a1 | 154 | |
199b2450 | 155 | catch_errors (print_stack_frame_stub, (char *)&args, "", RETURN_MASK_ERROR); |
bd5635a1 RP |
156 | } |
157 | ||
c94e7e75 JK |
158 | struct print_args_args { |
159 | struct symbol *func; | |
160 | struct frame_info *fi; | |
161 | }; | |
162 | ||
163 | static int print_args_stub PARAMS ((char *)); | |
164 | ||
165 | /* Pass the args the way catch_errors wants them. */ | |
166 | static int | |
167 | print_args_stub (args) | |
168 | char *args; | |
169 | { | |
170 | int numargs; | |
171 | struct print_args_args *p = (struct print_args_args *)args; | |
172 | FRAME_NUM_ARGS (numargs, (p->fi)); | |
199b2450 | 173 | print_frame_args (p->func, p->fi, numargs, gdb_stdout); |
c94e7e75 JK |
174 | return 0; |
175 | } | |
176 | ||
bd5635a1 RP |
177 | void |
178 | print_frame_info (fi, level, source, args) | |
179 | struct frame_info *fi; | |
180 | register int level; | |
181 | int source; | |
182 | int args; | |
183 | { | |
184 | struct symtab_and_line sal; | |
185 | struct symbol *func; | |
186 | register char *funname = 0; | |
bd5d07d9 | 187 | enum language funlang = language_unknown; |
dff84871 PS |
188 | char buf[MAX_REGISTER_RAW_SIZE]; |
189 | CORE_ADDR sp; | |
190 | ||
05052b63 JK |
191 | #if 0 |
192 | /* On the 68k, this spends too much time in m68k_find_saved_regs. */ | |
193 | ||
dff84871 PS |
194 | /* Get the value of SP_REGNUM relative to the frame. */ |
195 | get_saved_register (buf, (int *)NULL, (CORE_ADDR *)NULL, | |
196 | FRAME_INFO_ID (fi), SP_REGNUM, (enum lval_type *)NULL); | |
197 | sp = extract_address (buf, REGISTER_RAW_SIZE (SP_REGNUM)); | |
198 | ||
199 | /* This is not a perfect test, because if a function alloca's some | |
200 | memory, puts some code there, and then jumps into it, then the test | |
78cab901 JK |
201 | will succeed even though there is no call dummy. Probably best is |
202 | to check for a bp_call_dummy breakpoint. */ | |
dff84871 | 203 | if (PC_IN_CALL_DUMMY (fi->pc, sp, fi->frame)) |
05052b63 JK |
204 | #else |
205 | if (frame_in_dummy (fi)) | |
206 | #endif | |
df2a1bd7 JK |
207 | { |
208 | /* Do this regardless of SOURCE because we don't have any source | |
209 | to list for this frame. */ | |
210 | if (level >= 0) | |
211 | printf_filtered ("#%-2d ", level); | |
212 | printf_filtered ("<function called from gdb>\n"); | |
213 | return; | |
214 | } | |
cee86be3 JK |
215 | if (fi->signal_handler_caller) |
216 | { | |
217 | /* Do this regardless of SOURCE because we don't have any source | |
218 | to list for this frame. */ | |
219 | if (level >= 0) | |
220 | printf_filtered ("#%-2d ", level); | |
221 | printf_filtered ("<signal handler called>\n"); | |
222 | return; | |
223 | } | |
b4fde6fa | 224 | |
46c28185 RP |
225 | /* If fi is not the innermost frame, that normally means that fi->pc |
226 | points to *after* the call instruction, and we want to get the line | |
227 | containing the call, never the next line. But if the next frame is | |
f1de67d3 PS |
228 | a signal_handler_caller or a dummy frame, then the next frame was |
229 | not entered as the result of a call, and we want to get the line | |
230 | containing fi->pc. */ | |
46c28185 RP |
231 | sal = |
232 | find_pc_line (fi->pc, | |
f1de67d3 PS |
233 | fi->next != NULL |
234 | && !fi->next->signal_handler_caller | |
235 | && !frame_in_dummy (fi->next)); | |
46c28185 | 236 | |
bd5635a1 RP |
237 | func = find_pc_function (fi->pc); |
238 | if (func) | |
239 | { | |
240 | /* In certain pathological cases, the symtabs give the wrong | |
241 | function (when we are in the first function in a file which | |
242 | is compiled without debugging symbols, the previous function | |
243 | is compiled with debugging symbols, and the "foo.o" symbol | |
244 | that is supposed to tell us where the file with debugging symbols | |
245 | ends has been truncated by ar because it is longer than 15 | |
dff84871 PS |
246 | characters). This also occurs if the user uses asm() to create |
247 | a function but not stabs for it (in a file compiled -g). | |
bd5635a1 | 248 | |
b4fde6fa | 249 | So look in the minimal symbol tables as well, and if it comes |
bd5635a1 | 250 | up with a larger address for the function use that instead. |
b4fde6fa | 251 | I don't think this can ever cause any problems; there shouldn't |
dff84871 PS |
252 | be any minimal symbols in the middle of a function; if this is |
253 | ever changed many parts of GDB will need to be changed (and we'll | |
254 | create a find_pc_minimal_function or some such). */ | |
b4fde6fa FF |
255 | |
256 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); | |
257 | if (msymbol != NULL | |
bd5d07d9 | 258 | && (SYMBOL_VALUE_ADDRESS (msymbol) |
bd5635a1 RP |
259 | > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) |
260 | { | |
d24c0599 JK |
261 | #if 0 |
262 | /* There is no particular reason to think the line number | |
263 | information is wrong. Someone might have just put in | |
264 | a label with asm() but left the line numbers alone. */ | |
bd5635a1 RP |
265 | /* In this case we have no way of knowing the source file |
266 | and line number, so don't print them. */ | |
267 | sal.symtab = 0; | |
d24c0599 | 268 | #endif |
bd5635a1 RP |
269 | /* We also don't know anything about the function besides |
270 | its address and name. */ | |
271 | func = 0; | |
bd5d07d9 FF |
272 | funname = SYMBOL_NAME (msymbol); |
273 | funlang = SYMBOL_LANGUAGE (msymbol); | |
bd5635a1 RP |
274 | } |
275 | else | |
bd5d07d9 FF |
276 | { |
277 | funname = SYMBOL_NAME (func); | |
278 | funlang = SYMBOL_LANGUAGE (func); | |
279 | } | |
bd5635a1 RP |
280 | } |
281 | else | |
282 | { | |
b4fde6fa FF |
283 | register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); |
284 | if (msymbol != NULL) | |
bd5d07d9 FF |
285 | { |
286 | funname = SYMBOL_NAME (msymbol); | |
287 | funlang = SYMBOL_LANGUAGE (msymbol); | |
288 | } | |
bd5635a1 RP |
289 | } |
290 | ||
291 | if (source >= 0 || !sal.symtab) | |
292 | { | |
293 | if (level >= 0) | |
294 | printf_filtered ("#%-2d ", level); | |
295 | if (addressprint) | |
296 | if (fi->pc != sal.pc || !sal.symtab) | |
833e0d94 | 297 | { |
d24c0599 | 298 | print_address_numeric (fi->pc, 1, gdb_stdout); |
833e0d94 JK |
299 | printf_filtered (" in "); |
300 | } | |
199b2450 | 301 | fprintf_symbol_filtered (gdb_stdout, funname ? funname : "??", funlang, |
05052b63 | 302 | DMGL_ANSI); |
bd5635a1 | 303 | wrap_here (" "); |
199b2450 | 304 | fputs_filtered (" (", gdb_stdout); |
bd5635a1 RP |
305 | if (args) |
306 | { | |
c94e7e75 JK |
307 | struct print_args_args args; |
308 | args.fi = fi; | |
309 | args.func = func; | |
23a8e291 | 310 | catch_errors (print_args_stub, (char *)&args, "", RETURN_MASK_ERROR); |
bd5635a1 RP |
311 | } |
312 | printf_filtered (")"); | |
313 | if (sal.symtab && sal.symtab->filename) | |
314 | { | |
315 | wrap_here (" "); | |
316 | printf_filtered (" at %s:%d", sal.symtab->filename, sal.line); | |
317 | } | |
b4fde6fa FF |
318 | |
319 | #ifdef PC_LOAD_SEGMENT | |
320 | /* If we couldn't print out function name but if can figure out what | |
321 | load segment this pc value is from, at least print out some info | |
322 | about its load segment. */ | |
323 | if (!funname) { | |
324 | wrap_here (" "); | |
325 | printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc)); | |
326 | } | |
327 | #endif | |
bd5635a1 RP |
328 | printf_filtered ("\n"); |
329 | } | |
330 | ||
331 | if ((source != 0) && sal.symtab) | |
332 | { | |
333 | int done = 0; | |
334 | int mid_statement = source < 0 && fi->pc != sal.pc; | |
d24c0599 | 335 | if (annotation_level) |
c94e7e75 JK |
336 | done = identify_source_line (sal.symtab, sal.line, mid_statement, |
337 | fi->pc); | |
bd5635a1 RP |
338 | if (!done) |
339 | { | |
340 | if (addressprint && mid_statement) | |
833e0d94 | 341 | { |
d24c0599 | 342 | print_address_numeric (fi->pc, 1, gdb_stdout); |
833e0d94 JK |
343 | printf_filtered ("\t"); |
344 | } | |
bd5635a1 RP |
345 | print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); |
346 | } | |
cadbb07a | 347 | current_source_line = max (sal.line - lines_to_list/2, 1); |
bd5635a1 RP |
348 | } |
349 | if (source != 0) | |
350 | set_default_breakpoint (1, fi->pc, sal.symtab, sal.line); | |
351 | ||
199b2450 | 352 | gdb_flush (gdb_stdout); |
bd5635a1 RP |
353 | } |
354 | ||
bd5635a1 RP |
355 | /* |
356 | * Read a frame specification in whatever the appropriate format is. | |
777bef06 JK |
357 | * Call error() if the specification is in any way invalid (i.e. |
358 | * this function never returns NULL). | |
bd5635a1 RP |
359 | */ |
360 | static FRAME | |
361 | parse_frame_specification (frame_exp) | |
362 | char *frame_exp; | |
363 | { | |
364 | int numargs = 0; | |
bd5d07d9 | 365 | #define MAXARGS 4 |
78cab901 | 366 | CORE_ADDR args[MAXARGS]; |
bd5635a1 RP |
367 | |
368 | if (frame_exp) | |
369 | { | |
370 | char *addr_string, *p; | |
371 | struct cleanup *tmp_cleanup; | |
372 | ||
373 | while (*frame_exp == ' ') frame_exp++; | |
bd5635a1 | 374 | |
bd5d07d9 | 375 | while (*frame_exp) |
bd5635a1 | 376 | { |
bd5d07d9 FF |
377 | if (numargs > MAXARGS) |
378 | error ("Too many args in frame specification"); | |
379 | /* Parse an argument. */ | |
380 | for (p = frame_exp; *p && *p != ' '; p++) | |
381 | ; | |
bd5635a1 RP |
382 | addr_string = savestring(frame_exp, p - frame_exp); |
383 | ||
384 | { | |
385 | tmp_cleanup = make_cleanup (free, addr_string); | |
bd5d07d9 | 386 | args[numargs++] = parse_and_eval_address (addr_string); |
bd5635a1 RP |
387 | do_cleanups (tmp_cleanup); |
388 | } | |
389 | ||
bd5d07d9 | 390 | /* Skip spaces, move to possible next arg. */ |
bd5635a1 | 391 | while (*p == ' ') p++; |
bd5d07d9 | 392 | frame_exp = p; |
bd5635a1 RP |
393 | } |
394 | } | |
395 | ||
396 | switch (numargs) | |
397 | { | |
398 | case 0: | |
777bef06 JK |
399 | if (selected_frame == NULL) |
400 | error ("No selected frame."); | |
bd5635a1 RP |
401 | return selected_frame; |
402 | /* NOTREACHED */ | |
403 | case 1: | |
404 | { | |
bd5d07d9 | 405 | int level = args[0]; |
bd5635a1 RP |
406 | FRAME fid = find_relative_frame (get_current_frame (), &level); |
407 | FRAME tfid; | |
408 | ||
409 | if (level == 0) | |
410 | /* find_relative_frame was successful */ | |
411 | return fid; | |
412 | ||
d24c0599 JK |
413 | /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications |
414 | take at least 2 addresses. It is important to detect this case | |
415 | here so that "frame 100" does not give a confusing error message | |
416 | like "frame specification requires two addresses". This of course | |
417 | does not solve the "frame 100" problem for machines on which | |
418 | a frame specification can be made with one address. To solve | |
419 | that, we need a new syntax for a specifying a frame by address. | |
420 | I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for | |
421 | two args, etc.), but people might think that is too much typing, | |
422 | so I guess *0x23,0x45 would be a possible alternative (commas | |
423 | really should be used instead of spaces to delimit; using spaces | |
424 | normally works in an expression). */ | |
425 | #ifdef SETUP_ARBITRARY_FRAME | |
426 | error ("No frame %d", args[0]); | |
427 | #endif | |
428 | ||
bd5635a1 RP |
429 | /* If (s)he specifies the frame with an address, he deserves what |
430 | (s)he gets. Still, give the highest one that matches. */ | |
431 | ||
432 | for (fid = get_current_frame (); | |
bd5d07d9 | 433 | fid && FRAME_FP (fid) != args[0]; |
bd5635a1 RP |
434 | fid = get_prev_frame (fid)) |
435 | ; | |
436 | ||
437 | if (fid) | |
438 | while ((tfid = get_prev_frame (fid)) && | |
bd5d07d9 | 439 | (FRAME_FP (tfid) == args[0])) |
bd5635a1 RP |
440 | fid = tfid; |
441 | ||
bd5d07d9 | 442 | /* We couldn't identify the frame as an existing frame, but |
d24c0599 | 443 | perhaps we can create one with a single argument. */ |
bd5635a1 | 444 | } |
bd5d07d9 FF |
445 | |
446 | default: | |
447 | #ifdef SETUP_ARBITRARY_FRAME | |
448 | return SETUP_ARBITRARY_FRAME (numargs, args); | |
bd5635a1 | 449 | #else |
bd5d07d9 FF |
450 | /* Usual case. Do it here rather than have everyone supply |
451 | a SETUP_ARBITRARY_FRAME that does this. */ | |
452 | if (numargs == 1) | |
453 | return create_new_frame (args[0], 0); | |
454 | error ("Too many args in frame specification"); | |
bd5635a1 RP |
455 | #endif |
456 | /* NOTREACHED */ | |
457 | } | |
bd5635a1 RP |
458 | /* NOTREACHED */ |
459 | } | |
460 | ||
461 | /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except | |
462 | that if it is unsure about the answer, it returns 0 | |
463 | instead of guessing (this happens on the VAX and i960, for example). | |
464 | ||
465 | On most machines, we never have to guess about the args address, | |
466 | so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */ | |
467 | #if !defined (FRAME_ARGS_ADDRESS_CORRECT) | |
468 | #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS | |
469 | #endif | |
470 | ||
471 | /* Print verbosely the selected frame or the frame at address ADDR. | |
472 | This means absolutely all information in the frame is printed. */ | |
473 | ||
474 | static void | |
b4fde6fa | 475 | frame_info (addr_exp, from_tty) |
bd5635a1 | 476 | char *addr_exp; |
b4fde6fa | 477 | int from_tty; |
bd5635a1 RP |
478 | { |
479 | FRAME frame; | |
480 | struct frame_info *fi; | |
481 | struct frame_saved_regs fsr; | |
482 | struct symtab_and_line sal; | |
483 | struct symbol *func; | |
89e0bbcd | 484 | struct symtab *s; |
bd5635a1 RP |
485 | FRAME calling_frame; |
486 | int i, count; | |
487 | char *funname = 0; | |
bd5d07d9 | 488 | enum language funlang = language_unknown; |
bd5635a1 RP |
489 | |
490 | if (!target_has_stack) | |
6fe90fc8 | 491 | error ("No stack."); |
bd5635a1 RP |
492 | |
493 | frame = parse_frame_specification (addr_exp); | |
494 | if (!frame) | |
495 | error ("Invalid frame specified."); | |
496 | ||
497 | fi = get_frame_info (frame); | |
dff84871 | 498 | sal = find_pc_line (fi->pc, |
f1de67d3 PS |
499 | fi->next != NULL |
500 | && !fi->next->signal_handler_caller | |
501 | && !frame_in_dummy (fi->next)); | |
bd5635a1 | 502 | func = get_frame_function (frame); |
89e0bbcd | 503 | s = find_pc_symtab(fi->pc); |
bd5635a1 | 504 | if (func) |
bd5d07d9 FF |
505 | { |
506 | funname = SYMBOL_NAME (func); | |
507 | funlang = SYMBOL_LANGUAGE (func); | |
508 | } | |
bd5635a1 RP |
509 | else |
510 | { | |
b4fde6fa FF |
511 | register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); |
512 | if (msymbol != NULL) | |
bd5d07d9 FF |
513 | { |
514 | funname = SYMBOL_NAME (msymbol); | |
515 | funlang = SYMBOL_LANGUAGE (msymbol); | |
516 | } | |
bd5635a1 RP |
517 | } |
518 | calling_frame = get_prev_frame (frame); | |
519 | ||
833e0d94 JK |
520 | if (!addr_exp && selected_frame_level >= 0) |
521 | { | |
5e678752 | 522 | printf_filtered ("Stack level %d, frame at ", selected_frame_level); |
d24c0599 | 523 | print_address_numeric (FRAME_FP(frame), 1, gdb_stdout); |
833e0d94 JK |
524 | printf_filtered (":\n"); |
525 | } | |
526 | else | |
527 | { | |
528 | printf_filtered ("Stack frame at "); | |
d24c0599 | 529 | print_address_numeric (FRAME_FP(frame), 1, gdb_stdout); |
833e0d94 JK |
530 | printf_filtered (":\n"); |
531 | } | |
532 | printf_filtered (" %s = ", | |
533 | reg_names[PC_REGNUM]); | |
d24c0599 | 534 | print_address_numeric (fi->pc, 1, gdb_stdout); |
bd5635a1 RP |
535 | |
536 | wrap_here (" "); | |
537 | if (funname) | |
b0077123 JG |
538 | { |
539 | printf_filtered (" in "); | |
199b2450 | 540 | fprintf_symbol_filtered (gdb_stdout, funname, funlang, |
5e81259d | 541 | DMGL_ANSI | DMGL_PARAMS); |
b0077123 | 542 | } |
bd5635a1 RP |
543 | wrap_here (" "); |
544 | if (sal.symtab) | |
545 | printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line); | |
546 | puts_filtered ("; "); | |
547 | wrap_here (" "); | |
833e0d94 | 548 | printf_filtered ("saved %s ", reg_names[PC_REGNUM]); |
d24c0599 | 549 | print_address_numeric (FRAME_SAVED_PC (frame), 1, gdb_stdout); |
833e0d94 | 550 | printf_filtered ("\n"); |
b4fde6fa FF |
551 | |
552 | { | |
553 | int frameless = 0; | |
554 | #ifdef FRAMELESS_FUNCTION_INVOCATION | |
555 | FRAMELESS_FUNCTION_INVOCATION (fi, frameless); | |
556 | #endif | |
557 | if (frameless) | |
558 | printf_filtered (" (FRAMELESS),"); | |
559 | } | |
560 | ||
bd5635a1 | 561 | if (calling_frame) |
833e0d94 JK |
562 | { |
563 | printf_filtered (" called by frame at "); | |
d24c0599 | 564 | print_address_numeric (FRAME_FP (calling_frame), 1, gdb_stdout); |
833e0d94 | 565 | } |
23a8e291 | 566 | if (fi->next && calling_frame) |
bd5635a1 RP |
567 | puts_filtered (","); |
568 | wrap_here (" "); | |
23a8e291 | 569 | if (fi->next) |
833e0d94 JK |
570 | { |
571 | printf_filtered (" caller of frame at "); | |
d24c0599 | 572 | print_address_numeric (fi->next->frame, 1, gdb_stdout); |
833e0d94 | 573 | } |
23a8e291 | 574 | if (fi->next || calling_frame) |
bd5635a1 | 575 | puts_filtered ("\n"); |
89e0bbcd | 576 | if (s) |
833e0d94 | 577 | printf_filtered (" source language %s.\n", language_str (s->language)); |
bd5635a1 | 578 | |
bd5d07d9 FF |
579 | #ifdef PRINT_EXTRA_FRAME_INFO |
580 | PRINT_EXTRA_FRAME_INFO (fi); | |
581 | #endif | |
582 | ||
bd5635a1 RP |
583 | { |
584 | /* Address of the argument list for this frame, or 0. */ | |
585 | CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi); | |
586 | /* Number of args for this frame, or -1 if unknown. */ | |
587 | int numargs; | |
588 | ||
589 | if (arg_list == 0) | |
833e0d94 | 590 | printf_filtered (" Arglist at unknown address.\n"); |
bd5635a1 RP |
591 | else |
592 | { | |
833e0d94 | 593 | printf_filtered (" Arglist at "); |
d24c0599 | 594 | print_address_numeric (arg_list, 1, gdb_stdout); |
833e0d94 | 595 | printf_filtered (","); |
bd5635a1 RP |
596 | |
597 | FRAME_NUM_ARGS (numargs, fi); | |
598 | if (numargs < 0) | |
599 | puts_filtered (" args: "); | |
600 | else if (numargs == 0) | |
601 | puts_filtered (" no args."); | |
602 | else if (numargs == 1) | |
603 | puts_filtered (" 1 arg: "); | |
604 | else | |
605 | printf_filtered (" %d args: ", numargs); | |
199b2450 | 606 | print_frame_args (func, fi, numargs, gdb_stdout); |
bd5635a1 RP |
607 | puts_filtered ("\n"); |
608 | } | |
609 | } | |
b4fde6fa FF |
610 | { |
611 | /* Address of the local variables for this frame, or 0. */ | |
612 | CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi); | |
613 | ||
614 | if (arg_list == 0) | |
833e0d94 | 615 | printf_filtered (" Locals at unknown address,"); |
b4fde6fa | 616 | else |
833e0d94 JK |
617 | { |
618 | printf_filtered (" Locals at "); | |
d24c0599 | 619 | print_address_numeric (arg_list, 1, gdb_stdout); |
833e0d94 JK |
620 | printf_filtered (","); |
621 | } | |
b4fde6fa | 622 | } |
bd5635a1 RP |
623 | |
624 | #if defined (FRAME_FIND_SAVED_REGS) | |
625 | get_frame_saved_regs (fi, &fsr); | |
626 | /* The sp is special; what's returned isn't the save address, but | |
627 | actually the value of the previous frame's sp. */ | |
833e0d94 | 628 | printf_filtered (" Previous frame's sp is "); |
d24c0599 | 629 | print_address_numeric (fsr.regs[SP_REGNUM], 1, gdb_stdout); |
833e0d94 | 630 | printf_filtered ("\n"); |
bd5635a1 RP |
631 | count = 0; |
632 | for (i = 0; i < NUM_REGS; i++) | |
633 | if (fsr.regs[i] && i != SP_REGNUM) | |
634 | { | |
635 | if (count == 0) | |
636 | puts_filtered (" Saved registers:\n "); | |
637 | else | |
638 | puts_filtered (","); | |
639 | wrap_here (" "); | |
833e0d94 | 640 | printf_filtered (" %s at ", reg_names[i]); |
d24c0599 | 641 | print_address_numeric (fsr.regs[i], 1, gdb_stdout); |
bd5635a1 RP |
642 | count++; |
643 | } | |
644 | if (count) | |
645 | puts_filtered ("\n"); | |
f1de67d3 PS |
646 | #else /* Have FRAME_FIND_SAVED_REGS. */ |
647 | puts_filtered ("\n"); | |
bd5635a1 RP |
648 | #endif /* Have FRAME_FIND_SAVED_REGS. */ |
649 | } | |
650 | ||
651 | #if 0 | |
652 | /* Set a limit on the number of frames printed by default in a | |
653 | backtrace. */ | |
654 | ||
655 | static int backtrace_limit; | |
656 | ||
657 | static void | |
658 | set_backtrace_limit_command (count_exp, from_tty) | |
659 | char *count_exp; | |
660 | int from_tty; | |
661 | { | |
662 | int count = parse_and_eval_address (count_exp); | |
663 | ||
664 | if (count < 0) | |
665 | error ("Negative argument not meaningful as backtrace limit."); | |
666 | ||
667 | backtrace_limit = count; | |
668 | } | |
669 | ||
670 | static void | |
671 | backtrace_limit_info (arg, from_tty) | |
672 | char *arg; | |
673 | int from_tty; | |
674 | { | |
675 | if (arg) | |
676 | error ("\"Info backtrace-limit\" takes no arguments."); | |
677 | ||
199b2450 | 678 | printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit); |
bd5635a1 RP |
679 | } |
680 | #endif | |
681 | ||
682 | /* Print briefly all stack frames or just the innermost COUNT frames. */ | |
683 | ||
684 | static void | |
685 | backtrace_command (count_exp, from_tty) | |
686 | char *count_exp; | |
687 | int from_tty; | |
688 | { | |
689 | struct frame_info *fi; | |
690 | register int count; | |
691 | register FRAME frame; | |
692 | register int i; | |
693 | register FRAME trailing; | |
694 | register int trailing_level; | |
695 | ||
777bef06 JK |
696 | if (!target_has_stack) |
697 | error ("No stack."); | |
698 | ||
bd5635a1 RP |
699 | /* The following code must do two things. First, it must |
700 | set the variable TRAILING to the frame from which we should start | |
701 | printing. Second, it must set the variable count to the number | |
702 | of frames which we should print, or -1 if all of them. */ | |
703 | trailing = get_current_frame (); | |
704 | trailing_level = 0; | |
705 | if (count_exp) | |
706 | { | |
707 | count = parse_and_eval_address (count_exp); | |
708 | if (count < 0) | |
709 | { | |
710 | FRAME current; | |
711 | ||
712 | count = -count; | |
713 | ||
714 | current = trailing; | |
715 | while (current && count--) | |
716 | { | |
717 | QUIT; | |
718 | current = get_prev_frame (current); | |
719 | } | |
720 | ||
721 | /* Will stop when CURRENT reaches the top of the stack. TRAILING | |
722 | will be COUNT below it. */ | |
723 | while (current) | |
724 | { | |
725 | QUIT; | |
726 | trailing = get_prev_frame (trailing); | |
727 | current = get_prev_frame (current); | |
728 | trailing_level++; | |
729 | } | |
730 | ||
731 | count = -1; | |
732 | } | |
733 | } | |
734 | else | |
735 | count = -1; | |
736 | ||
737 | if (info_verbose) | |
738 | { | |
739 | struct partial_symtab *ps; | |
740 | ||
741 | /* Read in symbols for all of the frames. Need to do this in | |
742 | a separate pass so that "Reading in symbols for xxx" messages | |
743 | don't screw up the appearance of the backtrace. Also | |
744 | if people have strong opinions against reading symbols for | |
745 | backtrace this may have to be an option. */ | |
746 | i = count; | |
747 | for (frame = trailing; | |
748 | frame != NULL && i--; | |
749 | frame = get_prev_frame (frame)) | |
750 | { | |
751 | QUIT; | |
752 | fi = get_frame_info (frame); | |
753 | ps = find_pc_psymtab (fi->pc); | |
754 | if (ps) | |
3de61d8c | 755 | PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */ |
bd5635a1 RP |
756 | } |
757 | } | |
758 | ||
759 | for (i = 0, frame = trailing; | |
760 | frame && count--; | |
761 | i++, frame = get_prev_frame (frame)) | |
762 | { | |
763 | QUIT; | |
764 | fi = get_frame_info (frame); | |
199b2450 TL |
765 | |
766 | /* Don't use print_stack_frame; if an error() occurs it probably | |
767 | means further attempts to backtrace would fail (on the other | |
768 | hand, perhaps the code does or could be fixed to make sure | |
769 | the frame->prev field gets set to NULL in that case). */ | |
bd5635a1 RP |
770 | print_frame_info (fi, trailing_level + i, 0, 1); |
771 | } | |
772 | ||
773 | /* If we've stopped before the end, mention that. */ | |
774 | if (frame && from_tty) | |
775 | printf_filtered ("(More stack frames follow...)\n"); | |
776 | } | |
777 | \f | |
778 | /* Print the local variables of a block B active in FRAME. | |
779 | Return 1 if any variables were printed; 0 otherwise. */ | |
780 | ||
781 | static int | |
782 | print_block_frame_locals (b, frame, stream) | |
783 | struct block *b; | |
784 | register FRAME frame; | |
199b2450 | 785 | register GDB_FILE *stream; |
bd5635a1 RP |
786 | { |
787 | int nsyms; | |
788 | register int i; | |
789 | register struct symbol *sym; | |
790 | register int values_printed = 0; | |
791 | ||
792 | nsyms = BLOCK_NSYMS (b); | |
793 | ||
794 | for (i = 0; i < nsyms; i++) | |
795 | { | |
796 | sym = BLOCK_SYM (b, i); | |
f1de67d3 | 797 | switch (SYMBOL_CLASS (sym)) |
bd5635a1 | 798 | { |
f1de67d3 PS |
799 | case LOC_LOCAL: |
800 | case LOC_REGISTER: | |
801 | case LOC_STATIC: | |
802 | case LOC_BASEREG: | |
bd5635a1 | 803 | values_printed = 1; |
bd5d07d9 | 804 | fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream); |
bd5635a1 RP |
805 | fputs_filtered (" = ", stream); |
806 | print_variable_value (sym, frame, stream); | |
807 | fprintf_filtered (stream, "\n"); | |
f1de67d3 PS |
808 | break; |
809 | ||
810 | default: | |
811 | /* Ignore symbols which are not locals. */ | |
812 | break; | |
bd5635a1 RP |
813 | } |
814 | } | |
815 | return values_printed; | |
816 | } | |
817 | ||
cadbb07a | 818 | /* Same, but print labels. */ |
bd5635a1 RP |
819 | |
820 | static int | |
cadbb07a | 821 | print_block_frame_labels (b, have_default, stream) |
bd5635a1 | 822 | struct block *b; |
bd5635a1 | 823 | int *have_default; |
199b2450 | 824 | register GDB_FILE *stream; |
bd5635a1 RP |
825 | { |
826 | int nsyms; | |
827 | register int i; | |
828 | register struct symbol *sym; | |
829 | register int values_printed = 0; | |
830 | ||
831 | nsyms = BLOCK_NSYMS (b); | |
832 | ||
833 | for (i = 0; i < nsyms; i++) | |
834 | { | |
835 | sym = BLOCK_SYM (b, i); | |
bd5d07d9 | 836 | if (STREQ (SYMBOL_NAME (sym), "default")) |
bd5635a1 RP |
837 | { |
838 | if (*have_default) | |
839 | continue; | |
840 | *have_default = 1; | |
841 | } | |
842 | if (SYMBOL_CLASS (sym) == LOC_LABEL) | |
843 | { | |
844 | struct symtab_and_line sal; | |
845 | sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); | |
846 | values_printed = 1; | |
bd5d07d9 | 847 | fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream); |
bd5635a1 | 848 | if (addressprint) |
833e0d94 JK |
849 | { |
850 | fprintf_filtered (stream, " "); | |
d24c0599 | 851 | print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, stream); |
833e0d94 | 852 | } |
bd5635a1 RP |
853 | fprintf_filtered (stream, " in file %s, line %d\n", |
854 | sal.symtab->filename, sal.line); | |
bd5635a1 RP |
855 | } |
856 | } | |
857 | return values_printed; | |
858 | } | |
859 | ||
860 | /* Print on STREAM all the local variables in frame FRAME, | |
861 | including all the blocks active in that frame | |
862 | at its current pc. | |
863 | ||
864 | Returns 1 if the job was done, | |
865 | or 0 if nothing was printed because we have no info | |
866 | on the function running in FRAME. */ | |
867 | ||
c4668207 | 868 | static void |
bd5635a1 RP |
869 | print_frame_local_vars (frame, stream) |
870 | register FRAME frame; | |
199b2450 | 871 | register GDB_FILE *stream; |
bd5635a1 RP |
872 | { |
873 | register struct block *block = get_frame_block (frame); | |
874 | register int values_printed = 0; | |
875 | ||
876 | if (block == 0) | |
877 | { | |
878 | fprintf_filtered (stream, "No symbol table info available.\n"); | |
c4668207 | 879 | return; |
bd5635a1 RP |
880 | } |
881 | ||
882 | while (block != 0) | |
883 | { | |
884 | if (print_block_frame_locals (block, frame, stream)) | |
885 | values_printed = 1; | |
886 | /* After handling the function's top-level block, stop. | |
887 | Don't continue to its superblock, the block of | |
888 | per-file symbols. */ | |
889 | if (BLOCK_FUNCTION (block)) | |
890 | break; | |
891 | block = BLOCK_SUPERBLOCK (block); | |
892 | } | |
893 | ||
894 | if (!values_printed) | |
895 | { | |
896 | fprintf_filtered (stream, "No locals.\n"); | |
bd5635a1 | 897 | } |
bd5635a1 RP |
898 | } |
899 | ||
900 | /* Same, but print labels. */ | |
901 | ||
c4668207 | 902 | static void |
bd5635a1 RP |
903 | print_frame_label_vars (frame, this_level_only, stream) |
904 | register FRAME frame; | |
905 | int this_level_only; | |
199b2450 | 906 | register GDB_FILE *stream; |
bd5635a1 | 907 | { |
bd5635a1 RP |
908 | register struct blockvector *bl; |
909 | register struct block *block = get_frame_block (frame); | |
910 | register int values_printed = 0; | |
911 | int index, have_default = 0; | |
912 | char *blocks_printed; | |
913 | struct frame_info *fi = get_frame_info (frame); | |
914 | CORE_ADDR pc = fi->pc; | |
915 | ||
916 | if (block == 0) | |
917 | { | |
918 | fprintf_filtered (stream, "No symbol table info available.\n"); | |
c4668207 | 919 | return; |
bd5635a1 RP |
920 | } |
921 | ||
922 | bl = blockvector_for_pc (BLOCK_END (block) - 4, &index); | |
923 | blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); | |
3de61d8c | 924 | memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); |
bd5635a1 RP |
925 | |
926 | while (block != 0) | |
927 | { | |
928 | CORE_ADDR end = BLOCK_END (block) - 4; | |
929 | int last_index; | |
930 | ||
931 | if (bl != blockvector_for_pc (end, &index)) | |
932 | error ("blockvector blotch"); | |
933 | if (BLOCKVECTOR_BLOCK (bl, index) != block) | |
934 | error ("blockvector botch"); | |
935 | last_index = BLOCKVECTOR_NBLOCKS (bl); | |
936 | index += 1; | |
937 | ||
938 | /* Don't print out blocks that have gone by. */ | |
939 | while (index < last_index | |
940 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc) | |
941 | index++; | |
942 | ||
943 | while (index < last_index | |
944 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end) | |
945 | { | |
946 | if (blocks_printed[index] == 0) | |
947 | { | |
cadbb07a | 948 | if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream)) |
bd5635a1 RP |
949 | values_printed = 1; |
950 | blocks_printed[index] = 1; | |
951 | } | |
952 | index++; | |
953 | } | |
954 | if (have_default) | |
c4668207 | 955 | return; |
bd5635a1 | 956 | if (values_printed && this_level_only) |
c4668207 | 957 | return; |
bd5635a1 RP |
958 | |
959 | /* After handling the function's top-level block, stop. | |
960 | Don't continue to its superblock, the block of | |
961 | per-file symbols. */ | |
962 | if (BLOCK_FUNCTION (block)) | |
963 | break; | |
964 | block = BLOCK_SUPERBLOCK (block); | |
965 | } | |
966 | ||
967 | if (!values_printed && !this_level_only) | |
968 | { | |
969 | fprintf_filtered (stream, "No catches.\n"); | |
bd5635a1 | 970 | } |
bd5635a1 RP |
971 | } |
972 | ||
e1ce8aa5 | 973 | /* ARGSUSED */ |
bd5635a1 RP |
974 | static void |
975 | locals_info (args, from_tty) | |
976 | char *args; | |
977 | int from_tty; | |
978 | { | |
cadbb07a JG |
979 | if (!selected_frame) |
980 | error ("No frame selected."); | |
199b2450 | 981 | print_frame_local_vars (selected_frame, gdb_stdout); |
bd5635a1 RP |
982 | } |
983 | ||
984 | static void | |
b4fde6fa FF |
985 | catch_info (ignore, from_tty) |
986 | char *ignore; | |
987 | int from_tty; | |
bd5635a1 | 988 | { |
cadbb07a JG |
989 | if (!selected_frame) |
990 | error ("No frame selected."); | |
199b2450 | 991 | print_frame_label_vars (selected_frame, 0, gdb_stdout); |
bd5635a1 RP |
992 | } |
993 | ||
c4668207 | 994 | static void |
bd5635a1 RP |
995 | print_frame_arg_vars (frame, stream) |
996 | register FRAME frame; | |
199b2450 | 997 | register GDB_FILE *stream; |
bd5635a1 RP |
998 | { |
999 | struct symbol *func = get_frame_function (frame); | |
1000 | register struct block *b; | |
1001 | int nsyms; | |
1002 | register int i; | |
1003 | register struct symbol *sym, *sym2; | |
1004 | register int values_printed = 0; | |
1005 | ||
1006 | if (func == 0) | |
1007 | { | |
1008 | fprintf_filtered (stream, "No symbol table info available.\n"); | |
c4668207 | 1009 | return; |
bd5635a1 RP |
1010 | } |
1011 | ||
1012 | b = SYMBOL_BLOCK_VALUE (func); | |
1013 | nsyms = BLOCK_NSYMS (b); | |
1014 | ||
1015 | for (i = 0; i < nsyms; i++) | |
1016 | { | |
1017 | sym = BLOCK_SYM (b, i); | |
46c28185 | 1018 | switch (SYMBOL_CLASS (sym)) |
bd5635a1 | 1019 | { |
46c28185 RP |
1020 | case LOC_ARG: |
1021 | case LOC_LOCAL_ARG: | |
1022 | case LOC_REF_ARG: | |
1023 | case LOC_REGPARM: | |
1024 | case LOC_REGPARM_ADDR: | |
1025 | case LOC_BASEREG_ARG: | |
bd5635a1 | 1026 | values_printed = 1; |
bd5d07d9 | 1027 | fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream); |
bd5635a1 | 1028 | fputs_filtered (" = ", stream); |
31258e4f JK |
1029 | |
1030 | /* We have to look up the symbol because arguments can have | |
1031 | two entries (one a parameter, one a local) and the one we | |
1032 | want is the local, which lookup_symbol will find for us. | |
1033 | This includes gcc1 (not gcc2) on the sparc when passing a | |
1034 | small structure and gcc2 when the argument type is float | |
1035 | and it is passed as a double and converted to float by | |
1036 | the prologue (in the latter case the type of the LOC_ARG | |
1037 | symbol is double and the type of the LOC_LOCAL symbol is | |
6fe90fc8 JK |
1038 | float). There are also LOC_ARG/LOC_REGISTER pairs which |
1039 | are not combined in symbol-reading. */ | |
31258e4f | 1040 | |
bd5635a1 RP |
1041 | sym2 = lookup_symbol (SYMBOL_NAME (sym), |
1042 | b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL); | |
1043 | print_variable_value (sym2, frame, stream); | |
1044 | fprintf_filtered (stream, "\n"); | |
46c28185 RP |
1045 | break; |
1046 | ||
1047 | default: | |
1048 | /* Don't worry about things which aren't arguments. */ | |
1049 | break; | |
bd5635a1 RP |
1050 | } |
1051 | } | |
1052 | ||
1053 | if (!values_printed) | |
1054 | { | |
1055 | fprintf_filtered (stream, "No arguments.\n"); | |
bd5635a1 | 1056 | } |
bd5635a1 RP |
1057 | } |
1058 | ||
1059 | static void | |
b4fde6fa FF |
1060 | args_info (ignore, from_tty) |
1061 | char *ignore; | |
1062 | int from_tty; | |
bd5635a1 | 1063 | { |
cadbb07a JG |
1064 | if (!selected_frame) |
1065 | error ("No frame selected."); | |
199b2450 | 1066 | print_frame_arg_vars (selected_frame, gdb_stdout); |
bd5635a1 RP |
1067 | } |
1068 | \f | |
1069 | /* Select frame FRAME, and note that its stack level is LEVEL. | |
1070 | LEVEL may be -1 if an actual level number is not known. */ | |
1071 | ||
1072 | void | |
1073 | select_frame (frame, level) | |
1074 | FRAME frame; | |
1075 | int level; | |
1076 | { | |
89e0bbcd JG |
1077 | register struct symtab *s; |
1078 | ||
bd5635a1 RP |
1079 | selected_frame = frame; |
1080 | selected_frame_level = level; | |
89e0bbcd JG |
1081 | |
1082 | /* Ensure that symbols for this frame are read in. Also, determine the | |
1083 | source language of this frame, and switch to it if desired. */ | |
bd5635a1 | 1084 | if (frame) |
89e0bbcd JG |
1085 | { |
1086 | s = find_pc_symtab (get_frame_info (frame)->pc); | |
1087 | if (s | |
91ec58ee | 1088 | && s->language != current_language->la_language |
89e0bbcd JG |
1089 | && s->language != language_unknown |
1090 | && language_mode == language_mode_auto) { | |
1091 | set_language(s->language); | |
1092 | } | |
1093 | } | |
bd5635a1 RP |
1094 | } |
1095 | ||
777bef06 JK |
1096 | /* Store the selected frame and its level into *FRAMEP and *LEVELP. |
1097 | If there is no selected frame, *FRAMEP is set to NULL. */ | |
bd5635a1 RP |
1098 | |
1099 | void | |
1100 | record_selected_frame (frameaddrp, levelp) | |
1101 | FRAME_ADDR *frameaddrp; | |
1102 | int *levelp; | |
1103 | { | |
b4fde6fa | 1104 | *frameaddrp = selected_frame ? FRAME_FP (selected_frame) : 0; |
bd5635a1 RP |
1105 | *levelp = selected_frame_level; |
1106 | } | |
1107 | ||
1108 | /* Return the symbol-block in which the selected frame is executing. | |
1109 | Can return zero under various legitimate circumstances. */ | |
1110 | ||
1111 | struct block * | |
1112 | get_selected_block () | |
1113 | { | |
1114 | if (!target_has_stack) | |
1115 | return 0; | |
1116 | ||
1117 | if (!selected_frame) | |
1118 | return get_current_block (); | |
1119 | return get_frame_block (selected_frame); | |
1120 | } | |
1121 | ||
1122 | /* Find a frame a certain number of levels away from FRAME. | |
1123 | LEVEL_OFFSET_PTR points to an int containing the number of levels. | |
1124 | Positive means go to earlier frames (up); negative, the reverse. | |
1125 | The int that contains the number of levels is counted toward | |
1126 | zero as the frames for those levels are found. | |
1127 | If the top or bottom frame is reached, that frame is returned, | |
1128 | but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates | |
1129 | how much farther the original request asked to go. */ | |
1130 | ||
1131 | FRAME | |
1132 | find_relative_frame (frame, level_offset_ptr) | |
1133 | register FRAME frame; | |
1134 | register int* level_offset_ptr; | |
1135 | { | |
1136 | register FRAME prev; | |
d8ce1326 | 1137 | register FRAME frame1; |
bd5635a1 RP |
1138 | |
1139 | /* Going up is simple: just do get_prev_frame enough times | |
1140 | or until initial frame is reached. */ | |
1141 | while (*level_offset_ptr > 0) | |
1142 | { | |
1143 | prev = get_prev_frame (frame); | |
1144 | if (prev == 0) | |
1145 | break; | |
1146 | (*level_offset_ptr)--; | |
1147 | frame = prev; | |
1148 | } | |
d8ce1326 | 1149 | /* Going down is just as simple. */ |
bd5635a1 RP |
1150 | if (*level_offset_ptr < 0) |
1151 | { | |
cadbb07a JG |
1152 | while (*level_offset_ptr < 0) { |
1153 | frame1 = get_next_frame (frame); | |
1154 | if (!frame1) | |
1155 | break; | |
1156 | frame = frame1; | |
1157 | (*level_offset_ptr)++; | |
1158 | } | |
bd5635a1 RP |
1159 | } |
1160 | return frame; | |
1161 | } | |
1162 | ||
c4668207 | 1163 | /* The "select_frame" command. With no arg, NOP. |
bd5635a1 RP |
1164 | With arg LEVEL_EXP, select the frame at level LEVEL if it is a |
1165 | valid level. Otherwise, treat level_exp as an address expression | |
b0077123 | 1166 | and select it. See parse_frame_specification for more info on proper |
bd5635a1 RP |
1167 | frame expressions. */ |
1168 | ||
c4668207 | 1169 | /* ARGSUSED */ |
bd5635a1 | 1170 | static void |
c4668207 | 1171 | select_frame_command (level_exp, from_tty) |
bd5635a1 RP |
1172 | char *level_exp; |
1173 | int from_tty; | |
1174 | { | |
1175 | register FRAME frame, frame1; | |
1176 | unsigned int level = 0; | |
1177 | ||
1178 | if (!target_has_stack) | |
1179 | error ("No stack."); | |
1180 | ||
1181 | frame = parse_frame_specification (level_exp); | |
1182 | ||
cadbb07a JG |
1183 | /* Try to figure out what level this frame is. But if there is |
1184 | no current stack, don't error out -- let the user set one. */ | |
1185 | frame1 = 0; | |
1186 | if (get_current_frame()) { | |
1187 | for (frame1 = get_prev_frame (0); | |
1188 | frame1 && frame1 != frame; | |
1189 | frame1 = get_prev_frame (frame1)) | |
1190 | level++; | |
1191 | } | |
bd5635a1 RP |
1192 | |
1193 | if (!frame1) | |
1194 | level = 0; | |
1195 | ||
1196 | select_frame (frame, level); | |
b0077123 | 1197 | } |
bd5635a1 | 1198 | |
b0077123 | 1199 | /* The "frame" command. With no arg, print selected frame briefly. |
c4668207 | 1200 | With arg, behaves like select_frame and then prints the selected |
b0077123 | 1201 | frame. */ |
bd5635a1 | 1202 | |
b0077123 JG |
1203 | static void |
1204 | frame_command (level_exp, from_tty) | |
1205 | char *level_exp; | |
1206 | int from_tty; | |
1207 | { | |
c4668207 | 1208 | select_frame_command (level_exp, from_tty); |
bd5635a1 RP |
1209 | print_stack_frame (selected_frame, selected_frame_level, 1); |
1210 | } | |
1211 | ||
1212 | /* Select the frame up one or COUNT stack levels | |
1213 | from the previously selected frame, and print it briefly. */ | |
1214 | ||
e1ce8aa5 | 1215 | /* ARGSUSED */ |
bd5635a1 RP |
1216 | static void |
1217 | up_silently_command (count_exp, from_tty) | |
1218 | char *count_exp; | |
1219 | int from_tty; | |
1220 | { | |
1221 | register FRAME frame; | |
1222 | int count = 1, count1; | |
1223 | if (count_exp) | |
1224 | count = parse_and_eval_address (count_exp); | |
1225 | count1 = count; | |
1226 | ||
0f552c5f | 1227 | if (target_has_stack == 0 || selected_frame == 0) |
bd5635a1 RP |
1228 | error ("No stack."); |
1229 | ||
1230 | frame = find_relative_frame (selected_frame, &count1); | |
1231 | if (count1 != 0 && count_exp == 0) | |
1232 | error ("Initial frame selected; you cannot go up."); | |
1233 | select_frame (frame, selected_frame_level + count - count1); | |
1234 | } | |
1235 | ||
1236 | static void | |
1237 | up_command (count_exp, from_tty) | |
1238 | char *count_exp; | |
1239 | int from_tty; | |
1240 | { | |
1241 | up_silently_command (count_exp, from_tty); | |
1242 | print_stack_frame (selected_frame, selected_frame_level, 1); | |
1243 | } | |
1244 | ||
1245 | /* Select the frame down one or COUNT stack levels | |
1246 | from the previously selected frame, and print it briefly. */ | |
1247 | ||
e1ce8aa5 | 1248 | /* ARGSUSED */ |
bd5635a1 RP |
1249 | static void |
1250 | down_silently_command (count_exp, from_tty) | |
1251 | char *count_exp; | |
1252 | int from_tty; | |
1253 | { | |
1254 | register FRAME frame; | |
1255 | int count = -1, count1; | |
1256 | if (count_exp) | |
1257 | count = - parse_and_eval_address (count_exp); | |
1258 | count1 = count; | |
1259 | ||
0f552c5f | 1260 | if (target_has_stack == 0 || selected_frame == 0) |
89e0bbcd JG |
1261 | error ("No stack."); |
1262 | ||
bd5635a1 RP |
1263 | frame = find_relative_frame (selected_frame, &count1); |
1264 | if (count1 != 0 && count_exp == 0) | |
4f983400 JK |
1265 | { |
1266 | ||
1267 | /* We only do this if count_exp is not specified. That way "down" | |
1268 | means to really go down (and let me know if that is | |
1269 | impossible), but "down 9999" can be used to mean go all the way | |
1270 | down without getting an error. */ | |
1271 | ||
1272 | error ("Bottom (i.e., innermost) frame selected; you cannot go down."); | |
1273 | } | |
1274 | ||
bd5635a1 RP |
1275 | select_frame (frame, selected_frame_level + count - count1); |
1276 | } | |
1277 | ||
1278 | ||
1279 | static void | |
1280 | down_command (count_exp, from_tty) | |
1281 | char *count_exp; | |
1282 | int from_tty; | |
1283 | { | |
1284 | down_silently_command (count_exp, from_tty); | |
1285 | print_stack_frame (selected_frame, selected_frame_level, 1); | |
1286 | } | |
1287 | \f | |
1288 | static void | |
1289 | return_command (retval_exp, from_tty) | |
1290 | char *retval_exp; | |
1291 | int from_tty; | |
1292 | { | |
777bef06 JK |
1293 | struct symbol *thisfun; |
1294 | FRAME_ADDR selected_frame_addr; | |
1295 | CORE_ADDR selected_frame_pc; | |
bd5635a1 | 1296 | FRAME frame; |
d24c0599 | 1297 | value_ptr return_value = NULL; |
bd5635a1 | 1298 | |
777bef06 JK |
1299 | if (selected_frame == NULL) |
1300 | error ("No selected frame."); | |
1301 | thisfun = get_frame_function (selected_frame); | |
1302 | selected_frame_addr = FRAME_FP (selected_frame); | |
1303 | selected_frame_pc = (get_frame_info (selected_frame))->pc; | |
1304 | ||
78cab901 | 1305 | /* Compute the return value (if any -- possibly getting errors here). */ |
0f552c5f JG |
1306 | |
1307 | if (retval_exp) | |
1308 | { | |
1309 | return_value = parse_and_eval (retval_exp); | |
78cab901 JK |
1310 | |
1311 | /* Make sure we have fully evaluated it, since | |
1312 | it might live in the stack frame we're about to pop. */ | |
1313 | if (VALUE_LAZY (return_value)) | |
1314 | value_fetch_lazy (return_value); | |
0f552c5f JG |
1315 | } |
1316 | ||
bd5635a1 RP |
1317 | /* If interactive, require confirmation. */ |
1318 | ||
1319 | if (from_tty) | |
1320 | { | |
1321 | if (thisfun != 0) | |
1322 | { | |
bd5d07d9 | 1323 | if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun))) |
b4fde6fa FF |
1324 | { |
1325 | error ("Not confirmed."); | |
1326 | /* NOTREACHED */ | |
1327 | } | |
bd5635a1 RP |
1328 | } |
1329 | else | |
1330 | if (!query ("Make selected stack frame return now? ")) | |
1331 | error ("Not confirmed."); | |
1332 | } | |
1333 | ||
1334 | /* Do the real work. Pop until the specified frame is current. We | |
1335 | use this method because the selected_frame is not valid after | |
1336 | a POP_FRAME. The pc comparison makes this work even if the | |
1337 | selected frame shares its fp with another frame. */ | |
1338 | ||
1339 | while ( selected_frame_addr != FRAME_FP (frame = get_current_frame()) | |
1340 | || selected_frame_pc != (get_frame_info (frame))->pc ) | |
1341 | POP_FRAME; | |
1342 | ||
1343 | /* Then pop that frame. */ | |
1344 | ||
1345 | POP_FRAME; | |
1346 | ||
1347 | /* Compute the return value (if any) and store in the place | |
1348 | for return values. */ | |
1349 | ||
1350 | if (retval_exp) | |
0f552c5f | 1351 | set_return_value (return_value); |
bd5635a1 RP |
1352 | |
1353 | /* If interactive, print the frame that is now current. */ | |
1354 | ||
1355 | if (from_tty) | |
1356 | frame_command ("0", 1); | |
1357 | } | |
89e0bbcd JG |
1358 | |
1359 | /* Gets the language of the current frame. */ | |
1360 | enum language | |
1361 | get_frame_language() | |
1362 | { | |
1363 | register struct symtab *s; | |
1364 | FRAME fr; | |
1365 | enum language flang; /* The language of the current frame */ | |
1366 | ||
1367 | fr = get_frame_info(selected_frame); | |
1368 | if(fr) | |
1369 | { | |
1370 | s = find_pc_symtab(fr->pc); | |
1371 | if(s) | |
1372 | flang = s->language; | |
1373 | else | |
1374 | flang = language_unknown; | |
1375 | } | |
1376 | else | |
1377 | flang = language_unknown; | |
1378 | ||
1379 | return flang; | |
1380 | } | |
bd5635a1 RP |
1381 | \f |
1382 | void | |
1383 | _initialize_stack () | |
1384 | { | |
1385 | #if 0 | |
1386 | backtrace_limit = 30; | |
1387 | #endif | |
1388 | ||
1389 | add_com ("return", class_stack, return_command, | |
1390 | "Make selected stack frame return to its caller.\n\ | |
1391 | Control remains in the debugger, but when you continue\n\ | |
1392 | execution will resume in the frame above the one now selected.\n\ | |
1393 | If an argument is given, it is an expression for the value to return."); | |
1394 | ||
1395 | add_com ("up", class_stack, up_command, | |
1396 | "Select and print stack frame that called this one.\n\ | |
1397 | An argument says how many frames up to go."); | |
1398 | add_com ("up-silently", class_support, up_silently_command, | |
1399 | "Same as the `up' command, but does not print anything.\n\ | |
1400 | This is useful in command scripts."); | |
1401 | ||
1402 | add_com ("down", class_stack, down_command, | |
1403 | "Select and print stack frame called by this one.\n\ | |
1404 | An argument says how many frames down to go."); | |
1405 | add_com_alias ("do", "down", class_stack, 1); | |
3de61d8c | 1406 | add_com_alias ("dow", "down", class_stack, 1); |
bd5635a1 RP |
1407 | add_com ("down-silently", class_support, down_silently_command, |
1408 | "Same as the `down' command, but does not print anything.\n\ | |
1409 | This is useful in command scripts."); | |
1410 | ||
1411 | add_com ("frame", class_stack, frame_command, | |
1412 | "Select and print a stack frame.\n\ | |
1413 | With no argument, print the selected stack frame. (See also \"info frame\").\n\ | |
1414 | An argument specifies the frame to select.\n\ | |
1415 | It can be a stack frame number or the address of the frame.\n\ | |
1416 | With argument, nothing is printed if input is coming from\n\ | |
1417 | a command file or a user-defined command."); | |
1418 | ||
1419 | add_com_alias ("f", "frame", class_stack, 1); | |
1420 | ||
c4668207 | 1421 | add_com ("select-frame", class_stack, select_frame_command, |
b0077123 JG |
1422 | "Select a stack frame without printing anything.\n\ |
1423 | An argument specifies the frame to select.\n\ | |
1424 | It can be a stack frame number or the address of the frame.\n"); | |
1425 | ||
bd5635a1 RP |
1426 | add_com ("backtrace", class_stack, backtrace_command, |
1427 | "Print backtrace of all stack frames, or innermost COUNT frames.\n\ | |
1428 | With a negative argument, print outermost -COUNT frames."); | |
1429 | add_com_alias ("bt", "backtrace", class_stack, 0); | |
1430 | add_com_alias ("where", "backtrace", class_alias, 0); | |
1431 | add_info ("stack", backtrace_command, | |
1432 | "Backtrace of the stack, or innermost COUNT frames."); | |
1433 | add_info_alias ("s", "stack", 1); | |
1434 | add_info ("frame", frame_info, | |
1435 | "All about selected stack frame, or frame at ADDR."); | |
1436 | add_info_alias ("f", "frame", 1); | |
1437 | add_info ("locals", locals_info, | |
1438 | "Local variables of current stack frame."); | |
1439 | add_info ("args", args_info, | |
1440 | "Argument variables of current stack frame."); | |
1441 | add_info ("catch", catch_info, | |
1442 | "Exceptions that can be caught in the current stack frame."); | |
1443 | ||
1444 | #if 0 | |
1445 | add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command, | |
1446 | "Specify maximum number of frames for \"backtrace\" to print by default.", | |
1447 | &setlist); | |
1448 | add_info ("backtrace-limit", backtrace_limit_info, | |
1449 | "The maximum number of frames for \"backtrace\" to print by default."); | |
1450 | #endif | |
1451 | } |