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