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