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