Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Print and select stack frames for GDB, the GNU debugger. |
8926118c | 2 | |
42a4f53d | 3 | Copyright (C) 1986-2019 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
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. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 19 | |
c906108c | 20 | #include "defs.h" |
c906108c SS |
21 | #include "value.h" |
22 | #include "symtab.h" | |
23 | #include "gdbtypes.h" | |
24 | #include "expression.h" | |
25 | #include "language.h" | |
26 | #include "frame.h" | |
27 | #include "gdbcmd.h" | |
28 | #include "gdbcore.h" | |
29 | #include "target.h" | |
0378c332 | 30 | #include "source.h" |
c906108c SS |
31 | #include "breakpoint.h" |
32 | #include "demangle.h" | |
33 | #include "inferior.h" | |
34 | #include "annotate.h" | |
8b93c638 | 35 | #include "ui-out.h" |
fe898f56 | 36 | #include "block.h" |
b9362cc7 | 37 | #include "stack.h" |
de4f826b | 38 | #include "dictionary.h" |
898c62f5 | 39 | #include "reggroups.h" |
fc70c2a0 | 40 | #include "regcache.h" |
a77053c2 | 41 | #include "solib.h" |
033a42c2 | 42 | #include "valprint.h" |
8ea051c5 | 43 | #include "gdbthread.h" |
3567439c | 44 | #include "cp-support.h" |
30c33a9f | 45 | #include "disasm.h" |
edb3359d | 46 | #include "inline-frame.h" |
f8eba3c6 | 47 | #include "linespec.h" |
529480d0 | 48 | #include "cli/cli-utils.h" |
77e371c0 | 49 | #include "objfiles.h" |
c906108c | 50 | |
ccefe4c4 | 51 | #include "symfile.h" |
6dddc817 | 52 | #include "extension.h" |
76727919 | 53 | #include "observable.h" |
0b868b60 | 54 | #include "common/def-vector.h" |
ccefe4c4 | 55 | |
2421fe6f | 56 | /* The possible choices of "set print frame-arguments", and the value |
88408340 JB |
57 | of this setting. */ |
58 | ||
40478521 | 59 | static const char *const print_frame_arguments_choices[] = |
88408340 | 60 | {"all", "scalars", "none", NULL}; |
476f7b68 | 61 | static const char *print_frame_arguments = "scalars"; |
88408340 | 62 | |
e7045703 DE |
63 | /* If non-zero, don't invoke pretty-printers for frame arguments. */ |
64 | static int print_raw_frame_arguments; | |
65 | ||
e18b2753 JK |
66 | /* The possible choices of "set print entry-values", and the value |
67 | of this setting. */ | |
68 | ||
69 | const char print_entry_values_no[] = "no"; | |
70 | const char print_entry_values_only[] = "only"; | |
71 | const char print_entry_values_preferred[] = "preferred"; | |
72 | const char print_entry_values_if_needed[] = "if-needed"; | |
73 | const char print_entry_values_both[] = "both"; | |
74 | const char print_entry_values_compact[] = "compact"; | |
75 | const char print_entry_values_default[] = "default"; | |
40478521 | 76 | static const char *const print_entry_values_choices[] = |
e18b2753 JK |
77 | { |
78 | print_entry_values_no, | |
79 | print_entry_values_only, | |
80 | print_entry_values_preferred, | |
81 | print_entry_values_if_needed, | |
82 | print_entry_values_both, | |
83 | print_entry_values_compact, | |
84 | print_entry_values_default, | |
85 | NULL | |
86 | }; | |
87 | const char *print_entry_values = print_entry_values_default; | |
88 | ||
c378eb4e | 89 | /* Prototypes for local functions. */ |
c906108c | 90 | |
12615cba PW |
91 | static void print_frame_local_vars (struct frame_info *frame, |
92 | bool quiet, | |
93 | const char *regexp, const char *t_regexp, | |
94 | int num_tabs, struct ui_file *stream); | |
c906108c | 95 | |
033a42c2 MK |
96 | static void print_frame (struct frame_info *frame, int print_level, |
97 | enum print_what print_what, int print_args, | |
c5394b80 JM |
98 | struct symtab_and_line sal); |
99 | ||
1bfeeb0f JL |
100 | static void set_last_displayed_sal (int valid, |
101 | struct program_space *pspace, | |
102 | CORE_ADDR addr, | |
103 | struct symtab *symtab, | |
104 | int line); | |
105 | ||
f67ffa6a AB |
106 | static struct frame_info *find_frame_for_function (const char *); |
107 | static struct frame_info *find_frame_for_address (CORE_ADDR); | |
108 | ||
c906108c SS |
109 | /* Zero means do things normally; we are interacting directly with the |
110 | user. One means print the full filename and linenumber when a | |
111 | frame is printed, and do so in a format emacs18/emacs19.22 can | |
112 | parse. Two means print similar annotations, but in many more | |
113 | cases and in a slightly different syntax. */ | |
114 | ||
115 | int annotation_level = 0; | |
1bfeeb0f JL |
116 | |
117 | /* These variables hold the last symtab and line we displayed to the user. | |
118 | * This is where we insert a breakpoint or a skiplist entry by default. */ | |
119 | static int last_displayed_sal_valid = 0; | |
120 | static struct program_space *last_displayed_pspace = 0; | |
121 | static CORE_ADDR last_displayed_addr = 0; | |
122 | static struct symtab *last_displayed_symtab = 0; | |
123 | static int last_displayed_line = 0; | |
c906108c | 124 | \f |
c5aa993b | 125 | |
edb3359d DJ |
126 | /* Return 1 if we should display the address in addition to the location, |
127 | because we are in the middle of a statement. */ | |
128 | ||
129 | static int | |
130 | frame_show_address (struct frame_info *frame, | |
131 | struct symtab_and_line sal) | |
132 | { | |
133 | /* If there is a line number, but no PC, then there is no location | |
134 | information associated with this sal. The only way that should | |
135 | happen is for the call sites of inlined functions (SAL comes from | |
136 | find_frame_sal). Otherwise, we would have some PC range if the | |
137 | SAL came from a line table. */ | |
138 | if (sal.line != 0 && sal.pc == 0 && sal.end == 0) | |
139 | { | |
140 | if (get_next_frame (frame) == NULL) | |
00431a78 | 141 | gdb_assert (inline_skipped_frames (inferior_thread ()) > 0); |
edb3359d DJ |
142 | else |
143 | gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME); | |
144 | return 0; | |
145 | } | |
146 | ||
147 | return get_frame_pc (frame) != sal.pc; | |
148 | } | |
149 | ||
4034d0ff AT |
150 | /* See frame.h. */ |
151 | ||
152 | void | |
153 | print_stack_frame_to_uiout (struct ui_out *uiout, struct frame_info *frame, | |
154 | int print_level, enum print_what print_what, | |
155 | int set_current_sal) | |
156 | { | |
67ad9399 | 157 | scoped_restore save_uiout = make_scoped_restore (¤t_uiout, uiout); |
4034d0ff AT |
158 | |
159 | print_stack_frame (frame, print_level, print_what, set_current_sal); | |
4034d0ff AT |
160 | } |
161 | ||
f9acce4a | 162 | /* Show or print a stack frame FRAME briefly. The output is formatted |
d762c46a AC |
163 | according to PRINT_LEVEL and PRINT_WHAT printing the frame's |
164 | relative level, function name, argument list, and file name and | |
165 | line number. If the frame's PC is not at the beginning of the | |
166 | source line, the actual PC is printed at the beginning. */ | |
c906108c SS |
167 | |
168 | void | |
033a42c2 | 169 | print_stack_frame (struct frame_info *frame, int print_level, |
08d72866 PA |
170 | enum print_what print_what, |
171 | int set_current_sal) | |
c906108c | 172 | { |
c906108c | 173 | |
aaf9e9fd | 174 | /* For mi, alway print location and address. */ |
112e8700 | 175 | if (current_uiout->is_mi_like_p ()) |
311b5970 | 176 | print_what = LOC_AND_ADDRESS; |
c906108c | 177 | |
a70b8144 | 178 | try |
311b5970 | 179 | { |
08d72866 PA |
180 | print_frame_info (frame, print_level, print_what, 1 /* print_args */, |
181 | set_current_sal); | |
182 | if (set_current_sal) | |
5166082f | 183 | set_current_sal_from_frame (frame); |
311b5970 | 184 | } |
230d2906 | 185 | catch (const gdb_exception_error &e) |
492d29ea PA |
186 | { |
187 | } | |
311b5970 | 188 | } |
c906108c | 189 | |
033a42c2 MK |
190 | /* Print nameless arguments of frame FRAME on STREAM, where START is |
191 | the offset of the first nameless argument, and NUM is the number of | |
192 | nameless arguments to print. FIRST is nonzero if this is the first | |
193 | argument (not just the first nameless argument). */ | |
8d3b0994 AC |
194 | |
195 | static void | |
033a42c2 | 196 | print_frame_nameless_args (struct frame_info *frame, long start, int num, |
8d3b0994 AC |
197 | int first, struct ui_file *stream) |
198 | { | |
e17a4113 UW |
199 | struct gdbarch *gdbarch = get_frame_arch (frame); |
200 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
8d3b0994 AC |
201 | int i; |
202 | CORE_ADDR argsaddr; | |
203 | long arg_value; | |
204 | ||
205 | for (i = 0; i < num; i++) | |
206 | { | |
207 | QUIT; | |
033a42c2 | 208 | argsaddr = get_frame_args_address (frame); |
8d3b0994 AC |
209 | if (!argsaddr) |
210 | return; | |
e17a4113 UW |
211 | arg_value = read_memory_integer (argsaddr + start, |
212 | sizeof (int), byte_order); | |
8d3b0994 AC |
213 | if (!first) |
214 | fprintf_filtered (stream, ", "); | |
215 | fprintf_filtered (stream, "%ld", arg_value); | |
216 | first = 0; | |
217 | start += sizeof (int); | |
218 | } | |
219 | } | |
220 | ||
93d86cef JK |
221 | /* Print single argument of inferior function. ARG must be already |
222 | read in. | |
223 | ||
224 | Errors are printed as if they would be the parameter value. Use zeroed ARG | |
225 | iff it should not be printed accoring to user settings. */ | |
226 | ||
227 | static void | |
228 | print_frame_arg (const struct frame_arg *arg) | |
229 | { | |
230 | struct ui_out *uiout = current_uiout; | |
93d86cef | 231 | |
d7e74731 | 232 | string_file stb; |
93d86cef JK |
233 | |
234 | gdb_assert (!arg->val || !arg->error); | |
e18b2753 JK |
235 | gdb_assert (arg->entry_kind == print_entry_values_no |
236 | || arg->entry_kind == print_entry_values_only | |
112e8700 | 237 | || (!uiout->is_mi_like_p () |
e18b2753 | 238 | && arg->entry_kind == print_entry_values_compact)); |
93d86cef | 239 | |
46b9c129 TT |
240 | annotate_arg_emitter arg_emitter; |
241 | ui_out_emit_tuple tuple_emitter (uiout, NULL); | |
d7e74731 | 242 | fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym), |
93d86cef | 243 | SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI); |
e18b2753 JK |
244 | if (arg->entry_kind == print_entry_values_compact) |
245 | { | |
246 | /* It is OK to provide invalid MI-like stream as with | |
247 | PRINT_ENTRY_VALUE_COMPACT we never use MI. */ | |
d7e74731 | 248 | stb.puts ("="); |
e18b2753 | 249 | |
d7e74731 | 250 | fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym), |
e18b2753 JK |
251 | SYMBOL_LANGUAGE (arg->sym), |
252 | DMGL_PARAMS | DMGL_ANSI); | |
253 | } | |
254 | if (arg->entry_kind == print_entry_values_only | |
255 | || arg->entry_kind == print_entry_values_compact) | |
d7e74731 | 256 | stb.puts ("@entry"); |
80ae2043 | 257 | uiout->field_stream ("name", stb, ui_out_style_kind::VARIABLE); |
93d86cef | 258 | annotate_arg_name_end (); |
112e8700 | 259 | uiout->text ("="); |
93d86cef JK |
260 | |
261 | if (!arg->val && !arg->error) | |
112e8700 | 262 | uiout->text ("..."); |
93d86cef JK |
263 | else |
264 | { | |
265 | if (arg->error) | |
3d6e9d23 | 266 | stb.printf (_("<error reading variable: %s>"), arg->error); |
93d86cef JK |
267 | else |
268 | { | |
a70b8144 | 269 | try |
93d86cef JK |
270 | { |
271 | const struct language_defn *language; | |
272 | struct value_print_options opts; | |
273 | ||
274 | /* Avoid value_print because it will deref ref parameters. We | |
275 | just want to print their addresses. Print ??? for args whose | |
276 | address we do not know. We pass 2 as "recurse" to val_print | |
277 | because our standard indentation here is 4 spaces, and | |
278 | val_print indents 2 for each recurse. */ | |
279 | ||
280 | annotate_arg_value (value_type (arg->val)); | |
281 | ||
282 | /* Use the appropriate language to display our symbol, unless the | |
283 | user forced the language to a specific language. */ | |
284 | if (language_mode == language_mode_auto) | |
285 | language = language_def (SYMBOL_LANGUAGE (arg->sym)); | |
286 | else | |
287 | language = current_language; | |
288 | ||
2a998fc0 | 289 | get_no_prettyformat_print_options (&opts); |
3343315b | 290 | opts.deref_ref = 1; |
e7045703 | 291 | opts.raw = print_raw_frame_arguments; |
93d86cef JK |
292 | |
293 | /* True in "summary" mode, false otherwise. */ | |
294 | opts.summary = !strcmp (print_frame_arguments, "scalars"); | |
295 | ||
d7e74731 | 296 | common_val_print (arg->val, &stb, 2, &opts, language); |
93d86cef | 297 | } |
230d2906 | 298 | catch (const gdb_exception_error &except) |
492d29ea | 299 | { |
3d6e9d23 TT |
300 | stb.printf (_("<error reading variable: %s>"), |
301 | except.what ()); | |
492d29ea | 302 | } |
93d86cef | 303 | } |
93d86cef JK |
304 | } |
305 | ||
112e8700 | 306 | uiout->field_stream ("value", stb); |
93d86cef JK |
307 | } |
308 | ||
82a0a75f YQ |
309 | /* Read in inferior function local SYM at FRAME into ARGP. Caller is |
310 | responsible for xfree of ARGP->ERROR. This function never throws an | |
311 | exception. */ | |
312 | ||
313 | void | |
314 | read_frame_local (struct symbol *sym, struct frame_info *frame, | |
315 | struct frame_arg *argp) | |
316 | { | |
492d29ea PA |
317 | argp->sym = sym; |
318 | argp->val = NULL; | |
319 | argp->error = NULL; | |
320 | ||
a70b8144 | 321 | try |
82a0a75f | 322 | { |
63e43d3a | 323 | argp->val = read_var_value (sym, NULL, frame); |
82a0a75f | 324 | } |
230d2906 | 325 | catch (const gdb_exception_error &except) |
492d29ea | 326 | { |
3d6e9d23 | 327 | argp->error = xstrdup (except.what ()); |
492d29ea | 328 | } |
82a0a75f YQ |
329 | } |
330 | ||
93d86cef JK |
331 | /* Read in inferior function parameter SYM at FRAME into ARGP. Caller is |
332 | responsible for xfree of ARGP->ERROR. This function never throws an | |
333 | exception. */ | |
334 | ||
335 | void | |
336 | read_frame_arg (struct symbol *sym, struct frame_info *frame, | |
e18b2753 | 337 | struct frame_arg *argp, struct frame_arg *entryargp) |
93d86cef | 338 | { |
e18b2753 JK |
339 | struct value *val = NULL, *entryval = NULL; |
340 | char *val_error = NULL, *entryval_error = NULL; | |
341 | int val_equal = 0; | |
93d86cef | 342 | |
e18b2753 JK |
343 | if (print_entry_values != print_entry_values_only |
344 | && print_entry_values != print_entry_values_preferred) | |
345 | { | |
a70b8144 | 346 | try |
e18b2753 | 347 | { |
63e43d3a | 348 | val = read_var_value (sym, NULL, frame); |
e18b2753 | 349 | } |
230d2906 | 350 | catch (const gdb_exception_error &except) |
e18b2753 | 351 | { |
3d6e9d23 TT |
352 | val_error = (char *) alloca (except.message->size () + 1); |
353 | strcpy (val_error, except.what ()); | |
e18b2753 JK |
354 | } |
355 | } | |
356 | ||
24d6c2a0 TT |
357 | if (SYMBOL_COMPUTED_OPS (sym) != NULL |
358 | && SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry != NULL | |
e18b2753 JK |
359 | && print_entry_values != print_entry_values_no |
360 | && (print_entry_values != print_entry_values_if_needed | |
361 | || !val || value_optimized_out (val))) | |
362 | { | |
a70b8144 | 363 | try |
e18b2753 JK |
364 | { |
365 | const struct symbol_computed_ops *ops; | |
366 | ||
367 | ops = SYMBOL_COMPUTED_OPS (sym); | |
368 | entryval = ops->read_variable_at_entry (sym, frame); | |
369 | } | |
230d2906 | 370 | catch (const gdb_exception_error &except) |
e18b2753 | 371 | { |
492d29ea PA |
372 | if (except.error != NO_ENTRY_VALUE_ERROR) |
373 | { | |
3d6e9d23 TT |
374 | entryval_error = (char *) alloca (except.message->size () + 1); |
375 | strcpy (entryval_error, except.what ()); | |
492d29ea | 376 | } |
e18b2753 JK |
377 | } |
378 | ||
492d29ea PA |
379 | if (entryval != NULL && value_optimized_out (entryval)) |
380 | entryval = NULL; | |
e18b2753 JK |
381 | |
382 | if (print_entry_values == print_entry_values_compact | |
383 | || print_entry_values == print_entry_values_default) | |
384 | { | |
385 | /* For MI do not try to use print_entry_values_compact for ARGP. */ | |
386 | ||
112e8700 | 387 | if (val && entryval && !current_uiout->is_mi_like_p ()) |
e18b2753 | 388 | { |
744a8059 | 389 | struct type *type = value_type (val); |
e18b2753 | 390 | |
9a0dc9e3 PA |
391 | if (value_lazy (val)) |
392 | value_fetch_lazy (val); | |
393 | if (value_lazy (entryval)) | |
394 | value_fetch_lazy (entryval); | |
395 | ||
396 | if (value_contents_eq (val, 0, entryval, 0, TYPE_LENGTH (type))) | |
e18b2753 | 397 | { |
509f0fd9 JK |
398 | /* Initialize it just to avoid a GCC false warning. */ |
399 | struct value *val_deref = NULL, *entryval_deref; | |
a471c594 | 400 | |
216f72a1 | 401 | /* DW_AT_call_value does match with the current |
a471c594 | 402 | value. If it is a reference still try to verify if |
216f72a1 | 403 | dereferenced DW_AT_call_data_value does not differ. */ |
a471c594 | 404 | |
a70b8144 | 405 | try |
a471c594 | 406 | { |
744a8059 | 407 | struct type *type_deref; |
a471c594 JK |
408 | |
409 | val_deref = coerce_ref (val); | |
410 | if (value_lazy (val_deref)) | |
411 | value_fetch_lazy (val_deref); | |
744a8059 | 412 | type_deref = value_type (val_deref); |
a471c594 JK |
413 | |
414 | entryval_deref = coerce_ref (entryval); | |
415 | if (value_lazy (entryval_deref)) | |
416 | value_fetch_lazy (entryval_deref); | |
417 | ||
418 | /* If the reference addresses match but dereferenced | |
419 | content does not match print them. */ | |
420 | if (val != val_deref | |
9a0dc9e3 PA |
421 | && value_contents_eq (val_deref, 0, |
422 | entryval_deref, 0, | |
423 | TYPE_LENGTH (type_deref))) | |
a471c594 JK |
424 | val_equal = 1; |
425 | } | |
230d2906 | 426 | catch (const gdb_exception_error &except) |
492d29ea PA |
427 | { |
428 | /* If the dereferenced content could not be | |
429 | fetched do not display anything. */ | |
430 | if (except.error == NO_ENTRY_VALUE_ERROR) | |
431 | val_equal = 1; | |
432 | else if (except.message != NULL) | |
433 | { | |
3d6e9d23 TT |
434 | entryval_error |
435 | = (char *) alloca (except.message->size () + 1); | |
436 | strcpy (entryval_error, except.what ()); | |
492d29ea PA |
437 | } |
438 | } | |
a471c594 JK |
439 | |
440 | /* Value was not a reference; and its content matches. */ | |
441 | if (val == val_deref) | |
442 | val_equal = 1; | |
a471c594 JK |
443 | |
444 | if (val_equal) | |
445 | entryval = NULL; | |
e18b2753 JK |
446 | } |
447 | } | |
448 | ||
449 | /* Try to remove possibly duplicate error message for ENTRYARGP even | |
450 | in MI mode. */ | |
451 | ||
452 | if (val_error && entryval_error | |
453 | && strcmp (val_error, entryval_error) == 0) | |
454 | { | |
455 | entryval_error = NULL; | |
456 | ||
457 | /* Do not se VAL_EQUAL as the same error message may be shown for | |
458 | the entry value even if no entry values are present in the | |
459 | inferior. */ | |
460 | } | |
461 | } | |
462 | } | |
463 | ||
464 | if (entryval == NULL) | |
93d86cef | 465 | { |
e18b2753 JK |
466 | if (print_entry_values == print_entry_values_preferred) |
467 | { | |
492d29ea PA |
468 | gdb_assert (val == NULL); |
469 | ||
a70b8144 | 470 | try |
e18b2753 | 471 | { |
63e43d3a | 472 | val = read_var_value (sym, NULL, frame); |
e18b2753 | 473 | } |
230d2906 | 474 | catch (const gdb_exception_error &except) |
e18b2753 | 475 | { |
3d6e9d23 TT |
476 | val_error = (char *) alloca (except.message->size () + 1); |
477 | strcpy (val_error, except.what ()); | |
e18b2753 JK |
478 | } |
479 | } | |
480 | if (print_entry_values == print_entry_values_only | |
481 | || print_entry_values == print_entry_values_both | |
482 | || (print_entry_values == print_entry_values_preferred | |
483 | && (!val || value_optimized_out (val)))) | |
1ed8d800 YQ |
484 | { |
485 | entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym)); | |
486 | entryval_error = NULL; | |
487 | } | |
93d86cef | 488 | } |
e18b2753 JK |
489 | if ((print_entry_values == print_entry_values_compact |
490 | || print_entry_values == print_entry_values_if_needed | |
491 | || print_entry_values == print_entry_values_preferred) | |
492 | && (!val || value_optimized_out (val)) && entryval != NULL) | |
93d86cef | 493 | { |
e18b2753 JK |
494 | val = NULL; |
495 | val_error = NULL; | |
93d86cef JK |
496 | } |
497 | ||
498 | argp->sym = sym; | |
499 | argp->val = val; | |
500 | argp->error = val_error ? xstrdup (val_error) : NULL; | |
e18b2753 JK |
501 | if (!val && !val_error) |
502 | argp->entry_kind = print_entry_values_only; | |
503 | else if ((print_entry_values == print_entry_values_compact | |
504 | || print_entry_values == print_entry_values_default) && val_equal) | |
505 | { | |
506 | argp->entry_kind = print_entry_values_compact; | |
112e8700 | 507 | gdb_assert (!current_uiout->is_mi_like_p ()); |
e18b2753 JK |
508 | } |
509 | else | |
510 | argp->entry_kind = print_entry_values_no; | |
511 | ||
512 | entryargp->sym = sym; | |
513 | entryargp->val = entryval; | |
514 | entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL; | |
515 | if (!entryval && !entryval_error) | |
516 | entryargp->entry_kind = print_entry_values_no; | |
517 | else | |
518 | entryargp->entry_kind = print_entry_values_only; | |
93d86cef JK |
519 | } |
520 | ||
033a42c2 MK |
521 | /* Print the arguments of frame FRAME on STREAM, given the function |
522 | FUNC running in that frame (as a symbol), where NUM is the number | |
523 | of arguments according to the stack frame (or -1 if the number of | |
524 | arguments is unknown). */ | |
8d3b0994 | 525 | |
e3168615 | 526 | /* Note that currently the "number of arguments according to the |
033a42c2 | 527 | stack frame" is only known on VAX where i refers to the "number of |
e3168615 | 528 | ints of arguments according to the stack frame". */ |
8d3b0994 AC |
529 | |
530 | static void | |
033a42c2 MK |
531 | print_frame_args (struct symbol *func, struct frame_info *frame, |
532 | int num, struct ui_file *stream) | |
8d3b0994 | 533 | { |
79a45e25 | 534 | struct ui_out *uiout = current_uiout; |
8d3b0994 | 535 | int first = 1; |
8d3b0994 | 536 | /* Offset of next stack argument beyond the one we have seen that is |
033a42c2 MK |
537 | at the highest offset, or -1 if we haven't come to a stack |
538 | argument yet. */ | |
8d3b0994 | 539 | long highest_offset = -1; |
8d3b0994 AC |
540 | /* Number of ints of arguments that we have printed so far. */ |
541 | int args_printed = 0; | |
a6bac58e TT |
542 | /* True if we should print arguments, false otherwise. */ |
543 | int print_args = strcmp (print_frame_arguments, "none"); | |
8d3b0994 | 544 | |
8d3b0994 AC |
545 | if (func) |
546 | { | |
3977b71f | 547 | const struct block *b = SYMBOL_BLOCK_VALUE (func); |
8157b174 | 548 | struct block_iterator iter; |
033a42c2 | 549 | struct symbol *sym; |
8d3b0994 | 550 | |
de4f826b | 551 | ALL_BLOCK_SYMBOLS (b, iter, sym) |
8d3b0994 | 552 | { |
e18b2753 | 553 | struct frame_arg arg, entryarg; |
93d86cef | 554 | |
8d3b0994 AC |
555 | QUIT; |
556 | ||
557 | /* Keep track of the highest stack argument offset seen, and | |
558 | skip over any kinds of symbols we don't care about. */ | |
559 | ||
2a2d4dc3 AS |
560 | if (!SYMBOL_IS_ARGUMENT (sym)) |
561 | continue; | |
562 | ||
8d3b0994 AC |
563 | switch (SYMBOL_CLASS (sym)) |
564 | { | |
565 | case LOC_ARG: | |
566 | case LOC_REF_ARG: | |
567 | { | |
568 | long current_offset = SYMBOL_VALUE (sym); | |
033a42c2 | 569 | int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym)); |
8d3b0994 AC |
570 | |
571 | /* Compute address of next argument by adding the size of | |
572 | this argument and rounding to an int boundary. */ | |
573 | current_offset = | |
574 | ((current_offset + arg_size + sizeof (int) - 1) | |
575 | & ~(sizeof (int) - 1)); | |
576 | ||
033a42c2 MK |
577 | /* If this is the highest offset seen yet, set |
578 | highest_offset. */ | |
8d3b0994 AC |
579 | if (highest_offset == -1 |
580 | || (current_offset > highest_offset)) | |
581 | highest_offset = current_offset; | |
582 | ||
033a42c2 MK |
583 | /* Add the number of ints we're about to print to |
584 | args_printed. */ | |
8d3b0994 AC |
585 | args_printed += (arg_size + sizeof (int) - 1) / sizeof (int); |
586 | } | |
587 | ||
033a42c2 MK |
588 | /* We care about types of symbols, but don't need to |
589 | keep track of stack offsets in them. */ | |
2a2d4dc3 | 590 | case LOC_REGISTER: |
8d3b0994 | 591 | case LOC_REGPARM_ADDR: |
2a2d4dc3 AS |
592 | case LOC_COMPUTED: |
593 | case LOC_OPTIMIZED_OUT: | |
8d3b0994 | 594 | default: |
2a2d4dc3 | 595 | break; |
8d3b0994 AC |
596 | } |
597 | ||
598 | /* We have to look up the symbol because arguments can have | |
599 | two entries (one a parameter, one a local) and the one we | |
600 | want is the local, which lookup_symbol will find for us. | |
033a42c2 | 601 | This includes gcc1 (not gcc2) on SPARC when passing a |
8d3b0994 AC |
602 | small structure and gcc2 when the argument type is float |
603 | and it is passed as a double and converted to float by | |
604 | the prologue (in the latter case the type of the LOC_ARG | |
605 | symbol is double and the type of the LOC_LOCAL symbol is | |
606 | float). */ | |
033a42c2 MK |
607 | /* But if the parameter name is null, don't try it. Null |
608 | parameter names occur on the RS/6000, for traceback | |
609 | tables. FIXME, should we even print them? */ | |
8d3b0994 | 610 | |
3567439c | 611 | if (*SYMBOL_LINKAGE_NAME (sym)) |
8d3b0994 AC |
612 | { |
613 | struct symbol *nsym; | |
433759f7 | 614 | |
de63c46b PA |
615 | nsym = lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym), |
616 | b, VAR_DOMAIN).symbol; | |
55765a25 | 617 | gdb_assert (nsym != NULL); |
2a2d4dc3 AS |
618 | if (SYMBOL_CLASS (nsym) == LOC_REGISTER |
619 | && !SYMBOL_IS_ARGUMENT (nsym)) | |
8d3b0994 | 620 | { |
033a42c2 MK |
621 | /* There is a LOC_ARG/LOC_REGISTER pair. This means |
622 | that it was passed on the stack and loaded into a | |
623 | register, or passed in a register and stored in a | |
624 | stack slot. GDB 3.x used the LOC_ARG; GDB | |
625 | 4.0-4.11 used the LOC_REGISTER. | |
8d3b0994 AC |
626 | |
627 | Reasons for using the LOC_ARG: | |
033a42c2 MK |
628 | |
629 | (1) Because find_saved_registers may be slow for | |
630 | remote debugging. | |
631 | ||
632 | (2) Because registers are often re-used and stack | |
633 | slots rarely (never?) are. Therefore using | |
634 | the stack slot is much less likely to print | |
635 | garbage. | |
8d3b0994 AC |
636 | |
637 | Reasons why we might want to use the LOC_REGISTER: | |
033a42c2 MK |
638 | |
639 | (1) So that the backtrace prints the same value | |
640 | as "print foo". I see no compelling reason | |
641 | why this needs to be the case; having the | |
642 | backtrace print the value which was passed | |
643 | in, and "print foo" print the value as | |
644 | modified within the called function, makes | |
645 | perfect sense to me. | |
646 | ||
647 | Additional note: It might be nice if "info args" | |
648 | displayed both values. | |
649 | ||
650 | One more note: There is a case with SPARC | |
651 | structure passing where we need to use the | |
652 | LOC_REGISTER, but this is dealt with by creating | |
653 | a single LOC_REGPARM in symbol reading. */ | |
8d3b0994 AC |
654 | |
655 | /* Leave sym (the LOC_ARG) alone. */ | |
656 | ; | |
657 | } | |
658 | else | |
659 | sym = nsym; | |
660 | } | |
661 | ||
662 | /* Print the current arg. */ | |
663 | if (!first) | |
112e8700 SM |
664 | uiout->text (", "); |
665 | uiout->wrap_hint (" "); | |
8d3b0994 | 666 | |
93d86cef JK |
667 | if (!print_args) |
668 | { | |
669 | memset (&arg, 0, sizeof (arg)); | |
670 | arg.sym = sym; | |
e18b2753 JK |
671 | arg.entry_kind = print_entry_values_no; |
672 | memset (&entryarg, 0, sizeof (entryarg)); | |
673 | entryarg.sym = sym; | |
674 | entryarg.entry_kind = print_entry_values_no; | |
93d86cef JK |
675 | } |
676 | else | |
e18b2753 | 677 | read_frame_arg (sym, frame, &arg, &entryarg); |
8d3b0994 | 678 | |
e18b2753 JK |
679 | if (arg.entry_kind != print_entry_values_only) |
680 | print_frame_arg (&arg); | |
681 | ||
682 | if (entryarg.entry_kind != print_entry_values_no) | |
683 | { | |
684 | if (arg.entry_kind != print_entry_values_only) | |
685 | { | |
112e8700 SM |
686 | uiout->text (", "); |
687 | uiout->wrap_hint (" "); | |
e18b2753 JK |
688 | } |
689 | ||
690 | print_frame_arg (&entryarg); | |
691 | } | |
8d3b0994 | 692 | |
93d86cef | 693 | xfree (arg.error); |
e18b2753 | 694 | xfree (entryarg.error); |
8d3b0994 AC |
695 | |
696 | first = 0; | |
697 | } | |
698 | } | |
699 | ||
700 | /* Don't print nameless args in situations where we don't know | |
701 | enough about the stack to find them. */ | |
702 | if (num != -1) | |
703 | { | |
704 | long start; | |
705 | ||
706 | if (highest_offset == -1) | |
7500260a | 707 | start = gdbarch_frame_args_skip (get_frame_arch (frame)); |
8d3b0994 AC |
708 | else |
709 | start = highest_offset; | |
710 | ||
033a42c2 | 711 | print_frame_nameless_args (frame, start, num - args_printed, |
8d3b0994 AC |
712 | first, stream); |
713 | } | |
8d3b0994 AC |
714 | } |
715 | ||
033a42c2 MK |
716 | /* Set the current source and line to the location given by frame |
717 | FRAME, if possible. When CENTER is true, adjust so the relevant | |
718 | line is in the center of the next 'list'. */ | |
c789492a | 719 | |
7abfe014 | 720 | void |
5166082f | 721 | set_current_sal_from_frame (struct frame_info *frame) |
c789492a | 722 | { |
51abb421 | 723 | symtab_and_line sal = find_frame_sal (frame); |
5166082f | 724 | if (sal.symtab != NULL) |
51abb421 | 725 | set_current_source_symtab_and_line (sal); |
c789492a FL |
726 | } |
727 | ||
30c33a9f HZ |
728 | /* If ON, GDB will display disassembly of the next source line when |
729 | execution of the program being debugged stops. | |
481df73e HZ |
730 | If AUTO (which is the default), or there's no line info to determine |
731 | the source line of the next instruction, display disassembly of next | |
732 | instruction instead. */ | |
30c33a9f HZ |
733 | |
734 | static enum auto_boolean disassemble_next_line; | |
735 | ||
736 | static void | |
737 | show_disassemble_next_line (struct ui_file *file, int from_tty, | |
738 | struct cmd_list_element *c, | |
739 | const char *value) | |
740 | { | |
3e43a32a MS |
741 | fprintf_filtered (file, |
742 | _("Debugger's willingness to use " | |
743 | "disassemble-next-line is %s.\n"), | |
30c33a9f HZ |
744 | value); |
745 | } | |
746 | ||
30c33a9f HZ |
747 | /* Use TRY_CATCH to catch the exception from the gdb_disassembly |
748 | because it will be broken by filter sometime. */ | |
749 | ||
750 | static void | |
13274fc3 UW |
751 | do_gdb_disassembly (struct gdbarch *gdbarch, |
752 | int how_many, CORE_ADDR low, CORE_ADDR high) | |
30c33a9f | 753 | { |
30c33a9f | 754 | |
a70b8144 | 755 | try |
30c33a9f | 756 | { |
7a8eb317 | 757 | gdb_disassembly (gdbarch, current_uiout, |
79a45e25 PA |
758 | DISASSEMBLY_RAW_INSN, how_many, |
759 | low, high); | |
30c33a9f | 760 | } |
230d2906 | 761 | catch (const gdb_exception_error &exception) |
b1d288d3 JK |
762 | { |
763 | /* If an exception was thrown while doing the disassembly, print | |
764 | the error message, to give the user a clue of what happened. */ | |
765 | exception_print (gdb_stderr, exception); | |
766 | } | |
30c33a9f HZ |
767 | } |
768 | ||
033a42c2 | 769 | /* Print information about frame FRAME. The output is format according |
65aa373f | 770 | to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS. The meaning of |
033a42c2 MK |
771 | PRINT_WHAT is: |
772 | ||
773 | SRC_LINE: Print only source line. | |
774 | LOCATION: Print only location. | |
50c65c2d | 775 | SRC_AND_LOC: Print location and source line. |
033a42c2 MK |
776 | |
777 | Used in "where" output, and to emit breakpoint or step | |
778 | messages. */ | |
c906108c | 779 | |
7789c6f5 | 780 | void |
033a42c2 | 781 | print_frame_info (struct frame_info *frame, int print_level, |
08d72866 PA |
782 | enum print_what print_what, int print_args, |
783 | int set_current_sal) | |
c906108c | 784 | { |
5af949e3 | 785 | struct gdbarch *gdbarch = get_frame_arch (frame); |
c5394b80 JM |
786 | int source_print; |
787 | int location_print; | |
79a45e25 | 788 | struct ui_out *uiout = current_uiout; |
c906108c | 789 | |
033a42c2 | 790 | if (get_frame_type (frame) == DUMMY_FRAME |
36f15f55 UW |
791 | || get_frame_type (frame) == SIGTRAMP_FRAME |
792 | || get_frame_type (frame) == ARCH_FRAME) | |
c906108c | 793 | { |
2e783024 | 794 | ui_out_emit_tuple tuple_emitter (uiout, "frame"); |
c906108c | 795 | |
033a42c2 | 796 | annotate_frame_begin (print_level ? frame_relative_level (frame) : 0, |
5af949e3 | 797 | gdbarch, get_frame_pc (frame)); |
6a3fe0a4 | 798 | |
c906108c | 799 | /* Do this regardless of SOURCE because we don't have any source |
c5aa993b | 800 | to list for this frame. */ |
0faf0076 | 801 | if (print_level) |
52c6a6ac | 802 | { |
112e8700 SM |
803 | uiout->text ("#"); |
804 | uiout->field_fmt_int (2, ui_left, "level", | |
033a42c2 | 805 | frame_relative_level (frame)); |
52c6a6ac | 806 | } |
112e8700 | 807 | if (uiout->is_mi_like_p ()) |
52c6a6ac | 808 | { |
075559bc | 809 | annotate_frame_address (); |
112e8700 | 810 | uiout->field_core_addr ("addr", |
5af949e3 | 811 | gdbarch, get_frame_pc (frame)); |
075559bc | 812 | annotate_frame_address_end (); |
52c6a6ac | 813 | } |
6a3fe0a4 | 814 | |
033a42c2 | 815 | if (get_frame_type (frame) == DUMMY_FRAME) |
075559bc AC |
816 | { |
817 | annotate_function_call (); | |
cbe56571 TT |
818 | uiout->field_string ("func", "<function called from gdb>", |
819 | ui_out_style_kind::FUNCTION); | |
075559bc | 820 | } |
033a42c2 | 821 | else if (get_frame_type (frame) == SIGTRAMP_FRAME) |
075559bc AC |
822 | { |
823 | annotate_signal_handler_caller (); | |
cbe56571 TT |
824 | uiout->field_string ("func", "<signal handler called>", |
825 | ui_out_style_kind::FUNCTION); | |
075559bc | 826 | } |
36f15f55 UW |
827 | else if (get_frame_type (frame) == ARCH_FRAME) |
828 | { | |
cbe56571 TT |
829 | uiout->field_string ("func", "<cross-architecture call>", |
830 | ui_out_style_kind::FUNCTION); | |
36f15f55 | 831 | } |
112e8700 | 832 | uiout->text ("\n"); |
c906108c | 833 | annotate_frame_end (); |
075559bc | 834 | |
433e77fa HZ |
835 | /* If disassemble-next-line is set to auto or on output the next |
836 | instruction. */ | |
837 | if (disassemble_next_line == AUTO_BOOLEAN_AUTO | |
838 | || disassemble_next_line == AUTO_BOOLEAN_TRUE) | |
839 | do_gdb_disassembly (get_frame_arch (frame), 1, | |
840 | get_frame_pc (frame), get_frame_pc (frame) + 1); | |
841 | ||
c906108c SS |
842 | return; |
843 | } | |
844 | ||
033a42c2 MK |
845 | /* If FRAME is not the innermost frame, that normally means that |
846 | FRAME->pc points to *after* the call instruction, and we want to | |
847 | get the line containing the call, never the next line. But if | |
848 | the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the | |
849 | next frame was not entered as the result of a call, and we want | |
850 | to get the line containing FRAME->pc. */ | |
51abb421 | 851 | symtab_and_line sal = find_frame_sal (frame); |
c906108c | 852 | |
0faf0076 AC |
853 | location_print = (print_what == LOCATION |
854 | || print_what == LOC_AND_ADDRESS | |
855 | || print_what == SRC_AND_LOC); | |
c5394b80 JM |
856 | |
857 | if (location_print || !sal.symtab) | |
033a42c2 | 858 | print_frame (frame, print_level, print_what, print_args, sal); |
c5394b80 | 859 | |
0faf0076 | 860 | source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC); |
0378c332 | 861 | |
30c33a9f HZ |
862 | /* If disassemble-next-line is set to auto or on and doesn't have |
863 | the line debug messages for $pc, output the next instruction. */ | |
864 | if ((disassemble_next_line == AUTO_BOOLEAN_AUTO | |
865 | || disassemble_next_line == AUTO_BOOLEAN_TRUE) | |
866 | && source_print && !sal.symtab) | |
13274fc3 UW |
867 | do_gdb_disassembly (get_frame_arch (frame), 1, |
868 | get_frame_pc (frame), get_frame_pc (frame) + 1); | |
30c33a9f | 869 | |
c5394b80 JM |
870 | if (source_print && sal.symtab) |
871 | { | |
872 | int done = 0; | |
0faf0076 | 873 | int mid_statement = ((print_what == SRC_LINE) |
edb3359d | 874 | && frame_show_address (frame, sal)); |
c5394b80 JM |
875 | |
876 | if (annotation_level) | |
877 | done = identify_source_line (sal.symtab, sal.line, mid_statement, | |
033a42c2 | 878 | get_frame_pc (frame)); |
c5394b80 JM |
879 | if (!done) |
880 | { | |
9a4105ab | 881 | if (deprecated_print_frame_info_listing_hook) |
cbd3c883 MS |
882 | deprecated_print_frame_info_listing_hook (sal.symtab, |
883 | sal.line, | |
884 | sal.line + 1, 0); | |
ba4bbdcb | 885 | else |
c5394b80 | 886 | { |
79a45b7d | 887 | struct value_print_options opts; |
433759f7 | 888 | |
79a45b7d | 889 | get_user_print_options (&opts); |
ba4bbdcb | 890 | /* We used to do this earlier, but that is clearly |
c378eb4e | 891 | wrong. This function is used by many different |
ba4bbdcb KS |
892 | parts of gdb, including normal_stop in infrun.c, |
893 | which uses this to print out the current PC | |
894 | when we stepi/nexti into the middle of a source | |
c378eb4e MS |
895 | line. Only the command line really wants this |
896 | behavior. Other UIs probably would like the | |
cbd3c883 | 897 | ability to decide for themselves if it is desired. */ |
79a45b7d | 898 | if (opts.addressprint && mid_statement) |
ba4bbdcb | 899 | { |
112e8700 | 900 | uiout->field_core_addr ("addr", |
5af949e3 | 901 | gdbarch, get_frame_pc (frame)); |
112e8700 | 902 | uiout->text ("\t"); |
ba4bbdcb KS |
903 | } |
904 | ||
905 | print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); | |
c5394b80 | 906 | } |
c5394b80 | 907 | } |
30c33a9f HZ |
908 | |
909 | /* If disassemble-next-line is set to on and there is line debug | |
910 | messages, output assembly codes for next line. */ | |
911 | if (disassemble_next_line == AUTO_BOOLEAN_TRUE) | |
2b28d209 | 912 | do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end); |
c5394b80 JM |
913 | } |
914 | ||
08d72866 | 915 | if (set_current_sal) |
e3eebbd7 PA |
916 | { |
917 | CORE_ADDR pc; | |
918 | ||
919 | if (get_frame_pc_if_available (frame, &pc)) | |
1bfeeb0f | 920 | set_last_displayed_sal (1, sal.pspace, pc, sal.symtab, sal.line); |
e3eebbd7 | 921 | else |
1bfeeb0f | 922 | set_last_displayed_sal (0, 0, 0, 0, 0); |
e3eebbd7 | 923 | } |
c5394b80 JM |
924 | |
925 | annotate_frame_end (); | |
926 | ||
927 | gdb_flush (gdb_stdout); | |
928 | } | |
929 | ||
1bfeeb0f JL |
930 | /* Remember the last symtab and line we displayed, which we use e.g. |
931 | * as the place to put a breakpoint when the `break' command is | |
932 | * invoked with no arguments. */ | |
933 | ||
934 | static void | |
935 | set_last_displayed_sal (int valid, struct program_space *pspace, | |
936 | CORE_ADDR addr, struct symtab *symtab, | |
937 | int line) | |
938 | { | |
939 | last_displayed_sal_valid = valid; | |
940 | last_displayed_pspace = pspace; | |
941 | last_displayed_addr = addr; | |
942 | last_displayed_symtab = symtab; | |
943 | last_displayed_line = line; | |
4cb6da1c AR |
944 | if (valid && pspace == NULL) |
945 | { | |
4cb6da1c | 946 | clear_last_displayed_sal (); |
e36930bb PA |
947 | internal_error (__FILE__, __LINE__, |
948 | _("Trying to set NULL pspace.")); | |
4cb6da1c | 949 | } |
1bfeeb0f JL |
950 | } |
951 | ||
952 | /* Forget the last sal we displayed. */ | |
953 | ||
954 | void | |
955 | clear_last_displayed_sal (void) | |
956 | { | |
957 | last_displayed_sal_valid = 0; | |
958 | last_displayed_pspace = 0; | |
959 | last_displayed_addr = 0; | |
960 | last_displayed_symtab = 0; | |
961 | last_displayed_line = 0; | |
962 | } | |
963 | ||
964 | /* Is our record of the last sal we displayed valid? If not, | |
965 | * the get_last_displayed_* functions will return NULL or 0, as | |
966 | * appropriate. */ | |
967 | ||
968 | int | |
969 | last_displayed_sal_is_valid (void) | |
970 | { | |
971 | return last_displayed_sal_valid; | |
972 | } | |
973 | ||
974 | /* Get the pspace of the last sal we displayed, if it's valid. */ | |
975 | ||
976 | struct program_space * | |
977 | get_last_displayed_pspace (void) | |
978 | { | |
979 | if (last_displayed_sal_valid) | |
980 | return last_displayed_pspace; | |
981 | return 0; | |
982 | } | |
983 | ||
984 | /* Get the address of the last sal we displayed, if it's valid. */ | |
985 | ||
986 | CORE_ADDR | |
987 | get_last_displayed_addr (void) | |
988 | { | |
989 | if (last_displayed_sal_valid) | |
990 | return last_displayed_addr; | |
991 | return 0; | |
992 | } | |
993 | ||
994 | /* Get the symtab of the last sal we displayed, if it's valid. */ | |
995 | ||
996 | struct symtab* | |
997 | get_last_displayed_symtab (void) | |
998 | { | |
999 | if (last_displayed_sal_valid) | |
1000 | return last_displayed_symtab; | |
1001 | return 0; | |
1002 | } | |
1003 | ||
1004 | /* Get the line of the last sal we displayed, if it's valid. */ | |
1005 | ||
1006 | int | |
1007 | get_last_displayed_line (void) | |
1008 | { | |
1009 | if (last_displayed_sal_valid) | |
1010 | return last_displayed_line; | |
1011 | return 0; | |
1012 | } | |
1013 | ||
1014 | /* Get the last sal we displayed, if it's valid. */ | |
1015 | ||
51abb421 PA |
1016 | symtab_and_line |
1017 | get_last_displayed_sal () | |
1bfeeb0f | 1018 | { |
51abb421 PA |
1019 | symtab_and_line sal; |
1020 | ||
1bfeeb0f JL |
1021 | if (last_displayed_sal_valid) |
1022 | { | |
51abb421 PA |
1023 | sal.pspace = last_displayed_pspace; |
1024 | sal.pc = last_displayed_addr; | |
1025 | sal.symtab = last_displayed_symtab; | |
1026 | sal.line = last_displayed_line; | |
1bfeeb0f | 1027 | } |
51abb421 PA |
1028 | |
1029 | return sal; | |
1bfeeb0f JL |
1030 | } |
1031 | ||
1032 | ||
c6dc63a1 TT |
1033 | /* Attempt to obtain the name, FUNLANG and optionally FUNCP of the function |
1034 | corresponding to FRAME. */ | |
e9e07ba6 | 1035 | |
c6dc63a1 TT |
1036 | gdb::unique_xmalloc_ptr<char> |
1037 | find_frame_funname (struct frame_info *frame, enum language *funlang, | |
1038 | struct symbol **funcp) | |
c5394b80 JM |
1039 | { |
1040 | struct symbol *func; | |
c6dc63a1 | 1041 | gdb::unique_xmalloc_ptr<char> funname; |
8b93c638 | 1042 | |
f8f6f20b | 1043 | *funlang = language_unknown; |
e9e07ba6 JK |
1044 | if (funcp) |
1045 | *funcp = NULL; | |
c5394b80 | 1046 | |
edb3359d | 1047 | func = get_frame_function (frame); |
c906108c SS |
1048 | if (func) |
1049 | { | |
1050 | /* In certain pathological cases, the symtabs give the wrong | |
c5aa993b JM |
1051 | function (when we are in the first function in a file which |
1052 | is compiled without debugging symbols, the previous function | |
1053 | is compiled with debugging symbols, and the "foo.o" symbol | |
033a42c2 MK |
1054 | that is supposed to tell us where the file with debugging |
1055 | symbols ends has been truncated by ar because it is longer | |
1056 | than 15 characters). This also occurs if the user uses asm() | |
1057 | to create a function but not stabs for it (in a file compiled | |
1058 | with -g). | |
c5aa993b JM |
1059 | |
1060 | So look in the minimal symbol tables as well, and if it comes | |
1061 | up with a larger address for the function use that instead. | |
033a42c2 MK |
1062 | I don't think this can ever cause any problems; there |
1063 | shouldn't be any minimal symbols in the middle of a function; | |
1064 | if this is ever changed many parts of GDB will need to be | |
1065 | changed (and we'll create a find_pc_minimal_function or some | |
1066 | such). */ | |
1067 | ||
7cbd4a93 | 1068 | struct bound_minimal_symbol msymbol; |
edb3359d DJ |
1069 | |
1070 | /* Don't attempt to do this for inlined functions, which do not | |
1071 | have a corresponding minimal symbol. */ | |
1072 | if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func))) | |
1073 | msymbol | |
1074 | = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame)); | |
7cbd4a93 TT |
1075 | else |
1076 | memset (&msymbol, 0, sizeof (msymbol)); | |
c906108c | 1077 | |
7cbd4a93 | 1078 | if (msymbol.minsym != NULL |
77e371c0 | 1079 | && (BMSYMBOL_VALUE_ADDRESS (msymbol) |
2b1ffcfd | 1080 | > BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func)))) |
c906108c | 1081 | { |
c906108c SS |
1082 | /* We also don't know anything about the function besides |
1083 | its address and name. */ | |
1084 | func = 0; | |
c6dc63a1 | 1085 | funname.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym))); |
efd66ac6 | 1086 | *funlang = MSYMBOL_LANGUAGE (msymbol.minsym); |
c906108c SS |
1087 | } |
1088 | else | |
1089 | { | |
d10153cf TT |
1090 | const char *print_name = SYMBOL_PRINT_NAME (func); |
1091 | ||
f8f6f20b | 1092 | *funlang = SYMBOL_LANGUAGE (func); |
e9e07ba6 JK |
1093 | if (funcp) |
1094 | *funcp = func; | |
f8f6f20b | 1095 | if (*funlang == language_cplus) |
c5aa993b | 1096 | { |
033a42c2 MK |
1097 | /* It seems appropriate to use SYMBOL_PRINT_NAME() here, |
1098 | to display the demangled name that we already have | |
1099 | stored in the symbol table, but we stored a version | |
1100 | with DMGL_PARAMS turned on, and here we don't want to | |
3567439c | 1101 | display parameters. So remove the parameters. */ |
109483d9 | 1102 | funname = cp_remove_params (print_name); |
c5aa993b | 1103 | } |
d10153cf | 1104 | |
c6dc63a1 TT |
1105 | /* If we didn't hit the C++ case above, set *funname |
1106 | here. */ | |
1107 | if (funname == NULL) | |
1108 | funname.reset (xstrdup (print_name)); | |
c906108c SS |
1109 | } |
1110 | } | |
1111 | else | |
1112 | { | |
7cbd4a93 | 1113 | struct bound_minimal_symbol msymbol; |
e3eebbd7 | 1114 | CORE_ADDR pc; |
033a42c2 | 1115 | |
e3eebbd7 | 1116 | if (!get_frame_address_in_block_if_available (frame, &pc)) |
c6dc63a1 | 1117 | return funname; |
e3eebbd7 PA |
1118 | |
1119 | msymbol = lookup_minimal_symbol_by_pc (pc); | |
7cbd4a93 | 1120 | if (msymbol.minsym != NULL) |
c906108c | 1121 | { |
c6dc63a1 | 1122 | funname.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym))); |
efd66ac6 | 1123 | *funlang = MSYMBOL_LANGUAGE (msymbol.minsym); |
c906108c SS |
1124 | } |
1125 | } | |
c6dc63a1 TT |
1126 | |
1127 | return funname; | |
f8f6f20b TJB |
1128 | } |
1129 | ||
1130 | static void | |
1131 | print_frame (struct frame_info *frame, int print_level, | |
1132 | enum print_what print_what, int print_args, | |
1133 | struct symtab_and_line sal) | |
1134 | { | |
5af949e3 | 1135 | struct gdbarch *gdbarch = get_frame_arch (frame); |
79a45e25 | 1136 | struct ui_out *uiout = current_uiout; |
f8f6f20b | 1137 | enum language funlang = language_unknown; |
f8f6f20b | 1138 | struct value_print_options opts; |
e9e07ba6 | 1139 | struct symbol *func; |
e3eebbd7 PA |
1140 | CORE_ADDR pc = 0; |
1141 | int pc_p; | |
1142 | ||
1143 | pc_p = get_frame_pc_if_available (frame, &pc); | |
f8f6f20b | 1144 | |
c6dc63a1 TT |
1145 | gdb::unique_xmalloc_ptr<char> funname |
1146 | = find_frame_funname (frame, &funlang, &func); | |
c906108c | 1147 | |
033a42c2 | 1148 | annotate_frame_begin (print_level ? frame_relative_level (frame) : 0, |
e3eebbd7 | 1149 | gdbarch, pc); |
c5394b80 | 1150 | |
76f9c9cf TT |
1151 | { |
1152 | ui_out_emit_tuple tuple_emitter (uiout, "frame"); | |
c5394b80 | 1153 | |
76f9c9cf | 1154 | if (print_level) |
c5394b80 | 1155 | { |
76f9c9cf TT |
1156 | uiout->text ("#"); |
1157 | uiout->field_fmt_int (2, ui_left, "level", | |
1158 | frame_relative_level (frame)); | |
c5394b80 | 1159 | } |
76f9c9cf TT |
1160 | get_user_print_options (&opts); |
1161 | if (opts.addressprint) | |
1162 | if (!sal.symtab | |
1163 | || frame_show_address (frame, sal) | |
1164 | || print_what == LOC_AND_ADDRESS) | |
311b5970 | 1165 | { |
76f9c9cf TT |
1166 | annotate_frame_address (); |
1167 | if (pc_p) | |
1168 | uiout->field_core_addr ("addr", gdbarch, pc); | |
1169 | else | |
35fb8261 TT |
1170 | uiout->field_string ("addr", "<unavailable>", |
1171 | ui_out_style_kind::ADDRESS); | |
76f9c9cf TT |
1172 | annotate_frame_address_end (); |
1173 | uiout->text (" in "); | |
311b5970 | 1174 | } |
76f9c9cf TT |
1175 | annotate_frame_function_name (); |
1176 | ||
1177 | string_file stb; | |
c6dc63a1 | 1178 | fprintf_symbol_filtered (&stb, funname ? funname.get () : "??", |
76f9c9cf | 1179 | funlang, DMGL_ANSI); |
cbe56571 | 1180 | uiout->field_stream ("func", stb, ui_out_style_kind::FUNCTION); |
76f9c9cf TT |
1181 | uiout->wrap_hint (" "); |
1182 | annotate_frame_args (); | |
cbe56571 | 1183 | |
76f9c9cf TT |
1184 | uiout->text (" ("); |
1185 | if (print_args) | |
10f489e5 | 1186 | { |
76f9c9cf TT |
1187 | int numargs; |
1188 | ||
1189 | if (gdbarch_frame_num_args_p (gdbarch)) | |
10f489e5 | 1190 | { |
76f9c9cf TT |
1191 | numargs = gdbarch_frame_num_args (gdbarch, frame); |
1192 | gdb_assert (numargs >= 0); | |
10f489e5 | 1193 | } |
76f9c9cf TT |
1194 | else |
1195 | numargs = -1; | |
1196 | ||
1197 | { | |
1198 | ui_out_emit_list list_emitter (uiout, "args"); | |
a70b8144 | 1199 | try |
76f9c9cf TT |
1200 | { |
1201 | print_frame_args (func, frame, numargs, gdb_stdout); | |
1202 | } | |
230d2906 | 1203 | catch (const gdb_exception_error &e) |
76f9c9cf TT |
1204 | { |
1205 | } | |
10f489e5 | 1206 | |
76f9c9cf TT |
1207 | /* FIXME: ARGS must be a list. If one argument is a string it |
1208 | will have " that will not be properly escaped. */ | |
1209 | } | |
1210 | QUIT; | |
10f489e5 | 1211 | } |
76f9c9cf TT |
1212 | uiout->text (")"); |
1213 | if (sal.symtab) | |
1214 | { | |
1215 | const char *filename_display; | |
1b56eb55 | 1216 | |
76f9c9cf TT |
1217 | filename_display = symtab_to_filename_for_display (sal.symtab); |
1218 | annotate_frame_source_begin (); | |
1219 | uiout->wrap_hint (" "); | |
1220 | uiout->text (" at "); | |
1221 | annotate_frame_source_file (); | |
cbe56571 | 1222 | uiout->field_string ("file", filename_display, ui_out_style_kind::FILE); |
76f9c9cf TT |
1223 | if (uiout->is_mi_like_p ()) |
1224 | { | |
1225 | const char *fullname = symtab_to_fullname (sal.symtab); | |
433759f7 | 1226 | |
76f9c9cf TT |
1227 | uiout->field_string ("fullname", fullname); |
1228 | } | |
1229 | annotate_frame_source_file_end (); | |
1230 | uiout->text (":"); | |
1231 | annotate_frame_source_line (); | |
1232 | uiout->field_int ("line", sal.line); | |
1233 | annotate_frame_source_end (); | |
1234 | } | |
c906108c | 1235 | |
76f9c9cf TT |
1236 | if (pc_p && (funname == NULL || sal.symtab == NULL)) |
1237 | { | |
1238 | char *lib = solib_name_from_address (get_frame_program_space (frame), | |
1239 | get_frame_pc (frame)); | |
4d1eb6b4 | 1240 | |
76f9c9cf TT |
1241 | if (lib) |
1242 | { | |
1243 | annotate_frame_where (); | |
1244 | uiout->wrap_hint (" "); | |
1245 | uiout->text (" from "); | |
1246 | uiout->field_string ("from", lib); | |
1247 | } | |
1248 | } | |
6d52907e JV |
1249 | if (uiout->is_mi_like_p ()) |
1250 | uiout->field_string ("arch", | |
1251 | (gdbarch_bfd_arch_info (gdbarch))->printable_name); | |
76f9c9cf | 1252 | } |
e514a9d6 | 1253 | |
112e8700 | 1254 | uiout->text ("\n"); |
c906108c SS |
1255 | } |
1256 | \f | |
c5aa993b | 1257 | |
f67ffa6a AB |
1258 | /* Completion function for "frame function", "info frame function", and |
1259 | "select-frame function" commands. */ | |
c906108c | 1260 | |
f67ffa6a AB |
1261 | void |
1262 | frame_selection_by_function_completer (struct cmd_list_element *ignore, | |
1263 | completion_tracker &tracker, | |
1264 | const char *text, const char *word) | |
c906108c | 1265 | { |
f67ffa6a AB |
1266 | /* This is used to complete function names within a stack. It would be |
1267 | nice if we only offered functions that were actually in the stack. | |
1268 | However, this would mean unwinding the stack to completion, which | |
1269 | could take too long, or on a corrupted stack, possibly not end. | |
1270 | Instead, we offer all symbol names as a safer choice. */ | |
1271 | collect_symbol_completion_matches (tracker, | |
1272 | complete_symbol_mode::EXPRESSION, | |
1273 | symbol_name_match_type::EXPRESSION, | |
1274 | text, word); | |
1c8831c5 AC |
1275 | } |
1276 | ||
f67ffa6a AB |
1277 | /* Core of all the "info frame" sub-commands. Print information about a |
1278 | frame FI. If SELECTED_FRAME_P is true then the user didn't provide a | |
1279 | frame specification, they just entered 'info frame'. If the user did | |
1280 | provide a frame specification (for example 'info frame 0', 'info frame | |
1281 | level 1') then SELECTED_FRAME_P will be false. */ | |
c906108c SS |
1282 | |
1283 | static void | |
f67ffa6a | 1284 | info_frame_command_core (struct frame_info *fi, bool selected_frame_p) |
c906108c | 1285 | { |
c906108c SS |
1286 | struct symbol *func; |
1287 | struct symtab *s; | |
1288 | struct frame_info *calling_frame_info; | |
167e4384 | 1289 | int numregs; |
0d5cff50 | 1290 | const char *funname = 0; |
c906108c | 1291 | enum language funlang = language_unknown; |
82de1e5b | 1292 | const char *pc_regname; |
7500260a | 1293 | struct gdbarch *gdbarch; |
008f8f2e PA |
1294 | CORE_ADDR frame_pc; |
1295 | int frame_pc_p; | |
e5e6f788 YQ |
1296 | /* Initialize it to avoid "may be used uninitialized" warning. */ |
1297 | CORE_ADDR caller_pc = 0; | |
492d29ea | 1298 | int caller_pc_p = 0; |
c906108c | 1299 | |
12368003 | 1300 | gdbarch = get_frame_arch (fi); |
c906108c | 1301 | |
82de1e5b AC |
1302 | /* Name of the value returned by get_frame_pc(). Per comments, "pc" |
1303 | is not a good name. */ | |
12368003 | 1304 | if (gdbarch_pc_regnum (gdbarch) >= 0) |
3e8c568d | 1305 | /* OK, this is weird. The gdbarch_pc_regnum hardware register's value can |
82de1e5b AC |
1306 | easily not match that of the internal value returned by |
1307 | get_frame_pc(). */ | |
12368003 | 1308 | pc_regname = gdbarch_register_name (gdbarch, gdbarch_pc_regnum (gdbarch)); |
82de1e5b | 1309 | else |
3e8c568d | 1310 | /* But then, this is weird to. Even without gdbarch_pc_regnum, an |
82de1e5b AC |
1311 | architectures will often have a hardware register called "pc", |
1312 | and that register's value, again, can easily not match | |
1313 | get_frame_pc(). */ | |
1314 | pc_regname = "pc"; | |
1315 | ||
008f8f2e | 1316 | frame_pc_p = get_frame_pc_if_available (fi, &frame_pc); |
c906108c | 1317 | func = get_frame_function (fi); |
51abb421 | 1318 | symtab_and_line sal = find_frame_sal (fi); |
008f8f2e | 1319 | s = sal.symtab; |
2003f3d8 | 1320 | gdb::unique_xmalloc_ptr<char> func_only; |
c906108c SS |
1321 | if (func) |
1322 | { | |
3567439c | 1323 | funname = SYMBOL_PRINT_NAME (func); |
c5aa993b JM |
1324 | funlang = SYMBOL_LANGUAGE (func); |
1325 | if (funlang == language_cplus) | |
1326 | { | |
3567439c DJ |
1327 | /* It seems appropriate to use SYMBOL_PRINT_NAME() here, |
1328 | to display the demangled name that we already have | |
1329 | stored in the symbol table, but we stored a version | |
1330 | with DMGL_PARAMS turned on, and here we don't want to | |
1331 | display parameters. So remove the parameters. */ | |
109483d9 | 1332 | func_only = cp_remove_params (funname); |
433759f7 | 1333 | |
3567439c | 1334 | if (func_only) |
2003f3d8 | 1335 | funname = func_only.get (); |
c5aa993b | 1336 | } |
c906108c | 1337 | } |
008f8f2e | 1338 | else if (frame_pc_p) |
c906108c | 1339 | { |
7cbd4a93 | 1340 | struct bound_minimal_symbol msymbol; |
033a42c2 | 1341 | |
008f8f2e | 1342 | msymbol = lookup_minimal_symbol_by_pc (frame_pc); |
7cbd4a93 | 1343 | if (msymbol.minsym != NULL) |
c906108c | 1344 | { |
efd66ac6 TT |
1345 | funname = MSYMBOL_PRINT_NAME (msymbol.minsym); |
1346 | funlang = MSYMBOL_LANGUAGE (msymbol.minsym); | |
c906108c SS |
1347 | } |
1348 | } | |
1349 | calling_frame_info = get_prev_frame (fi); | |
1350 | ||
1c8831c5 | 1351 | if (selected_frame_p && frame_relative_level (fi) >= 0) |
c906108c | 1352 | { |
a3f17187 | 1353 | printf_filtered (_("Stack level %d, frame at "), |
1c8831c5 | 1354 | frame_relative_level (fi)); |
c906108c SS |
1355 | } |
1356 | else | |
1357 | { | |
a3f17187 | 1358 | printf_filtered (_("Stack frame at ")); |
c906108c | 1359 | } |
5af949e3 | 1360 | fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout); |
9c833c82 | 1361 | printf_filtered (":\n"); |
82de1e5b | 1362 | printf_filtered (" %s = ", pc_regname); |
008f8f2e PA |
1363 | if (frame_pc_p) |
1364 | fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout); | |
1365 | else | |
1366 | fputs_filtered ("<unavailable>", gdb_stdout); | |
c906108c SS |
1367 | |
1368 | wrap_here (" "); | |
1369 | if (funname) | |
1370 | { | |
1371 | printf_filtered (" in "); | |
1372 | fprintf_symbol_filtered (gdb_stdout, funname, funlang, | |
1373 | DMGL_ANSI | DMGL_PARAMS); | |
1374 | } | |
1375 | wrap_here (" "); | |
1376 | if (sal.symtab) | |
05cba821 JK |
1377 | printf_filtered (" (%s:%d)", symtab_to_filename_for_display (sal.symtab), |
1378 | sal.line); | |
c906108c SS |
1379 | puts_filtered ("; "); |
1380 | wrap_here (" "); | |
782d47df PA |
1381 | printf_filtered ("saved %s = ", pc_regname); |
1382 | ||
a038fa3e | 1383 | if (!frame_id_p (frame_unwind_caller_id (fi))) |
c620c3e4 | 1384 | val_print_not_saved (gdb_stdout); |
a038fa3e | 1385 | else |
782d47df | 1386 | { |
a70b8144 | 1387 | try |
782d47df | 1388 | { |
a038fa3e MM |
1389 | caller_pc = frame_unwind_caller_pc (fi); |
1390 | caller_pc_p = 1; | |
782d47df | 1391 | } |
230d2906 | 1392 | catch (const gdb_exception_error &ex) |
a038fa3e MM |
1393 | { |
1394 | switch (ex.error) | |
1395 | { | |
1396 | case NOT_AVAILABLE_ERROR: | |
1397 | val_print_unavailable (gdb_stdout); | |
1398 | break; | |
1399 | case OPTIMIZED_OUT_ERROR: | |
1400 | val_print_not_saved (gdb_stdout); | |
1401 | break; | |
1402 | default: | |
3d6e9d23 TT |
1403 | fprintf_filtered (gdb_stdout, _("<error: %s>"), |
1404 | ex.what ()); | |
a038fa3e MM |
1405 | break; |
1406 | } | |
1407 | } | |
782d47df | 1408 | } |
492d29ea PA |
1409 | |
1410 | if (caller_pc_p) | |
782d47df | 1411 | fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout); |
c906108c SS |
1412 | printf_filtered ("\n"); |
1413 | ||
55feb689 DJ |
1414 | if (calling_frame_info == NULL) |
1415 | { | |
1416 | enum unwind_stop_reason reason; | |
1417 | ||
1418 | reason = get_frame_unwind_stop_reason (fi); | |
1419 | if (reason != UNWIND_NO_REASON) | |
1420 | printf_filtered (_(" Outermost frame: %s\n"), | |
53e8a631 | 1421 | frame_stop_reason_string (fi)); |
55feb689 | 1422 | } |
111c6489 JK |
1423 | else if (get_frame_type (fi) == TAILCALL_FRAME) |
1424 | puts_filtered (" tail call frame"); | |
edb3359d DJ |
1425 | else if (get_frame_type (fi) == INLINE_FRAME) |
1426 | printf_filtered (" inlined into frame %d", | |
1427 | frame_relative_level (get_prev_frame (fi))); | |
1428 | else | |
c906108c SS |
1429 | { |
1430 | printf_filtered (" called by frame at "); | |
5af949e3 | 1431 | fputs_filtered (paddress (gdbarch, get_frame_base (calling_frame_info)), |
ed49a04f | 1432 | gdb_stdout); |
c906108c | 1433 | } |
75e3c1f9 | 1434 | if (get_next_frame (fi) && calling_frame_info) |
c906108c SS |
1435 | puts_filtered (","); |
1436 | wrap_here (" "); | |
75e3c1f9 | 1437 | if (get_next_frame (fi)) |
c906108c SS |
1438 | { |
1439 | printf_filtered (" caller of frame at "); | |
5af949e3 | 1440 | fputs_filtered (paddress (gdbarch, get_frame_base (get_next_frame (fi))), |
ed49a04f | 1441 | gdb_stdout); |
c906108c | 1442 | } |
75e3c1f9 | 1443 | if (get_next_frame (fi) || calling_frame_info) |
c906108c | 1444 | puts_filtered ("\n"); |
55feb689 | 1445 | |
c906108c | 1446 | if (s) |
1058bca7 AC |
1447 | printf_filtered (" source language %s.\n", |
1448 | language_str (s->language)); | |
c906108c | 1449 | |
c906108c SS |
1450 | { |
1451 | /* Address of the argument list for this frame, or 0. */ | |
da62e633 | 1452 | CORE_ADDR arg_list = get_frame_args_address (fi); |
c906108c SS |
1453 | /* Number of args for this frame, or -1 if unknown. */ |
1454 | int numargs; | |
1455 | ||
1456 | if (arg_list == 0) | |
1457 | printf_filtered (" Arglist at unknown address.\n"); | |
1458 | else | |
1459 | { | |
1460 | printf_filtered (" Arglist at "); | |
5af949e3 | 1461 | fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout); |
c906108c SS |
1462 | printf_filtered (","); |
1463 | ||
7500260a | 1464 | if (!gdbarch_frame_num_args_p (gdbarch)) |
983a287a AC |
1465 | { |
1466 | numargs = -1; | |
1467 | puts_filtered (" args: "); | |
1468 | } | |
c906108c | 1469 | else |
983a287a | 1470 | { |
7500260a | 1471 | numargs = gdbarch_frame_num_args (gdbarch, fi); |
983a287a AC |
1472 | gdb_assert (numargs >= 0); |
1473 | if (numargs == 0) | |
1474 | puts_filtered (" no args."); | |
1475 | else if (numargs == 1) | |
1476 | puts_filtered (" 1 arg: "); | |
1477 | else | |
1478 | printf_filtered (" %d args: ", numargs); | |
1479 | } | |
c906108c SS |
1480 | print_frame_args (func, fi, numargs, gdb_stdout); |
1481 | puts_filtered ("\n"); | |
1482 | } | |
1483 | } | |
1484 | { | |
1485 | /* Address of the local variables for this frame, or 0. */ | |
da62e633 | 1486 | CORE_ADDR arg_list = get_frame_locals_address (fi); |
c906108c SS |
1487 | |
1488 | if (arg_list == 0) | |
1489 | printf_filtered (" Locals at unknown address,"); | |
1490 | else | |
1491 | { | |
1492 | printf_filtered (" Locals at "); | |
5af949e3 | 1493 | fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout); |
c906108c SS |
1494 | printf_filtered (","); |
1495 | } | |
1496 | } | |
1497 | ||
4f460812 AC |
1498 | /* Print as much information as possible on the location of all the |
1499 | registers. */ | |
1500 | { | |
4f460812 AC |
1501 | int count; |
1502 | int i; | |
1503 | int need_nl = 1; | |
b0e4b369 | 1504 | int sp_regnum = gdbarch_sp_regnum (gdbarch); |
4f460812 AC |
1505 | |
1506 | /* The sp is special; what's displayed isn't the save address, but | |
1507 | the value of the previous frame's sp. This is a legacy thing, | |
1508 | at one stage the frame cached the previous frame's SP instead | |
1509 | of its address, hence it was easiest to just display the cached | |
1510 | value. */ | |
b0e4b369 | 1511 | if (sp_regnum >= 0) |
4f460812 | 1512 | { |
b0e4b369 AH |
1513 | struct value *value = frame_unwind_register_value (fi, sp_regnum); |
1514 | gdb_assert (value != NULL); | |
1515 | ||
1516 | if (!value_optimized_out (value) && value_entirely_available (value)) | |
4f460812 | 1517 | { |
b0e4b369 AH |
1518 | if (VALUE_LVAL (value) == not_lval) |
1519 | { | |
1520 | CORE_ADDR sp; | |
1521 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
1522 | int sp_size = register_size (gdbarch, sp_regnum); | |
1523 | ||
1524 | sp = extract_unsigned_integer (value_contents_all (value), | |
1525 | sp_size, byte_order); | |
1526 | ||
1527 | printf_filtered (" Previous frame's sp is "); | |
1528 | fputs_filtered (paddress (gdbarch, sp), gdb_stdout); | |
1529 | printf_filtered ("\n"); | |
1530 | } | |
1531 | else if (VALUE_LVAL (value) == lval_memory) | |
1532 | { | |
1533 | printf_filtered (" Previous frame's sp at "); | |
1534 | fputs_filtered (paddress (gdbarch, value_address (value)), | |
1535 | gdb_stdout); | |
1536 | printf_filtered ("\n"); | |
1537 | } | |
1538 | else if (VALUE_LVAL (value) == lval_register) | |
1539 | { | |
1540 | printf_filtered (" Previous frame's sp in %s\n", | |
1541 | gdbarch_register_name (gdbarch, | |
1542 | VALUE_REGNUM (value))); | |
1543 | } | |
1544 | ||
1545 | release_value (value); | |
4f460812 AC |
1546 | need_nl = 0; |
1547 | } | |
1548 | /* else keep quiet. */ | |
1549 | } | |
1550 | ||
1551 | count = 0; | |
f6efe3f8 | 1552 | numregs = gdbarch_num_cooked_regs (gdbarch); |
4f460812 | 1553 | for (i = 0; i < numregs; i++) |
b0e4b369 | 1554 | if (i != sp_regnum |
7500260a | 1555 | && gdbarch_register_reggroup_p (gdbarch, i, all_reggroup)) |
4f460812 | 1556 | { |
b0e4b369 AH |
1557 | enum lval_type lval; |
1558 | int optimized; | |
1559 | int unavailable; | |
1560 | CORE_ADDR addr; | |
1561 | int realnum; | |
1562 | ||
4f460812 AC |
1563 | /* Find out the location of the saved register without |
1564 | fetching the corresponding value. */ | |
0fdb4f18 PA |
1565 | frame_register_unwind (fi, i, &optimized, &unavailable, |
1566 | &lval, &addr, &realnum, NULL); | |
4f460812 AC |
1567 | /* For moment, only display registers that were saved on the |
1568 | stack. */ | |
0fdb4f18 | 1569 | if (!optimized && !unavailable && lval == lval_memory) |
4f460812 AC |
1570 | { |
1571 | if (count == 0) | |
1572 | puts_filtered (" Saved registers:\n "); | |
1573 | else | |
1574 | puts_filtered (","); | |
1575 | wrap_here (" "); | |
c9f4d572 | 1576 | printf_filtered (" %s at ", |
7500260a | 1577 | gdbarch_register_name (gdbarch, i)); |
5af949e3 | 1578 | fputs_filtered (paddress (gdbarch, addr), gdb_stdout); |
4f460812 AC |
1579 | count++; |
1580 | } | |
1581 | } | |
1582 | if (count || need_nl) | |
c906108c | 1583 | puts_filtered ("\n"); |
4f460812 | 1584 | } |
c906108c SS |
1585 | } |
1586 | ||
6a70eb7d PW |
1587 | /* Return the innermost frame at level LEVEL. */ |
1588 | ||
1589 | static struct frame_info * | |
1590 | leading_innermost_frame (int level) | |
1591 | { | |
1592 | struct frame_info *leading; | |
1593 | ||
1594 | leading = get_current_frame (); | |
1595 | ||
1596 | gdb_assert (level >= 0); | |
1597 | ||
1598 | while (leading != nullptr && level) | |
1599 | { | |
1600 | QUIT; | |
1601 | leading = get_prev_frame (leading); | |
1602 | level--; | |
1603 | } | |
1604 | ||
1605 | return leading; | |
1606 | } | |
1607 | ||
1608 | /* Return the starting frame needed to handle COUNT outermost frames. */ | |
1609 | ||
1610 | static struct frame_info * | |
1611 | trailing_outermost_frame (int count) | |
1612 | { | |
1613 | struct frame_info *current; | |
1614 | struct frame_info *trailing; | |
1615 | ||
1616 | trailing = get_current_frame (); | |
1617 | ||
1618 | gdb_assert (count > 0); | |
1619 | ||
1620 | current = trailing; | |
1621 | while (current != nullptr && count--) | |
1622 | { | |
1623 | QUIT; | |
1624 | current = get_prev_frame (current); | |
1625 | } | |
1626 | ||
1627 | /* Will stop when CURRENT reaches the top of the stack. | |
1628 | TRAILING will be COUNT below it. */ | |
1629 | while (current != nullptr) | |
1630 | { | |
1631 | QUIT; | |
1632 | trailing = get_prev_frame (trailing); | |
1633 | current = get_prev_frame (current); | |
1634 | } | |
1635 | ||
1636 | return trailing; | |
1637 | } | |
1638 | ||
f67ffa6a AB |
1639 | /* The core of all the "select-frame" sub-commands. Just wraps a call to |
1640 | SELECT_FRAME. */ | |
1641 | ||
1642 | static void | |
1643 | select_frame_command_core (struct frame_info *fi, bool ignored) | |
1644 | { | |
1645 | struct frame_info *prev_frame = get_selected_frame_if_set (); | |
1646 | select_frame (fi); | |
1647 | if (get_selected_frame_if_set () != prev_frame) | |
1648 | gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME); | |
1649 | } | |
1650 | ||
1651 | /* See stack.h. */ | |
1652 | ||
1653 | void | |
1654 | select_frame_for_mi (struct frame_info *fi) | |
1655 | { | |
e2eb806a | 1656 | select_frame_command_core (fi, false /* Ignored. */); |
f67ffa6a AB |
1657 | } |
1658 | ||
1659 | /* The core of all the "frame" sub-commands. Select frame FI, and if this | |
1660 | means we change frame send out a change notification (otherwise, just | |
1661 | reprint the current frame summary). */ | |
1662 | ||
1663 | static void | |
1664 | frame_command_core (struct frame_info *fi, bool ignored) | |
1665 | { | |
1666 | struct frame_info *prev_frame = get_selected_frame_if_set (); | |
1667 | ||
1668 | select_frame (fi); | |
1669 | if (get_selected_frame_if_set () != prev_frame) | |
1670 | gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME); | |
1671 | else | |
1672 | print_selected_thread_frame (current_uiout, USER_SELECTED_FRAME); | |
1673 | } | |
1674 | ||
1675 | /* The three commands 'frame', 'select-frame', and 'info frame' all have a | |
1676 | common set of sub-commands that allow a specific frame to be selected. | |
1677 | All of the sub-command functions are static methods within this class | |
1678 | template which is then instantiated below. The template parameter is a | |
1679 | callback used to implement the functionality of the base command | |
1680 | ('frame', 'select-frame', or 'info frame'). | |
1681 | ||
1682 | In the template parameter FI is the frame being selected. The | |
1683 | SELECTED_FRAME_P flag is true if the frame being selected was done by | |
1684 | default, which happens when the user uses the base command with no | |
1685 | arguments. For example the commands 'info frame', 'select-frame', | |
1686 | 'frame' will all cause SELECTED_FRAME_P to be true. In all other cases | |
1687 | SELECTED_FRAME_P is false. */ | |
1688 | ||
1689 | template <void (*FPTR) (struct frame_info *fi, bool selected_frame_p)> | |
1690 | class frame_command_helper | |
1691 | { | |
1692 | public: | |
1693 | ||
1694 | /* The "frame level" family of commands. The ARG is an integer that is | |
1695 | the frame's level in the stack. */ | |
1696 | static void | |
1697 | level (const char *arg, int from_tty) | |
1698 | { | |
1699 | int level = value_as_long (parse_and_eval (arg)); | |
1700 | struct frame_info *fid | |
1701 | = find_relative_frame (get_current_frame (), &level); | |
1702 | if (level != 0) | |
1703 | error (_("No frame at level %s."), arg); | |
1704 | FPTR (fid, false); | |
1705 | } | |
1706 | ||
1707 | /* The "frame address" family of commands. ARG is a stack-pointer | |
1708 | address for an existing frame. This command does not allow new | |
1709 | frames to be created. */ | |
1710 | ||
1711 | static void | |
1712 | address (const char *arg, int from_tty) | |
1713 | { | |
1714 | CORE_ADDR addr = value_as_address (parse_and_eval (arg)); | |
1715 | struct frame_info *fid = find_frame_for_address (addr); | |
1716 | if (fid == NULL) | |
1717 | error (_("No frame at address %s."), arg); | |
1718 | FPTR (fid, false); | |
1719 | } | |
1720 | ||
1721 | /* The "frame view" family of commands. ARG is one or two addresses and | |
1722 | is used to view a frame that might be outside the current backtrace. | |
1723 | The addresses are stack-pointer address, and (optional) pc-address. */ | |
1724 | ||
1725 | static void | |
1726 | view (const char *args, int from_tty) | |
1727 | { | |
1728 | struct frame_info *fid; | |
1729 | ||
1730 | if (args == NULL) | |
1731 | error (_("Missing address argument to view a frame")); | |
1732 | ||
1733 | gdb_argv argv (args); | |
1734 | ||
1735 | if (argv.count () == 2) | |
1736 | { | |
1737 | CORE_ADDR addr[2]; | |
1738 | ||
1739 | addr [0] = value_as_address (parse_and_eval (argv[0])); | |
1740 | addr [1] = value_as_address (parse_and_eval (argv[1])); | |
1741 | fid = create_new_frame (addr[0], addr[1]); | |
1742 | } | |
1743 | else | |
1744 | { | |
1745 | CORE_ADDR addr = value_as_address (parse_and_eval (argv[0])); | |
1746 | fid = create_new_frame (addr, false); | |
1747 | } | |
1748 | FPTR (fid, false); | |
1749 | } | |
1750 | ||
1751 | /* The "frame function" family of commands. ARG is the name of a | |
1752 | function within the stack, the first function (searching from frame | |
1753 | 0) with that name will be selected. */ | |
1754 | ||
1755 | static void | |
1756 | function (const char *arg, int from_tty) | |
1757 | { | |
1758 | if (arg == NULL) | |
1759 | error (_("Missing function name argument")); | |
1760 | struct frame_info *fid = find_frame_for_function (arg); | |
1761 | if (fid == NULL) | |
1762 | error (_("No frame for function \"%s\"."), arg); | |
1763 | FPTR (fid, false); | |
1764 | } | |
1765 | ||
1766 | /* The "frame" base command, that is, when no sub-command is specified. | |
1767 | If one argument is provided then we assume that this is a frame's | |
1768 | level as historically, this was the supported command syntax that was | |
1769 | used most often. | |
1770 | ||
1771 | If no argument is provided, then the current frame is selected. */ | |
1772 | ||
1773 | static void | |
1774 | base_command (const char *arg, int from_tty) | |
1775 | { | |
1776 | if (arg == NULL) | |
1777 | FPTR (get_selected_frame (_("No stack.")), true); | |
1778 | else | |
1779 | level (arg, from_tty); | |
1780 | } | |
1781 | }; | |
1782 | ||
1783 | /* Instantiate three FRAME_COMMAND_HELPER instances to implement the | |
1784 | sub-commands for 'info frame', 'frame', and 'select-frame' commands. */ | |
1785 | ||
1786 | static frame_command_helper <info_frame_command_core> info_frame_cmd; | |
1787 | static frame_command_helper <frame_command_core> frame_cmd; | |
1788 | static frame_command_helper <select_frame_command_core> select_frame_cmd; | |
1789 | ||
033a42c2 MK |
1790 | /* Print briefly all stack frames or just the innermost COUNT_EXP |
1791 | frames. */ | |
c906108c SS |
1792 | |
1793 | static void | |
1cf7e640 TT |
1794 | backtrace_command_1 (const char *count_exp, frame_filter_flags flags, |
1795 | int no_filters, int from_tty) | |
c906108c SS |
1796 | { |
1797 | struct frame_info *fi; | |
52f0bd74 | 1798 | int count; |
fb7eb8b5 | 1799 | int py_start = 0, py_end = 0; |
6dddc817 | 1800 | enum ext_lang_bt_status result = EXT_LANG_BT_ERROR; |
c906108c SS |
1801 | |
1802 | if (!target_has_stack) | |
8a3fe4f8 | 1803 | error (_("No stack.")); |
c906108c | 1804 | |
c906108c SS |
1805 | if (count_exp) |
1806 | { | |
bb518678 | 1807 | count = parse_and_eval_long (count_exp); |
c906108c | 1808 | if (count < 0) |
fb7eb8b5 | 1809 | py_start = count; |
1e611234 PM |
1810 | else |
1811 | { | |
1812 | py_start = 0; | |
6893c19a TT |
1813 | /* The argument to apply_ext_lang_frame_filter is the number |
1814 | of the final frame to print, and frames start at 0. */ | |
1815 | py_end = count - 1; | |
1e611234 | 1816 | } |
c906108c SS |
1817 | } |
1818 | else | |
1e611234 PM |
1819 | { |
1820 | py_end = -1; | |
1821 | count = -1; | |
1822 | } | |
c906108c | 1823 | |
1e611234 | 1824 | if (! no_filters) |
c906108c | 1825 | { |
6dddc817 | 1826 | enum ext_lang_frame_args arg_type; |
c906108c | 1827 | |
1cf7e640 | 1828 | flags |= PRINT_LEVEL | PRINT_FRAME_INFO | PRINT_ARGS; |
6893c19a TT |
1829 | if (from_tty) |
1830 | flags |= PRINT_MORE_FRAMES; | |
1e611234 PM |
1831 | |
1832 | if (!strcmp (print_frame_arguments, "scalars")) | |
1833 | arg_type = CLI_SCALAR_VALUES; | |
1834 | else if (!strcmp (print_frame_arguments, "all")) | |
1835 | arg_type = CLI_ALL_VALUES; | |
1836 | else | |
1837 | arg_type = NO_VALUES; | |
1838 | ||
6dddc817 DE |
1839 | result = apply_ext_lang_frame_filter (get_current_frame (), flags, |
1840 | arg_type, current_uiout, | |
1841 | py_start, py_end); | |
1e611234 | 1842 | } |
6dddc817 | 1843 | |
1e611234 PM |
1844 | /* Run the inbuilt backtrace if there are no filters registered, or |
1845 | "no-filters" has been specified from the command. */ | |
6dddc817 | 1846 | if (no_filters || result == EXT_LANG_BT_NO_FILTERS) |
1e611234 | 1847 | { |
fb7eb8b5 TT |
1848 | struct frame_info *trailing; |
1849 | ||
1850 | /* The following code must do two things. First, it must set the | |
1851 | variable TRAILING to the frame from which we should start | |
1852 | printing. Second, it must set the variable count to the number | |
1853 | of frames which we should print, or -1 if all of them. */ | |
fb7eb8b5 TT |
1854 | |
1855 | if (count_exp != NULL && count < 0) | |
1856 | { | |
6a70eb7d | 1857 | trailing = trailing_outermost_frame (-count); |
fb7eb8b5 TT |
1858 | count = -1; |
1859 | } | |
6a70eb7d PW |
1860 | else |
1861 | trailing = get_current_frame (); | |
fb7eb8b5 | 1862 | |
59f66be3 | 1863 | for (fi = trailing; fi && count--; fi = get_prev_frame (fi)) |
1e611234 PM |
1864 | { |
1865 | QUIT; | |
1866 | ||
1867 | /* Don't use print_stack_frame; if an error() occurs it probably | |
1868 | means further attempts to backtrace would fail (on the other | |
1869 | hand, perhaps the code does or could be fixed to make sure | |
1870 | the frame->prev field gets set to NULL in that case). */ | |
1871 | ||
08d72866 | 1872 | print_frame_info (fi, 1, LOCATION, 1, 0); |
1cf7e640 | 1873 | if ((flags & PRINT_LOCALS) != 0) |
d0548fa2 PM |
1874 | { |
1875 | struct frame_id frame_id = get_frame_id (fi); | |
8f043999 | 1876 | |
12615cba | 1877 | print_frame_local_vars (fi, false, NULL, NULL, 1, gdb_stdout); |
8f043999 | 1878 | |
d0548fa2 PM |
1879 | /* print_frame_local_vars invalidates FI. */ |
1880 | fi = frame_find_by_id (frame_id); | |
1881 | if (fi == NULL) | |
1882 | { | |
1883 | trailing = NULL; | |
1884 | warning (_("Unable to restore previously selected frame.")); | |
1885 | break; | |
1886 | } | |
8f043999 | 1887 | } |
55feb689 | 1888 | |
1e611234 PM |
1889 | /* Save the last frame to check for error conditions. */ |
1890 | trailing = fi; | |
1891 | } | |
c906108c | 1892 | |
1e611234 PM |
1893 | /* If we've stopped before the end, mention that. */ |
1894 | if (fi && from_tty) | |
1895 | printf_filtered (_("(More stack frames follow...)\n")); | |
55feb689 | 1896 | |
1e611234 PM |
1897 | /* If we've run out of frames, and the reason appears to be an error |
1898 | condition, print it. */ | |
1899 | if (fi == NULL && trailing != NULL) | |
1900 | { | |
1901 | enum unwind_stop_reason reason; | |
55feb689 | 1902 | |
1e611234 PM |
1903 | reason = get_frame_unwind_stop_reason (trailing); |
1904 | if (reason >= UNWIND_FIRST_ERROR) | |
1905 | printf_filtered (_("Backtrace stopped: %s\n"), | |
53e8a631 | 1906 | frame_stop_reason_string (trailing)); |
1e611234 | 1907 | } |
55feb689 | 1908 | } |
c906108c SS |
1909 | } |
1910 | ||
1911 | static void | |
0b39b52e | 1912 | backtrace_command (const char *arg, int from_tty) |
c906108c | 1913 | { |
ea3b0687 | 1914 | bool filters = true; |
1cf7e640 | 1915 | frame_filter_flags flags = 0; |
c906108c | 1916 | |
033a42c2 | 1917 | if (arg) |
c906108c | 1918 | { |
ea3b0687 | 1919 | bool done = false; |
c906108c | 1920 | |
ea3b0687 | 1921 | while (!done) |
c5aa993b | 1922 | { |
ea3b0687 TT |
1923 | const char *save_arg = arg; |
1924 | std::string this_arg = extract_arg (&arg); | |
c5aa993b | 1925 | |
ea3b0687 TT |
1926 | if (this_arg.empty ()) |
1927 | break; | |
c5aa993b | 1928 | |
ea3b0687 TT |
1929 | if (subset_compare (this_arg.c_str (), "no-filters")) |
1930 | filters = false; | |
1931 | else if (subset_compare (this_arg.c_str (), "full")) | |
1cf7e640 | 1932 | flags |= PRINT_LOCALS; |
978d6c75 TT |
1933 | else if (subset_compare (this_arg.c_str (), "hide")) |
1934 | flags |= PRINT_HIDE; | |
c5aa993b JM |
1935 | else |
1936 | { | |
ea3b0687 TT |
1937 | /* Not a recognized argument, so stop. */ |
1938 | arg = save_arg; | |
1939 | done = true; | |
c5aa993b | 1940 | } |
c5aa993b | 1941 | } |
ea3b0687 TT |
1942 | |
1943 | if (*arg == '\0') | |
1944 | arg = NULL; | |
c906108c SS |
1945 | } |
1946 | ||
1cf7e640 | 1947 | backtrace_command_1 (arg, flags, !filters /* no frame-filters */, from_tty); |
c906108c SS |
1948 | } |
1949 | ||
2c58c0a9 PA |
1950 | /* Iterate over the local variables of a block B, calling CB with |
1951 | CB_DATA. */ | |
c906108c | 1952 | |
2c58c0a9 | 1953 | static void |
3977b71f | 1954 | iterate_over_block_locals (const struct block *b, |
2c58c0a9 PA |
1955 | iterate_over_block_arg_local_vars_cb cb, |
1956 | void *cb_data) | |
c906108c | 1957 | { |
8157b174 | 1958 | struct block_iterator iter; |
de4f826b | 1959 | struct symbol *sym; |
c906108c | 1960 | |
de4f826b | 1961 | ALL_BLOCK_SYMBOLS (b, iter, sym) |
c906108c | 1962 | { |
c906108c SS |
1963 | switch (SYMBOL_CLASS (sym)) |
1964 | { | |
1965 | case LOC_LOCAL: | |
1966 | case LOC_REGISTER: | |
1967 | case LOC_STATIC: | |
4c2df51b | 1968 | case LOC_COMPUTED: |
41bd68f5 | 1969 | case LOC_OPTIMIZED_OUT: |
2a2d4dc3 AS |
1970 | if (SYMBOL_IS_ARGUMENT (sym)) |
1971 | break; | |
4357ac6c TT |
1972 | if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN) |
1973 | break; | |
2c58c0a9 | 1974 | (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data); |
c906108c SS |
1975 | break; |
1976 | ||
1977 | default: | |
1978 | /* Ignore symbols which are not locals. */ | |
1979 | break; | |
1980 | } | |
1981 | } | |
c906108c SS |
1982 | } |
1983 | ||
65c06092 | 1984 | |
c906108c SS |
1985 | /* Same, but print labels. */ |
1986 | ||
65c06092 JB |
1987 | #if 0 |
1988 | /* Commented out, as the code using this function has also been | |
1989 | commented out. FIXME:brobecker/2009-01-13: Find out why the code | |
1990 | was commented out in the first place. The discussion introducing | |
1991 | this change (2007-12-04: Support lexical blocks and function bodies | |
1992 | that occupy non-contiguous address ranges) did not explain why | |
1993 | this change was made. */ | |
c906108c | 1994 | static int |
5af949e3 UW |
1995 | print_block_frame_labels (struct gdbarch *gdbarch, struct block *b, |
1996 | int *have_default, struct ui_file *stream) | |
c906108c | 1997 | { |
8157b174 | 1998 | struct block_iterator iter; |
52f0bd74 AC |
1999 | struct symbol *sym; |
2000 | int values_printed = 0; | |
c906108c | 2001 | |
de4f826b | 2002 | ALL_BLOCK_SYMBOLS (b, iter, sym) |
c906108c | 2003 | { |
3567439c | 2004 | if (strcmp (SYMBOL_LINKAGE_NAME (sym), "default") == 0) |
c906108c SS |
2005 | { |
2006 | if (*have_default) | |
2007 | continue; | |
2008 | *have_default = 1; | |
2009 | } | |
2010 | if (SYMBOL_CLASS (sym) == LOC_LABEL) | |
2011 | { | |
2012 | struct symtab_and_line sal; | |
79a45b7d | 2013 | struct value_print_options opts; |
433759f7 | 2014 | |
c906108c SS |
2015 | sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); |
2016 | values_printed = 1; | |
de5ad195 | 2017 | fputs_filtered (SYMBOL_PRINT_NAME (sym), stream); |
79a45b7d TT |
2018 | get_user_print_options (&opts); |
2019 | if (opts.addressprint) | |
c906108c SS |
2020 | { |
2021 | fprintf_filtered (stream, " "); | |
5af949e3 UW |
2022 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (sym)), |
2023 | stream); | |
c906108c SS |
2024 | } |
2025 | fprintf_filtered (stream, " in file %s, line %d\n", | |
2026 | sal.symtab->filename, sal.line); | |
2027 | } | |
2028 | } | |
033a42c2 | 2029 | |
c906108c SS |
2030 | return values_printed; |
2031 | } | |
65c06092 | 2032 | #endif |
c906108c | 2033 | |
2c58c0a9 PA |
2034 | /* Iterate over all the local variables in block B, including all its |
2035 | superblocks, stopping when the top-level block is reached. */ | |
2036 | ||
2037 | void | |
3977b71f | 2038 | iterate_over_block_local_vars (const struct block *block, |
2c58c0a9 PA |
2039 | iterate_over_block_arg_local_vars_cb cb, |
2040 | void *cb_data) | |
2041 | { | |
2042 | while (block) | |
2043 | { | |
2044 | iterate_over_block_locals (block, cb, cb_data); | |
2045 | /* After handling the function's top-level block, stop. Don't | |
2046 | continue to its superblock, the block of per-file | |
2047 | symbols. */ | |
2048 | if (BLOCK_FUNCTION (block)) | |
2049 | break; | |
2050 | block = BLOCK_SUPERBLOCK (block); | |
2051 | } | |
2052 | } | |
2053 | ||
2054 | /* Data to be passed around in the calls to the locals and args | |
2055 | iterators. */ | |
c906108c | 2056 | |
2c58c0a9 PA |
2057 | struct print_variable_and_value_data |
2058 | { | |
12615cba PW |
2059 | gdb::optional<compiled_regex> preg; |
2060 | gdb::optional<compiled_regex> treg; | |
8f043999 | 2061 | struct frame_id frame_id; |
2c58c0a9 PA |
2062 | int num_tabs; |
2063 | struct ui_file *stream; | |
2064 | int values_printed; | |
2065 | }; | |
2066 | ||
c378eb4e | 2067 | /* The callback for the locals and args iterators. */ |
2c58c0a9 PA |
2068 | |
2069 | static void | |
2070 | do_print_variable_and_value (const char *print_name, | |
2071 | struct symbol *sym, | |
2072 | void *cb_data) | |
2073 | { | |
19ba03f4 SM |
2074 | struct print_variable_and_value_data *p |
2075 | = (struct print_variable_and_value_data *) cb_data; | |
8f043999 JK |
2076 | struct frame_info *frame; |
2077 | ||
12615cba PW |
2078 | if (p->preg.has_value () |
2079 | && p->preg->exec (SYMBOL_NATURAL_NAME (sym), 0, | |
2080 | NULL, 0) != 0) | |
2081 | return; | |
2082 | if (p->treg.has_value () | |
2083 | && !treg_matches_sym_type_name (*p->treg, sym)) | |
2084 | return; | |
2085 | ||
8f043999 JK |
2086 | frame = frame_find_by_id (p->frame_id); |
2087 | if (frame == NULL) | |
2088 | { | |
2089 | warning (_("Unable to restore previously selected frame.")); | |
2090 | return; | |
2091 | } | |
2092 | ||
2093 | print_variable_and_value (print_name, sym, frame, p->stream, p->num_tabs); | |
2094 | ||
2095 | /* print_variable_and_value invalidates FRAME. */ | |
2096 | frame = NULL; | |
2c58c0a9 | 2097 | |
2c58c0a9 PA |
2098 | p->values_printed = 1; |
2099 | } | |
c906108c | 2100 | |
12615cba PW |
2101 | /* Prepares the regular expression REG from REGEXP. |
2102 | If REGEXP is NULL, it results in an empty regular expression. */ | |
2103 | ||
2104 | static void | |
2105 | prepare_reg (const char *regexp, gdb::optional<compiled_regex> *reg) | |
2106 | { | |
2107 | if (regexp != NULL) | |
2108 | { | |
2109 | int cflags = REG_NOSUB | (case_sensitivity == case_sensitive_off | |
2110 | ? REG_ICASE : 0); | |
2111 | reg->emplace (regexp, cflags, _("Invalid regexp")); | |
2112 | } | |
2113 | else | |
2114 | reg->reset (); | |
2115 | } | |
2116 | ||
8f043999 JK |
2117 | /* Print all variables from the innermost up to the function block of FRAME. |
2118 | Print them with values to STREAM indented by NUM_TABS. | |
12615cba PW |
2119 | If REGEXP is not NULL, only print local variables whose name |
2120 | matches REGEXP. | |
2121 | If T_REGEXP is not NULL, only print local variables whose type | |
2122 | matches T_REGEXP. | |
2123 | If no local variables have been printed and !QUIET, prints a message | |
2124 | explaining why no local variables could be printed. | |
8f043999 JK |
2125 | |
2126 | This function will invalidate FRAME. */ | |
2127 | ||
c906108c | 2128 | static void |
12615cba PW |
2129 | print_frame_local_vars (struct frame_info *frame, |
2130 | bool quiet, | |
2131 | const char *regexp, const char *t_regexp, | |
2132 | int num_tabs, struct ui_file *stream) | |
c906108c | 2133 | { |
2c58c0a9 | 2134 | struct print_variable_and_value_data cb_data; |
3977b71f | 2135 | const struct block *block; |
1d4f5741 PA |
2136 | CORE_ADDR pc; |
2137 | ||
2138 | if (!get_frame_pc_if_available (frame, &pc)) | |
2139 | { | |
12615cba PW |
2140 | if (!quiet) |
2141 | fprintf_filtered (stream, | |
2142 | _("PC unavailable, cannot determine locals.\n")); | |
1d4f5741 PA |
2143 | return; |
2144 | } | |
c906108c | 2145 | |
2c58c0a9 | 2146 | block = get_frame_block (frame, 0); |
c906108c SS |
2147 | if (block == 0) |
2148 | { | |
12615cba PW |
2149 | if (!quiet) |
2150 | fprintf_filtered (stream, "No symbol table info available.\n"); | |
c906108c SS |
2151 | return; |
2152 | } | |
c5aa993b | 2153 | |
12615cba PW |
2154 | prepare_reg (regexp, &cb_data.preg); |
2155 | prepare_reg (t_regexp, &cb_data.treg); | |
8f043999 | 2156 | cb_data.frame_id = get_frame_id (frame); |
2c58c0a9 PA |
2157 | cb_data.num_tabs = 4 * num_tabs; |
2158 | cb_data.stream = stream; | |
2159 | cb_data.values_printed = 0; | |
2160 | ||
16c3b12f JB |
2161 | /* Temporarily change the selected frame to the given FRAME. |
2162 | This allows routines that rely on the selected frame instead | |
2163 | of being given a frame as parameter to use the correct frame. */ | |
45f25d6c | 2164 | scoped_restore_selected_frame restore_selected_frame; |
16c3b12f JB |
2165 | select_frame (frame); |
2166 | ||
45f25d6c AB |
2167 | iterate_over_block_local_vars (block, |
2168 | do_print_variable_and_value, | |
2169 | &cb_data); | |
8f043999 | 2170 | |
12615cba PW |
2171 | if (!cb_data.values_printed && !quiet) |
2172 | { | |
2173 | if (regexp == NULL && t_regexp == NULL) | |
2174 | fprintf_filtered (stream, _("No locals.\n")); | |
2175 | else | |
2176 | fprintf_filtered (stream, _("No matching locals.\n")); | |
2177 | } | |
c906108c SS |
2178 | } |
2179 | ||
c906108c | 2180 | void |
1d12d88f | 2181 | info_locals_command (const char *args, int from_tty) |
c906108c | 2182 | { |
12615cba PW |
2183 | std::string regexp; |
2184 | std::string t_regexp; | |
2185 | bool quiet = false; | |
2186 | ||
2187 | while (args != NULL | |
2188 | && extract_info_print_args (&args, &quiet, ®exp, &t_regexp)) | |
2189 | ; | |
2190 | ||
2191 | if (args != NULL) | |
2192 | report_unrecognized_option_error ("info locals", args); | |
2193 | ||
033a42c2 | 2194 | print_frame_local_vars (get_selected_frame (_("No frame selected.")), |
12615cba PW |
2195 | quiet, |
2196 | regexp.empty () ? NULL : regexp.c_str (), | |
2197 | t_regexp.empty () ? NULL : t_regexp.c_str (), | |
b04f3ab4 | 2198 | 0, gdb_stdout); |
c906108c SS |
2199 | } |
2200 | ||
d392224a | 2201 | /* Iterate over all the argument variables in block B. */ |
2c58c0a9 PA |
2202 | |
2203 | void | |
3977b71f | 2204 | iterate_over_block_arg_vars (const struct block *b, |
2c58c0a9 PA |
2205 | iterate_over_block_arg_local_vars_cb cb, |
2206 | void *cb_data) | |
c906108c | 2207 | { |
8157b174 | 2208 | struct block_iterator iter; |
52f0bd74 | 2209 | struct symbol *sym, *sym2; |
c906108c | 2210 | |
de4f826b | 2211 | ALL_BLOCK_SYMBOLS (b, iter, sym) |
c906108c | 2212 | { |
2a2d4dc3 AS |
2213 | /* Don't worry about things which aren't arguments. */ |
2214 | if (SYMBOL_IS_ARGUMENT (sym)) | |
c906108c | 2215 | { |
c906108c SS |
2216 | /* We have to look up the symbol because arguments can have |
2217 | two entries (one a parameter, one a local) and the one we | |
2218 | want is the local, which lookup_symbol will find for us. | |
2219 | This includes gcc1 (not gcc2) on the sparc when passing a | |
2220 | small structure and gcc2 when the argument type is float | |
2221 | and it is passed as a double and converted to float by | |
2222 | the prologue (in the latter case the type of the LOC_ARG | |
2223 | symbol is double and the type of the LOC_LOCAL symbol is | |
2224 | float). There are also LOC_ARG/LOC_REGISTER pairs which | |
2225 | are not combined in symbol-reading. */ | |
2226 | ||
de63c46b PA |
2227 | sym2 = lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym), |
2228 | b, VAR_DOMAIN).symbol; | |
2c58c0a9 | 2229 | (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data); |
c906108c SS |
2230 | } |
2231 | } | |
2c58c0a9 PA |
2232 | } |
2233 | ||
8f043999 JK |
2234 | /* Print all argument variables of the function of FRAME. |
2235 | Print them with values to STREAM. | |
12615cba PW |
2236 | If REGEXP is not NULL, only print argument variables whose name |
2237 | matches REGEXP. | |
2238 | If T_REGEXP is not NULL, only print argument variables whose type | |
2239 | matches T_REGEXP. | |
2240 | If no argument variables have been printed and !QUIET, prints a message | |
2241 | explaining why no argument variables could be printed. | |
8f043999 JK |
2242 | |
2243 | This function will invalidate FRAME. */ | |
2244 | ||
2c58c0a9 | 2245 | static void |
12615cba PW |
2246 | print_frame_arg_vars (struct frame_info *frame, |
2247 | bool quiet, | |
2248 | const char *regexp, const char *t_regexp, | |
2249 | struct ui_file *stream) | |
2c58c0a9 PA |
2250 | { |
2251 | struct print_variable_and_value_data cb_data; | |
2252 | struct symbol *func; | |
1d4f5741 | 2253 | CORE_ADDR pc; |
12615cba PW |
2254 | gdb::optional<compiled_regex> preg; |
2255 | gdb::optional<compiled_regex> treg; | |
1d4f5741 PA |
2256 | |
2257 | if (!get_frame_pc_if_available (frame, &pc)) | |
2258 | { | |
12615cba PW |
2259 | if (!quiet) |
2260 | fprintf_filtered (stream, | |
2261 | _("PC unavailable, cannot determine args.\n")); | |
1d4f5741 PA |
2262 | return; |
2263 | } | |
2c58c0a9 PA |
2264 | |
2265 | func = get_frame_function (frame); | |
2266 | if (func == NULL) | |
2267 | { | |
12615cba PW |
2268 | if (!quiet) |
2269 | fprintf_filtered (stream, _("No symbol table info available.\n")); | |
2c58c0a9 PA |
2270 | return; |
2271 | } | |
2272 | ||
12615cba PW |
2273 | prepare_reg (regexp, &cb_data.preg); |
2274 | prepare_reg (t_regexp, &cb_data.treg); | |
8f043999 | 2275 | cb_data.frame_id = get_frame_id (frame); |
2c58c0a9 | 2276 | cb_data.num_tabs = 0; |
d392224a | 2277 | cb_data.stream = stream; |
2c58c0a9 PA |
2278 | cb_data.values_printed = 0; |
2279 | ||
2280 | iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func), | |
2281 | do_print_variable_and_value, &cb_data); | |
033a42c2 | 2282 | |
8f043999 JK |
2283 | /* do_print_variable_and_value invalidates FRAME. */ |
2284 | frame = NULL; | |
2285 | ||
12615cba PW |
2286 | if (!cb_data.values_printed && !quiet) |
2287 | { | |
2288 | if (regexp == NULL && t_regexp == NULL) | |
2289 | fprintf_filtered (stream, _("No arguments.\n")); | |
2290 | else | |
2291 | fprintf_filtered (stream, _("No matching arguments.\n")); | |
2292 | } | |
c906108c SS |
2293 | } |
2294 | ||
2295 | void | |
12615cba | 2296 | info_args_command (const char *args, int from_tty) |
c906108c | 2297 | { |
12615cba PW |
2298 | std::string regexp; |
2299 | std::string t_regexp; | |
d54cfd76 | 2300 | bool quiet = false; |
12615cba PW |
2301 | |
2302 | while (args != NULL | |
2303 | && extract_info_print_args (&args, &quiet, ®exp, &t_regexp)) | |
2304 | ; | |
2305 | ||
2306 | if (args != NULL) | |
2307 | report_unrecognized_option_error ("info args", args); | |
2308 | ||
2309 | ||
033a42c2 | 2310 | print_frame_arg_vars (get_selected_frame (_("No frame selected.")), |
12615cba PW |
2311 | quiet, |
2312 | regexp.empty () ? NULL : regexp.c_str (), | |
2313 | t_regexp.empty () ? NULL : t_regexp.c_str (), | |
b04f3ab4 | 2314 | gdb_stdout); |
c906108c | 2315 | } |
c906108c | 2316 | \f |
c906108c | 2317 | /* Return the symbol-block in which the selected frame is executing. |
ae767bfb JB |
2318 | Can return zero under various legitimate circumstances. |
2319 | ||
2320 | If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant | |
2321 | code address within the block returned. We use this to decide | |
2322 | which macros are in scope. */ | |
c906108c | 2323 | |
3977b71f | 2324 | const struct block * |
ae767bfb | 2325 | get_selected_block (CORE_ADDR *addr_in_block) |
c906108c | 2326 | { |
d729566a | 2327 | if (!has_stack_frames ()) |
8ea051c5 PA |
2328 | return 0; |
2329 | ||
206415a3 | 2330 | return get_frame_block (get_selected_frame (NULL), addr_in_block); |
c906108c SS |
2331 | } |
2332 | ||
2333 | /* Find a frame a certain number of levels away from FRAME. | |
2334 | LEVEL_OFFSET_PTR points to an int containing the number of levels. | |
2335 | Positive means go to earlier frames (up); negative, the reverse. | |
2336 | The int that contains the number of levels is counted toward | |
2337 | zero as the frames for those levels are found. | |
2338 | If the top or bottom frame is reached, that frame is returned, | |
2339 | but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates | |
2340 | how much farther the original request asked to go. */ | |
2341 | ||
2342 | struct frame_info * | |
033a42c2 | 2343 | find_relative_frame (struct frame_info *frame, int *level_offset_ptr) |
c906108c | 2344 | { |
033a42c2 MK |
2345 | /* Going up is simple: just call get_prev_frame enough times or |
2346 | until the initial frame is reached. */ | |
c906108c SS |
2347 | while (*level_offset_ptr > 0) |
2348 | { | |
033a42c2 | 2349 | struct frame_info *prev = get_prev_frame (frame); |
433759f7 | 2350 | |
033a42c2 | 2351 | if (!prev) |
c906108c SS |
2352 | break; |
2353 | (*level_offset_ptr)--; | |
2354 | frame = prev; | |
2355 | } | |
033a42c2 | 2356 | |
c906108c | 2357 | /* Going down is just as simple. */ |
033a42c2 | 2358 | while (*level_offset_ptr < 0) |
c906108c | 2359 | { |
033a42c2 | 2360 | struct frame_info *next = get_next_frame (frame); |
433759f7 | 2361 | |
033a42c2 MK |
2362 | if (!next) |
2363 | break; | |
2364 | (*level_offset_ptr)++; | |
2365 | frame = next; | |
c906108c | 2366 | } |
033a42c2 | 2367 | |
c906108c SS |
2368 | return frame; |
2369 | } | |
2370 | ||
033a42c2 MK |
2371 | /* Select the frame up one or COUNT_EXP stack levels from the |
2372 | previously selected frame, and print it briefly. */ | |
c906108c | 2373 | |
c906108c | 2374 | static void |
d3d3328b | 2375 | up_silently_base (const char *count_exp) |
c906108c | 2376 | { |
033a42c2 MK |
2377 | struct frame_info *frame; |
2378 | int count = 1; | |
2379 | ||
c906108c | 2380 | if (count_exp) |
bb518678 | 2381 | count = parse_and_eval_long (count_exp); |
c5aa993b | 2382 | |
033a42c2 MK |
2383 | frame = find_relative_frame (get_selected_frame ("No stack."), &count); |
2384 | if (count != 0 && count_exp == NULL) | |
8a3fe4f8 | 2385 | error (_("Initial frame selected; you cannot go up.")); |
033a42c2 | 2386 | select_frame (frame); |
c906108c SS |
2387 | } |
2388 | ||
2389 | static void | |
0b39b52e | 2390 | up_silently_command (const char *count_exp, int from_tty) |
c906108c | 2391 | { |
c5aa993b | 2392 | up_silently_base (count_exp); |
c906108c SS |
2393 | } |
2394 | ||
2395 | static void | |
0b39b52e | 2396 | up_command (const char *count_exp, int from_tty) |
c906108c SS |
2397 | { |
2398 | up_silently_base (count_exp); | |
76727919 | 2399 | gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME); |
c906108c SS |
2400 | } |
2401 | ||
033a42c2 MK |
2402 | /* Select the frame down one or COUNT_EXP stack levels from the previously |
2403 | selected frame, and print it briefly. */ | |
c906108c | 2404 | |
c906108c | 2405 | static void |
d3d3328b | 2406 | down_silently_base (const char *count_exp) |
c906108c | 2407 | { |
52f0bd74 | 2408 | struct frame_info *frame; |
033a42c2 | 2409 | int count = -1; |
f89b749f | 2410 | |
c906108c | 2411 | if (count_exp) |
bb518678 | 2412 | count = -parse_and_eval_long (count_exp); |
c5aa993b | 2413 | |
033a42c2 MK |
2414 | frame = find_relative_frame (get_selected_frame ("No stack."), &count); |
2415 | if (count != 0 && count_exp == NULL) | |
c906108c | 2416 | { |
033a42c2 MK |
2417 | /* We only do this if COUNT_EXP is not specified. That way |
2418 | "down" means to really go down (and let me know if that is | |
2419 | impossible), but "down 9999" can be used to mean go all the | |
2420 | way down without getting an error. */ | |
c906108c | 2421 | |
033a42c2 | 2422 | error (_("Bottom (innermost) frame selected; you cannot go down.")); |
c906108c SS |
2423 | } |
2424 | ||
0f7d239c | 2425 | select_frame (frame); |
c906108c SS |
2426 | } |
2427 | ||
c906108c | 2428 | static void |
0b39b52e | 2429 | down_silently_command (const char *count_exp, int from_tty) |
c906108c SS |
2430 | { |
2431 | down_silently_base (count_exp); | |
c906108c SS |
2432 | } |
2433 | ||
2434 | static void | |
0b39b52e | 2435 | down_command (const char *count_exp, int from_tty) |
c906108c SS |
2436 | { |
2437 | down_silently_base (count_exp); | |
76727919 | 2438 | gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME); |
c906108c | 2439 | } |
033a42c2 | 2440 | |
8b93c638 | 2441 | void |
0b39b52e | 2442 | return_command (const char *retval_exp, int from_tty) |
c906108c | 2443 | { |
901900c4 MGD |
2444 | /* Initialize it just to avoid a GCC false warning. */ |
2445 | enum return_value_convention rv_conv = RETURN_VALUE_STRUCT_CONVENTION; | |
5ed92fa8 | 2446 | struct frame_info *thisframe; |
d80b854b | 2447 | struct gdbarch *gdbarch; |
c906108c | 2448 | struct symbol *thisfun; |
3d6d86c6 | 2449 | struct value *return_value = NULL; |
6a3a010b | 2450 | struct value *function = NULL; |
fc70c2a0 | 2451 | const char *query_prefix = ""; |
c906108c | 2452 | |
5ed92fa8 UW |
2453 | thisframe = get_selected_frame ("No selected frame."); |
2454 | thisfun = get_frame_function (thisframe); | |
d80b854b | 2455 | gdbarch = get_frame_arch (thisframe); |
c906108c | 2456 | |
edb3359d DJ |
2457 | if (get_frame_type (get_current_frame ()) == INLINE_FRAME) |
2458 | error (_("Can not force return from an inlined function.")); | |
2459 | ||
fc70c2a0 AC |
2460 | /* Compute the return value. If the computation triggers an error, |
2461 | let it bail. If the return type can't be handled, set | |
2462 | RETURN_VALUE to NULL, and QUERY_PREFIX to an informational | |
2463 | message. */ | |
c906108c SS |
2464 | if (retval_exp) |
2465 | { | |
4d01a485 | 2466 | expression_up retval_expr = parse_expression (retval_exp); |
c906108c SS |
2467 | struct type *return_type = NULL; |
2468 | ||
fc70c2a0 AC |
2469 | /* Compute the return value. Should the computation fail, this |
2470 | call throws an error. */ | |
4d01a485 | 2471 | return_value = evaluate_expression (retval_expr.get ()); |
c906108c | 2472 | |
fc70c2a0 AC |
2473 | /* Cast return value to the return type of the function. Should |
2474 | the cast fail, this call throws an error. */ | |
c906108c SS |
2475 | if (thisfun != NULL) |
2476 | return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun)); | |
2477 | if (return_type == NULL) | |
61ff14c6 | 2478 | { |
9eaf6705 TT |
2479 | if (retval_expr->elts[0].opcode != UNOP_CAST |
2480 | && retval_expr->elts[0].opcode != UNOP_CAST_TYPE) | |
61ff14c6 JK |
2481 | error (_("Return value type not available for selected " |
2482 | "stack frame.\n" | |
2483 | "Please use an explicit cast of the value to return.")); | |
2484 | return_type = value_type (return_value); | |
2485 | } | |
f168693b | 2486 | return_type = check_typedef (return_type); |
c906108c SS |
2487 | return_value = value_cast (return_type, return_value); |
2488 | ||
fc70c2a0 AC |
2489 | /* Make sure the value is fully evaluated. It may live in the |
2490 | stack frame we're about to pop. */ | |
d69fe07e | 2491 | if (value_lazy (return_value)) |
c906108c | 2492 | value_fetch_lazy (return_value); |
c906108c | 2493 | |
6a3a010b | 2494 | if (thisfun != NULL) |
63e43d3a | 2495 | function = read_var_value (thisfun, NULL, thisframe); |
6a3a010b | 2496 | |
bbfdfe1c | 2497 | rv_conv = RETURN_VALUE_REGISTER_CONVENTION; |
667e784f AC |
2498 | if (TYPE_CODE (return_type) == TYPE_CODE_VOID) |
2499 | /* If the return-type is "void", don't try to find the | |
2500 | return-value's location. However, do still evaluate the | |
2501 | return expression so that, even when the expression result | |
2502 | is discarded, side effects such as "return i++" still | |
033a42c2 | 2503 | occur. */ |
667e784f | 2504 | return_value = NULL; |
bbfdfe1c | 2505 | else if (thisfun != NULL) |
fc70c2a0 | 2506 | { |
bbfdfe1c DM |
2507 | rv_conv = struct_return_convention (gdbarch, function, return_type); |
2508 | if (rv_conv == RETURN_VALUE_STRUCT_CONVENTION | |
2509 | || rv_conv == RETURN_VALUE_ABI_RETURNS_ADDRESS) | |
2510 | { | |
2511 | query_prefix = "The location at which to store the " | |
2512 | "function's return value is unknown.\n" | |
2513 | "If you continue, the return value " | |
2514 | "that you specified will be ignored.\n"; | |
2515 | return_value = NULL; | |
2516 | } | |
fc70c2a0 | 2517 | } |
c906108c SS |
2518 | } |
2519 | ||
fc70c2a0 AC |
2520 | /* Does an interactive user really want to do this? Include |
2521 | information, such as how well GDB can handle the return value, in | |
2522 | the query message. */ | |
2523 | if (from_tty) | |
2524 | { | |
2525 | int confirmed; | |
433759f7 | 2526 | |
fc70c2a0 | 2527 | if (thisfun == NULL) |
e2e0b3e5 | 2528 | confirmed = query (_("%sMake selected stack frame return now? "), |
fc70c2a0 AC |
2529 | query_prefix); |
2530 | else | |
743649fd MW |
2531 | { |
2532 | if (TYPE_NO_RETURN (thisfun->type)) | |
d35b90fb | 2533 | warning (_("Function does not return normally to caller.")); |
743649fd MW |
2534 | confirmed = query (_("%sMake %s return now? "), query_prefix, |
2535 | SYMBOL_PRINT_NAME (thisfun)); | |
2536 | } | |
fc70c2a0 | 2537 | if (!confirmed) |
8a3fe4f8 | 2538 | error (_("Not confirmed")); |
fc70c2a0 | 2539 | } |
c906108c | 2540 | |
a45ae3ed UW |
2541 | /* Discard the selected frame and all frames inner-to it. */ |
2542 | frame_pop (get_selected_frame (NULL)); | |
c906108c | 2543 | |
a1f5b845 | 2544 | /* Store RETURN_VALUE in the just-returned register set. */ |
fc70c2a0 AC |
2545 | if (return_value != NULL) |
2546 | { | |
df407dfe | 2547 | struct type *return_type = value_type (return_value); |
b926417a | 2548 | struct gdbarch *cache_arch = get_current_regcache ()->arch (); |
42e2132c | 2549 | |
bbfdfe1c DM |
2550 | gdb_assert (rv_conv != RETURN_VALUE_STRUCT_CONVENTION |
2551 | && rv_conv != RETURN_VALUE_ABI_RETURNS_ADDRESS); | |
b926417a | 2552 | gdbarch_return_value (cache_arch, function, return_type, |
594f7785 | 2553 | get_current_regcache (), NULL /*read*/, |
0fd88904 | 2554 | value_contents (return_value) /*write*/); |
fc70c2a0 | 2555 | } |
1a2aab69 | 2556 | |
fc70c2a0 AC |
2557 | /* If we are at the end of a call dummy now, pop the dummy frame |
2558 | too. */ | |
e8bcf01f AC |
2559 | if (get_frame_type (get_current_frame ()) == DUMMY_FRAME) |
2560 | frame_pop (get_current_frame ()); | |
1a2aab69 | 2561 | |
edbbff4a | 2562 | select_frame (get_current_frame ()); |
c906108c | 2563 | /* If interactive, print the frame that is now current. */ |
c906108c | 2564 | if (from_tty) |
edbbff4a | 2565 | print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1); |
c906108c SS |
2566 | } |
2567 | ||
39f0c204 AB |
2568 | /* Find the most inner frame in the current stack for a function called |
2569 | FUNCTION_NAME. If no matching frame is found return NULL. */ | |
c906108c | 2570 | |
39f0c204 AB |
2571 | static struct frame_info * |
2572 | find_frame_for_function (const char *function_name) | |
c906108c | 2573 | { |
39f0c204 AB |
2574 | /* Used to hold the lower and upper addresses for each of the |
2575 | SYMTAB_AND_LINEs found for functions matching FUNCTION_NAME. */ | |
2576 | struct function_bounds | |
2577 | { | |
2578 | CORE_ADDR low, high; | |
2579 | }; | |
033a42c2 | 2580 | struct frame_info *frame; |
39f0c204 | 2581 | bool found = false; |
c906108c | 2582 | int level = 1; |
c906108c | 2583 | |
39f0c204 | 2584 | gdb_assert (function_name != NULL); |
c906108c | 2585 | |
edbbff4a | 2586 | frame = get_current_frame (); |
6c5b2ebe | 2587 | std::vector<symtab_and_line> sals |
39f0c204 AB |
2588 | = decode_line_with_current_source (function_name, |
2589 | DECODE_LINE_FUNFIRSTLINE); | |
0b868b60 | 2590 | gdb::def_vector<function_bounds> func_bounds (sals.size ()); |
39f0c204 | 2591 | for (size_t i = 0; i < sals.size (); i++) |
c906108c | 2592 | { |
6c5b2ebe | 2593 | if (sals[i].pspace != current_program_space) |
f8eba3c6 | 2594 | func_bounds[i].low = func_bounds[i].high = 0; |
6c5b2ebe PA |
2595 | else if (sals[i].pc == 0 |
2596 | || find_pc_partial_function (sals[i].pc, NULL, | |
f8eba3c6 TT |
2597 | &func_bounds[i].low, |
2598 | &func_bounds[i].high) == 0) | |
39f0c204 | 2599 | func_bounds[i].low = func_bounds[i].high = 0; |
c906108c SS |
2600 | } |
2601 | ||
2602 | do | |
2603 | { | |
6c5b2ebe | 2604 | for (size_t i = 0; (i < sals.size () && !found); i++) |
033a42c2 MK |
2605 | found = (get_frame_pc (frame) >= func_bounds[i].low |
2606 | && get_frame_pc (frame) < func_bounds[i].high); | |
c906108c SS |
2607 | if (!found) |
2608 | { | |
2609 | level = 1; | |
033a42c2 | 2610 | frame = find_relative_frame (frame, &level); |
c906108c SS |
2611 | } |
2612 | } | |
2613 | while (!found && level == 0); | |
2614 | ||
c906108c | 2615 | if (!found) |
39f0c204 AB |
2616 | frame = NULL; |
2617 | ||
2618 | return frame; | |
2619 | } | |
2620 | ||
2621 | /* Implements the dbx 'func' command. */ | |
2622 | ||
2623 | static void | |
2624 | func_command (const char *arg, int from_tty) | |
2625 | { | |
2626 | if (arg == NULL) | |
2627 | return; | |
2628 | ||
2629 | struct frame_info *frame = find_frame_for_function (arg); | |
2630 | if (frame == NULL) | |
61367c61 | 2631 | error (_("'%s' not within current stack frame."), arg); |
39f0c204 AB |
2632 | if (frame != get_selected_frame (NULL)) |
2633 | { | |
2634 | select_frame (frame); | |
2635 | print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1); | |
2636 | } | |
c906108c | 2637 | } |
033a42c2 | 2638 | |
6a70eb7d PW |
2639 | /* Apply a GDB command to all stack frames, or a set of identified frames, |
2640 | or innermost COUNT frames. | |
2641 | With a negative COUNT, apply command on outermost -COUNT frames. | |
2642 | ||
2643 | frame apply 3 info frame Apply 'info frame' to frames 0, 1, 2 | |
2644 | frame apply -3 info frame Apply 'info frame' to outermost 3 frames. | |
2645 | frame apply all x/i $pc Apply 'x/i $pc' cmd to all frames. | |
2646 | frame apply all -s p local_var_no_idea_in_which_frame | |
2647 | If a frame has a local variable called | |
2648 | local_var_no_idea_in_which_frame, print frame | |
2649 | and value of local_var_no_idea_in_which_frame. | |
2650 | frame apply all -s -q p local_var_no_idea_in_which_frame | |
2651 | Same as before, but only print the variable value. | |
2652 | frame apply level 2-5 0 4-7 -s p i = i + 1 | |
2653 | Adds 1 to the variable i in the specified frames. | |
2654 | Note that i will be incremented twice in | |
2655 | frames 4 and 5. */ | |
2656 | ||
2657 | /* Apply a GDB command to COUNT stack frames, starting at TRAILING. | |
2658 | CMD starts with 0 or more qcs flags followed by the GDB command to apply. | |
2659 | COUNT -1 means all frames starting at TRAILING. WHICH_COMMAND is used | |
2660 | for error messages. */ | |
2661 | ||
2662 | static void | |
2663 | frame_apply_command_count (const char *which_command, | |
2664 | const char *cmd, int from_tty, | |
2665 | struct frame_info *trailing, int count) | |
2666 | { | |
2667 | qcs_flags flags; | |
2668 | struct frame_info *fi; | |
2669 | ||
2670 | while (cmd != NULL && parse_flags_qcs (which_command, &cmd, &flags)) | |
2671 | ; | |
2672 | ||
2673 | if (cmd == NULL || *cmd == '\0') | |
2674 | error (_("Please specify a command to apply on the selected frames")); | |
2675 | ||
2676 | /* The below will restore the current inferior/thread/frame. | |
2677 | Usually, only the frame is effectively to be restored. | |
2678 | But in case CMD switches of inferior/thread, better restore | |
2679 | these also. */ | |
2680 | scoped_restore_current_thread restore_thread; | |
2681 | ||
2682 | for (fi = trailing; fi && count--; fi = get_prev_frame (fi)) | |
2683 | { | |
2684 | QUIT; | |
2685 | ||
2686 | select_frame (fi); | |
a70b8144 | 2687 | try |
6a70eb7d PW |
2688 | { |
2689 | std::string cmd_result; | |
2690 | { | |
2691 | /* In case CMD switches of inferior/thread/frame, the below | |
2692 | restores the inferior/thread/frame. FI can then be | |
2693 | set to the selected frame. */ | |
2694 | scoped_restore_current_thread restore_fi_current_frame; | |
2695 | ||
8a522c6c PW |
2696 | cmd_result = execute_command_to_string |
2697 | (cmd, from_tty, gdb_stdout->term_out ()); | |
6a70eb7d PW |
2698 | } |
2699 | fi = get_selected_frame (_("frame apply " | |
2700 | "unable to get selected frame.")); | |
2701 | if (!flags.silent || cmd_result.length () > 0) | |
2702 | { | |
2703 | if (!flags.quiet) | |
2704 | print_stack_frame (fi, 1, LOCATION, 0); | |
2705 | printf_filtered ("%s", cmd_result.c_str ()); | |
2706 | } | |
2707 | } | |
230d2906 | 2708 | catch (const gdb_exception_error &ex) |
6a70eb7d PW |
2709 | { |
2710 | fi = get_selected_frame (_("frame apply " | |
2711 | "unable to get selected frame.")); | |
2712 | if (!flags.silent) | |
2713 | { | |
2714 | if (!flags.quiet) | |
2715 | print_stack_frame (fi, 1, LOCATION, 0); | |
2716 | if (flags.cont) | |
3d6e9d23 | 2717 | printf_filtered ("%s\n", ex.what ()); |
6a70eb7d | 2718 | else |
eedc3f4f | 2719 | throw; |
6a70eb7d PW |
2720 | } |
2721 | } | |
6a70eb7d PW |
2722 | } |
2723 | } | |
2724 | ||
2725 | /* Implementation of the "frame apply level" command. */ | |
2726 | ||
2727 | static void | |
2728 | frame_apply_level_command (const char *cmd, int from_tty) | |
2729 | { | |
2730 | if (!target_has_stack) | |
2731 | error (_("No stack.")); | |
2732 | ||
2733 | bool level_found = false; | |
2734 | const char *levels_str = cmd; | |
2735 | number_or_range_parser levels (levels_str); | |
2736 | ||
2737 | /* Skip the LEVEL list to find the flags and command args. */ | |
2738 | while (!levels.finished ()) | |
2739 | { | |
8d49165d TT |
2740 | /* Call for effect. */ |
2741 | levels.get_number (); | |
6a70eb7d PW |
2742 | |
2743 | level_found = true; | |
2744 | if (levels.in_range ()) | |
2745 | levels.skip_range (); | |
2746 | } | |
2747 | ||
2748 | if (!level_found) | |
2749 | error (_("Missing or invalid LEVEL... argument")); | |
2750 | ||
2751 | cmd = levels.cur_tok (); | |
2752 | ||
2753 | /* Redo the LEVELS parsing, but applying COMMAND. */ | |
2754 | levels.init (levels_str); | |
2755 | while (!levels.finished ()) | |
2756 | { | |
2757 | const int level_beg = levels.get_number (); | |
2758 | int n_frames; | |
2759 | ||
2760 | if (levels.in_range ()) | |
2761 | { | |
2762 | n_frames = levels.end_value () - level_beg + 1; | |
2763 | levels.skip_range (); | |
2764 | } | |
2765 | else | |
2766 | n_frames = 1; | |
2767 | ||
2768 | frame_apply_command_count ("frame apply level", cmd, from_tty, | |
2769 | leading_innermost_frame (level_beg), n_frames); | |
2770 | } | |
2771 | } | |
2772 | ||
2773 | /* Implementation of the "frame apply all" command. */ | |
2774 | ||
2775 | static void | |
2776 | frame_apply_all_command (const char *cmd, int from_tty) | |
2777 | { | |
2778 | if (!target_has_stack) | |
2779 | error (_("No stack.")); | |
2780 | ||
2781 | frame_apply_command_count ("frame apply all", cmd, from_tty, | |
2782 | get_current_frame (), INT_MAX); | |
2783 | } | |
2784 | ||
2785 | /* Implementation of the "frame apply" command. */ | |
2786 | ||
2787 | static void | |
2788 | frame_apply_command (const char* cmd, int from_tty) | |
2789 | { | |
2790 | int count; | |
2791 | struct frame_info *trailing; | |
2792 | ||
2793 | if (!target_has_stack) | |
2794 | error (_("No stack.")); | |
2795 | ||
2796 | if (cmd == NULL) | |
2797 | error (_("Missing COUNT argument.")); | |
2798 | count = get_number_trailer (&cmd, 0); | |
2799 | if (count == 0) | |
2800 | error (_("Invalid COUNT argument.")); | |
2801 | ||
2802 | if (count < 0) | |
2803 | { | |
2804 | trailing = trailing_outermost_frame (-count); | |
2805 | count = -1; | |
2806 | } | |
2807 | else | |
2808 | trailing = get_current_frame (); | |
2809 | ||
2810 | frame_apply_command_count ("frame apply", cmd, from_tty, | |
2811 | trailing, count); | |
2812 | } | |
2813 | ||
2814 | /* Implementation of the "faas" command. */ | |
2815 | ||
2816 | static void | |
2817 | faas_command (const char *cmd, int from_tty) | |
2818 | { | |
2819 | std::string expanded = std::string ("frame apply all -s ") + cmd; | |
2820 | execute_command (expanded.c_str (), from_tty); | |
2821 | } | |
2822 | ||
2823 | ||
f67ffa6a AB |
2824 | /* Find inner-mode frame with frame address ADDRESS. Return NULL if no |
2825 | matching frame can be found. */ | |
2826 | ||
2827 | static struct frame_info * | |
2828 | find_frame_for_address (CORE_ADDR address) | |
2829 | { | |
2830 | struct frame_id id; | |
2831 | struct frame_info *fid; | |
2832 | ||
2833 | id = frame_id_build_wild (address); | |
2834 | ||
2835 | /* If (s)he specifies the frame with an address, he deserves | |
2836 | what (s)he gets. Still, give the highest one that matches. | |
2837 | (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't | |
2838 | know). */ | |
2839 | for (fid = get_current_frame (); | |
2840 | fid != NULL; | |
2841 | fid = get_prev_frame (fid)) | |
2842 | { | |
2843 | if (frame_id_eq (id, get_frame_id (fid))) | |
2844 | { | |
2845 | struct frame_info *prev_frame; | |
2846 | ||
2847 | while (1) | |
2848 | { | |
2849 | prev_frame = get_prev_frame (fid); | |
2850 | if (!prev_frame | |
2851 | || !frame_id_eq (id, get_frame_id (prev_frame))) | |
2852 | break; | |
2853 | fid = prev_frame; | |
2854 | } | |
2855 | return fid; | |
2856 | } | |
2857 | } | |
2858 | return NULL; | |
2859 | } | |
2860 | ||
2861 | \f | |
2862 | ||
2863 | /* Commands with a prefix of `frame apply'. */ | |
2864 | static struct cmd_list_element *frame_apply_cmd_list = NULL; | |
2865 | ||
6a70eb7d | 2866 | /* Commands with a prefix of `frame'. */ |
f67ffa6a AB |
2867 | static struct cmd_list_element *frame_cmd_list = NULL; |
2868 | ||
2869 | /* Commands with a prefix of `select frame'. */ | |
2870 | static struct cmd_list_element *select_frame_cmd_list = NULL; | |
2871 | ||
2872 | /* Commands with a prefix of `info frame'. */ | |
2873 | static struct cmd_list_element *info_frame_cmd_list = NULL; | |
6a70eb7d | 2874 | |
c906108c | 2875 | void |
fba45db2 | 2876 | _initialize_stack (void) |
c906108c | 2877 | { |
f67ffa6a | 2878 | struct cmd_list_element *cmd; |
6a70eb7d | 2879 | |
1bedd215 AC |
2880 | add_com ("return", class_stack, return_command, _("\ |
2881 | Make selected stack frame return to its caller.\n\ | |
c906108c SS |
2882 | Control remains in the debugger, but when you continue\n\ |
2883 | execution will resume in the frame above the one now selected.\n\ | |
1bedd215 AC |
2884 | If an argument is given, it is an expression for the value to return.")); |
2885 | ||
2886 | add_com ("up", class_stack, up_command, _("\ | |
2887 | Select and print stack frame that called this one.\n\ | |
2888 | An argument says how many frames up to go.")); | |
2889 | add_com ("up-silently", class_support, up_silently_command, _("\ | |
2890 | Same as the `up' command, but does not print anything.\n\ | |
2891 | This is useful in command scripts.")); | |
2892 | ||
2893 | add_com ("down", class_stack, down_command, _("\ | |
2894 | Select and print stack frame called by this one.\n\ | |
2895 | An argument says how many frames down to go.")); | |
c906108c SS |
2896 | add_com_alias ("do", "down", class_stack, 1); |
2897 | add_com_alias ("dow", "down", class_stack, 1); | |
1bedd215 AC |
2898 | add_com ("down-silently", class_support, down_silently_command, _("\ |
2899 | Same as the `down' command, but does not print anything.\n\ | |
2900 | This is useful in command scripts.")); | |
c906108c | 2901 | |
f67ffa6a AB |
2902 | add_prefix_cmd ("frame", class_stack, |
2903 | &frame_cmd.base_command, _("\ | |
2904 | Select and print a stack frame.\n\ | |
2905 | With no argument, print the selected stack frame. (See also \"info frame\").\n\ | |
2906 | A single numerical argument specifies the frame to select."), | |
2907 | &frame_cmd_list, "frame ", 1, &cmdlist); | |
c906108c SS |
2908 | |
2909 | add_com_alias ("f", "frame", class_stack, 1); | |
2910 | ||
6a70eb7d PW |
2911 | #define FRAME_APPLY_FLAGS_HELP "\ |
2912 | Prints the frame location information followed by COMMAND output.\n\ | |
2913 | FLAG arguments are -q (quiet), -c (continue), -s (silent).\n\ | |
2914 | Flag -q disables printing the frame location information.\n\ | |
2915 | By default, if a COMMAND raises an error, frame apply is aborted.\n\ | |
2916 | Flag -c indicates to print the error and continue.\n\ | |
2917 | Flag -s indicates to silently ignore a COMMAND that raises an error\n\ | |
2918 | or produces no output." | |
2919 | ||
2920 | add_prefix_cmd ("apply", class_stack, frame_apply_command, | |
2921 | _("Apply a command to a number of frames.\n\ | |
2922 | Usage: frame apply COUNT [FLAG]... COMMAND\n\ | |
2923 | With a negative COUNT argument, applies the command on outermost -COUNT frames.\n" | |
2924 | FRAME_APPLY_FLAGS_HELP), | |
f67ffa6a | 2925 | &frame_apply_cmd_list, "frame apply ", 1, &frame_cmd_list); |
6a70eb7d PW |
2926 | |
2927 | add_cmd ("all", class_stack, frame_apply_all_command, | |
2928 | _("\ | |
2929 | Apply a command to all frames.\n\ | |
2930 | \n\ | |
2931 | Usage: frame apply all [FLAG]... COMMAND\n" | |
2932 | FRAME_APPLY_FLAGS_HELP), | |
f67ffa6a | 2933 | &frame_apply_cmd_list); |
6a70eb7d PW |
2934 | |
2935 | add_cmd ("level", class_stack, frame_apply_level_command, | |
2936 | _("\ | |
2937 | Apply a command to a list of frames.\n\ | |
2938 | \n\ | |
2939 | Usage: frame apply level LEVEL... [FLAG]... COMMAND\n\ | |
2940 | ID is a space-separated list of LEVELs of frames to apply COMMAND on.\n" | |
2941 | FRAME_APPLY_FLAGS_HELP), | |
f67ffa6a | 2942 | &frame_apply_cmd_list); |
6a70eb7d PW |
2943 | |
2944 | add_com ("faas", class_stack, faas_command, _("\ | |
2945 | Apply a command to all frames (ignoring errors and empty output).\n\ | |
2946 | Usage: faas COMMAND\n\ | |
2947 | shortcut for 'frame apply all -s COMMAND'")); | |
2948 | ||
f67ffa6a AB |
2949 | |
2950 | add_prefix_cmd ("frame", class_stack, | |
2951 | &frame_cmd.base_command, _("\ | |
2952 | Select and print a stack frame.\n\ | |
2953 | With no argument, print the selected stack frame. (See also \"info frame\").\n\ | |
2954 | A single numerical argument specifies the frame to select."), | |
2955 | &frame_cmd_list, "frame ", 1, &cmdlist); | |
2956 | add_com_alias ("f", "frame", class_stack, 1); | |
2957 | ||
2958 | add_cmd ("address", class_stack, &frame_cmd.address, | |
2959 | _("\ | |
2960 | Select and print a stack frame by stack address\n\ | |
2961 | \n\ | |
2962 | Usage: frame address STACK-ADDRESS"), | |
2963 | &frame_cmd_list); | |
2964 | ||
2965 | add_cmd ("view", class_stack, &frame_cmd.view, | |
2966 | _("\ | |
2967 | View a stack frame that might be outside the current backtrace.\n\ | |
2968 | \n\ | |
2969 | Usage: frame view STACK-ADDRESS\n\ | |
2970 | frame view STACK-ADDRESS PC-ADDRESS"), | |
2971 | &frame_cmd_list); | |
2972 | ||
2973 | cmd = add_cmd ("function", class_stack, &frame_cmd.function, | |
2974 | _("\ | |
2975 | Select and print a stack frame by function name.\n\ | |
2976 | \n\ | |
2977 | Usage: frame function NAME\n\ | |
2978 | \n\ | |
2979 | The innermost frame that visited function NAME is selected."), | |
2980 | &frame_cmd_list); | |
2981 | set_cmd_completer (cmd, frame_selection_by_function_completer); | |
2982 | ||
2983 | ||
2984 | add_cmd ("level", class_stack, &frame_cmd.level, | |
2985 | _("\ | |
2986 | Select and print a stack frame by level.\n\ | |
2987 | \n\ | |
2988 | Usage: frame level LEVEL"), | |
2989 | &frame_cmd_list); | |
2990 | ||
2991 | cmd = add_prefix_cmd_suppress_notification ("select-frame", class_stack, | |
2992 | &select_frame_cmd.base_command, _("\ | |
1bedd215 | 2993 | Select a stack frame without printing anything.\n\ |
f67ffa6a AB |
2994 | A single numerical argument specifies the frame to select."), |
2995 | &select_frame_cmd_list, "select-frame ", 1, &cmdlist, | |
2996 | &cli_suppress_notification.user_selected_context); | |
2997 | ||
2998 | add_cmd_suppress_notification ("address", class_stack, | |
2999 | &select_frame_cmd.address, _("\ | |
3000 | Select a stack frame by stack address.\n\ | |
3001 | \n\ | |
3002 | Usage: select-frame address STACK-ADDRESS"), | |
3003 | &select_frame_cmd_list, | |
3004 | &cli_suppress_notification.user_selected_context); | |
3005 | ||
3006 | ||
3007 | add_cmd_suppress_notification ("view", class_stack, | |
3008 | &select_frame_cmd.view, _("\ | |
3009 | Select a stack frame that might be outside the current backtrace.\n\ | |
3010 | \n\ | |
3011 | Usage: select-frame view STACK-ADDRESS\n\ | |
3012 | select-frame view STACK-ADDRESS PC-ADDRESS"), | |
3013 | &select_frame_cmd_list, | |
4034d0ff | 3014 | &cli_suppress_notification.user_selected_context); |
c906108c | 3015 | |
f67ffa6a AB |
3016 | cmd = add_cmd_suppress_notification ("function", class_stack, |
3017 | &select_frame_cmd.function, _("\ | |
3018 | Select a stack frame by function name.\n\ | |
3019 | \n\ | |
3020 | Usage: select-frame function NAME"), | |
3021 | &select_frame_cmd_list, | |
3022 | &cli_suppress_notification.user_selected_context); | |
3023 | set_cmd_completer (cmd, frame_selection_by_function_completer); | |
3024 | ||
3025 | add_cmd_suppress_notification ("level", class_stack, | |
3026 | &select_frame_cmd.level, _("\ | |
3027 | Select a stack frame by level.\n\ | |
3028 | \n\ | |
3029 | Usage: select-frame level LEVEL"), | |
3030 | &select_frame_cmd_list, | |
3031 | &cli_suppress_notification.user_selected_context); | |
3032 | ||
1bedd215 AC |
3033 | add_com ("backtrace", class_stack, backtrace_command, _("\ |
3034 | Print backtrace of all stack frames, or innermost COUNT frames.\n\ | |
9507b29c TT |
3035 | Usage: backtrace [QUALIFIERS]... [COUNT]\n\ |
3036 | With a negative argument, print outermost -COUNT frames.\n\ | |
3037 | Use of the 'full' qualifier also prints the values of the local variables.\n\ | |
1e611234 | 3038 | Use of the 'no-filters' qualifier prohibits frame filters from executing\n\ |
9507b29c | 3039 | on this backtrace.")); |
c906108c | 3040 | add_com_alias ("bt", "backtrace", class_stack, 0); |
c906108c SS |
3041 | |
3042 | add_com_alias ("where", "backtrace", class_alias, 0); | |
3043 | add_info ("stack", backtrace_command, | |
1bedd215 | 3044 | _("Backtrace of the stack, or innermost COUNT frames.")); |
c906108c | 3045 | add_info_alias ("s", "stack", 1); |
f67ffa6a AB |
3046 | |
3047 | add_prefix_cmd ("frame", class_info, &info_frame_cmd.base_command, | |
3048 | _("All about the selected stack frame.\n\ | |
3049 | With no arguments, displays information about the currently selected stack\n\ | |
3050 | frame. Alternatively a frame specification may be provided (See \"frame\")\n\ | |
3051 | the information is then printed about the specified frame."), | |
3052 | &info_frame_cmd_list, "info frame ", 1, &infolist); | |
c906108c | 3053 | add_info_alias ("f", "frame", 1); |
f67ffa6a AB |
3054 | |
3055 | add_cmd ("address", class_stack, &info_frame_cmd.address, | |
3056 | _("\ | |
3057 | Print information about a stack frame selected by stack address.\n\ | |
3058 | \n\ | |
3059 | Usage: info frame address STACK-ADDRESS"), | |
3060 | &info_frame_cmd_list); | |
3061 | ||
3062 | add_cmd ("view", class_stack, &info_frame_cmd.view, | |
3063 | _("\ | |
3064 | Print information about a stack frame outside the current backtrace.\n\ | |
3065 | \n\ | |
3066 | Usage: info frame view STACK-ADDRESS\n\ | |
3067 | info frame view STACK-ADDRESS PC-ADDRESS"), | |
3068 | &info_frame_cmd_list); | |
3069 | ||
3070 | cmd = add_cmd ("function", class_stack, &info_frame_cmd.function, | |
3071 | _("\ | |
3072 | Print information about a stack frame selected by function name.\n\ | |
3073 | \n\ | |
3074 | Usage: info frame function NAME"), | |
3075 | &info_frame_cmd_list); | |
3076 | set_cmd_completer (cmd, frame_selection_by_function_completer); | |
3077 | ||
3078 | add_cmd ("level", class_stack, &info_frame_cmd.level, | |
3079 | _("\ | |
3080 | Print information about a stack frame selected by level.\n\ | |
3081 | \n\ | |
3082 | Usage: info frame level LEVEL"), | |
3083 | &info_frame_cmd_list); | |
3084 | ||
11db9430 | 3085 | add_info ("locals", info_locals_command, |
12615cba PW |
3086 | info_print_args_help (_("\ |
3087 | All local variables of current stack frame or those matching REGEXPs.\n\ | |
3088 | Usage: info locals [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\ | |
3089 | Prints the local variables of the current stack frame.\n"), | |
3090 | _("local variables"))); | |
11db9430 | 3091 | add_info ("args", info_args_command, |
12615cba PW |
3092 | info_print_args_help (_("\ |
3093 | All argument variables of current stack frame or those matching REGEXPs.\n\ | |
3094 | Usage: info args [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\ | |
3095 | Prints the argument variables of the current stack frame.\n"), | |
3096 | _("argument variables"))); | |
c906108c SS |
3097 | |
3098 | if (dbx_commands) | |
1bedd215 | 3099 | add_com ("func", class_stack, func_command, _("\ |
41827fc3 TT |
3100 | Select the stack frame that contains NAME.\n\ |
3101 | Usage: func NAME")); | |
c906108c | 3102 | |
88408340 JB |
3103 | add_setshow_enum_cmd ("frame-arguments", class_stack, |
3104 | print_frame_arguments_choices, &print_frame_arguments, | |
3105 | _("Set printing of non-scalar frame arguments"), | |
3106 | _("Show printing of non-scalar frame arguments"), | |
3107 | NULL, NULL, NULL, &setprintlist, &showprintlist); | |
3108 | ||
e7045703 DE |
3109 | add_setshow_boolean_cmd ("frame-arguments", no_class, |
3110 | &print_raw_frame_arguments, _("\ | |
3111 | Set whether to print frame arguments in raw form."), _("\ | |
3112 | Show whether to print frame arguments in raw form."), _("\ | |
3113 | If set, frame arguments are printed in raw form, bypassing any\n\ | |
3114 | pretty-printers for that value."), | |
3115 | NULL, NULL, | |
3116 | &setprintrawlist, &showprintrawlist); | |
3117 | ||
30c33a9f HZ |
3118 | add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack, |
3119 | &disassemble_next_line, _("\ | |
3e43a32a MS |
3120 | Set whether to disassemble next source line or insn when execution stops."), |
3121 | _("\ | |
3122 | Show whether to disassemble next source line or insn when execution stops."), | |
3123 | _("\ | |
80a0ea0f EZ |
3124 | If ON, GDB will display disassembly of the next source line, in addition\n\ |
3125 | to displaying the source line itself. If the next source line cannot\n\ | |
3126 | be displayed (e.g., source is unavailable or there's no line info), GDB\n\ | |
3127 | will display disassembly of next instruction instead of showing the\n\ | |
3128 | source line.\n\ | |
3129 | If AUTO, display disassembly of next instruction only if the source line\n\ | |
3130 | cannot be displayed.\n\ | |
3131 | If OFF (which is the default), never display the disassembly of the next\n\ | |
3132 | source line."), | |
30c33a9f HZ |
3133 | NULL, |
3134 | show_disassemble_next_line, | |
3135 | &setlist, &showlist); | |
a362e3d3 | 3136 | disassemble_next_line = AUTO_BOOLEAN_FALSE; |
e18b2753 JK |
3137 | |
3138 | add_setshow_enum_cmd ("entry-values", class_stack, | |
3139 | print_entry_values_choices, &print_entry_values, | |
3140 | _("Set printing of function arguments at function " | |
3141 | "entry"), | |
3142 | _("Show printing of function arguments at function " | |
3143 | "entry"), | |
3144 | _("\ | |
3145 | GDB can sometimes determine the values of function arguments at entry,\n\ | |
3146 | in addition to their current values. This option tells GDB whether\n\ | |
3147 | to print the current value, the value at entry (marked as val@entry),\n\ | |
3148 | or both. Note that one or both of these values may be <optimized out>."), | |
3149 | NULL, NULL, &setprintlist, &showprintlist); | |
c906108c | 3150 | } |