GDB (xrefs)
Loading...
Searching...
No Matches
printcmd.c
Go to the documentation of this file.
1/* Print values for GNU debugger GDB.
2
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "frame.h"
22#include "symtab.h"
23#include "gdbtypes.h"
24#include "value.h"
25#include "language.h"
26#include "c-lang.h"
27#include "expression.h"
28#include "gdbcore.h"
29#include "gdbcmd.h"
30#include "target.h"
31#include "breakpoint.h"
32#include "demangle.h"
33#include "gdb-demangle.h"
34#include "valprint.h"
35#include "annotate.h"
36#include "symfile.h" /* for overlay functions */
37#include "objfiles.h" /* ditto */
38#include "completer.h" /* for completion functions */
39#include "ui-out.h"
40#include "block.h"
41#include "disasm.h"
42#include "target-float.h"
43#include "observable.h"
44#include "solist.h"
45#include "parser-defs.h"
46#include "charset.h"
47#include "arch-utils.h"
48#include "cli/cli-utils.h"
49#include "cli/cli-option.h"
50#include "cli/cli-script.h"
51#include "cli/cli-style.h"
52#include "gdbsupport/format.h"
53#include "source.h"
54#include "gdbsupport/byte-vector.h"
55#include "gdbsupport/gdb_optional.h"
56#include "safe-ctype.h"
57#include "gdbsupport/rsp-low.h"
58
59/* Chain containing all defined memory-tag subcommands. */
60
62
63/* Last specified output format. */
64
65static char last_format = 0;
66
67/* Last specified examination size. 'b', 'h', 'w' or `q'. */
68
69static char last_size = 'w';
70
71/* Last specified count for the 'x' command. */
72
73static int last_count;
74
75/* Last specified tag-printing option. */
76
77static bool last_print_tags = false;
78
79/* Default address to examine next, and associated architecture. */
80
81static struct gdbarch *next_gdbarch;
82static CORE_ADDR next_address;
83
84/* Number of delay instructions following current disassembled insn. */
85
87
88/* Last address examined. */
89
90static CORE_ADDR last_examine_address;
91
92/* Contents of last address examined.
93 This is not valid past the end of the `x' command! */
94
96
97/* Largest offset between a symbolic value and an address, that will be
98 printed as `0x1234 <symbol+offset>'. */
99
100static unsigned int max_symbolic_offset = UINT_MAX;
101static void
102show_max_symbolic_offset (struct ui_file *file, int from_tty,
103 struct cmd_list_element *c, const char *value)
104{
105 gdb_printf (file,
106 _("The largest offset that will be "
107 "printed in <symbol+1234> form is %s.\n"),
108 value);
109}
110
111/* Append the source filename and linenumber of the symbol when
112 printing a symbolic value as `<symbol at filename:linenum>' if set. */
113static bool print_symbol_filename = false;
114static void
115show_print_symbol_filename (struct ui_file *file, int from_tty,
116 struct cmd_list_element *c, const char *value)
117{
118 gdb_printf (file, _("Printing of source filename and "
119 "line number with <symbol> is %s.\n"),
120 value);
121}
122
123/* Number of auto-display expression currently being displayed.
124 So that we can disable it if we get a signal within it.
125 -1 when not doing one. */
126
128
129/* Last allocated display number. */
130
131static int display_number;
132
134 {
135 display (const char *exp_string_, expression_up &&exp_,
136 const struct format_data &format_, struct program_space *pspace_,
137 const struct block *block_)
138 : exp_string (exp_string_),
139 exp (std::move (exp_)),
141 format (format_),
142 pspace (pspace_),
143 block (block_),
144 enabled_p (true)
145 {
146 }
147
148 /* The expression as the user typed it. */
149 std::string exp_string;
150
151 /* Expression to be evaluated and displayed. */
153
154 /* Item number of this auto-display item. */
156
157 /* Display format specified. */
159
160 /* Program space associated with `block'. */
162
163 /* Innermost block required by this expression when evaluated. */
164 const struct block *block;
165
166 /* Status of this display (enabled or disabled). */
168 };
169
170/* Expressions whose values should be displayed automatically each
171 time the program stops. */
172
173static std::vector<std::unique_ptr<struct display>> all_displays;
174
175/* Prototypes for local functions. */
176
177static void do_one_display (struct display *);
178
179
180/* Decode a format specification. *STRING_PTR should point to it.
181 OFORMAT and OSIZE are used as defaults for the format and size
182 if none are given in the format specification.
183 If OSIZE is zero, then the size field of the returned value
184 should be set only if a size is explicitly specified by the
185 user.
186 The structure returned describes all the data
187 found in the specification. In addition, *STRING_PTR is advanced
188 past the specification and past all whitespace following it. */
189
190static struct format_data
191decode_format (const char **string_ptr, int oformat, int osize)
192{
193 struct format_data val;
194 const char *p = *string_ptr;
195
196 val.format = '?';
197 val.size = '?';
198 val.count = 1;
199 val.raw = 0;
200 val.print_tags = false;
201
202 if (*p == '-')
203 {
204 val.count = -1;
205 p++;
206 }
207 if (*p >= '0' && *p <= '9')
208 val.count *= atoi (p);
209 while (*p >= '0' && *p <= '9')
210 p++;
211
212 /* Now process size or format letters that follow. */
213
214 while (1)
215 {
216 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
217 val.size = *p++;
218 else if (*p == 'r')
219 {
220 val.raw = 1;
221 p++;
222 }
223 else if (*p == 'm')
224 {
225 val.print_tags = true;
226 p++;
227 }
228 else if (*p >= 'a' && *p <= 'z')
229 val.format = *p++;
230 else
231 break;
232 }
233
234 *string_ptr = skip_spaces (p);
235
236 /* Set defaults for format and size if not specified. */
237 if (val.format == '?')
238 {
239 if (val.size == '?')
240 {
241 /* Neither has been specified. */
242 val.format = oformat;
243 val.size = osize;
244 }
245 else
246 /* If a size is specified, any format makes a reasonable
247 default except 'i'. */
248 val.format = oformat == 'i' ? 'x' : oformat;
249 }
250 else if (val.size == '?')
251 switch (val.format)
252 {
253 case 'a':
254 /* Pick the appropriate size for an address. This is deferred
255 until do_examine when we know the actual architecture to use.
256 A special size value of 'a' is used to indicate this case. */
257 val.size = osize ? 'a' : osize;
258 break;
259 case 'f':
260 /* Floating point has to be word or giantword. */
261 if (osize == 'w' || osize == 'g')
262 val.size = osize;
263 else
264 /* Default it to giantword if the last used size is not
265 appropriate. */
266 val.size = osize ? 'g' : osize;
267 break;
268 case 'c':
269 /* Characters default to one byte. */
270 val.size = osize ? 'b' : osize;
271 break;
272 case 's':
273 /* Display strings with byte size chars unless explicitly
274 specified. */
275 val.size = '\0';
276 break;
277
278 default:
279 /* The default is the size most recently specified. */
280 val.size = osize;
281 }
282
283 return val;
284}
285
286/* Print value VAL on stream according to OPTIONS.
287 Do not end with a newline.
288 SIZE is the letter for the size of datum being printed.
289 This is used to pad hex numbers so they line up. SIZE is 0
290 for print / output and set for examine. */
291
292static void
293print_formatted (struct value *val, int size,
294 const struct value_print_options *options,
295 struct ui_file *stream)
296{
297 struct type *type = check_typedef (value_type (val));
298 int len = type->length ();
299
300 if (VALUE_LVAL (val) == lval_memory)
301 next_address = value_address (val) + len;
302
303 if (size)
304 {
305 switch (options->format)
306 {
307 case 's':
308 {
309 struct type *elttype = value_type (val);
310
312 + val_print_string (elttype, NULL,
313 value_address (val), -1,
314 stream, options) * len);
315 }
316 return;
317
318 case 'i':
319 /* We often wrap here if there are long symbolic names. */
320 stream->wrap_here (4);
322 + gdb_print_insn (type->arch (),
323 value_address (val), stream,
325 return;
326 }
327 }
328
329 if (options->format == 0 || options->format == 's'
330 || type->code () == TYPE_CODE_VOID
331 || type->code () == TYPE_CODE_REF
332 || type->code () == TYPE_CODE_ARRAY
333 || type->code () == TYPE_CODE_STRING
334 || type->code () == TYPE_CODE_STRUCT
335 || type->code () == TYPE_CODE_UNION
336 || type->code () == TYPE_CODE_NAMESPACE)
337 value_print (val, stream, options);
338 else
339 /* User specified format, so don't look to the type to tell us
340 what to do. */
341 value_print_scalar_formatted (val, options, size, stream);
342}
343
344/* Return builtin floating point type of same length as TYPE.
345 If no such type is found, return TYPE itself. */
346static struct type *
348{
349 struct gdbarch *gdbarch = type->arch ();
350 const struct builtin_type *builtin = builtin_type (gdbarch);
351
352 if (type->length () == builtin->builtin_float->length ())
353 type = builtin->builtin_float;
354 else if (type->length () == builtin->builtin_double->length ())
355 type = builtin->builtin_double;
356 else if (type->length () == builtin->builtin_long_double->length ())
357 type = builtin->builtin_long_double;
358
359 return type;
360}
361
362/* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
363 according to OPTIONS and SIZE on STREAM. Formats s and i are not
364 supported at this level. */
365
366void
367print_scalar_formatted (const gdb_byte *valaddr, struct type *type,
368 const struct value_print_options *options,
369 int size, struct ui_file *stream)
370{
371 struct gdbarch *gdbarch = type->arch ();
372 unsigned int len = type->length ();
373 enum bfd_endian byte_order = type_byte_order (type);
374
375 /* String printing should go through val_print_scalar_formatted. */
376 gdb_assert (options->format != 's');
377
378 /* If the value is a pointer, and pointers and addresses are not the
379 same, then at this point, the value's length (in target bytes) is
380 gdbarch_addr_bit/TARGET_CHAR_BIT, not type->length (). */
381 if (type->code () == TYPE_CODE_PTR)
382 len = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT;
383
384 /* If we are printing it as unsigned, truncate it in case it is actually
385 a negative signed value (e.g. "print/u (short)-1" should print 65535
386 (if shorts are 16 bits) instead of 4294967295). */
387 if (options->format != 'c'
388 && (options->format != 'd' || type->is_unsigned ()))
389 {
390 if (len < type->length () && byte_order == BFD_ENDIAN_BIG)
391 valaddr += type->length () - len;
392 }
393
394 /* Allow LEN == 0, and in this case, don't assume that VALADDR is
395 valid. */
396 const gdb_byte zero = 0;
397 if (len == 0)
398 {
399 len = 1;
400 valaddr = &zero;
401 }
402
403 if (size != 0 && (options->format == 'x' || options->format == 't'))
404 {
405 /* Truncate to fit. */
406 unsigned newlen;
407 switch (size)
408 {
409 case 'b':
410 newlen = 1;
411 break;
412 case 'h':
413 newlen = 2;
414 break;
415 case 'w':
416 newlen = 4;
417 break;
418 case 'g':
419 newlen = 8;
420 break;
421 default:
422 error (_("Undefined output size \"%c\"."), size);
423 }
424 if (newlen < len && byte_order == BFD_ENDIAN_BIG)
425 valaddr += len - newlen;
426 len = newlen;
427 }
428
429 /* Biased range types and sub-word scalar types must be handled
430 here; the value is correctly computed by unpack_long. */
431 gdb::byte_vector converted_bytes;
432 /* Some cases below will unpack the value again. In the biased
433 range case, we want to avoid this, so we store the unpacked value
434 here for possible use later. */
435 gdb::optional<LONGEST> val_long;
437 && (options->format == 'o'
438 || options->format == 'x'
439 || options->format == 't'
440 || options->format == 'z'
441 || options->format == 'd'
442 || options->format == 'u'))
443 || (type->code () == TYPE_CODE_RANGE && type->bounds ()->bias != 0)
445 {
446 val_long.emplace (unpack_long (type, valaddr));
447 converted_bytes.resize (type->length ());
448 store_signed_integer (converted_bytes.data (), type->length (),
449 byte_order, *val_long);
450 valaddr = converted_bytes.data ();
451 }
452
453 /* Printing a non-float type as 'f' will interpret the data as if it were
454 of a floating-point type of the same length, if that exists. Otherwise,
455 the data is printed as integer. */
456 char format = options->format;
457 if (format == 'f' && type->code () != TYPE_CODE_FLT)
458 {
460 if (type->code () != TYPE_CODE_FLT)
461 format = 0;
462 }
463
464 switch (format)
465 {
466 case 'o':
467 print_octal_chars (stream, valaddr, len, byte_order);
468 break;
469 case 'd':
470 print_decimal_chars (stream, valaddr, len, true, byte_order);
471 break;
472 case 'u':
473 print_decimal_chars (stream, valaddr, len, false, byte_order);
474 break;
475 case 0:
476 if (type->code () != TYPE_CODE_FLT)
477 {
478 print_decimal_chars (stream, valaddr, len, !type->is_unsigned (),
479 byte_order);
480 break;
481 }
482 /* FALLTHROUGH */
483 case 'f':
484 print_floating (valaddr, type, stream);
485 break;
486
487 case 't':
488 print_binary_chars (stream, valaddr, len, byte_order, size > 0, options);
489 break;
490 case 'x':
491 print_hex_chars (stream, valaddr, len, byte_order, size > 0);
492 break;
493 case 'z':
494 print_hex_chars (stream, valaddr, len, byte_order, true);
495 break;
496 case 'c':
497 {
498 struct value_print_options opts = *options;
499
500 if (!val_long.has_value ())
501 val_long.emplace (unpack_long (type, valaddr));
502
503 opts.format = 0;
504 if (type->is_unsigned ())
506 else
508
509 value_print (value_from_longest (type, *val_long), stream, &opts);
510 }
511 break;
512
513 case 'a':
514 {
515 if (!val_long.has_value ())
516 val_long.emplace (unpack_long (type, valaddr));
517 print_address (gdbarch, *val_long, stream);
518 }
519 break;
520
521 default:
522 error (_("Undefined output format \"%c\"."), format);
523 }
524}
525
526/* Specify default address for `x' command.
527 The `info lines' command uses this. */
528
529void
530set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
531{
532 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
533
535 next_address = addr;
536
537 /* Make address available to the user as $_. */
539 value_from_pointer (ptr_type, addr));
540}
541
542/* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
543 after LEADIN. Print nothing if no symbolic name is found nearby.
544 Optionally also print source file and line number, if available.
545 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
546 or to interpret it as a possible C++ name and convert it back to source
547 form. However note that DO_DEMANGLE can be overridden by the specific
548 settings of the demangle and asm_demangle variables. Returns
549 non-zero if anything was printed; zero otherwise. */
550
551int
552print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
553 struct ui_file *stream,
554 int do_demangle, const char *leadin)
555{
556 std::string name, filename;
557 int unmapped = 0;
558 int offset = 0;
559 int line = 0;
560
561 if (build_address_symbolic (gdbarch, addr, do_demangle, false, &name,
562 &offset, &filename, &line, &unmapped))
563 return 0;
564
565 gdb_puts (leadin, stream);
566 if (unmapped)
567 gdb_puts ("<*", stream);
568 else
569 gdb_puts ("<", stream);
570 fputs_styled (name.c_str (), function_name_style.style (), stream);
571 if (offset != 0)
572 gdb_printf (stream, "%+d", offset);
573
574 /* Append source filename and line number if desired. Give specific
575 line # of this addr, if we have it; else line # of the nearest symbol. */
576 if (print_symbol_filename && !filename.empty ())
577 {
578 gdb_puts (line == -1 ? " in " : " at ", stream);
579 fputs_styled (filename.c_str (), file_name_style.style (), stream);
580 if (line != -1)
581 gdb_printf (stream, ":%d", line);
582 }
583 if (unmapped)
584 gdb_puts ("*>", stream);
585 else
586 gdb_puts (">", stream);
587
588 return 1;
589}
590
591/* See valprint.h. */
592
593int
595 CORE_ADDR addr, /* IN */
596 bool do_demangle, /* IN */
597 bool prefer_sym_over_minsym, /* IN */
598 std::string *name, /* OUT */
599 int *offset, /* OUT */
600 std::string *filename, /* OUT */
601 int *line, /* OUT */
602 int *unmapped) /* OUT */
603{
604 struct bound_minimal_symbol msymbol;
605 struct symbol *symbol;
606 CORE_ADDR name_location = 0;
607 struct obj_section *section = NULL;
608 const char *name_temp = "";
609
610 /* Let's say it is mapped (not unmapped). */
611 *unmapped = 0;
612
613 /* Determine if the address is in an overlay, and whether it is
614 mapped. */
616 {
617 section = find_pc_overlay (addr);
618 if (pc_in_unmapped_range (addr, section))
619 {
620 *unmapped = 1;
621 addr = overlay_mapped_address (addr, section);
622 }
623 }
624
625 /* Try to find the address in both the symbol table and the minsyms.
626 In most cases, we'll prefer to use the symbol instead of the
627 minsym. However, there are cases (see below) where we'll choose
628 to use the minsym instead. */
629
630 /* This is defective in the sense that it only finds text symbols. So
631 really this is kind of pointless--we should make sure that the
632 minimal symbols have everything we need (by changing that we could
633 save some memory, but for many debug format--ELF/DWARF or
634 anything/stabs--it would be inconvenient to eliminate those minimal
635 symbols anyway). */
636 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
637 symbol = find_pc_sect_function (addr, section);
638
639 if (symbol)
640 {
641 /* If this is a function (i.e. a code address), strip out any
642 non-address bits. For instance, display a pointer to the
643 first instruction of a Thumb function as <function>; the
644 second instruction will be <function+2>, even though the
645 pointer is <function+3>. This matches the ISA behavior. */
647
648 name_location = symbol->value_block ()->entry_pc ();
649 if (do_demangle || asm_demangle)
650 name_temp = symbol->print_name ();
651 else
652 name_temp = symbol->linkage_name ();
653 }
654
655 if (msymbol.minsym != NULL
656 && msymbol.minsym->has_size ()
657 && msymbol.minsym->size () == 0
658 && msymbol.minsym->type () != mst_text
659 && msymbol.minsym->type () != mst_text_gnu_ifunc
660 && msymbol.minsym->type () != mst_file_text)
661 msymbol.minsym = NULL;
662
663 if (msymbol.minsym != NULL)
664 {
665 /* Use the minsym if no symbol is found.
666
667 Additionally, use the minsym instead of a (found) symbol if
668 the following conditions all hold:
669 1) The prefer_sym_over_minsym flag is false.
670 2) The minsym address is identical to that of the address under
671 consideration.
672 3) The symbol address is not identical to that of the address
673 under consideration. */
674 if (symbol == NULL ||
675 (!prefer_sym_over_minsym
676 && msymbol.value_address () == addr
677 && name_location != addr))
678 {
679 /* If this is a function (i.e. a code address), strip out any
680 non-address bits. For instance, display a pointer to the
681 first instruction of a Thumb function as <function>; the
682 second instruction will be <function+2>, even though the
683 pointer is <function+3>. This matches the ISA behavior. */
684 if (msymbol.minsym->type () == mst_text
685 || msymbol.minsym->type () == mst_text_gnu_ifunc
686 || msymbol.minsym->type () == mst_file_text
687 || msymbol.minsym->type () == mst_solib_trampoline)
689
690 symbol = 0;
691 name_location = msymbol.value_address ();
692 if (do_demangle || asm_demangle)
693 name_temp = msymbol.minsym->print_name ();
694 else
695 name_temp = msymbol.minsym->linkage_name ();
696 }
697 }
698 if (symbol == NULL && msymbol.minsym == NULL)
699 return 1;
700
701 /* If the nearest symbol is too far away, don't print anything symbolic. */
702
703 /* For when CORE_ADDR is larger than unsigned int, we do math in
704 CORE_ADDR. But when we detect unsigned wraparound in the
705 CORE_ADDR math, we ignore this test and print the offset,
706 because addr+max_symbolic_offset has wrapped through the end
707 of the address space back to the beginning, giving bogus comparison. */
708 if (addr > name_location + max_symbolic_offset
709 && name_location + max_symbolic_offset > name_location)
710 return 1;
711
712 *offset = (LONGEST) addr - name_location;
713
714 *name = name_temp;
715
717 {
718 struct symtab_and_line sal;
719
720 sal = find_pc_sect_line (addr, section, 0);
721
722 if (sal.symtab)
723 {
724 *filename = symtab_to_filename_for_display (sal.symtab);
725 *line = sal.line;
726 }
727 }
728 return 0;
729}
730
731
732/* Print address ADDR symbolically on STREAM.
733 First print it as a number. Then perhaps print
734 <SYMBOL + OFFSET> after the number. */
735
736void
738 CORE_ADDR addr, struct ui_file *stream)
739{
740 fputs_styled (paddress (gdbarch, addr), address_style.style (), stream);
741 print_address_symbolic (gdbarch, addr, stream, asm_demangle, " ");
742}
743
744/* Return a prefix for instruction address:
745 "=> " for current instruction, else " ". */
746
747const char *
748pc_prefix (CORE_ADDR addr)
749{
750 if (has_stack_frames ())
751 {
752 frame_info_ptr frame;
753 CORE_ADDR pc;
754
755 frame = get_selected_frame (NULL);
756 if (get_frame_pc_if_available (frame, &pc) && pc == addr)
757 return "=> ";
758 }
759 return " ";
760}
761
762/* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
763 controls whether to print the symbolic name "raw" or demangled.
764 Return non-zero if anything was printed; zero otherwise. */
765
766int
768 struct gdbarch *gdbarch, CORE_ADDR addr,
769 struct ui_file *stream, int do_demangle)
770{
771 if (opts->addressprint)
772 {
773 fputs_styled (paddress (gdbarch, addr), address_style.style (), stream);
774 print_address_symbolic (gdbarch, addr, stream, do_demangle, " ");
775 }
776 else
777 {
778 return print_address_symbolic (gdbarch, addr, stream, do_demangle, "");
779 }
780 return 1;
781}
782
783
784/* Find the address of the instruction that is INST_COUNT instructions before
785 the instruction at ADDR.
786 Since some architectures have variable-length instructions, we can't just
787 simply subtract INST_COUNT * INSN_LEN from ADDR. Instead, we use line
788 number information to locate the nearest known instruction boundary,
789 and disassemble forward from there. If we go out of the symbol range
790 during disassembling, we return the lowest address we've got so far and
791 set the number of instructions read to INST_READ. */
792
793static CORE_ADDR
795 int inst_count, int *inst_read)
796{
797 /* The vector PCS is used to store instruction addresses within
798 a pc range. */
799 CORE_ADDR loop_start, loop_end, p;
800 std::vector<CORE_ADDR> pcs;
801 struct symtab_and_line sal;
802
803 *inst_read = 0;
804 loop_start = loop_end = addr;
805
806 /* In each iteration of the outer loop, we get a pc range that ends before
807 LOOP_START, then we count and store every instruction address of the range
808 iterated in the loop.
809 If the number of instructions counted reaches INST_COUNT, return the
810 stored address that is located INST_COUNT instructions back from ADDR.
811 If INST_COUNT is not reached, we subtract the number of counted
812 instructions from INST_COUNT, and go to the next iteration. */
813 do
814 {
815 pcs.clear ();
816 sal = find_pc_sect_line (loop_start, NULL, 1);
817 if (sal.line <= 0)
818 {
819 /* We reach here when line info is not available. In this case,
820 we print a message and just exit the loop. The return value
821 is calculated after the loop. */
822 gdb_printf (_("No line number information available "
823 "for address "));
824 gdb_stdout->wrap_here (2);
825 print_address (gdbarch, loop_start - 1, gdb_stdout);
826 gdb_printf ("\n");
827 break;
828 }
829
830 loop_end = loop_start;
831 loop_start = sal.pc;
832
833 /* This loop pushes instruction addresses in the range from
834 LOOP_START to LOOP_END. */
835 for (p = loop_start; p < loop_end;)
836 {
837 pcs.push_back (p);
838 p += gdb_insn_length (gdbarch, p);
839 }
840
841 inst_count -= pcs.size ();
842 *inst_read += pcs.size ();
843 }
844 while (inst_count > 0);
845
846 /* After the loop, the vector PCS has instruction addresses of the last
847 source line we processed, and INST_COUNT has a negative value.
848 We return the address at the index of -INST_COUNT in the vector for
849 the reason below.
850 Let's assume the following instruction addresses and run 'x/-4i 0x400e'.
851 Line X of File
852 0x4000
853 0x4001
854 0x4005
855 Line Y of File
856 0x4009
857 0x400c
858 => 0x400e
859 0x4011
860 find_instruction_backward is called with INST_COUNT = 4 and expected to
861 return 0x4001. When we reach here, INST_COUNT is set to -1 because
862 it was subtracted by 2 (from Line Y) and 3 (from Line X). The value
863 4001 is located at the index 1 of the last iterated line (= Line X),
864 which is simply calculated by -INST_COUNT.
865 The case when the length of PCS is 0 means that we reached an area for
866 which line info is not available. In such case, we return LOOP_START,
867 which was the lowest instruction address that had line info. */
868 p = pcs.size () > 0 ? pcs[-inst_count] : loop_start;
869
870 /* INST_READ includes all instruction addresses in a pc range. Need to
871 exclude the beginning part up to the address we're returning. That
872 is, exclude {0x4000} in the example above. */
873 if (inst_count < 0)
874 *inst_read += inst_count;
875
876 return p;
877}
878
879/* Backward read LEN bytes of target memory from address MEMADDR + LEN,
880 placing the results in GDB's memory from MYADDR + LEN. Returns
881 a count of the bytes actually read. */
882
883static int
885 CORE_ADDR memaddr, gdb_byte *myaddr, int len)
886{
887 int errcode;
888 int nread; /* Number of bytes actually read. */
889
890 /* First try a complete read. */
891 errcode = target_read_memory (memaddr, myaddr, len);
892 if (errcode == 0)
893 {
894 /* Got it all. */
895 nread = len;
896 }
897 else
898 {
899 /* Loop, reading one byte at a time until we get as much as we can. */
900 memaddr += len;
901 myaddr += len;
902 for (nread = 0; nread < len; ++nread)
903 {
904 errcode = target_read_memory (--memaddr, --myaddr, 1);
905 if (errcode != 0)
906 {
907 /* The read was unsuccessful, so exit the loop. */
908 gdb_printf (_("Cannot access memory at address %s\n"),
909 paddress (gdbarch, memaddr));
910 break;
911 }
912 }
913 }
914 return nread;
915}
916
917/* Returns true if X (which is LEN bytes wide) is the number zero. */
918
919static int
920integer_is_zero (const gdb_byte *x, int len)
921{
922 int i = 0;
923
924 while (i < len && x[i] == 0)
925 ++i;
926 return (i == len);
927}
928
929/* Find the start address of a string in which ADDR is included.
930 Basically we search for '\0' and return the next address,
931 but if OPTIONS->PRINT_MAX is smaller than the length of a string,
932 we stop searching and return the address to print characters as many as
933 PRINT_MAX from the string. */
934
935static CORE_ADDR
937 CORE_ADDR addr, int count, int char_size,
938 const struct value_print_options *options,
939 int *strings_counted)
940{
941 const int chunk_size = 0x20;
942 int read_error = 0;
943 int chars_read = 0;
944 int chars_to_read = chunk_size;
945 int chars_counted = 0;
946 int count_original = count;
947 CORE_ADDR string_start_addr = addr;
948
949 gdb_assert (char_size == 1 || char_size == 2 || char_size == 4);
950 gdb::byte_vector buffer (chars_to_read * char_size);
951 while (count > 0 && read_error == 0)
952 {
953 int i;
954
955 addr -= chars_to_read * char_size;
956 chars_read = read_memory_backward (gdbarch, addr, buffer.data (),
957 chars_to_read * char_size);
958 chars_read /= char_size;
959 read_error = (chars_read == chars_to_read) ? 0 : 1;
960 /* Searching for '\0' from the end of buffer in backward direction. */
961 for (i = 0; i < chars_read && count > 0 ; ++i, ++chars_counted)
962 {
963 int offset = (chars_to_read - i - 1) * char_size;
964
965 if (integer_is_zero (&buffer[offset], char_size)
966 || chars_counted == options->print_max)
967 {
968 /* Found '\0' or reached print_max. As OFFSET is the offset to
969 '\0', we add CHAR_SIZE to return the start address of
970 a string. */
971 --count;
972 string_start_addr = addr + offset + char_size;
973 chars_counted = 0;
974 }
975 }
976 }
977
978 /* Update STRINGS_COUNTED with the actual number of loaded strings. */
979 *strings_counted = count_original - count;
980
981 if (read_error != 0)
982 {
983 /* In error case, STRING_START_ADDR is pointing to the string that
984 was last successfully loaded. Rewind the partially loaded string. */
985 string_start_addr -= chars_counted * char_size;
986 }
987
988 return string_start_addr;
989}
990
991/* Examine data at address ADDR in format FMT.
992 Fetch it from memory and print on gdb_stdout. */
993
994static void
995do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
996{
997 char format = 0;
998 char size;
999 int count = 1;
1000 struct type *val_type = NULL;
1001 int i;
1002 int maxelts;
1003 struct value_print_options opts;
1004 int need_to_update_next_address = 0;
1005 CORE_ADDR addr_rewound = 0;
1006
1007 format = fmt.format;
1008 size = fmt.size;
1009 count = fmt.count;
1011 next_address = addr;
1012
1013 /* Instruction format implies fetch single bytes
1014 regardless of the specified size.
1015 The case of strings is handled in decode_format, only explicit
1016 size operator are not changed to 'b'. */
1017 if (format == 'i')
1018 size = 'b';
1019
1020 if (size == 'a')
1021 {
1022 /* Pick the appropriate size for an address. */
1023 if (gdbarch_ptr_bit (next_gdbarch) == 64)
1024 size = 'g';
1025 else if (gdbarch_ptr_bit (next_gdbarch) == 32)
1026 size = 'w';
1027 else if (gdbarch_ptr_bit (next_gdbarch) == 16)
1028 size = 'h';
1029 else
1030 /* Bad value for gdbarch_ptr_bit. */
1031 internal_error (_("failed internal consistency check"));
1032 }
1033
1034 if (size == 'b')
1036 else if (size == 'h')
1038 else if (size == 'w')
1040 else if (size == 'g')
1042
1043 if (format == 's')
1044 {
1045 struct type *char_type = NULL;
1046
1047 /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char
1048 if type is not found. */
1049 if (size == 'h')
1051 else if (size == 'w')
1053 if (char_type)
1054 val_type = char_type;
1055 else
1056 {
1057 if (size != '\0' && size != 'b')
1058 warning (_("Unable to display strings with "
1059 "size '%c', using 'b' instead."), size);
1060 size = 'b';
1062 }
1063 }
1064
1065 maxelts = 8;
1066 if (size == 'w')
1067 maxelts = 4;
1068 if (size == 'g')
1069 maxelts = 2;
1070 if (format == 's' || format == 'i')
1071 maxelts = 1;
1072
1073 get_formatted_print_options (&opts, format);
1074
1075 if (count < 0)
1076 {
1077 /* This is the negative repeat count case.
1078 We rewind the address based on the given repeat count and format,
1079 then examine memory from there in forward direction. */
1080
1081 count = -count;
1082 if (format == 'i')
1083 {
1085 &count);
1086 }
1087 else if (format == 's')
1088 {
1090 val_type->length (),
1091 &opts, &count);
1092 }
1093 else
1094 {
1095 next_address = addr - count * val_type->length ();
1096 }
1097
1098 /* The following call to print_formatted updates next_address in every
1099 iteration. In backward case, we store the start address here
1100 and update next_address with it before exiting the function. */
1101 addr_rewound = (format == 's'
1102 ? next_address - val_type->length ()
1103 : next_address);
1104 need_to_update_next_address = 1;
1105 }
1106
1107 /* Whether we need to print the memory tag information for the current
1108 address range. */
1109 bool print_range_tag = true;
1110 uint32_t gsize = gdbarch_memtag_granule_size (gdbarch);
1111
1112 /* Print as many objects as specified in COUNT, at most maxelts per line,
1113 with the address of the next one at the start of each line. */
1114
1115 while (count > 0)
1116 {
1117 QUIT;
1118
1119 CORE_ADDR tag_laddr = 0, tag_haddr = 0;
1120
1121 /* Print the memory tag information if requested. */
1122 if (fmt.print_tags && print_range_tag
1124 {
1125 tag_laddr = align_down (next_address, gsize);
1126 tag_haddr = align_down (next_address + gsize, gsize);
1127
1128 struct value *v_addr
1129 = value_from_ulongest (builtin_type (gdbarch)->builtin_data_ptr,
1130 tag_laddr);
1131
1133 {
1134 /* Fetch the allocation tag. */
1135 struct value *tag
1137 std::string atag
1139
1140 if (!atag.empty ())
1141 {
1142 gdb_printf (_("<Allocation Tag %s for range [%s,%s)>\n"),
1143 atag.c_str (),
1144 paddress (gdbarch, tag_laddr),
1145 paddress (gdbarch, tag_haddr));
1146 }
1147 }
1148 print_range_tag = false;
1149 }
1150
1151 if (format == 'i')
1154 gdb_printf (":");
1155 for (i = maxelts;
1156 i > 0 && count > 0;
1157 i--, count--)
1158 {
1159 gdb_printf ("\t");
1160 /* Note that print_formatted sets next_address for the next
1161 object. */
1163
1164 /* The value to be displayed is not fetched greedily.
1165 Instead, to avoid the possibility of a fetched value not
1166 being used, its retrieval is delayed until the print code
1167 uses it. When examining an instruction stream, the
1168 disassembler will perform its own memory fetch using just
1169 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
1170 the disassembler be modified so that LAST_EXAMINE_VALUE
1171 is left with the byte sequence from the last complete
1172 instruction fetched from memory? */
1175
1177
1178 /* Display any branch delay slots following the final insn. */
1179 if (format == 'i' && count == 1)
1180 count += branch_delay_insns;
1181
1182 /* Update the tag range based on the current address being
1183 processed. */
1184 if (tag_haddr <= next_address)
1185 print_range_tag = true;
1186 }
1187 gdb_printf ("\n");
1188 }
1189
1190 if (need_to_update_next_address)
1191 next_address = addr_rewound;
1192}
1193
1194static void
1195validate_format (struct format_data fmt, const char *cmdname)
1196{
1197 if (fmt.size != 0)
1198 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
1199 if (fmt.count != 1)
1200 error (_("Item count other than 1 is meaningless in \"%s\" command."),
1201 cmdname);
1202 if (fmt.format == 'i')
1203 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
1204 fmt.format, cmdname);
1205}
1206
1207/* Parse print command format string into *OPTS and update *EXPP.
1208 CMDNAME should name the current command. */
1209
1210void
1211print_command_parse_format (const char **expp, const char *cmdname,
1212 value_print_options *opts)
1213{
1214 const char *exp = *expp;
1215
1216 /* opts->raw value might already have been set by 'set print raw-values'
1217 or by using 'print -raw-values'.
1218 So, do not set opts->raw to 0, only set it to 1 if /r is given. */
1219 if (exp && *exp == '/')
1220 {
1221 format_data fmt;
1222
1223 exp++;
1224 fmt = decode_format (&exp, last_format, 0);
1225 validate_format (fmt, cmdname);
1226 last_format = fmt.format;
1227
1228 opts->format = fmt.format;
1229 opts->raw = opts->raw || fmt.raw;
1230 }
1231 else
1232 {
1233 opts->format = 0;
1234 }
1235
1236 *expp = exp;
1237}
1238
1239/* See valprint.h. */
1240
1241void
1243{
1244 int histindex = record_latest_value (val);
1245
1246 annotate_value_history_begin (histindex, value_type (val));
1247
1248 gdb_printf ("$%d = ", histindex);
1249
1251
1252 print_formatted (val, 0, &opts, gdb_stdout);
1253 gdb_printf ("\n");
1254
1256}
1257
1258/* Returns true if memory tags should be validated. False otherwise. */
1259
1260static bool
1262{
1263 gdb_assert (value != nullptr && value_type (value) != nullptr);
1264
1266 return false;
1267
1268 enum type_code code = value_type (value)->code ();
1269
1270 /* Skip non-address values. */
1271 if (code != TYPE_CODE_PTR
1273 return false;
1274
1275 /* OK, we have an address value. Check we have a complete value we
1276 can extract. */
1279 return false;
1280
1281 /* We do. Check whether it includes any tags. */
1283}
1284
1285/* Helper for parsing arguments for print_command_1. */
1286
1287static struct value *
1289 bool voidprint)
1290{
1291 get_user_print_options (print_opts);
1292 /* Override global settings with explicit options, if any. */
1293 auto group = make_value_print_options_def_group (print_opts);
1296
1297 print_command_parse_format (&args, "print", print_opts);
1298
1299 const char *exp = args;
1300
1301 if (exp != nullptr && *exp)
1302 {
1303 /* VOIDPRINT is true to indicate that we do want to print a void
1304 value, so invert it for parse_expression. */
1305 expression_up expr = parse_expression (exp, nullptr, !voidprint);
1306 return evaluate_expression (expr.get ());
1307 }
1308
1309 return access_value_history (0);
1310}
1311
1312/* Implementation of the "print" and "call" commands. */
1313
1314static void
1315print_command_1 (const char *args, int voidprint)
1316{
1317 value_print_options print_opts;
1318
1319 struct value *val = process_print_command_args (args, &print_opts, voidprint);
1320
1321 if (voidprint || (val && value_type (val) &&
1322 value_type (val)->code () != TYPE_CODE_VOID))
1323 {
1324 /* If memory tagging validation is on, check if the tag is valid. */
1325 if (print_opts.memory_tag_violations)
1326 {
1327 try
1328 {
1329 if (should_validate_memtags (val)
1331 {
1332 /* Fetch the logical tag. */
1333 struct value *tag
1336 std::string ltag
1338
1339 /* Fetch the allocation tag. */
1340 tag = gdbarch_get_memtag (target_gdbarch (), val,
1342 std::string atag
1344
1345 gdb_printf (_("Logical tag (%s) does not match the "
1346 "allocation tag (%s).\n"),
1347 ltag.c_str (), atag.c_str ());
1348 }
1349 }
1350 catch (gdb_exception_error &ex)
1351 {
1352 if (ex.error == TARGET_CLOSE_ERROR)
1353 throw;
1354
1356 _("Could not validate memory tag: %s\n"),
1357 ex.message->c_str ());
1358 }
1359 }
1360
1361 print_value (val, print_opts);
1362 }
1363}
1364
1365/* Called from command completion function to skip over /FMT
1366 specifications, allowing the rest of the line to be completed. Returns
1367 true if the /FMT is at the end of the current line and there is nothing
1368 left to complete, otherwise false is returned.
1369
1370 In either case *ARGS can be updated to point after any part of /FMT that
1371 is present.
1372
1373 This function is designed so that trying to complete '/' will offer no
1374 completions, the user needs to insert the format specification
1375 themselves. Trying to complete '/FMT' (where FMT is any non-empty set
1376 of alpha-numeric characters) will cause readline to insert a single
1377 space, setting the user up to enter the expression. */
1378
1379static bool
1380skip_over_slash_fmt (completion_tracker &tracker, const char **args)
1381{
1382 const char *text = *args;
1383
1384 if (text[0] == '/')
1385 {
1386 bool in_fmt;
1387 tracker.set_use_custom_word_point (true);
1388
1389 if (text[1] == '\0')
1390 {
1391 /* The user tried to complete after typing just the '/' character
1392 of the /FMT string. Step the completer past the '/', but we
1393 don't offer any completions. */
1394 in_fmt = true;
1395 ++text;
1396 }
1397 else
1398 {
1399 /* The user has typed some characters after the '/', we assume
1400 this is a complete /FMT string, first skip over it. */
1401 text = skip_to_space (text);
1402
1403 if (*text == '\0')
1404 {
1405 /* We're at the end of the input string. The user has typed
1406 '/FMT' and asked for a completion. Push an empty
1407 completion string, this will cause readline to insert a
1408 space so the user now has '/FMT '. */
1409 in_fmt = true;
1410 tracker.add_completion (make_unique_xstrdup (text));
1411 }
1412 else
1413 {
1414 /* The user has already typed things after the /FMT, skip the
1415 whitespace and return false. Whoever called this function
1416 should then try to complete what comes next. */
1417 in_fmt = false;
1418 text = skip_spaces (text);
1419 }
1420 }
1421
1422 tracker.advance_custom_word_point_by (text - *args);
1423 *args = text;
1424 return in_fmt;
1425 }
1426
1427 return false;
1428}
1429
1430/* See valprint.h. */
1431
1432void
1434 completion_tracker &tracker,
1435 const char *text, const char * /*word*/)
1436{
1437 const auto group = make_value_print_options_def_group (nullptr);
1439 (tracker, &text, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER, group))
1440 return;
1441
1442 if (skip_over_slash_fmt (tracker, &text))
1443 return;
1444
1445 const char *word = advance_to_expression_complete_word_point (tracker, text);
1446 expression_completer (ignore, tracker, text, word);
1447}
1448
1449static void
1450print_command (const char *exp, int from_tty)
1451{
1452 print_command_1 (exp, true);
1453}
1454
1455/* Same as print, except it doesn't print void results. */
1456static void
1457call_command (const char *exp, int from_tty)
1458{
1459 print_command_1 (exp, false);
1460}
1461
1462/* Implementation of the "output" command. */
1463
1464void
1465output_command (const char *exp, int from_tty)
1466{
1467 char format = 0;
1468 struct value *val;
1469 struct format_data fmt;
1470 struct value_print_options opts;
1471
1472 fmt.size = 0;
1473 fmt.raw = 0;
1474
1475 if (exp && *exp == '/')
1476 {
1477 exp++;
1478 fmt = decode_format (&exp, 0, 0);
1479 validate_format (fmt, "output");
1480 format = fmt.format;
1481 }
1482
1484
1485 val = evaluate_expression (expr.get ());
1486
1488
1490 opts.raw = fmt.raw;
1491 print_formatted (val, fmt.size, &opts, gdb_stdout);
1492
1494
1496}
1497
1498static void
1499set_command (const char *exp, int from_tty)
1500{
1502
1503 switch (expr->op->opcode ())
1504 {
1505 case UNOP_PREINCREMENT:
1506 case UNOP_POSTINCREMENT:
1507 case UNOP_PREDECREMENT:
1508 case UNOP_POSTDECREMENT:
1509 case BINOP_ASSIGN:
1510 case BINOP_ASSIGN_MODIFY:
1511 case BINOP_COMMA:
1512 break;
1513 default:
1514 warning
1515 (_("Expression is not an assignment (and might have no effect)"));
1516 }
1517
1518 evaluate_expression (expr.get ());
1519}
1520
1521static void
1522info_symbol_command (const char *arg, int from_tty)
1523{
1524 struct minimal_symbol *msymbol;
1525 struct obj_section *osect;
1526 CORE_ADDR addr, sect_addr;
1527 int matches = 0;
1528 unsigned int offset;
1529
1530 if (!arg)
1531 error_no_arg (_("address"));
1532
1536 {
1537 /* Only process each object file once, even if there's a separate
1538 debug file. */
1540 continue;
1541
1542 sect_addr = overlay_mapped_address (addr, osect);
1543
1544 if (osect->addr () <= sect_addr && sect_addr < osect->endaddr ()
1545 && (msymbol
1547 osect).minsym))
1548 {
1549 const char *obj_name, *mapped, *sec_name, *msym_name;
1550 const char *loc_string;
1551
1552 matches = 1;
1553 offset = sect_addr - msymbol->value_address (objfile);
1554 mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
1555 sec_name = osect->the_bfd_section->name;
1556 msym_name = msymbol->print_name ();
1557
1558 /* Don't print the offset if it is zero.
1559 We assume there's no need to handle i18n of "sym + offset". */
1560 std::string string_holder;
1561 if (offset)
1562 {
1563 string_holder = string_printf ("%s + %u", msym_name, offset);
1564 loc_string = string_holder.c_str ();
1565 }
1566 else
1567 loc_string = msym_name;
1568
1569 gdb_assert (osect->objfile && objfile_name (osect->objfile));
1570 obj_name = objfile_name (osect->objfile);
1571
1573 if (pc_in_unmapped_range (addr, osect))
1574 if (section_is_overlay (osect))
1575 gdb_printf (_("%s in load address range of "
1576 "%s overlay section %s of %s\n"),
1577 loc_string, mapped, sec_name, obj_name);
1578 else
1579 gdb_printf (_("%s in load address range of "
1580 "section %s of %s\n"),
1581 loc_string, sec_name, obj_name);
1582 else
1583 if (section_is_overlay (osect))
1584 gdb_printf (_("%s in %s overlay section %s of %s\n"),
1585 loc_string, mapped, sec_name, obj_name);
1586 else
1587 gdb_printf (_("%s in section %s of %s\n"),
1588 loc_string, sec_name, obj_name);
1589 else
1590 if (pc_in_unmapped_range (addr, osect))
1591 if (section_is_overlay (osect))
1592 gdb_printf (_("%s in load address range of %s overlay "
1593 "section %s\n"),
1594 loc_string, mapped, sec_name);
1595 else
1597 (_("%s in load address range of section %s\n"),
1598 loc_string, sec_name);
1599 else
1600 if (section_is_overlay (osect))
1601 gdb_printf (_("%s in %s overlay section %s\n"),
1602 loc_string, mapped, sec_name);
1603 else
1604 gdb_printf (_("%s in section %s\n"),
1605 loc_string, sec_name);
1606 }
1607 }
1608 if (matches == 0)
1609 gdb_printf (_("No symbol matches %s.\n"), arg);
1610}
1611
1612static void
1613info_address_command (const char *exp, int from_tty)
1614{
1615 struct gdbarch *gdbarch;
1616 int regno;
1617 struct symbol *sym;
1618 struct bound_minimal_symbol msymbol;
1619 long val;
1620 struct obj_section *section;
1621 CORE_ADDR load_addr, context_pc = 0;
1622 struct field_of_this_result is_a_field_of_this;
1623
1624 if (exp == 0)
1625 error (_("Argument required."));
1626
1627 sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN,
1628 &is_a_field_of_this).symbol;
1629 if (sym == NULL)
1630 {
1631 if (is_a_field_of_this.type != NULL)
1632 {
1633 gdb_printf ("Symbol \"");
1635 current_language->la_language, DMGL_ANSI);
1636 gdb_printf ("\" is a field of the local class variable ");
1638 gdb_printf ("`self'\n"); /* ObjC equivalent of "this" */
1639 else
1640 gdb_printf ("`this'\n");
1641 return;
1642 }
1643
1644 msymbol = lookup_bound_minimal_symbol (exp);
1645
1646 if (msymbol.minsym != NULL)
1647 {
1648 struct objfile *objfile = msymbol.objfile;
1649
1650 gdbarch = objfile->arch ();
1651 load_addr = msymbol.value_address ();
1652
1653 gdb_printf ("Symbol \"");
1655 current_language->la_language, DMGL_ANSI);
1656 gdb_printf ("\" is at ");
1658 gdb_stdout);
1659 gdb_printf (" in a file compiled without debugging");
1660 section = msymbol.minsym->obj_section (objfile);
1661 if (section_is_overlay (section))
1662 {
1663 load_addr = overlay_unmapped_address (load_addr, section);
1664 gdb_printf (",\n -- loaded at ");
1665 fputs_styled (paddress (gdbarch, load_addr),
1667 gdb_stdout);
1668 gdb_printf (" in overlay section %s",
1669 section->the_bfd_section->name);
1670 }
1671 gdb_printf (".\n");
1672 }
1673 else
1674 error (_("No symbol \"%s\" in current context."), exp);
1675 return;
1676 }
1677
1678 gdb_printf ("Symbol \"");
1679 gdb_puts (sym->print_name ());
1680 gdb_printf ("\" is ");
1681 val = sym->value_longest ();
1682 if (sym->is_objfile_owned ())
1683 section = sym->obj_section (sym->objfile ());
1684 else
1685 section = NULL;
1686 gdbarch = sym->arch ();
1687
1688 if (SYMBOL_COMPUTED_OPS (sym) != NULL)
1689 {
1690 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, context_pc,
1691 gdb_stdout);
1692 gdb_printf (".\n");
1693 return;
1694 }
1695
1696 switch (sym->aclass ())
1697 {
1698 case LOC_CONST:
1699 case LOC_CONST_BYTES:
1700 gdb_printf ("constant");
1701 break;
1702
1703 case LOC_LABEL:
1704 gdb_printf ("a label at address ");
1705 load_addr = sym->value_address ();
1707 gdb_stdout);
1708 if (section_is_overlay (section))
1709 {
1710 load_addr = overlay_unmapped_address (load_addr, section);
1711 gdb_printf (",\n -- loaded at ");
1713 gdb_stdout);
1714 gdb_printf (" in overlay section %s",
1715 section->the_bfd_section->name);
1716 }
1717 break;
1718
1719 case LOC_COMPUTED:
1720 gdb_assert_not_reached ("LOC_COMPUTED variable missing a method");
1721
1722 case LOC_REGISTER:
1723 /* GDBARCH is the architecture associated with the objfile the symbol
1724 is defined in; the target architecture may be different, and may
1725 provide additional registers. However, we do not know the target
1726 architecture at this point. We assume the objfile architecture
1727 will contain all the standard registers that occur in debug info
1728 in that objfile. */
1729 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1730
1731 if (sym->is_argument ())
1732 gdb_printf (_("an argument in register %s"),
1734 else
1735 gdb_printf (_("a variable in register %s"),
1737 break;
1738
1739 case LOC_STATIC:
1740 gdb_printf (_("static storage at address "));
1741 load_addr = sym->value_address ();
1743 gdb_stdout);
1744 if (section_is_overlay (section))
1745 {
1746 load_addr = overlay_unmapped_address (load_addr, section);
1747 gdb_printf (_(",\n -- loaded at "));
1749 gdb_stdout);
1750 gdb_printf (_(" in overlay section %s"),
1751 section->the_bfd_section->name);
1752 }
1753 break;
1754
1755 case LOC_REGPARM_ADDR:
1756 /* Note comment at LOC_REGISTER. */
1757 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1758 gdb_printf (_("address of an argument in register %s"),
1760 break;
1761
1762 case LOC_ARG:
1763 gdb_printf (_("an argument at offset %ld"), val);
1764 break;
1765
1766 case LOC_LOCAL:
1767 gdb_printf (_("a local variable at frame offset %ld"), val);
1768 break;
1769
1770 case LOC_REF_ARG:
1771 gdb_printf (_("a reference argument at offset %ld"), val);
1772 break;
1773
1774 case LOC_TYPEDEF:
1775 gdb_printf (_("a typedef"));
1776 break;
1777
1778 case LOC_BLOCK:
1779 gdb_printf (_("a function at address "));
1780 load_addr = sym->value_block ()->entry_pc ();
1782 gdb_stdout);
1783 if (section_is_overlay (section))
1784 {
1785 load_addr = overlay_unmapped_address (load_addr, section);
1786 gdb_printf (_(",\n -- loaded at "));
1788 gdb_stdout);
1789 gdb_printf (_(" in overlay section %s"),
1790 section->the_bfd_section->name);
1791 }
1792 break;
1793
1794 case LOC_UNRESOLVED:
1795 {
1796 struct bound_minimal_symbol msym;
1797
1799 if (msym.minsym == NULL)
1800 gdb_printf ("unresolved");
1801 else
1802 {
1803 section = msym.obj_section ();
1804
1805 if (section
1806 && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
1807 {
1808 load_addr = msym.minsym->value_raw_address ();
1809 gdb_printf (_("a thread-local variable at offset %s "
1810 "in the thread-local storage for `%s'"),
1811 paddress (gdbarch, load_addr),
1812 objfile_name (section->objfile));
1813 }
1814 else
1815 {
1816 load_addr = msym.value_address ();
1817 gdb_printf (_("static storage at address "));
1818 fputs_styled (paddress (gdbarch, load_addr),
1820 if (section_is_overlay (section))
1821 {
1822 load_addr = overlay_unmapped_address (load_addr, section);
1823 gdb_printf (_(",\n -- loaded at "));
1824 fputs_styled (paddress (gdbarch, load_addr),
1826 gdb_stdout);
1827 gdb_printf (_(" in overlay section %s"),
1828 section->the_bfd_section->name);
1829 }
1830 }
1831 }
1832 }
1833 break;
1834
1835 case LOC_OPTIMIZED_OUT:
1836 gdb_printf (_("optimized out"));
1837 break;
1838
1839 default:
1840 gdb_printf (_("of unknown (botched) type"));
1841 break;
1842 }
1843 gdb_printf (".\n");
1844}
1845
1846
1847static void
1848x_command (const char *exp, int from_tty)
1849{
1850 struct format_data fmt;
1851 struct value *val;
1852
1853 fmt.format = last_format ? last_format : 'x';
1855 fmt.size = last_size;
1856 fmt.count = 1;
1857 fmt.raw = 0;
1858
1859 /* If there is no expression and no format, use the most recent
1860 count. */
1861 if (exp == nullptr && last_count > 0)
1862 fmt.count = last_count;
1863
1864 if (exp && *exp == '/')
1865 {
1866 const char *tmp = exp + 1;
1867
1868 fmt = decode_format (&tmp, last_format, last_size);
1869 exp = (char *) tmp;
1870 }
1871
1872 last_count = fmt.count;
1873
1874 /* If we have an expression, evaluate it and use it as the address. */
1875
1876 if (exp != 0 && *exp != 0)
1877 {
1879 /* Cause expression not to be there any more if this command is
1880 repeated with Newline. But don't clobber a user-defined
1881 command's definition. */
1882 if (from_tty)
1884 val = evaluate_expression (expr.get ());
1885 if (TYPE_IS_REFERENCE (value_type (val)))
1886 val = coerce_ref (val);
1887 /* In rvalue contexts, such as this, functions are coerced into
1888 pointers to functions. This makes "x/i main" work. */
1889 if (value_type (val)->code () == TYPE_CODE_FUNC
1890 && VALUE_LVAL (val) == lval_memory)
1892 else
1894
1895 next_gdbarch = expr->gdbarch;
1896 }
1897
1898 if (!next_gdbarch)
1899 error_no_arg (_("starting display address"));
1900
1902
1903 /* If the examine succeeds, we remember its size and format for next
1904 time. Set last_size to 'b' for strings. */
1905 if (fmt.format == 's')
1906 last_size = 'b';
1907 else
1908 last_size = fmt.size;
1909 last_format = fmt.format;
1910
1911 /* Remember tag-printing setting. */
1913
1914 /* Set a couple of internal variables if appropriate. */
1915 if (last_examine_value != nullptr)
1916 {
1917 /* Make last address examined available to the user as $_. Use
1918 the correct pointer type. */
1919 struct type *pointer_type
1924
1925 /* Make contents of last address examined available to the user
1926 as $__. If the last value has not been fetched from memory
1927 then don't fetch it now; instead mark it by voiding the $__
1928 variable. */
1929 if (value_lazy (last_examine_value.get ()))
1931 else
1933 }
1934}
1935
1936/* Command completion for the 'display' and 'x' commands. */
1937
1938static void
1940 completion_tracker &tracker,
1941 const char *text, const char * /*word*/)
1942{
1943 if (skip_over_slash_fmt (tracker, &text))
1944 return;
1945
1946 const char *word = advance_to_expression_complete_word_point (tracker, text);
1947 expression_completer (ignore, tracker, text, word);
1948}
1949
1950
1951
1952/* Add an expression to the auto-display chain.
1953 Specify the expression. */
1954
1955static void
1956display_command (const char *arg, int from_tty)
1957{
1958 struct format_data fmt;
1959 struct display *newobj;
1960 const char *exp = arg;
1961
1962 if (exp == 0)
1963 {
1964 do_displays ();
1965 return;
1966 }
1967
1968 if (*exp == '/')
1969 {
1970 exp++;
1971 fmt = decode_format (&exp, 0, 0);
1972 if (fmt.size && fmt.format == 0)
1973 fmt.format = 'x';
1974 if (fmt.format == 'i' || fmt.format == 's')
1975 fmt.size = 'b';
1976 }
1977 else
1978 {
1979 fmt.format = 0;
1980 fmt.size = 0;
1981 fmt.count = 0;
1982 fmt.raw = 0;
1983 }
1984
1986 expression_up expr = parse_expression (exp, &tracker);
1987
1988 newobj = new display (exp, std::move (expr), fmt,
1989 current_program_space, tracker.block ());
1990 all_displays.emplace_back (newobj);
1991
1992 if (from_tty)
1993 do_one_display (newobj);
1994
1995 dont_repeat ();
1996}
1997
1998/* Clear out the display_chain. Done when new symtabs are loaded,
1999 since this invalidates the types stored in many expressions. */
2000
2001void
2003{
2004 all_displays.clear ();
2005}
2006
2007/* Delete the auto-display DISPLAY. */
2008
2009static void
2011{
2012 gdb_assert (display != NULL);
2013
2014 auto iter = std::find_if (all_displays.begin (),
2015 all_displays.end (),
2016 [=] (const std::unique_ptr<struct display> &item)
2017 {
2018 return item.get () == display;
2019 });
2020 gdb_assert (iter != all_displays.end ());
2021 all_displays.erase (iter);
2022}
2023
2024/* Call FUNCTION on each of the displays whose numbers are given in
2025 ARGS. DATA is passed unmodified to FUNCTION. */
2026
2027static void
2028map_display_numbers (const char *args,
2029 gdb::function_view<void (struct display *)> function)
2030{
2031 int num;
2032
2033 if (args == NULL)
2034 error_no_arg (_("one or more display numbers"));
2035
2036 number_or_range_parser parser (args);
2037
2038 while (!parser.finished ())
2039 {
2040 const char *p = parser.cur_tok ();
2041
2042 num = parser.get_number ();
2043 if (num == 0)
2044 warning (_("bad display number at or near '%s'"), p);
2045 else
2046 {
2047 auto iter = std::find_if (all_displays.begin (),
2048 all_displays.end (),
2049 [=] (const std::unique_ptr<display> &item)
2050 {
2051 return item->number == num;
2052 });
2053 if (iter == all_displays.end ())
2054 gdb_printf (_("No display number %d.\n"), num);
2055 else
2056 function (iter->get ());
2057 }
2058 }
2059}
2060
2061/* "undisplay" command. */
2062
2063static void
2064undisplay_command (const char *args, int from_tty)
2065{
2066 if (args == NULL)
2067 {
2068 if (query (_("Delete all auto-display expressions? ")))
2069 clear_displays ();
2070 dont_repeat ();
2071 return;
2072 }
2073
2075 dont_repeat ();
2076}
2077
2078/* Display a single auto-display.
2079 Do nothing if the display cannot be printed in the current context,
2080 or if the display is disabled. */
2081
2082static void
2084{
2085 int within_current_scope;
2086
2087 if (!d->enabled_p)
2088 return;
2089
2090 /* The expression carries the architecture that was used at parse time.
2091 This is a problem if the expression depends on architecture features
2092 (e.g. register numbers), and the current architecture is now different.
2093 For example, a display statement like "display/i $pc" is expected to
2094 display the PC register of the current architecture, not the arch at
2095 the time the display command was given. Therefore, we re-parse the
2096 expression if the current architecture has changed. */
2097 if (d->exp != NULL && d->exp->gdbarch != get_current_arch ())
2098 {
2099 d->exp.reset ();
2100 d->block = NULL;
2101 }
2102
2103 if (d->exp == NULL)
2104 {
2105
2106 try
2107 {
2109 d->exp = parse_expression (d->exp_string.c_str (), &tracker);
2110 d->block = tracker.block ();
2111 }
2112 catch (const gdb_exception &ex)
2113 {
2114 /* Can't re-parse the expression. Disable this display item. */
2115 d->enabled_p = false;
2116 warning (_("Unable to display \"%s\": %s"),
2117 d->exp_string.c_str (), ex.what ());
2118 return;
2119 }
2120 }
2121
2122 if (d->block)
2123 {
2124 if (d->pspace == current_program_space)
2125 within_current_scope = contained_in (get_selected_block (0), d->block,
2126 true);
2127 else
2128 within_current_scope = 0;
2129 }
2130 else
2131 within_current_scope = 1;
2132 if (!within_current_scope)
2133 return;
2134
2135 scoped_restore save_display_number
2136 = make_scoped_restore (&current_display_number, d->number);
2137
2139 gdb_printf ("%d", d->number);
2141 gdb_printf (": ");
2142 if (d->format.size)
2143 {
2144
2146
2147 gdb_printf ("x/");
2148 if (d->format.count != 1)
2149 gdb_printf ("%d", d->format.count);
2150 gdb_printf ("%c", d->format.format);
2151 if (d->format.format != 'i' && d->format.format != 's')
2152 gdb_printf ("%c", d->format.size);
2153 gdb_printf (" ");
2154
2156
2157 gdb_puts (d->exp_string.c_str ());
2159
2160 if (d->format.count != 1 || d->format.format == 'i')
2161 gdb_printf ("\n");
2162 else
2163 gdb_printf (" ");
2164
2166
2167 try
2168 {
2169 struct value *val;
2170 CORE_ADDR addr;
2171
2172 val = evaluate_expression (d->exp.get ());
2173 addr = value_as_address (val);
2174 if (d->format.format == 'i')
2175 addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
2176 do_examine (d->format, d->exp->gdbarch, addr);
2177 }
2178 catch (const gdb_exception_error &ex)
2179 {
2180 gdb_printf (_("%p[<error: %s>%p]\n"),
2181 metadata_style.style ().ptr (), ex.what (),
2182 nullptr);
2183 }
2184 }
2185 else
2186 {
2187 struct value_print_options opts;
2188
2190
2191 if (d->format.format)
2192 gdb_printf ("/%c ", d->format.format);
2193
2195
2196 gdb_puts (d->exp_string.c_str ());
2198
2199 gdb_printf (" = ");
2200
2202
2204 opts.raw = d->format.raw;
2205
2206 try
2207 {
2208 struct value *val;
2209
2210 val = evaluate_expression (d->exp.get ());
2211 print_formatted (val, d->format.size, &opts, gdb_stdout);
2212 }
2213 catch (const gdb_exception_error &ex)
2214 {
2216 _("<error: %s>"), ex.what ());
2217 }
2218
2219 gdb_printf ("\n");
2220 }
2221
2223
2225}
2226
2227/* Display all of the values on the auto-display chain which can be
2228 evaluated in the current scope. */
2229
2230void
2232{
2233 for (auto &d : all_displays)
2234 do_one_display (d.get ());
2235}
2236
2237/* Delete the auto-display which we were in the process of displaying.
2238 This is done when there is an error or a signal. */
2239
2240void
2242{
2243 for (auto &d : all_displays)
2244 if (d->number == num)
2245 {
2246 d->enabled_p = false;
2247 return;
2248 }
2249 gdb_printf (_("No display number %d.\n"), num);
2250}
2251
2252void
2254{
2255 if (current_display_number >= 0)
2256 {
2259 _("Disabling display %d to "
2260 "avoid infinite recursion.\n"),
2262 }
2264}
2265
2266static void
2267info_display_command (const char *ignore, int from_tty)
2268{
2269 if (all_displays.empty ())
2270 gdb_printf (_("There are no auto-display expressions now.\n"));
2271 else
2272 gdb_printf (_("Auto-display expressions now in effect:\n\
2273Num Enb Expression\n"));
2274
2275 for (auto &d : all_displays)
2276 {
2277 gdb_printf ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
2278 if (d->format.size)
2279 gdb_printf ("/%d%c%c ", d->format.count, d->format.size,
2280 d->format.format);
2281 else if (d->format.format)
2282 gdb_printf ("/%c ", d->format.format);
2283 gdb_puts (d->exp_string.c_str ());
2284 if (d->block && !contained_in (get_selected_block (0), d->block, true))
2285 gdb_printf (_(" (cannot be evaluated in the current context)"));
2286 gdb_printf ("\n");
2287 }
2288}
2289
2290/* Implementation of both the "disable display" and "enable display"
2291 commands. ENABLE decides what to do. */
2292
2293static void
2294enable_disable_display_command (const char *args, int from_tty, bool enable)
2295{
2296 if (args == NULL)
2297 {
2298 for (auto &d : all_displays)
2299 d->enabled_p = enable;
2300 return;
2301 }
2302
2303 map_display_numbers (args,
2304 [=] (struct display *d)
2305 {
2306 d->enabled_p = enable;
2307 });
2308}
2309
2310/* The "enable display" command. */
2311
2312static void
2313enable_display_command (const char *args, int from_tty)
2314{
2315 enable_disable_display_command (args, from_tty, true);
2316}
2317
2318/* The "disable display" command. */
2319
2320static void
2321disable_display_command (const char *args, int from_tty)
2322{
2323 enable_disable_display_command (args, from_tty, false);
2324}
2325
2326/* display_chain items point to blocks and expressions. Some expressions in
2327 turn may point to symbols.
2328 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
2329 obstack_free'd when a shared library is unloaded.
2330 Clear pointers that are about to become dangling.
2331 Both .exp and .block fields will be restored next time we need to display
2332 an item by re-parsing .exp_string field in the new execution context. */
2333
2334static void
2336{
2337 struct program_space *pspace;
2338
2339 /* With no symbol file we cannot have a block or expression from it. */
2340 if (objfile == NULL)
2341 return;
2342 pspace = objfile->pspace;
2344 {
2346 gdb_assert (objfile->pspace == pspace);
2347 }
2348
2349 for (auto &d : all_displays)
2350 {
2351 if (d->pspace != pspace)
2352 continue;
2353
2354 struct objfile *bl_objf = nullptr;
2355 if (d->block != nullptr)
2356 {
2357 bl_objf = block_objfile (d->block);
2358 if (bl_objf->separate_debug_objfile_backlink != nullptr)
2359 bl_objf = bl_objf->separate_debug_objfile_backlink;
2360 }
2361
2362 if (bl_objf == objfile
2363 || (d->exp != NULL && exp_uses_objfile (d->exp.get (), objfile)))
2364 {
2365 d->exp.reset ();
2366 d->block = NULL;
2367 }
2368 }
2369}
2370
2371
2372/* Print the value in stack frame FRAME of a variable specified by a
2373 struct symbol. NAME is the name to print; if NULL then VAR's print
2374 name will be used. STREAM is the ui_file on which to print the
2375 value. INDENT specifies the number of indent levels to print
2376 before printing the variable name.
2377
2378 This function invalidates FRAME. */
2379
2380void
2381print_variable_and_value (const char *name, struct symbol *var,
2382 frame_info_ptr frame,
2383 struct ui_file *stream, int indent)
2384{
2385
2386 if (!name)
2387 name = var->print_name ();
2388
2389 gdb_printf (stream, "%*s%ps = ", 2 * indent, "",
2391
2392 try
2393 {
2394 struct value *val;
2395 struct value_print_options opts;
2396
2397 /* READ_VAR_VALUE needs a block in order to deal with non-local
2398 references (i.e. to handle nested functions). In this context, we
2399 print variables that are local to this frame, so we can avoid passing
2400 a block to it. */
2401 val = read_var_value (var, NULL, frame);
2402 get_user_print_options (&opts);
2403 opts.deref_ref = 1;
2404 common_val_print_checked (val, stream, indent, &opts, current_language);
2405
2406 /* common_val_print invalidates FRAME when a pretty printer calls inferior
2407 function. */
2408 frame = NULL;
2409 }
2410 catch (const gdb_exception_error &except)
2411 {
2413 "<error reading variable %s (%s)>", name,
2414 except.what ());
2415 }
2416
2417 gdb_printf (stream, "\n");
2418}
2419
2420/* Subroutine of ui_printf to simplify it.
2421 Print VALUE to STREAM using FORMAT.
2422 VALUE is a C-style string either on the target or
2423 in a GDB internal variable. */
2424
2425static void
2426printf_c_string (struct ui_file *stream, const char *format,
2427 struct value *value)
2428{
2429 const gdb_byte *str;
2430
2431 if (value_type (value)->code () != TYPE_CODE_PTR
2434 {
2435 size_t len = value_type (value)->length ();
2436
2437 /* Copy the internal var value to TEM_STR and append a terminating null
2438 character. This protects against corrupted C-style strings that lack
2439 the terminating null char. It also allows Ada-style strings (not
2440 null terminated) to be printed without problems. */
2441 gdb_byte *tem_str = (gdb_byte *) alloca (len + 1);
2442
2443 memcpy (tem_str, value_contents (value).data (), len);
2444 tem_str [len] = 0;
2445 str = tem_str;
2446 }
2447 else
2448 {
2449 CORE_ADDR tem = value_as_address (value);;
2450
2451 if (tem == 0)
2452 {
2453 DIAGNOSTIC_PUSH
2454 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2455 gdb_printf (stream, format, "(null)");
2456 DIAGNOSTIC_POP
2457 return;
2458 }
2459
2460 /* This is a %s argument. Find the length of the string. */
2461 size_t len;
2462
2463 for (len = 0;; len++)
2464 {
2465 gdb_byte c;
2466
2467 QUIT;
2468 read_memory (tem + len, &c, 1);
2469 if (c == 0)
2470 break;
2471 }
2472
2473 /* Copy the string contents into a string inside GDB. */
2474 gdb_byte *tem_str = (gdb_byte *) alloca (len + 1);
2475
2476 if (len != 0)
2477 read_memory (tem, tem_str, len);
2478 tem_str[len] = 0;
2479 str = tem_str;
2480 }
2481
2482 DIAGNOSTIC_PUSH
2483 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2484 gdb_printf (stream, format, (char *) str);
2485 DIAGNOSTIC_POP
2486}
2487
2488/* Subroutine of ui_printf to simplify it.
2489 Print VALUE to STREAM using FORMAT.
2490 VALUE is a wide C-style string on the target or
2491 in a GDB internal variable. */
2492
2493static void
2494printf_wide_c_string (struct ui_file *stream, const char *format,
2495 struct value *value)
2496{
2497 const gdb_byte *str;
2498 size_t len;
2499 struct gdbarch *gdbarch = value_type (value)->arch ();
2500 struct type *wctype = lookup_typename (current_language,
2501 "wchar_t", NULL, 0);
2502 int wcwidth = wctype->length ();
2503
2506 {
2507 str = value_contents (value).data ();
2508 len = value_type (value)->length ();
2509 }
2510 else
2511 {
2512 CORE_ADDR tem = value_as_address (value);
2513
2514 if (tem == 0)
2515 {
2516 DIAGNOSTIC_PUSH
2517 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2518 gdb_printf (stream, format, "(null)");
2519 DIAGNOSTIC_POP
2520 return;
2521 }
2522
2523 /* This is a %s argument. Find the length of the string. */
2524 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2525 gdb_byte *buf = (gdb_byte *) alloca (wcwidth);
2526
2527 for (len = 0;; len += wcwidth)
2528 {
2529 QUIT;
2530 read_memory (tem + len, buf, wcwidth);
2531 if (extract_unsigned_integer (buf, wcwidth, byte_order) == 0)
2532 break;
2533 }
2534
2535 /* Copy the string contents into a string inside GDB. */
2536 gdb_byte *tem_str = (gdb_byte *) alloca (len + wcwidth);
2537
2538 if (len != 0)
2539 read_memory (tem, tem_str, len);
2540 memset (&tem_str[len], 0, wcwidth);
2541 str = tem_str;
2542 }
2543
2544 auto_obstack output;
2545
2547 host_charset (),
2548 str, len, wcwidth,
2549 &output, translit_char);
2550 obstack_grow_str0 (&output, "");
2551
2552 DIAGNOSTIC_PUSH
2553 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2554 gdb_printf (stream, format, obstack_base (&output));
2555 DIAGNOSTIC_POP
2556}
2557
2558/* Subroutine of ui_printf to simplify it.
2559 Print VALUE, a floating point value, to STREAM using FORMAT. */
2560
2561static void
2562printf_floating (struct ui_file *stream, const char *format,
2563 struct value *value, enum argclass argclass)
2564{
2565 /* Parameter data. */
2566 struct type *param_type = value_type (value);
2567 struct gdbarch *gdbarch = param_type->arch ();
2568
2569 /* Determine target type corresponding to the format string. */
2570 struct type *fmt_type;
2571 switch (argclass)
2572 {
2573 case double_arg:
2574 fmt_type = builtin_type (gdbarch)->builtin_double;
2575 break;
2576 case long_double_arg:
2578 break;
2579 case dec32float_arg:
2581 break;
2582 case dec64float_arg:
2584 break;
2585 case dec128float_arg:
2586 fmt_type = builtin_type (gdbarch)->builtin_declong;
2587 break;
2588 default:
2589 gdb_assert_not_reached ("unexpected argument class");
2590 }
2591
2592 /* To match the traditional GDB behavior, the conversion is
2593 done differently depending on the type of the parameter:
2594
2595 - if the parameter has floating-point type, it's value
2596 is converted to the target type;
2597
2598 - otherwise, if the parameter has a type that is of the
2599 same size as a built-in floating-point type, the value
2600 bytes are interpreted as if they were of that type, and
2601 then converted to the target type (this is not done for
2602 decimal floating-point argument classes);
2603
2604 - otherwise, if the source value has an integer value,
2605 it's value is converted to the target type;
2606
2607 - otherwise, an error is raised.
2608
2609 In either case, the result of the conversion is a byte buffer
2610 formatted in the target format for the target type. */
2611
2612 if (fmt_type->code () == TYPE_CODE_FLT)
2613 {
2614 param_type = float_type_from_length (param_type);
2615 if (param_type != value_type (value))
2616 value = value_from_contents (param_type,
2617 value_contents (value).data ());
2618 }
2619
2620 value = value_cast (fmt_type, value);
2621
2622 /* Convert the value to a string and print it. */
2623 std::string str
2624 = target_float_to_string (value_contents (value).data (), fmt_type, format);
2625 gdb_puts (str.c_str (), stream);
2626}
2627
2628/* Subroutine of ui_printf to simplify it.
2629 Print VALUE, a target pointer, to STREAM using FORMAT. */
2630
2631static void
2632printf_pointer (struct ui_file *stream, const char *format,
2633 struct value *value)
2634{
2635 /* We avoid the host's %p because pointers are too
2636 likely to be the wrong size. The only interesting
2637 modifier for %p is a width; extract that, and then
2638 handle %p as glibc would: %#x or a literal "(nil)". */
2639
2640 const char *p;
2641 char *fmt, *fmt_p;
2642#ifdef PRINTF_HAS_LONG_LONG
2643 long long val = value_as_long (value);
2644#else
2645 long val = value_as_long (value);
2646#endif
2647
2648 fmt = (char *) alloca (strlen (format) + 5);
2649
2650 /* Copy up to the leading %. */
2651 p = format;
2652 fmt_p = fmt;
2653 while (*p)
2654 {
2655 int is_percent = (*p == '%');
2656
2657 *fmt_p++ = *p++;
2658 if (is_percent)
2659 {
2660 if (*p == '%')
2661 *fmt_p++ = *p++;
2662 else
2663 break;
2664 }
2665 }
2666
2667 if (val != 0)
2668 *fmt_p++ = '#';
2669
2670 /* Copy any width or flags. Only the "-" flag is valid for pointers
2671 -- see the format_pieces constructor. */
2672 while (*p == '-' || (*p >= '0' && *p < '9'))
2673 *fmt_p++ = *p++;
2674
2675 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2676 if (val != 0)
2677 {
2678#ifdef PRINTF_HAS_LONG_LONG
2679 *fmt_p++ = 'l';
2680#endif
2681 *fmt_p++ = 'l';
2682 *fmt_p++ = 'x';
2683 *fmt_p++ = '\0';
2684 DIAGNOSTIC_PUSH
2685 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2686 gdb_printf (stream, fmt, val);
2687 DIAGNOSTIC_POP
2688 }
2689 else
2690 {
2691 *fmt_p++ = 's';
2692 *fmt_p++ = '\0';
2693 DIAGNOSTIC_PUSH
2694 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2695 gdb_printf (stream, fmt, "(nil)");
2696 DIAGNOSTIC_POP
2697 }
2698}
2699
2700/* printf "printf format string" ARG to STREAM. */
2701
2702static void
2703ui_printf (const char *arg, struct ui_file *stream)
2704{
2705 const char *s = arg;
2706 std::vector<struct value *> val_args;
2707
2708 if (s == 0)
2709 error_no_arg (_("format-control string and values to print"));
2710
2711 s = skip_spaces (s);
2712
2713 /* A format string should follow, enveloped in double quotes. */
2714 if (*s++ != '"')
2715 error (_("Bad format string, missing '\"'."));
2716
2717 format_pieces fpieces (&s);
2718
2719 if (*s++ != '"')
2720 error (_("Bad format string, non-terminated '\"'."));
2721
2722 s = skip_spaces (s);
2723
2724 if (*s != ',' && *s != 0)
2725 error (_("Invalid argument syntax"));
2726
2727 if (*s == ',')
2728 s++;
2729 s = skip_spaces (s);
2730
2731 {
2732 int nargs_wanted;
2733 int i;
2734 const char *current_substring;
2735
2736 nargs_wanted = 0;
2737 for (auto &&piece : fpieces)
2738 if (piece.argclass != literal_piece)
2739 ++nargs_wanted;
2740
2741 /* Now, parse all arguments and evaluate them.
2742 Store the VALUEs in VAL_ARGS. */
2743
2744 while (*s != '\0')
2745 {
2746 const char *s1;
2747
2748 s1 = s;
2749 val_args.push_back (parse_to_comma_and_eval (&s1));
2750
2751 s = s1;
2752 if (*s == ',')
2753 s++;
2754 }
2755
2756 if (val_args.size () != nargs_wanted)
2757 error (_("Wrong number of arguments for specified format-string"));
2758
2759 /* Now actually print them. */
2760 i = 0;
2761 for (auto &&piece : fpieces)
2762 {
2763 current_substring = piece.string;
2764 switch (piece.argclass)
2765 {
2766 case string_arg:
2767 printf_c_string (stream, current_substring, val_args[i]);
2768 break;
2769 case wide_string_arg:
2770 printf_wide_c_string (stream, current_substring, val_args[i]);
2771 break;
2772 case wide_char_arg:
2773 {
2774 struct gdbarch *gdbarch = value_type (val_args[i])->arch ();
2775 struct type *wctype = lookup_typename (current_language,
2776 "wchar_t", NULL, 0);
2777 struct type *valtype;
2778 const gdb_byte *bytes;
2779
2780 valtype = value_type (val_args[i]);
2781 if (valtype->length () != wctype->length ()
2782 || valtype->code () != TYPE_CODE_INT)
2783 error (_("expected wchar_t argument for %%lc"));
2784
2785 bytes = value_contents (val_args[i]).data ();
2786
2787 auto_obstack output;
2788
2790 host_charset (),
2791 bytes, valtype->length (),
2792 valtype->length (),
2793 &output, translit_char);
2794 obstack_grow_str0 (&output, "");
2795
2796 DIAGNOSTIC_PUSH
2797 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2798 gdb_printf (stream, current_substring,
2799 obstack_base (&output));
2800 DIAGNOSTIC_POP
2801 }
2802 break;
2803 case long_long_arg:
2804#ifdef PRINTF_HAS_LONG_LONG
2805 {
2806 long long val = value_as_long (val_args[i]);
2807
2808 DIAGNOSTIC_PUSH
2809 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2810 gdb_printf (stream, current_substring, val);
2811 DIAGNOSTIC_POP
2812 break;
2813 }
2814#else
2815 error (_("long long not supported in printf"));
2816#endif
2817 case int_arg:
2818 {
2819 int val = value_as_long (val_args[i]);
2820
2821 DIAGNOSTIC_PUSH
2822 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2823 gdb_printf (stream, current_substring, val);
2824 DIAGNOSTIC_POP
2825 break;
2826 }
2827 case long_arg:
2828 {
2829 long val = value_as_long (val_args[i]);
2830
2831 DIAGNOSTIC_PUSH
2832 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2833 gdb_printf (stream, current_substring, val);
2834 DIAGNOSTIC_POP
2835 break;
2836 }
2837 case size_t_arg:
2838 {
2839 size_t val = value_as_long (val_args[i]);
2840
2841 DIAGNOSTIC_PUSH
2842 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2843 gdb_printf (stream, current_substring, val);
2844 DIAGNOSTIC_POP
2845 break;
2846 }
2847 /* Handles floating-point values. */
2848 case double_arg:
2849 case long_double_arg:
2850 case dec32float_arg:
2851 case dec64float_arg:
2852 case dec128float_arg:
2853 printf_floating (stream, current_substring, val_args[i],
2854 piece.argclass);
2855 break;
2856 case ptr_arg:
2857 printf_pointer (stream, current_substring, val_args[i]);
2858 break;
2859 case literal_piece:
2860 /* Print a portion of the format string that has no
2861 directives. Note that this will not include any
2862 ordinary %-specs, but it might include "%%". That is
2863 why we use gdb_printf and not gdb_puts here.
2864 Also, we pass a dummy argument because some platforms
2865 have modified GCC to include -Wformat-security by
2866 default, which will warn here if there is no
2867 argument. */
2868 DIAGNOSTIC_PUSH
2869 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2870 gdb_printf (stream, current_substring, 0);
2871 DIAGNOSTIC_POP
2872 break;
2873 default:
2874 internal_error (_("failed internal consistency check"));
2875 }
2876 /* Maybe advance to the next argument. */
2877 if (piece.argclass != literal_piece)
2878 ++i;
2879 }
2880 }
2881}
2882
2883/* Implement the "printf" command. */
2884
2885static void
2886printf_command (const char *arg, int from_tty)
2887{
2888 ui_printf (arg, gdb_stdout);
2889 gdb_stdout->reset_style ();
2890 gdb_stdout->wrap_here (0);
2891 gdb_stdout->flush ();
2892}
2893
2894/* Implement the "eval" command. */
2895
2896static void
2897eval_command (const char *arg, int from_tty)
2898{
2899 string_file stb;
2900
2901 ui_printf (arg, &stb);
2902
2903 std::string expanded = insert_user_defined_cmd_args (stb.c_str ());
2904
2905 execute_command (expanded.c_str (), from_tty);
2906}
2907
2908/* Convenience function for error checking in memory-tag commands. */
2909
2910static void
2911show_addr_not_tagged (CORE_ADDR address)
2912{
2913 error (_("Address %s not in a region mapped with a memory tagging flag."),
2914 paddress (target_gdbarch (), address));
2915}
2916
2917/* Convenience function for error checking in memory-tag commands. */
2918
2919static void
2921{
2922 error (_("Memory tagging not supported or disabled by the current"
2923 " architecture."));
2924}
2925
2926/* Implement the "memory-tag" prefix command. */
2927
2928static void
2929memory_tag_command (const char *arg, int from_tty)
2930{
2932}
2933
2934/* Helper for print-logical-tag and print-allocation-tag. */
2935
2936static void
2937memory_tag_print_tag_command (const char *args, enum memtag_type tag_type)
2938{
2939 if (args == nullptr)
2940 error_no_arg (_("address or pointer"));
2941
2942 /* Parse args into a value. If the value is a pointer or an address,
2943 then fetch the logical or allocation tag. */
2944 value_print_options print_opts;
2945
2946 struct value *val = process_print_command_args (args, &print_opts, true);
2947
2948 /* If the address is not in a region memory mapped with a memory tagging
2949 flag, it is no use trying to access/manipulate its allocation tag.
2950
2951 It is OK to manipulate the logical tag though. */
2952 if (tag_type == memtag_type::allocation
2955
2956 struct value *tag_value
2957 = gdbarch_get_memtag (target_gdbarch (), val, tag_type);
2958 std::string tag = gdbarch_memtag_to_string (target_gdbarch (), tag_value);
2959
2960 if (tag.empty ())
2961 gdb_printf (_("%s tag unavailable.\n"),
2962 tag_type
2963 == memtag_type::logical? "Logical" : "Allocation");
2964
2965 struct value *v_tag = process_print_command_args (tag.c_str (),
2966 &print_opts,
2967 true);
2968 print_opts.output_format = 'x';
2969 print_value (v_tag, print_opts);
2970}
2971
2972/* Implement the "memory-tag print-logical-tag" command. */
2973
2974static void
2975memory_tag_print_logical_tag_command (const char *args, int from_tty)
2976{
2979
2981}
2982
2983/* Implement the "memory-tag print-allocation-tag" command. */
2984
2985static void
2986memory_tag_print_allocation_tag_command (const char *args, int from_tty)
2987{
2990
2992}
2993
2994/* Parse ARGS and extract ADDR and TAG.
2995 ARGS should have format <expression> <tag bytes>. */
2996
2997static void
2998parse_with_logical_tag_input (const char *args, struct value **val,
2999 gdb::byte_vector &tags,
3000 value_print_options *print_opts)
3001{
3002 /* Fetch the address. */
3003 std::string address_string = extract_string_maybe_quoted (&args);
3004
3005 /* Parse the address into a value. */
3006 *val = process_print_command_args (address_string.c_str (), print_opts,
3007 true);
3008
3009 /* Fetch the tag bytes. */
3010 std::string tag_string = extract_string_maybe_quoted (&args);
3011
3012 /* Validate the input. */
3013 if (address_string.empty () || tag_string.empty ())
3014 error (_("Missing arguments."));
3015
3016 if (tag_string.length () != 2)
3017 error (_("Error parsing tags argument. The tag should be 2 digits."));
3018
3019 tags = hex2bin (tag_string.c_str ());
3020}
3021
3022/* Implement the "memory-tag with-logical-tag" command. */
3023
3024static void
3025memory_tag_with_logical_tag_command (const char *args, int from_tty)
3026{
3029
3030 if (args == nullptr)
3031 error_no_arg (_("<address> <tag>"));
3032
3033 gdb::byte_vector tags;
3034 struct value *val;
3035 value_print_options print_opts;
3036
3037 /* Parse the input. */
3038 parse_with_logical_tag_input (args, &val, tags, &print_opts);
3039
3040 /* Setting the logical tag is just a local operation that does not touch
3041 any memory from the target. Given an input value, we modify the value
3042 to include the appropriate tag.
3043
3044 For this reason we need to cast the argument value to a
3045 (void *) pointer. This is so we have the right type for the gdbarch
3046 hook to manipulate the value and insert the tag.
3047
3048 Otherwise, this would fail if, for example, GDB parsed the argument value
3049 into an int-sized value and the pointer value has a type of greater
3050 length. */
3051
3052 /* Cast to (void *). */
3053 val = value_cast (builtin_type (target_gdbarch ())->builtin_data_ptr,
3054 val);
3055
3056 /* Length doesn't matter for a logical tag. Pass 0. */
3057 if (!gdbarch_set_memtags (target_gdbarch (), val, 0, tags,
3059 gdb_printf (_("Could not update the logical tag data.\n"));
3060 else
3061 {
3062 /* Always print it in hex format. */
3063 print_opts.output_format = 'x';
3064 print_value (val, print_opts);
3065 }
3066}
3067
3068/* Parse ARGS and extract ADDR, LENGTH and TAGS. */
3069
3070static void
3071parse_set_allocation_tag_input (const char *args, struct value **val,
3072 size_t *length, gdb::byte_vector &tags)
3073{
3074 /* Fetch the address. */
3075 std::string address_string = extract_string_maybe_quoted (&args);
3076
3077 /* Parse the address into a value. */
3078 value_print_options print_opts;
3079 *val = process_print_command_args (address_string.c_str (), &print_opts,
3080 true);
3081
3082 /* Fetch the length. */
3083 std::string length_string = extract_string_maybe_quoted (&args);
3084
3085 /* Fetch the tag bytes. */
3086 std::string tags_string = extract_string_maybe_quoted (&args);
3087
3088 /* Validate the input. */
3089 if (address_string.empty () || length_string.empty () || tags_string.empty ())
3090 error (_("Missing arguments."));
3091
3092 errno = 0;
3093 const char *trailer = nullptr;
3094 LONGEST parsed_length = strtoulst (length_string.c_str (), &trailer, 10);
3095
3096 if (errno != 0 || (trailer != nullptr && trailer[0] != '\0'))
3097 error (_("Error parsing length argument."));
3098
3099 if (parsed_length <= 0)
3100 error (_("Invalid zero or negative length."));
3101
3102 *length = parsed_length;
3103
3104 if (tags_string.length () % 2)
3105 error (_("Error parsing tags argument. Tags should be 2 digits per byte."));
3106
3107 tags = hex2bin (tags_string.c_str ());
3108
3109 /* If the address is not in a region memory mapped with a memory tagging
3110 flag, it is no use trying to access/manipulate its allocation tag. */
3113}
3114
3115/* Implement the "memory-tag set-allocation-tag" command.
3116 ARGS should be in the format <address> <length> <tags>. */
3117
3118static void
3119memory_tag_set_allocation_tag_command (const char *args, int from_tty)
3120{
3123
3124 if (args == nullptr)
3125 error_no_arg (_("<starting address> <length> <tag bytes>"));
3126
3127 gdb::byte_vector tags;
3128 size_t length = 0;
3129 struct value *val;
3130
3131 /* Parse the input. */
3132 parse_set_allocation_tag_input (args, &val, &length, tags);
3133
3134 if (!gdbarch_set_memtags (target_gdbarch (), val, length, tags,
3136 gdb_printf (_("Could not update the allocation tag(s).\n"));
3137 else
3138 gdb_printf (_("Allocation tag(s) updated successfully.\n"));
3139}
3140
3141/* Implement the "memory-tag check" command. */
3142
3143static void
3144memory_tag_check_command (const char *args, int from_tty)
3145{
3148
3149 if (args == nullptr)
3150 error (_("Argument required (address or pointer)"));
3151
3152 /* Parse the expression into a value. If the value is an address or
3153 pointer, then check its logical tag against the allocation tag. */
3154 value_print_options print_opts;
3155
3156 struct value *val = process_print_command_args (args, &print_opts, true);
3157
3158 /* If the address is not in a region memory mapped with a memory tagging
3159 flag, it is no use trying to access/manipulate its allocation tag. */
3162
3163 CORE_ADDR addr = value_as_address (val);
3164
3165 /* Check if the tag is valid. */
3167 {
3168 struct value *tag
3170 std::string ltag
3172
3173 tag = gdbarch_get_memtag (target_gdbarch (), val,
3175 std::string atag
3177
3178 gdb_printf (_("Logical tag (%s) does not match"
3179 " the allocation tag (%s) for address %s.\n"),
3180 ltag.c_str (), atag.c_str (),
3181 paddress (target_gdbarch (), addr));
3182 }
3183 else
3184 {
3185 struct value *tag
3187 std::string ltag
3189
3190 gdb_printf (_("Memory tags for address %s match (%s).\n"),
3191 paddress (target_gdbarch (), addr), ltag.c_str ());
3192 }
3193}
3194
3195void _initialize_printcmd ();
3196void
3198{
3199 struct cmd_list_element *c;
3200
3202
3204 "printcmd");
3205
3206 add_info ("address", info_address_command,
3207 _("Describe where symbol SYM is stored.\n\
3208Usage: info address SYM"));
3209
3210 add_info ("symbol", info_symbol_command, _("\
3211Describe what symbol is at location ADDR.\n\
3212Usage: info symbol ADDR\n\
3213Only for symbols with fixed locations (global or static scope)."));
3214
3215 c = add_com ("x", class_vars, x_command, _("\
3216Examine memory: x/FMT ADDRESS.\n\
3217ADDRESS is an expression for the memory address to examine.\n\
3218FMT is a repeat count followed by a format letter and a size letter.\n\
3219Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
3220 t(binary), f(float), a(address), i(instruction), c(char), s(string)\n\
3221 and z(hex, zero padded on the left).\n\
3222Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
3223The specified number of objects of the specified size are printed\n\
3224according to the format. If a negative number is specified, memory is\n\
3225examined backward from the address.\n\n\
3226Defaults for format and size letters are those previously used.\n\
3227Default count is 1. Default address is following last thing printed\n\
3228with this command or \"print\"."));
3230
3231 add_info ("display", info_display_command, _("\
3232Expressions to display when program stops, with code numbers.\n\
3233Usage: info display"));
3234
3235 add_cmd ("undisplay", class_vars, undisplay_command, _("\
3236Cancel some expressions to be displayed when program stops.\n\
3237Usage: undisplay [NUM]...\n\
3238Arguments are the code numbers of the expressions to stop displaying.\n\
3239No argument means cancel all automatic-display expressions.\n\
3240\"delete display\" has the same effect as this command.\n\
3241Do \"info display\" to see current list of code numbers."),
3242 &cmdlist);
3243
3244 c = add_com ("display", class_vars, display_command, _("\
3245Print value of expression EXP each time the program stops.\n\
3246Usage: display[/FMT] EXP\n\
3247/FMT may be used before EXP as in the \"print\" command.\n\
3248/FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
3249as in the \"x\" command, and then EXP is used to get the address to examine\n\
3250and examining is done as in the \"x\" command.\n\n\
3251With no argument, display all currently requested auto-display expressions.\n\
3252Use \"undisplay\" to cancel display requests previously made."));
3254
3255 add_cmd ("display", class_vars, enable_display_command, _("\
3256Enable some expressions to be displayed when program stops.\n\
3257Usage: enable display [NUM]...\n\
3258Arguments are the code numbers of the expressions to resume displaying.\n\
3259No argument means enable all automatic-display expressions.\n\
3260Do \"info display\" to see current list of code numbers."), &enablelist);
3261
3262 add_cmd ("display", class_vars, disable_display_command, _("\
3263Disable some expressions to be displayed when program stops.\n\
3264Usage: disable display [NUM]...\n\
3265Arguments are the code numbers of the expressions to stop displaying.\n\
3266No argument means disable all automatic-display expressions.\n\
3267Do \"info display\" to see current list of code numbers."), &disablelist);
3268
3269 add_cmd ("display", class_vars, undisplay_command, _("\
3270Cancel some expressions to be displayed when program stops.\n\
3271Usage: delete display [NUM]...\n\
3272Arguments are the code numbers of the expressions to stop displaying.\n\
3273No argument means cancel all automatic-display expressions.\n\
3274Do \"info display\" to see current list of code numbers."), &deletelist);
3275
3276 add_com ("printf", class_vars, printf_command, _("\
3277Formatted printing, like the C \"printf\" function.\n\
3278Usage: printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
3279This supports most C printf format specifications, like %s, %d, etc."));
3280
3281 add_com ("output", class_vars, output_command, _("\
3282Like \"print\" but don't put in value history and don't print newline.\n\
3283Usage: output EXP\n\
3284This is useful in user-defined commands."));
3285
3287Evaluate expression EXP and assign result to variable VAR.\n\
3288Usage: set VAR = EXP\n\
3289This uses assignment syntax appropriate for the current language\n\
3290(VAR = EXP or VAR := EXP for example).\n\
3291VAR may be a debugger \"convenience\" variable (names starting\n\
3292with $), a register (a few standard names starting with $), or an actual\n\
3293variable in the program being debugged. EXP is any valid expression.\n\
3294Use \"set variable\" for variables with names identical to set subcommands.\n\
3295\n\
3296With a subcommand, this command modifies parts of the gdb environment.\n\
3297You can see these environment settings with the \"show\" command."),
3298 &setlist, 1, &cmdlist);
3299
3300 /* "call" is the same as "set", but handy for dbx users to call fns. */
3301 c = add_com ("call", class_vars, call_command, _("\
3302Call a function in the program.\n\
3303Usage: call EXP\n\
3304The argument is the function name and arguments, in the notation of the\n\
3305current working language. The result is printed and saved in the value\n\
3306history, if it is not void."));
3308
3309 cmd_list_element *set_variable_cmd
3310 = add_cmd ("variable", class_vars, set_command, _("\
3311Evaluate expression EXP and assign result to variable VAR.\n\
3312Usage: set variable VAR = EXP\n\
3313This uses assignment syntax appropriate for the current language\n\
3314(VAR = EXP or VAR := EXP for example).\n\
3315VAR may be a debugger \"convenience\" variable (names starting\n\
3316with $), a register (a few standard names starting with $), or an actual\n\
3317variable in the program being debugged. EXP is any valid expression.\n\
3318This may usually be abbreviated to simply \"set\"."),
3319 &setlist);
3320 add_alias_cmd ("var", set_variable_cmd, class_vars, 0, &setlist);
3321
3322 const auto print_opts = make_value_print_options_def_group (nullptr);
3323
3324 static const std::string print_help = gdb::option::build_help (_("\
3325Print value of expression EXP.\n\
3326Usage: print [[OPTION]... --] [/FMT] [EXP]\n\
3327\n\
3328Options:\n\
3329%OPTIONS%\n\
3330\n\
3331Note: because this command accepts arbitrary expressions, if you\n\
3332specify any command option, you must use a double dash (\"--\")\n\
3333to mark the end of option processing. E.g.: \"print -o -- myobj\".\n\
3334\n\
3335Variables accessible are those of the lexical environment of the selected\n\
3336stack frame, plus all those whose scope is global or an entire file.\n\
3337\n\
3338$NUM gets previous value number NUM. $ and $$ are the last two values.\n\
3339$$NUM refers to NUM'th value back from the last one.\n\
3340Names starting with $ refer to registers (with the values they would have\n\
3341if the program were to return to the stack frame now selected, restoring\n\
3342all registers saved by frames farther in) or else to debugger\n\
3343\"convenience\" variables (any such name not a known register).\n\
3344Use assignment expressions to give values to convenience variables.\n\
3345\n\
3346{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
3347@ is a binary operator for treating consecutive data objects\n\
3348anywhere in memory as an array. FOO@NUM gives an array whose first\n\
3349element is FOO, whose second element is stored in the space following\n\
3350where FOO is stored, etc. FOO must be an expression whose value\n\
3351resides in memory.\n\
3352\n\
3353EXP may be preceded with /FMT, where FMT is a format letter\n\
3354but no count or size letter (see \"x\" command)."),
3355 print_opts);
3356
3357 cmd_list_element *print_cmd
3358 = add_com ("print", class_vars, print_command, print_help.c_str ());
3360 add_com_alias ("p", print_cmd, class_vars, 1);
3361 add_com_alias ("inspect", print_cmd, class_vars, 1);
3362
3363 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
3364 &max_symbolic_offset, _("\
3365Set the largest offset that will be printed in <SYMBOL+1234> form."), _("\
3366Show the largest offset that will be printed in <SYMBOL+1234> form."), _("\
3367Tell GDB to only display the symbolic form of an address if the\n\
3368offset between the closest earlier symbol and the address is less than\n\
3369the specified maximum offset. The default is \"unlimited\", which tells GDB\n\
3370to always print the symbolic form of an address if any symbol precedes\n\
3371it. Zero is equivalent to \"unlimited\"."),
3372 NULL,
3375 add_setshow_boolean_cmd ("symbol-filename", no_class,
3377Set printing of source filename and line number with <SYMBOL>."), _("\
3378Show printing of source filename and line number with <SYMBOL>."), NULL,
3379 NULL,
3382
3383 add_com ("eval", no_class, eval_command, _("\
3384Construct a GDB command and then evaluate it.\n\
3385Usage: eval \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
3386Convert the arguments to a string as \"printf\" would, but then\n\
3387treat this string as a command line, and evaluate it."));
3388
3389 /* Memory tagging commands. */
3390 add_prefix_cmd ("memory-tag", class_vars, memory_tag_command, _("\
3391Generic command for printing and manipulating memory tag properties."),
3392 &memory_tag_list, 0, &cmdlist);
3393 add_cmd ("print-logical-tag", class_vars,
3395 ("Print the logical tag from POINTER.\n\
3396Usage: memory-tag print-logical-tag <POINTER>.\n\
3397<POINTER> is an expression that evaluates to a pointer.\n\
3398Print the logical tag contained in POINTER. The tag interpretation is\n\
3399architecture-specific."),
3401 add_cmd ("print-allocation-tag", class_vars,
3403 _("Print the allocation tag for ADDRESS.\n\
3404Usage: memory-tag print-allocation-tag <ADDRESS>.\n\
3405<ADDRESS> is an expression that evaluates to a memory address.\n\
3406Print the allocation tag associated with the memory address ADDRESS.\n\
3407The tag interpretation is architecture-specific."),
3410 _("Print a POINTER with a specific logical TAG.\n\
3411Usage: memory-tag with-logical-tag <POINTER> <TAG>\n\
3412<POINTER> is an expression that evaluates to a pointer.\n\
3413<TAG> is a sequence of hex bytes that is interpreted by the architecture\n\
3414as a single memory tag."),
3416 add_cmd ("set-allocation-tag", class_vars,
3418 _("Set the allocation tag(s) for a memory range.\n\
3419Usage: memory-tag set-allocation-tag <ADDRESS> <LENGTH> <TAG_BYTES>\n\
3420<ADDRESS> is an expression that evaluates to a memory address\n\
3421<LENGTH> is the number of bytes that is added to <ADDRESS> to calculate\n\
3422the memory range.\n\
3423<TAG_BYTES> is a sequence of hex bytes that is interpreted by the\n\
3424architecture as one or more memory tags.\n\
3425Sets the tags of the memory range [ADDRESS, ADDRESS + LENGTH)\n\
3426to TAG_BYTES.\n\
3427\n\
3428If the number of tags is greater than or equal to the number of tag granules\n\
3429in the [ADDRESS, ADDRESS + LENGTH) range, only the tags up to the\n\
3430number of tag granules are updated.\n\
3431\n\
3432If the number of tags is less than the number of tag granules, then the\n\
3433command is a fill operation. The TAG_BYTES are interpreted as a pattern\n\
3434that gets repeated until the number of tag granules in the memory range\n\
3435[ADDRESS, ADDRESS + LENGTH) is updated."),
3438 _("Validate a pointer's logical tag against the allocation tag.\n\
3439Usage: memory-tag check <POINTER>\n\
3440<POINTER> is an expression that evaluates to a pointer\n\
3441Fetch the logical and allocation tags for POINTER and compare them\n\
3442for equality. If the tags do not match, print additional information about\n\
3443the tag mismatch."),
3445}
const char *const name
int code
Definition ada-lex.l:688
void annotate_display_number_end(void)
Definition annotate.c:350
void annotate_display_expression(void)
Definition annotate.c:364
void annotate_value_end(void)
Definition annotate.c:336
void annotate_value_history_begin(int histindex, struct type *type)
Definition annotate.c:300
void annotate_display_end(void)
Definition annotate.c:385
void annotate_display_value(void)
Definition annotate.c:378
void annotate_display_begin(void)
Definition annotate.c:343
void annotate_display_format(void)
Definition annotate.c:357
void annotate_value_history_end(void)
Definition annotate.c:329
void annotate_display_expression_end(void)
Definition annotate.c:371
void annotate_value_history_value(void)
Definition annotate.c:322
void annotate_value_begin(struct type *type)
Definition annotate.c:311
struct gdbarch * get_current_arch(void)
Definition arch-utils.c:846
struct gdbarch * target_gdbarch(void)
constexpr std::string_view s1
Definition 2.cc:26
struct objfile * block_objfile(const struct block *block)
Definition block.c:46
bool contained_in(const struct block *a, const struct block *b, bool allow_nested)
Definition block.c:71
struct symbol * find_pc_sect_function(CORE_ADDR pc, struct obj_section *section)
Definition blockframe.c:136
bool c_is_string_type_p(struct type *type)
Definition c-lang.c:695
const char * target_wide_charset(struct gdbarch *gdbarch)
Definition charset.c:432
const char * host_charset(void)
Definition charset.c:416
void convert_between_encodings(const char *from, const char *to, const gdb_byte *bytes, unsigned int num_bytes, int width, struct obstack *output, enum transliterations translit)
Definition charset.c:497
@ translit_char
Definition charset.h:48
ui_file_style style() const
Definition cli-style.c:169
void add_completion(gdb::unique_xmalloc_ptr< char > name, completion_match_for_lcd *match_for_lcd=NULL, const char *text=NULL, const char *word=NULL)
Definition completer.c:1579
void advance_custom_word_point_by(int len)
Definition completer.c:2049
void set_use_custom_word_point(bool enable)
Definition completer.h:349
const struct block * block() const
bool finished() const
Definition cli-utils.c:327
const char * cur_tok() const
Definition cli-utils.h:106
const char * c_str() const
Definition ui-file.h:218
virtual void wrap_here(int indent)
Definition ui-file.h:117
struct cmd_list_element * showprintlist
Definition cli-cmds.c:161
struct cmd_list_element * deletelist
Definition cli-cmds.c:105
void error_no_arg(const char *why)
Definition cli-cmds.c:204
struct cmd_list_element * cmdlist
Definition cli-cmds.c:85
struct cmd_list_element * setprintlist
Definition cli-cmds.c:159
struct cmd_list_element * setlist
Definition cli-cmds.c:117
struct cmd_list_element * disablelist
Definition cli-cmds.c:97
struct cmd_list_element * enablelist
Definition cli-cmds.c:93
set_show_commands add_setshow_uinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
Definition cli-decode.c:294
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition cli-decode.c:233
void set_cmd_completer_handle_brkchars(struct cmd_list_element *cmd, completer_handle_brkchars_ftype *func)
Definition cli-decode.c:125
cmd_list_element * add_com_alias(const char *name, cmd_list_element *target, command_class theclass, int abbrev_flag)
void help_list(struct cmd_list_element *list, const char *cmdtype, enum command_class theclass, struct ui_file *stream)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
Definition cli-decode.c:357
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:739
struct cmd_list_element * add_info(const char *name, cmd_simple_func_ftype *fun, const char *doc)
std::string insert_user_defined_cmd_args(const char *line)
Definition cli-script.c:838
cli_style_option address_style
cli_style_option function_name_style
cli_style_option variable_name_style
cli_style_option file_name_style
cli_style_option metadata_style
void dont_repeat()
Definition top.c:809
@ all_commands
Definition command.h:50
@ class_vars
Definition command.h:55
@ no_class
Definition command.h:53
void set_repeat_arguments(const char *args)
Definition top.c:565
void expression_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
Definition completer.c:1092
const char * advance_to_expression_complete_word_point(completion_tracker &tracker, const char *text)
Definition completer.c:422
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition corefile.c:237
static void store_signed_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, LONGEST val)
Definition defs.h:554
@ language_objc
Definition defs.h:215
@ lval_memory
Definition defs.h:364
@ lval_internalvar
Definition defs.h:368
#define UINT_MAX
Definition defs.h:453
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:526
#define QUIT
Definition defs.h:186
int gdb_print_insn(struct gdbarch *gdbarch, CORE_ADDR memaddr, struct ui_file *stream, int *branch_delay_insns)
Definition disasm.c:1202
int gdb_insn_length(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition disasm.c:1215
struct value * parse_to_comma_and_eval(const char **expp)
Definition eval.c:82
struct value * evaluate_expression(struct expression *exp, struct type *expect_type)
Definition eval.c:113
CORE_ADDR parse_and_eval_address(const char *exp)
Definition eval.c:52
std::unique_ptr< expression > expression_up
Definition expression.h:229
expression_up parse_expression(const char *, innermost_block_tracker *=nullptr, bool void_context_p=false)
Definition parse.c:546
struct value * read_var_value(struct symbol *var, const struct block *var_block, frame_info_ptr frame)
Definition findvar.c:787
bool get_frame_pc_if_available(frame_info_ptr frame, CORE_ADDR *pc)
Definition frame.c:2599
bool has_stack_frames()
Definition frame.c:1784
frame_info_ptr get_selected_frame(const char *message)
Definition frame.c:1813
const struct block * get_selected_block(CORE_ADDR *addr_in_block)
Definition stack.c:2602
bool asm_demangle
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1370
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
Definition gdbarch.c:2142
std::string gdbarch_memtag_to_string(struct gdbarch *gdbarch, struct value *tag)
Definition gdbarch.c:3121
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1708
bool gdbarch_set_memtags(struct gdbarch *gdbarch, struct value *address, size_t length, const gdb::byte_vector &tags, memtag_type tag_type)
Definition gdbarch.c:3172
struct value * gdbarch_get_memtag(struct gdbarch *gdbarch, struct value *address, memtag_type tag_type)
Definition gdbarch.c:3189
bool gdbarch_tagged_address_p(struct gdbarch *gdbarch, struct value *address)
Definition gdbarch.c:3138
bool gdbarch_memtag_matches_p(struct gdbarch *gdbarch, struct value *address)
Definition gdbarch.c:3155
CORE_ADDR gdbarch_memtag_granule_size(struct gdbarch *gdbarch)
Definition gdbarch.c:3206
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition gdbarch.c:3087
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1691
memtag_type
Definition gdbarch.h:128
void execute_command(const char *, int)
Definition top.c:574
enum bfd_endian type_byte_order(const struct type *type)
Definition gdbtypes.c:4018
struct type * lookup_pointer_type(struct type *type)
Definition gdbtypes.c:402
struct type * lookup_typename(const struct language_defn *language, const char *name, const struct block *block, int noerr)
Definition gdbtypes.c:1702
bool is_fixed_point_type(struct type *type)
Definition gdbtypes.c:6116
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:3010
#define TYPE_IS_REFERENCE(t)
Definition gdbtypes.h:156
type_code
Definition gdbtypes.h:99
size_t size
Definition go32-nat.c:241
const struct language_defn * current_language
Definition language.c:83
bound_minimal_symbol lookup_minimal_symbol_by_pc_section(CORE_ADDR pc_in, struct obj_section *section, lookup_msym_prefer prefer, bound_minimal_symbol *previous)
Definition minsyms.c:725
struct bound_minimal_symbol lookup_bound_minimal_symbol(const char *name)
Definition minsyms.c:481
Definition ada-exp.h:80
observable< struct objfile * > free_objfile
bool process_options(const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:616
@ PROCESS_OPTIONS_REQUIRE_DELIMITER
Definition cli-option.h:302
std::string build_help(const char *help_tmpl, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:743
bool complete_options(completion_tracker &tracker, const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:457
Definition aarch64.h:50
const char * objfile_name(const struct objfile *objfile)
Definition objfiles.c:1308
#define ALL_OBJFILE_OSECTIONS(objfile, osect)
Definition objfiles.h:130
bool exp_uses_objfile(struct expression *exp, struct objfile *objfile)
Definition parse.c:675
void print_scalar_formatted(const gdb_byte *valaddr, struct type *type, const struct value_print_options *options, int size, struct ui_file *stream)
Definition printcmd.c:367
static CORE_ADDR last_examine_address
Definition printcmd.c:90
int build_address_symbolic(struct gdbarch *gdbarch, CORE_ADDR addr, bool do_demangle, bool prefer_sym_over_minsym, std::string *name, int *offset, std::string *filename, int *line, int *unmapped)
Definition printcmd.c:594
static char last_size
Definition printcmd.c:69
static void undisplay_command(const char *args, int from_tty)
Definition printcmd.c:2064
static int last_count
Definition printcmd.c:73
static bool print_symbol_filename
Definition printcmd.c:113
void set_next_address(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition printcmd.c:530
static void parse_with_logical_tag_input(const char *args, struct value **val, gdb::byte_vector &tags, value_print_options *print_opts)
Definition printcmd.c:2998
static void enable_display_command(const char *args, int from_tty)
Definition printcmd.c:2313
static void printf_floating(struct ui_file *stream, const char *format, struct value *value, enum argclass argclass)
Definition printcmd.c:2562
static void eval_command(const char *arg, int from_tty)
Definition printcmd.c:2897
static value_ref_ptr last_examine_value
Definition printcmd.c:95
static void disable_display_command(const char *args, int from_tty)
Definition printcmd.c:2321
static void do_one_display(struct display *)
Definition printcmd.c:2083
static void printf_pointer(struct ui_file *stream, const char *format, struct value *value)
Definition printcmd.c:2632
void _initialize_printcmd()
Definition printcmd.c:3197
int print_address_symbolic(struct gdbarch *gdbarch, CORE_ADDR addr, struct ui_file *stream, int do_demangle, const char *leadin)
Definition printcmd.c:552
static void memory_tag_print_logical_tag_command(const char *args, int from_tty)
Definition printcmd.c:2975
static void info_display_command(const char *ignore, int from_tty)
Definition printcmd.c:2267
static void printf_c_string(struct ui_file *stream, const char *format, struct value *value)
Definition printcmd.c:2426
static void ui_printf(const char *arg, struct ui_file *stream)
Definition printcmd.c:2703
static void info_address_command(const char *exp, int from_tty)
Definition printcmd.c:1613
static bool last_print_tags
Definition printcmd.c:77
static void display_command(const char *arg, int from_tty)
Definition printcmd.c:1956
static void memory_tag_command(const char *arg, int from_tty)
Definition printcmd.c:2929
static struct type * float_type_from_length(struct type *type)
Definition printcmd.c:347
void disable_display(int num)
Definition printcmd.c:2241
static void show_print_symbol_filename(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition printcmd.c:115
static int branch_delay_insns
Definition printcmd.c:86
static struct cmd_list_element * memory_tag_list
Definition printcmd.c:61
static struct format_data decode_format(const char **string_ptr, int oformat, int osize)
Definition printcmd.c:191
static int integer_is_zero(const gdb_byte *x, int len)
Definition printcmd.c:920
static void set_command(const char *exp, int from_tty)
Definition printcmd.c:1499
static void printf_wide_c_string(struct ui_file *stream, const char *format, struct value *value)
Definition printcmd.c:2494
static void enable_disable_display_command(const char *args, int from_tty, bool enable)
Definition printcmd.c:2294
static void printf_command(const char *arg, int from_tty)
Definition printcmd.c:2886
static bool should_validate_memtags(struct value *value)
Definition printcmd.c:1261
static CORE_ADDR find_instruction_backward(struct gdbarch *gdbarch, CORE_ADDR addr, int inst_count, int *inst_read)
Definition printcmd.c:794
static void memory_tag_set_allocation_tag_command(const char *args, int from_tty)
Definition printcmd.c:3119
void print_command_parse_format(const char **expp, const char *cmdname, value_print_options *opts)
Definition printcmd.c:1211
static CORE_ADDR next_address
Definition printcmd.c:82
static void print_formatted(struct value *val, int size, const struct value_print_options *options, struct ui_file *stream)
Definition printcmd.c:293
void disable_current_display(void)
Definition printcmd.c:2253
static struct gdbarch * next_gdbarch
Definition printcmd.c:81
static void show_max_symbolic_offset(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition printcmd.c:102
static void clear_dangling_display_expressions(struct objfile *objfile)
Definition printcmd.c:2335
static unsigned int max_symbolic_offset
Definition printcmd.c:100
const char * pc_prefix(CORE_ADDR addr)
Definition printcmd.c:748
static CORE_ADDR find_string_backward(struct gdbarch *gdbarch, CORE_ADDR addr, int count, int char_size, const struct value_print_options *options, int *strings_counted)
Definition printcmd.c:936
static void memory_tag_with_logical_tag_command(const char *args, int from_tty)
Definition printcmd.c:3025
static std::vector< std::unique_ptr< struct display > > all_displays
Definition printcmd.c:173
static void show_addr_not_tagged(CORE_ADDR address)
Definition printcmd.c:2911
static void validate_format(struct format_data fmt, const char *cmdname)
Definition printcmd.c:1195
void print_value(value *val, const value_print_options &opts)
Definition printcmd.c:1242
static void print_command(const char *exp, int from_tty)
Definition printcmd.c:1450
static void memory_tag_print_allocation_tag_command(const char *args, int from_tty)
Definition printcmd.c:2986
static int display_number
Definition printcmd.c:131
static bool skip_over_slash_fmt(completion_tracker &tracker, const char **args)
Definition printcmd.c:1380
void print_command_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
Definition printcmd.c:1433
void print_variable_and_value(const char *name, struct symbol *var, frame_info_ptr frame, struct ui_file *stream, int indent)
Definition printcmd.c:2381
static void delete_display(struct display *display)
Definition printcmd.c:2010
int print_address_demangle(const struct value_print_options *opts, struct gdbarch *gdbarch, CORE_ADDR addr, struct ui_file *stream, int do_demangle)
Definition printcmd.c:767
static void memory_tag_check_command(const char *args, int from_tty)
Definition printcmd.c:3144
static void print_command_1(const char *args, int voidprint)
Definition printcmd.c:1315
void clear_displays()
Definition printcmd.c:2002
static void parse_set_allocation_tag_input(const char *args, struct value **val, size_t *length, gdb::byte_vector &tags)
Definition printcmd.c:3071
static void map_display_numbers(const char *args, gdb::function_view< void(struct display *)> function)
Definition printcmd.c:2028
void do_displays(void)
Definition printcmd.c:2231
static void memory_tag_print_tag_command(const char *args, enum memtag_type tag_type)
Definition printcmd.c:2937
static int current_display_number
Definition printcmd.c:127
static void do_examine(struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
Definition printcmd.c:995
void output_command(const char *exp, int from_tty)
Definition printcmd.c:1465
void print_address(struct gdbarch *gdbarch, CORE_ADDR addr, struct ui_file *stream)
Definition printcmd.c:737
static void show_memory_tagging_unsupported(void)
Definition printcmd.c:2920
static char last_format
Definition printcmd.c:65
static void call_command(const char *exp, int from_tty)
Definition printcmd.c:1457
static void x_command(const char *exp, int from_tty)
Definition printcmd.c:1848
static void info_symbol_command(const char *arg, int from_tty)
Definition printcmd.c:1522
static struct value * process_print_command_args(const char *args, value_print_options *print_opts, bool voidprint)
Definition printcmd.c:1288
static void display_and_x_command_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
Definition printcmd.c:1939
static int read_memory_backward(struct gdbarch *gdbarch, CORE_ADDR memaddr, gdb_byte *myaddr, int len)
Definition printcmd.c:884
struct program_space * current_program_space
Definition progspace.c:39
#define enable()
Definition ser-go32.c:239
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition source.c:1287
struct symbol * symbol
Definition symtab.h:1494
Definition block.h:109
CORE_ADDR entry_pc() const
Definition block.h:199
struct objfile * objfile
Definition minsyms.h:54
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
struct obj_section * obj_section() const
Definition minsyms.h:58
struct type * builtin_declong
Definition gdbtypes.h:2268
struct type * builtin_double
Definition gdbtypes.h:2258
struct type * builtin_int8
Definition gdbtypes.h:2281
struct type * builtin_data_ptr
Definition gdbtypes.h:2303
struct type * builtin_true_unsigned_char
Definition gdbtypes.h:2275
struct type * builtin_long_double
Definition gdbtypes.h:2259
struct type * builtin_char16
Definition gdbtypes.h:2295
struct type * builtin_int64
Definition gdbtypes.h:2289
struct type * builtin_decfloat
Definition gdbtypes.h:2266
struct type * builtin_int32
Definition gdbtypes.h:2287
struct type * builtin_decdouble
Definition gdbtypes.h:2267
struct type * builtin_char32
Definition gdbtypes.h:2296
struct type * builtin_int16
Definition gdbtypes.h:2283
struct type * builtin_float
Definition gdbtypes.h:2257
struct type * builtin_true_char
Definition gdbtypes.h:2274
bool enabled_p
Definition printcmd.c:167
std::string exp_string
Definition printcmd.c:149
display(const char *exp_string_, expression_up &&exp_, const struct format_data &format_, struct program_space *pspace_, const struct block *block_)
Definition printcmd.c:135
const struct block * block
Definition printcmd.c:164
expression_up exp
Definition printcmd.c:152
struct format_data format
Definition printcmd.c:158
int number
Definition printcmd.c:155
struct program_space * pspace
Definition printcmd.c:161
struct type * type
Definition symtab.h:1979
bool print_tags
Definition valprint.h:253
char format
Definition valprint.h:251
unsigned char raw
Definition valprint.h:257
const char * print_name() const
Definition symtab.h:474
struct obj_section * obj_section(const struct objfile *objfile) const
Definition symtab.c:1088
const char * linkage_name() const
Definition symtab.h:459
enum language la_language
Definition language.h:275
unsigned long size() const
Definition symtab.h:756
CORE_ADDR value_raw_address() const
Definition symtab.h:735
bool has_size() const
Definition symtab.h:771
minimal_symbol_type type() const
Definition symtab.h:742
CORE_ADDR value_address(objfile *objfile) const
Definition symtab.c:421
CORE_ADDR addr() const
Definition objfiles.h:822
CORE_ADDR endaddr() const
Definition objfiles.h:829
struct objfile * objfile
Definition objfiles.h:838
CORE_ADDR offset() const
Definition objfiles.h:810
struct bfd_section * the_bfd_section
Definition objfiles.h:835
struct objfile * separate_debug_objfile_backlink
Definition objfiles.h:743
struct program_space * pspace
Definition objfiles.h:641
struct gdbarch * arch() const
Definition objfiles.h:482
objfiles_range objfiles()
Definition progspace.h:209
bool multi_objfile_p() const
Definition progspace.h:244
LONGEST bias
Definition gdbtypes.h:708
const block * value_block() const
Definition symtab.h:1348
address_class aclass() const
Definition symtab.h:1235
LONGEST value_longest() const
Definition symtab.h:1305
bool is_objfile_owned() const
Definition symtab.h:1250
bool is_argument() const
Definition symtab.h:1260
CORE_ADDR value_address() const
Definition symtab.h:1315
struct objfile * objfile() const
Definition symtab.c:6477
symbol()
Definition symtab.h:1198
struct gdbarch * arch
Definition symtab.h:1417
struct obj_section * section
Definition symtab.h:2265
struct symtab * symtab
Definition symtab.h:2263
CORE_ADDR pc
Definition symtab.h:2272
type_code code() const
Definition gdbtypes.h:927
ULONGEST length() const
Definition gdbtypes.h:954
bool is_unsigned() const
Definition gdbtypes.h:1063
struct type * pointer_type
Definition gdbtypes.h:1404
gdbarch * arch() const
Definition gdbtypes.c:245
bool bit_size_differs_p() const
Definition gdbtypes.h:1371
range_bounds * bounds() const
Definition gdbtypes.h:1028
const ui_file_style * ptr() const
Definition ui-style.h:233
unsigned int print_max
Definition valprint.h:58
bool memory_tag_violations
Definition valprint.h:72
Definition value.c:181
struct obj_section * find_pc_overlay(CORE_ADDR pc)
Definition symfile.c:3133
CORE_ADDR overlay_unmapped_address(CORE_ADDR pc, struct obj_section *section)
Definition symfile.c:3067
int section_is_mapped(struct obj_section *osect)
Definition symfile.c:2978
CORE_ADDR overlay_mapped_address(CORE_ADDR pc, struct obj_section *section)
Definition symfile.c:3085
CORE_ADDR pc_in_unmapped_range(CORE_ADDR pc, struct obj_section *section)
Definition symfile.c:3014
int section_is_overlay(struct obj_section *section)
Definition symfile.c:2940
enum overlay_debugging_state overlay_debugging
Definition symfile.c:2932
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
Definition symtab.c:1967
struct symtab_and_line find_pc_sect_line(CORE_ADDR pc, struct obj_section *section, int notcurrent)
Definition symtab.c:3033
@ LOC_STATIC
Definition symtab.h:950
@ LOC_BLOCK
Definition symtab.h:999
@ LOC_LABEL
Definition symtab.h:993
@ LOC_REGISTER
Definition symtab.h:964
@ LOC_REF_ARG
Definition symtab.h:972
@ LOC_UNRESOLVED
Definition symtab.h:1028
@ LOC_LOCAL
Definition symtab.h:984
@ LOC_CONST
Definition symtab.h:946
@ LOC_CONST_BYTES
Definition symtab.h:1004
@ LOC_OPTIMIZED_OUT
Definition symtab.h:1033
@ LOC_TYPEDEF
Definition symtab.h:989
@ LOC_REGPARM_ADDR
Definition symtab.h:980
@ LOC_COMPUTED
Definition symtab.h:1037
@ LOC_ARG
Definition symtab.h:968
@ mst_solib_trampoline
Definition symtab.h:688
@ mst_file_text
Definition symtab.h:691
@ mst_text
Definition symtab.h:655
@ mst_text_gnu_ifunc
Definition symtab.h:664
#define SYMBOL_COMPUTED_OPS(symbol)
Definition symtab.h:1504
@ VAR_DOMAIN
Definition symtab.h:881
#define SYMBOL_REGISTER_OPS(symbol)
Definition symtab.h:1506
std::string target_float_to_string(const gdb_byte *addr, const struct type *type, const char *format)
bool target_supports_memory_tagging()
Definition target.c:816
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1771
static styled_string_s * styled_string(const ui_file_style &style, const char *str, styled_string_s &&tmp={})
Definition ui-out.h:151
int query(const char *ctlstr,...)
Definition utils.c:1010
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition utils.c:3114
void fprintf_styled(struct ui_file *stream, const ui_file_style &style, const char *format,...)
Definition utils.c:1877
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1865
void fputs_styled(const char *linebuffer, const ui_file_style &style, struct ui_file *stream)
Definition utils.c:1796
void fprintf_symbol(struct ui_file *stream, const char *name, enum language lang, int arg_mode)
Definition utils.c:1960
void gdb_flush(struct ui_file *stream)
Definition utils.c:1477
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition utils.c:1788
#define gdb_stderr
Definition utils.h:193
#define gdb_stdout
Definition utils.h:188
struct value * value_at_lazy(struct type *type, CORE_ADDR addr)
Definition valops.c:1028
struct value * value_cast(struct type *type, struct value *arg2)
Definition valops.c:408
void get_formatted_print_options(struct value_print_options *opts, char format)
Definition valprint.c:145
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:1172
void value_print_scalar_formatted(struct value *val, const struct value_print_options *options, int size, struct ui_file *stream)
Definition valprint.c:1259
void print_decimal_chars(struct ui_file *stream, const gdb_byte *valaddr, unsigned len, bool is_signed, enum bfd_endian byte_order)
Definition valprint.c:1686
void print_octal_chars(struct ui_file *stream, const gdb_byte *valaddr, unsigned len, enum bfd_endian byte_order)
Definition valprint.c:1485
gdb::option::option_def_group make_value_print_options_def_group(value_print_options *opts)
Definition valprint.c:3024
int val_print_string(struct type *elttype, const char *encoding, CORE_ADDR addr, int len, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:2598
void get_user_print_options(struct value_print_options *opts)
Definition valprint.c:128
void common_val_print_checked(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition valprint.c:1158
void print_hex_chars(struct ui_file *stream, const gdb_byte *valaddr, unsigned len, enum bfd_endian byte_order, bool zero_pad)
Definition valprint.c:1822
void print_floating(const gdb_byte *valaddr, struct type *type, struct ui_file *stream)
Definition valprint.c:1373
void print_binary_chars(struct ui_file *stream, const gdb_byte *valaddr, unsigned len, enum bfd_endian byte_order, bool zero_pad, const struct value_print_options *options)
Definition valprint.c:1381
struct type * value_type(const struct value *value)
Definition value.c:1109
int value_entirely_available(struct value *value)
Definition value.c:408
int value_lazy(const struct value *value)
Definition value.c:1440
void clear_internalvar(struct internalvar *var)
Definition value.c:2498
CORE_ADDR value_as_address(struct value *val)
Definition value.c:2804
struct value * value_from_ulongest(struct type *type, ULONGEST num)
Definition value.c:3637
CORE_ADDR value_address(const struct value *value)
Definition value.c:1607
int record_latest_value(struct value *val)
Definition value.c:1926
struct value * value_from_longest(struct type *type, LONGEST num)
Definition value.c:3625
struct value * coerce_ref(struct value *arg)
Definition value.c:3902
struct value * value_from_contents(struct type *type, const gdb_byte *contents)
Definition value.c:3730
void set_internalvar(struct internalvar *var, struct value *val)
Definition value.c:2404
gdb::array_view< const gdb_byte > value_contents(struct value *value)
Definition value.c:1464
struct internalvar * lookup_internalvar(const char *name)
Definition value.c:2235
LONGEST value_as_long(struct value *val)
Definition value.c:2791
int value_optimized_out(struct value *value)
Definition value.c:1481
struct value * value_from_pointer(struct type *type, CORE_ADDR addr)
Definition value.c:3651
struct value * access_value_history(int num)
Definition value.c:1947
value_ref_ptr release_value(struct value *val)
Definition value.c:1714
LONGEST unpack_long(struct type *type, const gdb_byte *valaddr)
Definition value.c:2921
#define VALUE_LVAL(val)
Definition value.h:438
gdb::ref_ptr< struct value, value_ref_policy > value_ref_ptr
Definition value.h:120