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