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