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