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