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