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