1 /* Print values for GNU debugger GDB.
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
27 #include "expression.h"
31 #include "breakpoint.h"
33 #include "gdb-demangle.h"
38 #include "completer.h"
42 #include "target-float.h"
43 #include "observable.h"
45 #include "parser-defs.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"
54 #include "gdbsupport/byte-vector.h"
56 #include "gdbsupport/gdb-safe-ctype.h"
57 #include "gdbsupport/rsp-low.h"
60 /* Chain containing all defined memory-tag subcommands. */
62 static struct cmd_list_element
*memory_tag_list
;
64 /* Last specified output format. */
66 static char last_format
= 0;
68 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
70 static char last_size
= 'w';
72 /* Last specified count for the 'x' command. */
74 static int last_count
;
76 /* Last specified tag-printing option. */
78 static bool last_print_tags
= false;
80 /* Default address to examine next, and associated architecture. */
82 static struct gdbarch
*next_gdbarch
;
83 static CORE_ADDR next_address
;
85 /* Number of delay instructions following current disassembled insn. */
87 static int branch_delay_insns
;
89 /* Last address examined. */
91 static CORE_ADDR last_examine_address
;
93 /* Contents of last address examined.
94 This is not valid past the end of the `x' command! */
96 static value_ref_ptr last_examine_value
;
98 /* Largest offset between a symbolic value and an address, that will be
99 printed as `0x1234 <symbol+offset>'. */
101 static unsigned int max_symbolic_offset
= UINT_MAX
;
103 show_max_symbolic_offset (struct ui_file
*file
, int from_tty
,
104 struct cmd_list_element
*c
, const char *value
)
107 _("The largest offset that will be "
108 "printed in <symbol+1234> form is %s.\n"),
112 /* Append the source filename and linenumber of the symbol when
113 printing a symbolic value as `<symbol at filename:linenum>' if set. */
114 static bool print_symbol_filename
= false;
116 show_print_symbol_filename (struct ui_file
*file
, int from_tty
,
117 struct cmd_list_element
*c
, const char *value
)
119 gdb_printf (file
, _("Printing of source filename and "
120 "line number with <symbol> is %s.\n"),
124 /* Number of auto-display expression currently being displayed.
125 So that we can disable it if we get a signal within it.
126 -1 when not doing one. */
128 static int current_display_number
;
130 /* Last allocated display number. */
132 static int display_number
;
136 display (const char *exp_string_
, expression_up
&&exp_
,
137 const struct format_data
&format_
, struct program_space
*pspace_
,
138 const struct block
*block_
)
139 : exp_string (exp_string_
),
140 exp (std::move (exp_
)),
141 number (++display_number
),
149 /* The expression as the user typed it. */
150 std::string exp_string
;
152 /* Expression to be evaluated and displayed. */
155 /* Item number of this auto-display item. */
158 /* Display format specified. */
159 struct format_data format
;
161 /* Program space associated with `block'. */
162 struct program_space
*pspace
;
164 /* Innermost block required by this expression when evaluated. */
165 const struct block
*block
;
167 /* Status of this display (enabled or disabled). */
171 /* Expressions whose values should be displayed automatically each
172 time the program stops. */
174 static std::vector
<std::unique_ptr
<struct display
>> all_displays
;
176 /* Prototypes for local functions. */
178 static void do_one_display (struct display
*);
181 /* Decode a format specification. *STRING_PTR should point to it.
182 OFORMAT and OSIZE are used as defaults for the format and size
183 if none are given in the format specification.
184 If OSIZE is zero, then the size field of the returned value
185 should be set only if a size is explicitly specified by the
187 The structure returned describes all the data
188 found in the specification. In addition, *STRING_PTR is advanced
189 past the specification and past all whitespace following it. */
191 static struct format_data
192 decode_format (const char **string_ptr
, int oformat
, int osize
)
194 struct format_data val
;
195 const char *p
= *string_ptr
;
201 val
.print_tags
= false;
208 if (*p
>= '0' && *p
<= '9')
209 val
.count
*= atoi (p
);
210 while (*p
>= '0' && *p
<= '9')
213 /* Now process size or format letters that follow. */
217 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
226 val
.print_tags
= true;
229 else if (*p
>= 'a' && *p
<= 'z')
235 *string_ptr
= skip_spaces (p
);
237 /* Set defaults for format and size if not specified. */
238 if (val
.format
== '?')
242 /* Neither has been specified. */
243 val
.format
= oformat
;
247 /* If a size is specified, any format makes a reasonable
248 default except 'i'. */
249 val
.format
= oformat
== 'i' ? 'x' : oformat
;
251 else if (val
.size
== '?')
255 /* Pick the appropriate size for an address. This is deferred
256 until do_examine when we know the actual architecture to use.
257 A special size value of 'a' is used to indicate this case. */
258 val
.size
= osize
? 'a' : osize
;
261 /* Floating point has to be word or giantword. */
262 if (osize
== 'w' || osize
== 'g')
265 /* Default it to giantword if the last used size is not
267 val
.size
= osize
? 'g' : osize
;
270 /* Characters default to one byte. */
271 val
.size
= osize
? 'b' : osize
;
274 /* Display strings with byte size chars unless explicitly
280 /* The default is the size most recently specified. */
287 /* Print value VAL on stream according to OPTIONS.
288 Do not end with a newline.
289 SIZE is the letter for the size of datum being printed.
290 This is used to pad hex numbers so they line up. SIZE is 0
291 for print / output and set for examine. */
294 print_formatted (struct value
*val
, int size
,
295 const struct value_print_options
*options
,
296 struct ui_file
*stream
)
298 struct type
*type
= check_typedef (val
->type ());
299 int len
= type
->length ();
301 if (val
->lval () == lval_memory
)
302 next_address
= val
->address () + len
;
306 switch (options
->format
)
310 struct type
*elttype
= val
->type ();
312 next_address
= (val
->address ()
313 + val_print_string (elttype
, NULL
,
315 stream
, options
) * len
);
320 /* We often wrap here if there are long symbolic names. */
321 stream
->wrap_here (4);
322 next_address
= (val
->address ()
323 + gdb_print_insn (type
->arch (),
324 val
->address (), stream
,
325 &branch_delay_insns
));
330 if (options
->format
== 0 || options
->format
== 's'
331 || type
->code () == TYPE_CODE_VOID
332 || type
->code () == TYPE_CODE_REF
333 || type
->code () == TYPE_CODE_ARRAY
334 || type
->code () == TYPE_CODE_STRING
335 || type
->code () == TYPE_CODE_STRUCT
336 || type
->code () == TYPE_CODE_UNION
337 || type
->code () == TYPE_CODE_NAMESPACE
)
338 value_print (val
, stream
, options
);
340 /* User specified format, so don't look to the type to tell us
342 value_print_scalar_formatted (val
, options
, size
, stream
);
345 /* Return builtin floating point type of same length as TYPE.
346 If no such type is found, return TYPE itself. */
348 float_type_from_length (struct type
*type
)
350 struct gdbarch
*gdbarch
= type
->arch ();
351 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
353 if (type
->length () == builtin
->builtin_half
->length ())
354 type
= builtin
->builtin_half
;
355 else if (type
->length () == builtin
->builtin_float
->length ())
356 type
= builtin
->builtin_float
;
357 else if (type
->length () == builtin
->builtin_double
->length ())
358 type
= builtin
->builtin_double
;
359 else if (type
->length () == builtin
->builtin_long_double
->length ())
360 type
= builtin
->builtin_long_double
;
365 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
366 according to OPTIONS and SIZE on STREAM. Formats s and i are not
367 supported at this level. */
370 print_scalar_formatted (const gdb_byte
*valaddr
, struct type
*type
,
371 const struct value_print_options
*options
,
372 int size
, struct ui_file
*stream
)
374 struct gdbarch
*gdbarch
= type
->arch ();
375 unsigned int len
= type
->length ();
376 enum bfd_endian byte_order
= type_byte_order (type
);
378 /* String printing should go through val_print_scalar_formatted. */
379 gdb_assert (options
->format
!= 's');
381 /* If the value is a pointer, and pointers and addresses are not the
382 same, then at this point, the value's length (in target bytes) is
383 gdbarch_addr_bit/TARGET_CHAR_BIT, not type->length (). */
384 if (type
->code () == TYPE_CODE_PTR
)
385 len
= gdbarch_addr_bit (gdbarch
) / TARGET_CHAR_BIT
;
387 /* If we are printing it as unsigned, truncate it in case it is actually
388 a negative signed value (e.g. "print/u (short)-1" should print 65535
389 (if shorts are 16 bits) instead of 4294967295). */
390 if (options
->format
!= 'c'
391 && (options
->format
!= 'd' || type
->is_unsigned ()))
393 if (len
< type
->length () && byte_order
== BFD_ENDIAN_BIG
)
394 valaddr
+= type
->length () - len
;
397 /* Allow LEN == 0, and in this case, don't assume that VALADDR is
399 const gdb_byte zero
= 0;
406 if (size
!= 0 && (options
->format
== 'x' || options
->format
== 't'))
408 /* Truncate to fit. */
425 error (_("Undefined output size \"%c\"."), size
);
427 if (newlen
< len
&& byte_order
== BFD_ENDIAN_BIG
)
428 valaddr
+= len
- newlen
;
432 /* Biased range types and sub-word scalar types must be handled
433 here; the value is correctly computed by unpack_long. */
434 gdb::byte_vector converted_bytes
;
435 /* Some cases below will unpack the value again. In the biased
436 range case, we want to avoid this, so we store the unpacked value
437 here for possible use later. */
438 std::optional
<LONGEST
> val_long
;
439 if ((is_fixed_point_type (type
)
440 && (options
->format
== 'o'
441 || options
->format
== 'x'
442 || options
->format
== 't'
443 || options
->format
== 'z'
444 || options
->format
== 'd'
445 || options
->format
== 'u'))
446 || (type
->code () == TYPE_CODE_RANGE
&& type
->bounds ()->bias
!= 0)
447 || type
->bit_size_differs_p ())
449 val_long
.emplace (unpack_long (type
, valaddr
));
450 converted_bytes
.resize (type
->length ());
451 store_signed_integer (converted_bytes
.data (), type
->length (),
452 byte_order
, *val_long
);
453 valaddr
= converted_bytes
.data ();
456 /* Printing a non-float type as 'f' will interpret the data as if it were
457 of a floating-point type of the same length, if that exists. Otherwise,
458 the data is printed as integer. */
459 char format
= options
->format
;
460 if (format
== 'f' && type
->code () != TYPE_CODE_FLT
)
462 type
= float_type_from_length (type
);
463 if (type
->code () != TYPE_CODE_FLT
)
470 print_octal_chars (stream
, valaddr
, len
, byte_order
);
473 print_decimal_chars (stream
, valaddr
, len
, true, byte_order
);
476 print_decimal_chars (stream
, valaddr
, len
, false, byte_order
);
479 if (type
->code () != TYPE_CODE_FLT
)
481 print_decimal_chars (stream
, valaddr
, len
, !type
->is_unsigned (),
487 print_floating (valaddr
, type
, stream
);
491 print_binary_chars (stream
, valaddr
, len
, byte_order
, size
> 0, options
);
494 print_hex_chars (stream
, valaddr
, len
, byte_order
, size
> 0);
497 print_hex_chars (stream
, valaddr
, len
, byte_order
, true);
501 struct value_print_options opts
= *options
;
503 if (!val_long
.has_value ())
504 val_long
.emplace (unpack_long (type
, valaddr
));
507 if (type
->is_unsigned ())
508 type
= builtin_type (gdbarch
)->builtin_true_unsigned_char
;
510 type
= builtin_type (gdbarch
)->builtin_true_char
;
512 value_print (value_from_longest (type
, *val_long
), stream
, &opts
);
518 if (!val_long
.has_value ())
519 val_long
.emplace (unpack_long (type
, valaddr
));
520 print_address (gdbarch
, *val_long
, stream
);
525 error (_("Undefined output format \"%c\"."), format
);
529 /* Specify default address for `x' command.
530 The `info lines' command uses this. */
533 set_next_address (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
535 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
537 next_gdbarch
= gdbarch
;
540 /* Make address available to the user as $_. */
541 set_internalvar (lookup_internalvar ("_"),
542 value_from_pointer (ptr_type
, addr
));
545 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
546 after LEADIN. Print nothing if no symbolic name is found nearby.
547 Optionally also print source file and line number, if available.
548 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
549 or to interpret it as a possible C++ name and convert it back to source
550 form. However note that DO_DEMANGLE can be overridden by the specific
551 settings of the demangle and asm_demangle variables. Returns
552 non-zero if anything was printed; zero otherwise. */
555 print_address_symbolic (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
556 struct ui_file
*stream
,
557 int do_demangle
, const char *leadin
)
559 std::string name
, filename
;
564 if (build_address_symbolic (gdbarch
, addr
, do_demangle
, false, &name
,
565 &offset
, &filename
, &line
, &unmapped
))
568 gdb_puts (leadin
, stream
);
570 gdb_puts ("<*", stream
);
572 gdb_puts ("<", stream
);
573 fputs_styled (name
.c_str (), function_name_style
.style (), stream
);
575 gdb_printf (stream
, "%+d", offset
);
577 /* Append source filename and line number if desired. Give specific
578 line # of this addr, if we have it; else line # of the nearest symbol. */
579 if (print_symbol_filename
&& !filename
.empty ())
581 gdb_puts (line
== -1 ? " in " : " at ", stream
);
582 fputs_styled (filename
.c_str (), file_name_style
.style (), stream
);
584 gdb_printf (stream
, ":%d", line
);
587 gdb_puts ("*>", stream
);
589 gdb_puts (">", stream
);
594 /* See valprint.h. */
597 build_address_symbolic (struct gdbarch
*gdbarch
,
598 CORE_ADDR addr
, /* IN */
599 bool do_demangle
, /* IN */
600 bool prefer_sym_over_minsym
, /* IN */
601 std::string
*name
, /* OUT */
602 int *offset
, /* OUT */
603 std::string
*filename
, /* OUT */
605 int *unmapped
) /* OUT */
607 struct bound_minimal_symbol msymbol
;
608 struct symbol
*symbol
;
609 CORE_ADDR name_location
= 0;
610 struct obj_section
*section
= NULL
;
611 const char *name_temp
= "";
613 /* Let's say it is mapped (not unmapped). */
616 /* Determine if the address is in an overlay, and whether it is
618 if (overlay_debugging
)
620 section
= find_pc_overlay (addr
);
621 if (pc_in_unmapped_range (addr
, section
))
624 addr
= overlay_mapped_address (addr
, section
);
628 /* Try to find the address in both the symbol table and the minsyms.
629 In most cases, we'll prefer to use the symbol instead of the
630 minsym. However, there are cases (see below) where we'll choose
631 to use the minsym instead. */
633 /* This is defective in the sense that it only finds text symbols. So
634 really this is kind of pointless--we should make sure that the
635 minimal symbols have everything we need (by changing that we could
636 save some memory, but for many debug format--ELF/DWARF or
637 anything/stabs--it would be inconvenient to eliminate those minimal
639 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
640 symbol
= find_pc_sect_function (addr
, section
);
644 /* If this is a function (i.e. a code address), strip out any
645 non-address bits. For instance, display a pointer to the
646 first instruction of a Thumb function as <function>; the
647 second instruction will be <function+2>, even though the
648 pointer is <function+3>. This matches the ISA behavior. */
649 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
651 name_location
= symbol
->value_block ()->entry_pc ();
652 if (do_demangle
|| asm_demangle
)
653 name_temp
= symbol
->print_name ();
655 name_temp
= symbol
->linkage_name ();
658 if (msymbol
.minsym
!= NULL
659 && msymbol
.minsym
->has_size ()
660 && msymbol
.minsym
->size () == 0
661 && msymbol
.minsym
->type () != mst_text
662 && msymbol
.minsym
->type () != mst_text_gnu_ifunc
663 && msymbol
.minsym
->type () != mst_file_text
)
664 msymbol
.minsym
= NULL
;
666 if (msymbol
.minsym
!= NULL
)
668 /* Use the minsym if no symbol is found.
670 Additionally, use the minsym instead of a (found) symbol if
671 the following conditions all hold:
672 1) The prefer_sym_over_minsym flag is false.
673 2) The minsym address is identical to that of the address under
675 3) The symbol address is not identical to that of the address
676 under consideration. */
677 if (symbol
== NULL
||
678 (!prefer_sym_over_minsym
679 && msymbol
.value_address () == addr
680 && name_location
!= addr
))
682 /* If this is a function (i.e. a code address), strip out any
683 non-address bits. For instance, display a pointer to the
684 first instruction of a Thumb function as <function>; the
685 second instruction will be <function+2>, even though the
686 pointer is <function+3>. This matches the ISA behavior. */
687 if (msymbol
.minsym
->type () == mst_text
688 || msymbol
.minsym
->type () == mst_text_gnu_ifunc
689 || msymbol
.minsym
->type () == mst_file_text
690 || msymbol
.minsym
->type () == mst_solib_trampoline
)
691 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
694 name_location
= msymbol
.value_address ();
695 if (do_demangle
|| asm_demangle
)
696 name_temp
= msymbol
.minsym
->print_name ();
698 name_temp
= msymbol
.minsym
->linkage_name ();
701 if (symbol
== NULL
&& msymbol
.minsym
== NULL
)
704 /* If the nearest symbol is too far away, don't print anything symbolic. */
706 /* For when CORE_ADDR is larger than unsigned int, we do math in
707 CORE_ADDR. But when we detect unsigned wraparound in the
708 CORE_ADDR math, we ignore this test and print the offset,
709 because addr+max_symbolic_offset has wrapped through the end
710 of the address space back to the beginning, giving bogus comparison. */
711 if (addr
> name_location
+ max_symbolic_offset
712 && name_location
+ max_symbolic_offset
> name_location
)
715 *offset
= (LONGEST
) addr
- name_location
;
719 if (print_symbol_filename
)
721 struct symtab_and_line sal
;
723 sal
= find_pc_sect_line (addr
, section
, 0);
727 *filename
= symtab_to_filename_for_display (sal
.symtab
);
735 /* Print address ADDR symbolically on STREAM.
736 First print it as a number. Then perhaps print
737 <SYMBOL + OFFSET> after the number. */
740 print_address (struct gdbarch
*gdbarch
,
741 CORE_ADDR addr
, struct ui_file
*stream
)
743 fputs_styled (paddress (gdbarch
, addr
), address_style
.style (), stream
);
744 print_address_symbolic (gdbarch
, addr
, stream
, asm_demangle
, " ");
747 /* Return a prefix for instruction address:
748 "=> " for current instruction, else " ". */
751 pc_prefix (CORE_ADDR addr
)
753 if (has_stack_frames ())
755 frame_info_ptr frame
;
758 frame
= get_selected_frame (NULL
);
759 if (get_frame_pc_if_available (frame
, &pc
) && pc
== addr
)
765 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
766 controls whether to print the symbolic name "raw" or demangled.
767 Return non-zero if anything was printed; zero otherwise. */
770 print_address_demangle (const struct value_print_options
*opts
,
771 struct gdbarch
*gdbarch
, CORE_ADDR addr
,
772 struct ui_file
*stream
, int do_demangle
)
774 if (opts
->addressprint
)
776 fputs_styled (paddress (gdbarch
, addr
), address_style
.style (), stream
);
777 print_address_symbolic (gdbarch
, addr
, stream
, do_demangle
, " ");
781 return print_address_symbolic (gdbarch
, addr
, stream
, do_demangle
, "");
787 /* Find the address of the instruction that is INST_COUNT instructions before
788 the instruction at ADDR.
789 Since some architectures have variable-length instructions, we can't just
790 simply subtract INST_COUNT * INSN_LEN from ADDR. Instead, we use line
791 number information to locate the nearest known instruction boundary,
792 and disassemble forward from there. If we go out of the symbol range
793 during disassembling, we return the lowest address we've got so far and
794 set the number of instructions read to INST_READ. */
797 find_instruction_backward (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
798 int inst_count
, int *inst_read
)
800 /* The vector PCS is used to store instruction addresses within
802 CORE_ADDR loop_start
, loop_end
, p
;
803 std::vector
<CORE_ADDR
> pcs
;
804 struct symtab_and_line sal
;
807 loop_start
= loop_end
= addr
;
809 /* In each iteration of the outer loop, we get a pc range that ends before
810 LOOP_START, then we count and store every instruction address of the range
811 iterated in the loop.
812 If the number of instructions counted reaches INST_COUNT, return the
813 stored address that is located INST_COUNT instructions back from ADDR.
814 If INST_COUNT is not reached, we subtract the number of counted
815 instructions from INST_COUNT, and go to the next iteration. */
819 sal
= find_pc_sect_line (loop_start
, NULL
, 1);
822 /* We reach here when line info is not available. In this case,
823 we print a message and just exit the loop. The return value
824 is calculated after the loop. */
825 gdb_printf (_("No line number information available "
827 gdb_stdout
->wrap_here (2);
828 print_address (gdbarch
, loop_start
- 1, gdb_stdout
);
833 loop_end
= loop_start
;
836 /* This loop pushes instruction addresses in the range from
837 LOOP_START to LOOP_END. */
838 for (p
= loop_start
; p
< loop_end
;)
841 p
+= gdb_insn_length (gdbarch
, p
);
844 inst_count
-= pcs
.size ();
845 *inst_read
+= pcs
.size ();
847 while (inst_count
> 0);
849 /* After the loop, the vector PCS has instruction addresses of the last
850 source line we processed, and INST_COUNT has a negative value.
851 We return the address at the index of -INST_COUNT in the vector for
853 Let's assume the following instruction addresses and run 'x/-4i 0x400e'.
863 find_instruction_backward is called with INST_COUNT = 4 and expected to
864 return 0x4001. When we reach here, INST_COUNT is set to -1 because
865 it was subtracted by 2 (from Line Y) and 3 (from Line X). The value
866 4001 is located at the index 1 of the last iterated line (= Line X),
867 which is simply calculated by -INST_COUNT.
868 The case when the length of PCS is 0 means that we reached an area for
869 which line info is not available. In such case, we return LOOP_START,
870 which was the lowest instruction address that had line info. */
871 p
= pcs
.size () > 0 ? pcs
[-inst_count
] : loop_start
;
873 /* INST_READ includes all instruction addresses in a pc range. Need to
874 exclude the beginning part up to the address we're returning. That
875 is, exclude {0x4000} in the example above. */
877 *inst_read
+= inst_count
;
882 /* Backward read LEN bytes of target memory from address MEMADDR + LEN,
883 placing the results in GDB's memory from MYADDR + LEN. Returns
884 a count of the bytes actually read. */
887 read_memory_backward (struct gdbarch
*gdbarch
,
888 CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
891 int nread
; /* Number of bytes actually read. */
893 /* First try a complete read. */
894 errcode
= target_read_memory (memaddr
, myaddr
, len
);
902 /* Loop, reading one byte at a time until we get as much as we can. */
905 for (nread
= 0; nread
< len
; ++nread
)
907 errcode
= target_read_memory (--memaddr
, --myaddr
, 1);
910 /* The read was unsuccessful, so exit the loop. */
911 gdb_printf (_("Cannot access memory at address %s\n"),
912 paddress (gdbarch
, memaddr
));
920 /* Returns true if X (which is LEN bytes wide) is the number zero. */
923 integer_is_zero (const gdb_byte
*x
, int len
)
927 while (i
< len
&& x
[i
] == 0)
932 /* Find the start address of a string in which ADDR is included.
933 Basically we search for '\0' and return the next address,
934 but if OPTIONS->PRINT_MAX is smaller than the length of a string,
935 we stop searching and return the address to print characters as many as
936 PRINT_MAX from the string. */
939 find_string_backward (struct gdbarch
*gdbarch
,
940 CORE_ADDR addr
, int count
, int char_size
,
941 const struct value_print_options
*options
,
942 int *strings_counted
)
944 const int chunk_size
= 0x20;
947 int chars_to_read
= chunk_size
;
948 int chars_counted
= 0;
949 int count_original
= count
;
950 CORE_ADDR string_start_addr
= addr
;
952 gdb_assert (char_size
== 1 || char_size
== 2 || char_size
== 4);
953 gdb::byte_vector
buffer (chars_to_read
* char_size
);
954 while (count
> 0 && read_error
== 0)
958 addr
-= chars_to_read
* char_size
;
959 chars_read
= read_memory_backward (gdbarch
, addr
, buffer
.data (),
960 chars_to_read
* char_size
);
961 chars_read
/= char_size
;
962 read_error
= (chars_read
== chars_to_read
) ? 0 : 1;
963 unsigned int print_max_chars
= get_print_max_chars (options
);
964 /* Searching for '\0' from the end of buffer in backward direction. */
965 for (i
= 0; i
< chars_read
&& count
> 0 ; ++i
, ++chars_counted
)
967 int offset
= (chars_to_read
- i
- 1) * char_size
;
969 if (integer_is_zero (&buffer
[offset
], char_size
)
970 || chars_counted
== print_max_chars
)
972 /* Found '\0' or reached `print_max_chars'. As OFFSET
973 is the offset to '\0', we add CHAR_SIZE to return
974 the start address of a string. */
976 string_start_addr
= addr
+ offset
+ char_size
;
982 /* Update STRINGS_COUNTED with the actual number of loaded strings. */
983 *strings_counted
= count_original
- count
;
987 /* In error case, STRING_START_ADDR is pointing to the string that
988 was last successfully loaded. Rewind the partially loaded string. */
989 string_start_addr
-= chars_counted
* char_size
;
992 return string_start_addr
;
995 /* Examine data at address ADDR in format FMT.
996 Fetch it from memory and print on gdb_stdout. */
999 do_examine (struct format_data fmt
, struct gdbarch
*gdbarch
, CORE_ADDR addr
)
1004 struct type
*val_type
= NULL
;
1007 struct value_print_options opts
;
1008 int need_to_update_next_address
= 0;
1009 CORE_ADDR addr_rewound
= 0;
1011 format
= fmt
.format
;
1014 next_gdbarch
= gdbarch
;
1015 next_address
= addr
;
1017 /* Instruction format implies fetch single bytes
1018 regardless of the specified size.
1019 The case of strings is handled in decode_format, only explicit
1020 size operator are not changed to 'b'. */
1026 /* Pick the appropriate size for an address. */
1027 if (gdbarch_ptr_bit (next_gdbarch
) == 64)
1029 else if (gdbarch_ptr_bit (next_gdbarch
) == 32)
1031 else if (gdbarch_ptr_bit (next_gdbarch
) == 16)
1034 /* Bad value for gdbarch_ptr_bit. */
1035 internal_error (_("failed internal consistency check"));
1039 val_type
= builtin_type (next_gdbarch
)->builtin_int8
;
1040 else if (size
== 'h')
1041 val_type
= builtin_type (next_gdbarch
)->builtin_int16
;
1042 else if (size
== 'w')
1043 val_type
= builtin_type (next_gdbarch
)->builtin_int32
;
1044 else if (size
== 'g')
1045 val_type
= builtin_type (next_gdbarch
)->builtin_int64
;
1049 struct type
*char_type
= NULL
;
1051 /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char
1052 if type is not found. */
1054 char_type
= builtin_type (next_gdbarch
)->builtin_char16
;
1055 else if (size
== 'w')
1056 char_type
= builtin_type (next_gdbarch
)->builtin_char32
;
1058 val_type
= char_type
;
1061 if (size
!= '\0' && size
!= 'b')
1062 warning (_("Unable to display strings with "
1063 "size '%c', using 'b' instead."), size
);
1065 val_type
= builtin_type (next_gdbarch
)->builtin_int8
;
1074 if (format
== 's' || format
== 'i')
1077 get_formatted_print_options (&opts
, format
);
1081 /* This is the negative repeat count case.
1082 We rewind the address based on the given repeat count and format,
1083 then examine memory from there in forward direction. */
1088 next_address
= find_instruction_backward (gdbarch
, addr
, count
,
1091 else if (format
== 's')
1093 next_address
= find_string_backward (gdbarch
, addr
, count
,
1094 val_type
->length (),
1099 next_address
= addr
- count
* val_type
->length ();
1102 /* The following call to print_formatted updates next_address in every
1103 iteration. In backward case, we store the start address here
1104 and update next_address with it before exiting the function. */
1105 addr_rewound
= (format
== 's'
1106 ? next_address
- val_type
->length ()
1108 need_to_update_next_address
= 1;
1111 /* Whether we need to print the memory tag information for the current
1113 bool print_range_tag
= true;
1114 uint32_t gsize
= gdbarch_memtag_granule_size (gdbarch
);
1116 /* Print as many objects as specified in COUNT, at most maxelts per line,
1117 with the address of the next one at the start of each line. */
1123 CORE_ADDR tag_laddr
= 0, tag_haddr
= 0;
1125 /* Print the memory tag information if requested. */
1126 if (fmt
.print_tags
&& print_range_tag
1127 && target_supports_memory_tagging ())
1129 tag_laddr
= align_down (next_address
, gsize
);
1130 tag_haddr
= align_down (next_address
+ gsize
, gsize
);
1132 struct value
*v_addr
1133 = value_from_ulongest (builtin_type (gdbarch
)->builtin_data_ptr
,
1136 if (gdbarch_tagged_address_p (current_inferior ()->arch (), v_addr
))
1138 /* Fetch the allocation tag. */
1140 = gdbarch_get_memtag (gdbarch
, v_addr
, memtag_type::allocation
);
1142 = gdbarch_memtag_to_string (gdbarch
, tag
);
1146 gdb_printf (_("<Allocation Tag %s for range [%s,%s)>\n"),
1148 paddress (gdbarch
, tag_laddr
),
1149 paddress (gdbarch
, tag_haddr
));
1152 print_range_tag
= false;
1156 gdb_puts (pc_prefix (next_address
));
1157 print_address (next_gdbarch
, next_address
, gdb_stdout
);
1164 /* Note that print_formatted sets next_address for the next
1166 last_examine_address
= next_address
;
1168 /* The value to be displayed is not fetched greedily.
1169 Instead, to avoid the possibility of a fetched value not
1170 being used, its retrieval is delayed until the print code
1171 uses it. When examining an instruction stream, the
1172 disassembler will perform its own memory fetch using just
1173 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
1174 the disassembler be modified so that LAST_EXAMINE_VALUE
1175 is left with the byte sequence from the last complete
1176 instruction fetched from memory? */
1178 = release_value (value_at_lazy (val_type
, next_address
));
1180 print_formatted (last_examine_value
.get (), size
, &opts
, gdb_stdout
);
1182 /* Display any branch delay slots following the final insn. */
1183 if (format
== 'i' && count
== 1)
1184 count
+= branch_delay_insns
;
1186 /* Update the tag range based on the current address being
1188 if (tag_haddr
<= next_address
)
1189 print_range_tag
= true;
1194 if (need_to_update_next_address
)
1195 next_address
= addr_rewound
;
1199 validate_format (struct format_data fmt
, const char *cmdname
)
1202 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
1204 error (_("Item count other than 1 is meaningless in \"%s\" command."),
1206 if (fmt
.format
== 'i')
1207 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
1208 fmt
.format
, cmdname
);
1211 /* Parse print command format string into *OPTS and update *EXPP.
1212 CMDNAME should name the current command. */
1215 print_command_parse_format (const char **expp
, const char *cmdname
,
1216 value_print_options
*opts
)
1218 const char *exp
= *expp
;
1220 /* opts->raw value might already have been set by 'set print raw-values'
1221 or by using 'print -raw-values'.
1222 So, do not set opts->raw to 0, only set it to 1 if /r is given. */
1223 if (exp
&& *exp
== '/')
1228 fmt
= decode_format (&exp
, last_format
, 0);
1229 validate_format (fmt
, cmdname
);
1230 last_format
= fmt
.format
;
1232 opts
->format
= fmt
.format
;
1233 opts
->raw
= opts
->raw
|| fmt
.raw
;
1243 /* See valprint.h. */
1246 print_value (value
*val
, const value_print_options
&opts
)
1248 /* This setting allows large arrays to be printed by limiting the
1249 number of elements that are loaded into GDB's memory; we only
1250 need to load as many array elements as we plan to print. */
1251 scoped_array_length_limiting
limit_large_arrays (opts
.print_max
);
1253 int histindex
= val
->record_latest ();
1255 annotate_value_history_begin (histindex
, val
->type ());
1257 std::string idx
= string_printf ("$%d", histindex
);
1258 gdb_printf ("%ps = ", styled_string (variable_name_style
.style (),
1261 annotate_value_history_value ();
1263 print_formatted (val
, 0, &opts
, gdb_stdout
);
1266 annotate_value_history_end ();
1269 /* Returns true if memory tags should be validated. False otherwise. */
1272 should_validate_memtags (struct value
*value
)
1274 gdb_assert (value
!= nullptr && value
->type () != nullptr);
1276 if (!target_supports_memory_tagging ())
1279 enum type_code code
= value
->type ()->code ();
1281 /* Skip non-address values. */
1282 if (code
!= TYPE_CODE_PTR
1283 && !TYPE_IS_REFERENCE (value
->type ()))
1286 /* OK, we have an address value. Check we have a complete value we
1288 if (value
->optimized_out ()
1289 || !value
->entirely_available ())
1292 /* We do. Check whether it includes any tags. */
1293 return gdbarch_tagged_address_p (current_inferior ()->arch (), value
);
1296 /* Helper for parsing arguments for print_command_1. */
1298 static struct value
*
1299 process_print_command_args (const char *args
, value_print_options
*print_opts
,
1302 get_user_print_options (print_opts
);
1303 /* Override global settings with explicit options, if any. */
1304 auto group
= make_value_print_options_def_group (print_opts
);
1305 gdb::option::process_options
1306 (&args
, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER
, group
);
1308 print_command_parse_format (&args
, "print", print_opts
);
1310 const char *exp
= args
;
1312 if (exp
!= nullptr && *exp
)
1314 /* This setting allows large arrays to be printed by limiting the
1315 number of elements that are loaded into GDB's memory; we only
1316 need to load as many array elements as we plan to print. */
1317 scoped_array_length_limiting
limit_large_arrays (print_opts
->print_max
);
1319 /* VOIDPRINT is true to indicate that we do want to print a void
1320 value, so invert it for parse_expression. */
1321 parser_flags flags
= 0;
1323 flags
= PARSER_VOID_CONTEXT
;
1324 expression_up expr
= parse_expression (exp
, nullptr, flags
);
1325 return expr
->evaluate ();
1328 return access_value_history (0);
1331 /* Implementation of the "print" and "call" commands. */
1334 print_command_1 (const char *args
, int voidprint
)
1336 value_print_options print_opts
;
1338 struct value
*val
= process_print_command_args (args
, &print_opts
, voidprint
);
1340 if (voidprint
|| (val
&& val
->type () &&
1341 val
->type ()->code () != TYPE_CODE_VOID
))
1343 /* If memory tagging validation is on, check if the tag is valid. */
1344 if (print_opts
.memory_tag_violations
)
1348 gdbarch
*arch
= current_inferior ()->arch ();
1350 if (should_validate_memtags (val
)
1351 && !gdbarch_memtag_matches_p (arch
, val
))
1353 /* Fetch the logical tag. */
1355 = gdbarch_get_memtag (arch
, val
, memtag_type::logical
);
1356 std::string ltag
= gdbarch_memtag_to_string (arch
, tag
);
1358 /* Fetch the allocation tag. */
1359 tag
= gdbarch_get_memtag (arch
, val
,
1360 memtag_type::allocation
);
1361 std::string atag
= gdbarch_memtag_to_string (arch
, tag
);
1363 gdb_printf (_("Logical tag (%s) does not match the "
1364 "allocation tag (%s).\n"),
1365 ltag
.c_str (), atag
.c_str ());
1368 catch (gdb_exception_error
&ex
)
1370 if (ex
.error
== TARGET_CLOSE_ERROR
)
1373 gdb_printf (gdb_stderr
,
1374 _("Could not validate memory tag: %s\n"),
1375 ex
.message
->c_str ());
1379 print_value (val
, print_opts
);
1383 /* See valprint.h. */
1386 print_command_completer (struct cmd_list_element
*ignore
,
1387 completion_tracker
&tracker
,
1388 const char *text
, const char * /*word*/)
1390 const auto group
= make_value_print_options_def_group (nullptr);
1391 if (gdb::option::complete_options
1392 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER
, group
))
1395 if (skip_over_slash_fmt (tracker
, &text
))
1398 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1399 expression_completer (ignore
, tracker
, text
, word
);
1403 print_command (const char *exp
, int from_tty
)
1405 print_command_1 (exp
, true);
1408 /* Same as print, except it doesn't print void results. */
1410 call_command (const char *exp
, int from_tty
)
1412 print_command_1 (exp
, false);
1415 /* Implementation of the "output" command. */
1418 output_command (const char *exp
, int from_tty
)
1422 struct format_data fmt
;
1423 struct value_print_options opts
;
1428 if (exp
&& *exp
== '/')
1431 fmt
= decode_format (&exp
, 0, 0);
1432 validate_format (fmt
, "output");
1433 format
= fmt
.format
;
1436 expression_up expr
= parse_expression (exp
);
1438 val
= expr
->evaluate ();
1440 annotate_value_begin (val
->type ());
1442 get_formatted_print_options (&opts
, format
);
1445 /* This setting allows large arrays to be printed by limiting the
1446 number of elements that are loaded into GDB's memory; we only
1447 need to load as many array elements as we plan to print. */
1448 scoped_array_length_limiting
limit_large_arrays (opts
.print_max
);
1450 print_formatted (val
, fmt
.size
, &opts
, gdb_stdout
);
1452 annotate_value_end ();
1454 gdb_flush (gdb_stdout
);
1458 set_command (const char *exp
, int from_tty
)
1460 expression_up expr
= parse_expression (exp
);
1462 switch (expr
->first_opcode ())
1464 case UNOP_PREINCREMENT
:
1465 case UNOP_POSTINCREMENT
:
1466 case UNOP_PREDECREMENT
:
1467 case UNOP_POSTDECREMENT
:
1469 case BINOP_ASSIGN_MODIFY
:
1474 (_("Expression is not an assignment (and might have no effect)"));
1481 info_symbol_command (const char *arg
, int from_tty
)
1483 struct minimal_symbol
*msymbol
;
1484 CORE_ADDR addr
, sect_addr
;
1486 unsigned int offset
;
1489 error_no_arg (_("address"));
1491 addr
= parse_and_eval_address (arg
);
1492 for (objfile
*objfile
: current_program_space
->objfiles ())
1493 for (obj_section
*osect
: objfile
->sections ())
1495 /* Only process each object file once, even if there's a separate
1497 if (objfile
->separate_debug_objfile_backlink
)
1500 sect_addr
= overlay_mapped_address (addr
, osect
);
1502 if (osect
->addr () <= sect_addr
&& sect_addr
< osect
->endaddr ()
1504 = lookup_minimal_symbol_by_pc_section (sect_addr
,
1507 const char *obj_name
, *mapped
, *sec_name
, *msym_name
;
1508 const char *loc_string
;
1511 offset
= sect_addr
- msymbol
->value_address (objfile
);
1512 mapped
= section_is_mapped (osect
) ? _("mapped") : _("unmapped");
1513 sec_name
= osect
->the_bfd_section
->name
;
1514 msym_name
= msymbol
->print_name ();
1516 /* Don't print the offset if it is zero.
1517 We assume there's no need to handle i18n of "sym + offset". */
1518 std::string string_holder
;
1521 string_holder
= string_printf ("%s + %u", msym_name
, offset
);
1522 loc_string
= string_holder
.c_str ();
1525 loc_string
= msym_name
;
1527 gdb_assert (osect
->objfile
&& objfile_name (osect
->objfile
));
1528 obj_name
= objfile_name (osect
->objfile
);
1530 if (current_program_space
->multi_objfile_p ())
1531 if (pc_in_unmapped_range (addr
, osect
))
1532 if (section_is_overlay (osect
))
1533 gdb_printf (_("%s in load address range of "
1534 "%s overlay section %s of %s\n"),
1535 loc_string
, mapped
, sec_name
, obj_name
);
1537 gdb_printf (_("%s in load address range of "
1538 "section %s of %s\n"),
1539 loc_string
, sec_name
, obj_name
);
1541 if (section_is_overlay (osect
))
1542 gdb_printf (_("%s in %s overlay section %s of %s\n"),
1543 loc_string
, mapped
, sec_name
, obj_name
);
1545 gdb_printf (_("%s in section %s of %s\n"),
1546 loc_string
, sec_name
, obj_name
);
1548 if (pc_in_unmapped_range (addr
, osect
))
1549 if (section_is_overlay (osect
))
1550 gdb_printf (_("%s in load address range of %s overlay "
1552 loc_string
, mapped
, sec_name
);
1555 (_("%s in load address range of section %s\n"),
1556 loc_string
, sec_name
);
1558 if (section_is_overlay (osect
))
1559 gdb_printf (_("%s in %s overlay section %s\n"),
1560 loc_string
, mapped
, sec_name
);
1562 gdb_printf (_("%s in section %s\n"),
1563 loc_string
, sec_name
);
1567 gdb_printf (_("No symbol matches %s.\n"), arg
);
1571 info_address_command (const char *exp
, int from_tty
)
1573 struct gdbarch
*gdbarch
;
1576 struct bound_minimal_symbol msymbol
;
1578 struct obj_section
*section
;
1579 CORE_ADDR load_addr
, context_pc
= 0;
1580 struct field_of_this_result is_a_field_of_this
;
1583 error (_("Argument required."));
1585 sym
= lookup_symbol (exp
, get_selected_block (&context_pc
), VAR_DOMAIN
,
1586 &is_a_field_of_this
).symbol
;
1589 if (is_a_field_of_this
.type
!= NULL
)
1591 gdb_printf ("Symbol \"");
1592 fprintf_symbol (gdb_stdout
, exp
,
1593 current_language
->la_language
, DMGL_ANSI
);
1594 gdb_printf ("\" is a field of the local class variable ");
1595 if (current_language
->la_language
== language_objc
)
1596 gdb_printf ("`self'\n"); /* ObjC equivalent of "this" */
1598 gdb_printf ("`this'\n");
1602 msymbol
= lookup_bound_minimal_symbol (exp
);
1604 if (msymbol
.minsym
!= NULL
)
1606 struct objfile
*objfile
= msymbol
.objfile
;
1608 gdbarch
= objfile
->arch ();
1609 load_addr
= msymbol
.value_address ();
1611 gdb_printf ("Symbol \"");
1612 fprintf_symbol (gdb_stdout
, exp
,
1613 current_language
->la_language
, DMGL_ANSI
);
1614 gdb_printf ("\" is at ");
1615 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1617 gdb_printf (" in a file compiled without debugging");
1618 section
= msymbol
.minsym
->obj_section (objfile
);
1619 if (section_is_overlay (section
))
1621 load_addr
= overlay_unmapped_address (load_addr
, section
);
1622 gdb_printf (",\n -- loaded at ");
1623 fputs_styled (paddress (gdbarch
, load_addr
),
1624 address_style
.style (),
1626 gdb_printf (" in overlay section %s",
1627 section
->the_bfd_section
->name
);
1632 error (_("No symbol \"%s\" in current context."), exp
);
1636 gdb_printf ("Symbol \"");
1637 gdb_puts (sym
->print_name ());
1638 gdb_printf ("\" is ");
1639 val
= sym
->value_longest ();
1640 if (sym
->is_objfile_owned ())
1641 section
= sym
->obj_section (sym
->objfile ());
1644 gdbarch
= sym
->arch ();
1646 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
1648 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, context_pc
,
1654 switch (sym
->aclass ())
1657 case LOC_CONST_BYTES
:
1658 gdb_printf ("constant");
1662 gdb_printf ("a label at address ");
1663 load_addr
= sym
->value_address ();
1664 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1666 if (section_is_overlay (section
))
1668 load_addr
= overlay_unmapped_address (load_addr
, section
);
1669 gdb_printf (",\n -- loaded at ");
1670 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1672 gdb_printf (" in overlay section %s",
1673 section
->the_bfd_section
->name
);
1678 gdb_assert_not_reached ("LOC_COMPUTED variable missing a method");
1681 /* GDBARCH is the architecture associated with the objfile the symbol
1682 is defined in; the target architecture may be different, and may
1683 provide additional registers. However, we do not know the target
1684 architecture at this point. We assume the objfile architecture
1685 will contain all the standard registers that occur in debug info
1687 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1689 if (sym
->is_argument ())
1690 gdb_printf (_("an argument in register %s"),
1691 gdbarch_register_name (gdbarch
, regno
));
1693 gdb_printf (_("a variable in register %s"),
1694 gdbarch_register_name (gdbarch
, regno
));
1698 gdb_printf (_("static storage at address "));
1699 load_addr
= sym
->value_address ();
1700 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1702 if (section_is_overlay (section
))
1704 load_addr
= overlay_unmapped_address (load_addr
, section
);
1705 gdb_printf (_(",\n -- loaded at "));
1706 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1708 gdb_printf (_(" in overlay section %s"),
1709 section
->the_bfd_section
->name
);
1713 case LOC_REGPARM_ADDR
:
1714 /* Note comment at LOC_REGISTER. */
1715 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1716 gdb_printf (_("address of an argument in register %s"),
1717 gdbarch_register_name (gdbarch
, regno
));
1721 gdb_printf (_("an argument at offset %ld"), val
);
1725 gdb_printf (_("a local variable at frame offset %ld"), val
);
1729 gdb_printf (_("a reference argument at offset %ld"), val
);
1733 gdb_printf (_("a typedef"));
1737 gdb_printf (_("a function at address "));
1738 load_addr
= sym
->value_block ()->entry_pc ();
1739 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1741 if (section_is_overlay (section
))
1743 load_addr
= overlay_unmapped_address (load_addr
, section
);
1744 gdb_printf (_(",\n -- loaded at "));
1745 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1747 gdb_printf (_(" in overlay section %s"),
1748 section
->the_bfd_section
->name
);
1752 case LOC_UNRESOLVED
:
1754 struct bound_minimal_symbol msym
;
1756 msym
= lookup_bound_minimal_symbol (sym
->linkage_name ());
1757 if (msym
.minsym
== NULL
)
1758 gdb_printf ("unresolved");
1761 section
= msym
.obj_section ();
1764 && (section
->the_bfd_section
->flags
& SEC_THREAD_LOCAL
) != 0)
1766 load_addr
= CORE_ADDR (msym
.minsym
->unrelocated_address ());
1767 gdb_printf (_("a thread-local variable at offset %s "
1768 "in the thread-local storage for `%s'"),
1769 paddress (gdbarch
, load_addr
),
1770 objfile_name (section
->objfile
));
1774 load_addr
= msym
.value_address ();
1775 gdb_printf (_("static storage at address "));
1776 fputs_styled (paddress (gdbarch
, load_addr
),
1777 address_style
.style (), gdb_stdout
);
1778 if (section_is_overlay (section
))
1780 load_addr
= overlay_unmapped_address (load_addr
, section
);
1781 gdb_printf (_(",\n -- loaded at "));
1782 fputs_styled (paddress (gdbarch
, load_addr
),
1783 address_style
.style (),
1785 gdb_printf (_(" in overlay section %s"),
1786 section
->the_bfd_section
->name
);
1793 case LOC_OPTIMIZED_OUT
:
1794 gdb_printf (_("optimized out"));
1798 gdb_printf (_("of unknown (botched) type"));
1806 x_command (const char *exp
, int from_tty
)
1808 struct format_data fmt
;
1811 fmt
.format
= last_format
? last_format
: 'x';
1812 fmt
.print_tags
= last_print_tags
;
1813 fmt
.size
= last_size
;
1817 /* If there is no expression and no format, use the most recent
1819 if (exp
== nullptr && last_count
> 0)
1820 fmt
.count
= last_count
;
1822 if (exp
&& *exp
== '/')
1824 const char *tmp
= exp
+ 1;
1826 fmt
= decode_format (&tmp
, last_format
, last_size
);
1830 last_count
= fmt
.count
;
1832 /* If we have an expression, evaluate it and use it as the address. */
1834 if (exp
!= 0 && *exp
!= 0)
1836 expression_up expr
= parse_expression (exp
);
1837 /* Cause expression not to be there any more if this command is
1838 repeated with Newline. But don't clobber a user-defined
1839 command's definition. */
1841 set_repeat_arguments ("");
1842 val
= expr
->evaluate ();
1843 if (TYPE_IS_REFERENCE (val
->type ()))
1844 val
= coerce_ref (val
);
1845 /* In rvalue contexts, such as this, functions are coerced into
1846 pointers to functions. This makes "x/i main" work. */
1847 if (val
->type ()->code () == TYPE_CODE_FUNC
1848 && val
->lval () == lval_memory
)
1849 next_address
= val
->address ();
1851 next_address
= value_as_address (val
);
1853 next_gdbarch
= expr
->gdbarch
;
1857 error_no_arg (_("starting display address"));
1859 do_examine (fmt
, next_gdbarch
, next_address
);
1861 /* If the examine succeeds, we remember its size and format for next
1862 time. Set last_size to 'b' for strings. */
1863 if (fmt
.format
== 's')
1866 last_size
= fmt
.size
;
1867 last_format
= fmt
.format
;
1869 /* Remember tag-printing setting. */
1870 last_print_tags
= fmt
.print_tags
;
1872 /* Set a couple of internal variables if appropriate. */
1873 if (last_examine_value
!= nullptr)
1875 /* Make last address examined available to the user as $_. Use
1876 the correct pointer type. */
1877 struct type
*pointer_type
1878 = lookup_pointer_type (last_examine_value
->type ());
1879 set_internalvar (lookup_internalvar ("_"),
1880 value_from_pointer (pointer_type
,
1881 last_examine_address
));
1883 /* Make contents of last address examined available to the user
1884 as $__. If the last value has not been fetched from memory
1885 then don't fetch it now; instead mark it by voiding the $__
1887 if (last_examine_value
->lazy ())
1888 clear_internalvar (lookup_internalvar ("__"));
1890 set_internalvar (lookup_internalvar ("__"), last_examine_value
.get ());
1894 /* Command completion for the 'display' and 'x' commands. */
1897 display_and_x_command_completer (struct cmd_list_element
*ignore
,
1898 completion_tracker
&tracker
,
1899 const char *text
, const char * /*word*/)
1901 if (skip_over_slash_fmt (tracker
, &text
))
1904 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1905 expression_completer (ignore
, tracker
, text
, word
);
1910 /* Add an expression to the auto-display chain.
1911 Specify the expression. */
1914 display_command (const char *arg
, int from_tty
)
1916 struct format_data fmt
;
1917 struct display
*newobj
;
1918 const char *exp
= arg
;
1929 fmt
= decode_format (&exp
, 0, 0);
1930 if (fmt
.size
&& fmt
.format
== 0)
1932 if (fmt
.format
== 'i' || fmt
.format
== 's')
1943 innermost_block_tracker tracker
;
1944 expression_up expr
= parse_expression (exp
, &tracker
);
1946 newobj
= new display (exp
, std::move (expr
), fmt
,
1947 current_program_space
, tracker
.block ());
1948 all_displays
.emplace_back (newobj
);
1951 do_one_display (newobj
);
1956 /* Clear out the display_chain. Done when new symtabs are loaded,
1957 since this invalidates the types stored in many expressions. */
1962 all_displays
.clear ();
1965 /* Delete the auto-display DISPLAY. */
1968 delete_display (struct display
*display
)
1970 gdb_assert (display
!= NULL
);
1972 auto iter
= std::find_if (all_displays
.begin (),
1973 all_displays
.end (),
1974 [=] (const std::unique_ptr
<struct display
> &item
)
1976 return item
.get () == display
;
1978 gdb_assert (iter
!= all_displays
.end ());
1979 all_displays
.erase (iter
);
1982 /* Call FUNCTION on each of the displays whose numbers are given in
1983 ARGS. DATA is passed unmodified to FUNCTION. */
1986 map_display_numbers (const char *args
,
1987 gdb::function_view
<void (struct display
*)> function
)
1992 error_no_arg (_("one or more display numbers"));
1994 number_or_range_parser
parser (args
);
1996 while (!parser
.finished ())
1998 const char *p
= parser
.cur_tok ();
2000 num
= parser
.get_number ();
2002 warning (_("bad display number at or near '%s'"), p
);
2005 auto iter
= std::find_if (all_displays
.begin (),
2006 all_displays
.end (),
2007 [=] (const std::unique_ptr
<display
> &item
)
2009 return item
->number
== num
;
2011 if (iter
== all_displays
.end ())
2012 gdb_printf (_("No display number %d.\n"), num
);
2014 function (iter
->get ());
2019 /* "undisplay" command. */
2022 undisplay_command (const char *args
, int from_tty
)
2026 if (query (_("Delete all auto-display expressions? ")))
2032 map_display_numbers (args
, delete_display
);
2036 /* Display a single auto-display.
2037 Do nothing if the display cannot be printed in the current context,
2038 or if the display is disabled. */
2041 do_one_display (struct display
*d
)
2043 int within_current_scope
;
2048 /* The expression carries the architecture that was used at parse time.
2049 This is a problem if the expression depends on architecture features
2050 (e.g. register numbers), and the current architecture is now different.
2051 For example, a display statement like "display/i $pc" is expected to
2052 display the PC register of the current architecture, not the arch at
2053 the time the display command was given. Therefore, we re-parse the
2054 expression if the current architecture has changed. */
2055 if (d
->exp
!= NULL
&& d
->exp
->gdbarch
!= get_current_arch ())
2066 innermost_block_tracker tracker
;
2067 d
->exp
= parse_expression (d
->exp_string
.c_str (), &tracker
);
2068 d
->block
= tracker
.block ();
2070 catch (const gdb_exception_error
&ex
)
2072 /* Can't re-parse the expression. Disable this display item. */
2073 d
->enabled_p
= false;
2074 warning (_("Unable to display \"%s\": %s"),
2075 d
->exp_string
.c_str (), ex
.what ());
2082 if (d
->pspace
== current_program_space
)
2083 within_current_scope
= d
->block
->contains (get_selected_block (0),
2086 within_current_scope
= 0;
2089 within_current_scope
= 1;
2090 if (!within_current_scope
)
2093 scoped_restore save_display_number
2094 = make_scoped_restore (¤t_display_number
, d
->number
);
2096 annotate_display_begin ();
2097 gdb_printf ("%d", d
->number
);
2098 annotate_display_number_end ();
2103 annotate_display_format ();
2106 if (d
->format
.count
!= 1)
2107 gdb_printf ("%d", d
->format
.count
);
2108 gdb_printf ("%c", d
->format
.format
);
2109 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
2110 gdb_printf ("%c", d
->format
.size
);
2113 annotate_display_expression ();
2115 gdb_puts (d
->exp_string
.c_str ());
2116 annotate_display_expression_end ();
2118 if (d
->format
.count
!= 1 || d
->format
.format
== 'i')
2123 annotate_display_value ();
2130 val
= d
->exp
->evaluate ();
2131 addr
= value_as_address (val
);
2132 if (d
->format
.format
== 'i')
2133 addr
= gdbarch_addr_bits_remove (d
->exp
->gdbarch
, addr
);
2134 do_examine (d
->format
, d
->exp
->gdbarch
, addr
);
2136 catch (const gdb_exception_error
&ex
)
2138 gdb_printf (_("%p[<error: %s>%p]\n"),
2139 metadata_style
.style ().ptr (), ex
.what (),
2145 struct value_print_options opts
;
2147 annotate_display_format ();
2149 if (d
->format
.format
)
2150 gdb_printf ("/%c ", d
->format
.format
);
2152 annotate_display_expression ();
2154 gdb_puts (d
->exp_string
.c_str ());
2155 annotate_display_expression_end ();
2159 annotate_display_expression ();
2161 get_formatted_print_options (&opts
, d
->format
.format
);
2162 opts
.raw
= d
->format
.raw
;
2168 val
= d
->exp
->evaluate ();
2169 print_formatted (val
, d
->format
.size
, &opts
, gdb_stdout
);
2171 catch (const gdb_exception_error
&ex
)
2173 fprintf_styled (gdb_stdout
, metadata_style
.style (),
2174 _("<error: %s>"), ex
.what ());
2180 annotate_display_end ();
2182 gdb_flush (gdb_stdout
);
2185 /* Display all of the values on the auto-display chain which can be
2186 evaluated in the current scope. */
2191 for (auto &d
: all_displays
)
2192 do_one_display (d
.get ());
2195 /* Delete the auto-display which we were in the process of displaying.
2196 This is done when there is an error or a signal. */
2199 disable_display (int num
)
2201 for (auto &d
: all_displays
)
2202 if (d
->number
== num
)
2204 d
->enabled_p
= false;
2207 gdb_printf (_("No display number %d.\n"), num
);
2211 disable_current_display (void)
2213 if (current_display_number
>= 0)
2215 disable_display (current_display_number
);
2216 gdb_printf (gdb_stderr
,
2217 _("Disabling display %d to "
2218 "avoid infinite recursion.\n"),
2219 current_display_number
);
2221 current_display_number
= -1;
2225 info_display_command (const char *ignore
, int from_tty
)
2227 if (all_displays
.empty ())
2228 gdb_printf (_("There are no auto-display expressions now.\n"));
2230 gdb_printf (_("Auto-display expressions now in effect:\n\
2231 Num Enb Expression\n"));
2233 for (auto &d
: all_displays
)
2235 gdb_printf ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
2237 gdb_printf ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
2239 else if (d
->format
.format
)
2240 gdb_printf ("/%c ", d
->format
.format
);
2241 gdb_puts (d
->exp_string
.c_str ());
2242 if (d
->block
&& !d
->block
->contains (get_selected_block (0), true))
2243 gdb_printf (_(" (cannot be evaluated in the current context)"));
2248 /* Implementation of both the "disable display" and "enable display"
2249 commands. ENABLE decides what to do. */
2252 enable_disable_display_command (const char *args
, int from_tty
, bool enable
)
2256 for (auto &d
: all_displays
)
2257 d
->enabled_p
= enable
;
2261 map_display_numbers (args
,
2262 [=] (struct display
*d
)
2264 d
->enabled_p
= enable
;
2268 /* The "enable display" command. */
2271 enable_display_command (const char *args
, int from_tty
)
2273 enable_disable_display_command (args
, from_tty
, true);
2276 /* The "disable display" command. */
2279 disable_display_command (const char *args
, int from_tty
)
2281 enable_disable_display_command (args
, from_tty
, false);
2284 /* display_chain items point to blocks and expressions. Some expressions in
2285 turn may point to symbols.
2286 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
2287 obstack_free'd when a shared library is unloaded.
2288 Clear pointers that are about to become dangling.
2289 Both .exp and .block fields will be restored next time we need to display
2290 an item by re-parsing .exp_string field in the new execution context. */
2293 clear_dangling_display_expressions (struct objfile
*objfile
)
2295 program_space
*pspace
= objfile
->pspace
;
2296 if (objfile
->separate_debug_objfile_backlink
)
2298 objfile
= objfile
->separate_debug_objfile_backlink
;
2299 gdb_assert (objfile
->pspace
== pspace
);
2302 for (auto &d
: all_displays
)
2304 if (d
->pspace
!= pspace
)
2307 struct objfile
*bl_objf
= nullptr;
2308 if (d
->block
!= nullptr)
2310 bl_objf
= d
->block
->objfile ();
2311 if (bl_objf
->separate_debug_objfile_backlink
!= nullptr)
2312 bl_objf
= bl_objf
->separate_debug_objfile_backlink
;
2315 if (bl_objf
== objfile
2316 || (d
->exp
!= nullptr && d
->exp
->uses_objfile (objfile
)))
2325 /* Print the value in stack frame FRAME of a variable specified by a
2326 struct symbol. NAME is the name to print; if NULL then VAR's print
2327 name will be used. STREAM is the ui_file on which to print the
2328 value. INDENT specifies the number of indent levels to print
2329 before printing the variable name. */
2332 print_variable_and_value (const char *name
, struct symbol
*var
,
2333 frame_info_ptr frame
,
2334 struct ui_file
*stream
, int indent
)
2338 name
= var
->print_name ();
2340 gdb_printf (stream
, "%*s%ps = ", 2 * indent
, "",
2341 styled_string (variable_name_style
.style (), name
));
2346 struct value_print_options opts
;
2348 /* READ_VAR_VALUE needs a block in order to deal with non-local
2349 references (i.e. to handle nested functions). In this context, we
2350 print variables that are local to this frame, so we can avoid passing
2352 val
= read_var_value (var
, NULL
, frame
);
2353 get_user_print_options (&opts
);
2354 opts
.deref_ref
= true;
2355 common_val_print_checked (val
, stream
, indent
, &opts
, current_language
);
2357 catch (const gdb_exception_error
&except
)
2359 fprintf_styled (stream
, metadata_style
.style (),
2360 "<error reading variable %s (%s)>", name
,
2364 gdb_printf (stream
, "\n");
2367 /* Subroutine of ui_printf to simplify it.
2368 Print VALUE to STREAM using FORMAT.
2369 VALUE is a C-style string either on the target or
2370 in a GDB internal variable. */
2373 printf_c_string (struct ui_file
*stream
, const char *format
,
2374 struct value
*value
)
2376 gdb::byte_vector str
;
2378 if (((value
->type ()->code () != TYPE_CODE_PTR
&& value
->lval () == lval_internalvar
)
2379 || value
->type ()->code () == TYPE_CODE_ARRAY
)
2380 && c_is_string_type_p (value
->type ()))
2382 size_t len
= value
->type ()->length ();
2384 /* Copy the internal var value to TEM_STR and append a terminating null
2385 character. This protects against corrupted C-style strings that lack
2386 the terminating null char. It also allows Ada-style strings (not
2387 null terminated) to be printed without problems. */
2388 str
.resize (len
+ 1);
2390 memcpy (str
.data (), value
->contents ().data (), len
);
2395 CORE_ADDR tem
= value_as_address (value
);;
2400 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2401 gdb_printf (stream
, format
, "(null)");
2406 /* This is a %s argument. Build the string in STR which is
2408 gdb_assert (str
.size () == 0);
2410 for (len
= 0;; len
++)
2416 read_memory (tem
+ len
, &c
, 1);
2417 if (!exceeds_max_value_size (len
+ 1))
2423 if (exceeds_max_value_size (len
+ 1))
2424 error (_("printed string requires %s bytes, which is more than "
2425 "max-value-size"), plongest (len
+ 1));
2427 /* We will have passed through the above loop at least once, and will
2428 only exit the loop when we have pushed a zero byte onto the end of
2430 gdb_assert (str
.size () > 0);
2431 gdb_assert (str
.back () == 0);
2435 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2436 gdb_printf (stream
, format
, (char *) str
.data ());
2440 /* Subroutine of ui_printf to simplify it.
2441 Print VALUE to STREAM using FORMAT.
2442 VALUE is a wide C-style string on the target or
2443 in a GDB internal variable. */
2446 printf_wide_c_string (struct ui_file
*stream
, const char *format
,
2447 struct value
*value
)
2449 const gdb_byte
*str
;
2451 struct gdbarch
*gdbarch
= value
->type ()->arch ();
2452 struct type
*wctype
= lookup_typename (current_language
,
2453 "wchar_t", NULL
, 0);
2454 int wcwidth
= wctype
->length ();
2455 std::optional
<gdb::byte_vector
> tem_str
;
2457 if (value
->lval () == lval_internalvar
2458 && c_is_string_type_p (value
->type ()))
2460 str
= value
->contents ().data ();
2461 len
= value
->type ()->length ();
2465 CORE_ADDR tem
= value_as_address (value
);
2470 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2471 gdb_printf (stream
, format
, "(null)");
2476 /* This is a %s argument. Find the length of the string. */
2477 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2480 for (len
= 0;; len
+= wcwidth
)
2484 if (!exceeds_max_value_size (len
+ wcwidth
))
2486 tem_str
->resize (tem_str
->size () + wcwidth
);
2487 dst
= tem_str
->data () + len
;
2491 /* We still need to check for the null-character, so we need
2492 somewhere to place the data read from the inferior. We
2493 can't keep growing TEM_STR, it's gotten too big, so
2494 instead just read the new character into the start of
2495 TEMS_STR. This will corrupt the previously read contents,
2496 but we're not going to print this string anyway, we just
2497 want to know how big it would have been so we can tell the
2498 user in the error message (see below).
2500 And we know there will be space in this buffer so long as
2501 WCWIDTH is smaller than our LONGEST type, the
2502 max-value-size can't be smaller than a LONGEST. */
2503 dst
= tem_str
->data ();
2505 read_memory (tem
+ len
, dst
, wcwidth
);
2506 if (extract_unsigned_integer (dst
, wcwidth
, byte_order
) == 0)
2510 if (exceeds_max_value_size (len
+ wcwidth
))
2511 error (_("printed string requires %s bytes, which is more than "
2512 "max-value-size"), plongest (len
+ wcwidth
));
2514 str
= tem_str
->data ();
2517 auto_obstack output
;
2519 convert_between_encodings (target_wide_charset (gdbarch
),
2522 &output
, translit_char
);
2523 obstack_grow_str0 (&output
, "");
2526 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2527 gdb_printf (stream
, format
, obstack_base (&output
));
2531 /* Subroutine of ui_printf to simplify it.
2532 Print VALUE, a floating point value, to STREAM using FORMAT. */
2535 printf_floating (struct ui_file
*stream
, const char *format
,
2536 struct value
*value
, enum argclass argclass
)
2538 /* Parameter data. */
2539 struct type
*param_type
= value
->type ();
2540 struct gdbarch
*gdbarch
= param_type
->arch ();
2542 /* Determine target type corresponding to the format string. */
2543 struct type
*fmt_type
;
2547 fmt_type
= builtin_type (gdbarch
)->builtin_double
;
2549 case long_double_arg
:
2550 fmt_type
= builtin_type (gdbarch
)->builtin_long_double
;
2552 case dec32float_arg
:
2553 fmt_type
= builtin_type (gdbarch
)->builtin_decfloat
;
2555 case dec64float_arg
:
2556 fmt_type
= builtin_type (gdbarch
)->builtin_decdouble
;
2558 case dec128float_arg
:
2559 fmt_type
= builtin_type (gdbarch
)->builtin_declong
;
2562 gdb_assert_not_reached ("unexpected argument class");
2565 /* To match the traditional GDB behavior, the conversion is
2566 done differently depending on the type of the parameter:
2568 - if the parameter has floating-point type, it's value
2569 is converted to the target type;
2571 - otherwise, if the parameter has a type that is of the
2572 same size as a built-in floating-point type, the value
2573 bytes are interpreted as if they were of that type, and
2574 then converted to the target type (this is not done for
2575 decimal floating-point argument classes);
2577 - otherwise, if the source value has an integer value,
2578 it's value is converted to the target type;
2580 - otherwise, an error is raised.
2582 In either case, the result of the conversion is a byte buffer
2583 formatted in the target format for the target type. */
2585 if (fmt_type
->code () == TYPE_CODE_FLT
)
2587 param_type
= float_type_from_length (param_type
);
2588 if (param_type
!= value
->type ())
2589 value
= value_from_contents (param_type
,
2590 value
->contents ().data ());
2593 value
= value_cast (fmt_type
, value
);
2595 /* Convert the value to a string and print it. */
2597 = target_float_to_string (value
->contents ().data (), fmt_type
, format
);
2598 gdb_puts (str
.c_str (), stream
);
2601 /* Subroutine of ui_printf to simplify it.
2602 Print VALUE, a target pointer, to STREAM using FORMAT. */
2605 printf_pointer (struct ui_file
*stream
, const char *format
,
2606 struct value
*value
)
2608 /* We avoid the host's %p because pointers are too
2609 likely to be the wrong size. The only interesting
2610 modifier for %p is a width; extract that, and then
2611 handle %p as glibc would: %#x or a literal "(nil)". */
2613 #ifdef PRINTF_HAS_LONG_LONG
2614 long long val
= value_as_long (value
);
2616 long val
= value_as_long (value
);
2619 /* Build the new output format in FMT. */
2622 /* Copy up to the leading %. */
2623 const char *p
= format
;
2626 int is_percent
= (*p
== '%');
2628 fmt
.push_back (*p
++);
2632 fmt
.push_back (*p
++);
2639 fmt
.push_back ('#');
2641 /* Copy any width or flags. Only the "-" flag is valid for pointers
2642 -- see the format_pieces constructor. */
2643 while (*p
== '-' || (*p
>= '0' && *p
< '9'))
2644 fmt
.push_back (*p
++);
2646 gdb_assert (*p
== 'p' && *(p
+ 1) == '\0');
2649 #ifdef PRINTF_HAS_LONG_LONG
2650 fmt
.push_back ('l');
2652 fmt
.push_back ('l');
2653 fmt
.push_back ('x');
2655 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2656 gdb_printf (stream
, fmt
.c_str (), val
);
2661 fmt
.push_back ('s');
2663 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2664 gdb_printf (stream
, fmt
.c_str (), "(nil)");
2669 /* printf "printf format string" ARG to STREAM. */
2672 ui_printf (const char *arg
, struct ui_file
*stream
)
2674 const char *s
= arg
;
2675 std::vector
<struct value
*> val_args
;
2678 error_no_arg (_("format-control string and values to print"));
2680 s
= skip_spaces (s
);
2682 /* A format string should follow, enveloped in double quotes. */
2684 error (_("Bad format string, missing '\"'."));
2686 format_pieces
fpieces (&s
, false, true);
2689 error (_("Bad format string, non-terminated '\"'."));
2691 s
= skip_spaces (s
);
2693 if (*s
!= ',' && *s
!= 0)
2694 error (_("Invalid argument syntax"));
2698 s
= skip_spaces (s
);
2703 const char *current_substring
;
2706 for (auto &&piece
: fpieces
)
2707 if (piece
.argclass
!= literal_piece
)
2710 /* Now, parse all arguments and evaluate them.
2711 Store the VALUEs in VAL_ARGS. */
2718 val_args
.push_back (parse_to_comma_and_eval (&s1
));
2725 if (val_args
.size () != nargs_wanted
)
2726 error (_("Wrong number of arguments for specified format-string"));
2728 /* Now actually print them. */
2730 for (auto &&piece
: fpieces
)
2732 current_substring
= piece
.string
;
2733 switch (piece
.argclass
)
2736 printf_c_string (stream
, current_substring
, val_args
[i
]);
2738 case wide_string_arg
:
2739 printf_wide_c_string (stream
, current_substring
, val_args
[i
]);
2743 struct gdbarch
*gdbarch
= val_args
[i
]->type ()->arch ();
2744 struct type
*wctype
= lookup_typename (current_language
,
2745 "wchar_t", NULL
, 0);
2746 struct type
*valtype
;
2747 const gdb_byte
*bytes
;
2749 valtype
= val_args
[i
]->type ();
2750 if (valtype
->length () != wctype
->length ()
2751 || valtype
->code () != TYPE_CODE_INT
)
2752 error (_("expected wchar_t argument for %%lc"));
2754 bytes
= val_args
[i
]->contents ().data ();
2756 auto_obstack output
;
2758 convert_between_encodings (target_wide_charset (gdbarch
),
2760 bytes
, valtype
->length (),
2762 &output
, translit_char
);
2763 obstack_grow_str0 (&output
, "");
2766 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2767 gdb_printf (stream
, current_substring
,
2768 obstack_base (&output
));
2773 #ifdef PRINTF_HAS_LONG_LONG
2775 long long val
= value_as_long (val_args
[i
]);
2778 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2779 gdb_printf (stream
, current_substring
, val
);
2784 error (_("long long not supported in printf"));
2788 int val
= value_as_long (val_args
[i
]);
2791 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2792 gdb_printf (stream
, current_substring
, val
);
2798 long val
= value_as_long (val_args
[i
]);
2801 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2802 gdb_printf (stream
, current_substring
, val
);
2808 size_t val
= value_as_long (val_args
[i
]);
2811 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2812 gdb_printf (stream
, current_substring
, val
);
2816 /* Handles floating-point values. */
2818 case long_double_arg
:
2819 case dec32float_arg
:
2820 case dec64float_arg
:
2821 case dec128float_arg
:
2822 printf_floating (stream
, current_substring
, val_args
[i
],
2826 printf_pointer (stream
, current_substring
, val_args
[i
]);
2830 value_print_options print_opts
;
2831 get_user_print_options (&print_opts
);
2833 if (current_substring
[2] == '[')
2835 std::string
args (¤t_substring
[3],
2836 strlen (¤t_substring
[3]) - 1);
2838 const char *args_ptr
= args
.c_str ();
2840 /* Override global settings with explicit options, if
2843 = make_value_print_options_def_group (&print_opts
);
2844 gdb::option::process_options
2845 (&args_ptr
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
,
2848 if (*args_ptr
!= '\0')
2849 error (_("unexpected content in print options: %s"),
2853 print_formatted (val_args
[i
], 0, &print_opts
, stream
);
2857 /* Print a portion of the format string that has no
2858 directives. Note that this will not include any
2859 ordinary %-specs, but it might include "%%". That is
2860 why we use gdb_printf and not gdb_puts here.
2861 Also, we pass a dummy argument because some platforms
2862 have modified GCC to include -Wformat-security by
2863 default, which will warn here if there is no
2866 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2867 gdb_printf (stream
, current_substring
, 0);
2871 internal_error (_("failed internal consistency check"));
2873 /* Maybe advance to the next argument. */
2874 if (piece
.argclass
!= literal_piece
)
2880 /* Implement the "printf" command. */
2883 printf_command (const char *arg
, int from_tty
)
2885 ui_printf (arg
, gdb_stdout
);
2886 gdb_stdout
->reset_style ();
2887 gdb_stdout
->wrap_here (0);
2888 gdb_stdout
->flush ();
2891 /* Implement the "eval" command. */
2894 eval_command (const char *arg
, int from_tty
)
2898 ui_printf (arg
, &stb
);
2900 std::string expanded
= insert_user_defined_cmd_args (stb
.c_str ());
2902 execute_command (expanded
.c_str (), from_tty
);
2905 /* Convenience function for error checking in memory-tag commands. */
2908 show_addr_not_tagged (CORE_ADDR address
)
2910 error (_("Address %s not in a region mapped with a memory tagging flag."),
2911 paddress (current_inferior ()->arch (), address
));
2914 /* Convenience function for error checking in memory-tag commands. */
2917 show_memory_tagging_unsupported (void)
2919 error (_("Memory tagging not supported or disabled by the current"
2923 /* Implement the "memory-tag" prefix command. */
2926 memory_tag_command (const char *arg
, int from_tty
)
2928 help_list (memory_tag_list
, "memory-tag ", all_commands
, gdb_stdout
);
2931 /* Helper for print-logical-tag and print-allocation-tag. */
2934 memory_tag_print_tag_command (const char *args
, enum memtag_type tag_type
)
2936 if (args
== nullptr)
2937 error_no_arg (_("address or pointer"));
2939 /* Parse args into a value. If the value is a pointer or an address,
2940 then fetch the logical or allocation tag. */
2941 value_print_options print_opts
;
2943 struct value
*val
= process_print_command_args (args
, &print_opts
, true);
2944 gdbarch
*arch
= current_inferior ()->arch ();
2946 /* If the address is not in a region memory mapped with a memory tagging
2947 flag, it is no use trying to access/manipulate its allocation tag.
2949 It is OK to manipulate the logical tag though. */
2950 if (tag_type
== memtag_type::allocation
2951 && !gdbarch_tagged_address_p (arch
, val
))
2952 show_addr_not_tagged (value_as_address (val
));
2954 value
*tag_value
= gdbarch_get_memtag (arch
, val
, tag_type
);
2955 std::string tag
= gdbarch_memtag_to_string (arch
, tag_value
);
2958 gdb_printf (_("%s tag unavailable.\n"),
2960 == memtag_type::logical
? "Logical" : "Allocation");
2962 struct value
*v_tag
= process_print_command_args (tag
.c_str (),
2965 print_opts
.output_format
= 'x';
2966 print_value (v_tag
, print_opts
);
2969 /* Implement the "memory-tag print-logical-tag" command. */
2972 memory_tag_print_logical_tag_command (const char *args
, int from_tty
)
2974 if (!target_supports_memory_tagging ())
2975 show_memory_tagging_unsupported ();
2977 memory_tag_print_tag_command (args
, memtag_type::logical
);
2980 /* Implement the "memory-tag print-allocation-tag" command. */
2983 memory_tag_print_allocation_tag_command (const char *args
, int from_tty
)
2985 if (!target_supports_memory_tagging ())
2986 show_memory_tagging_unsupported ();
2988 memory_tag_print_tag_command (args
, memtag_type::allocation
);
2991 /* Parse ARGS and extract ADDR and TAG.
2992 ARGS should have format <expression> <tag bytes>. */
2995 parse_with_logical_tag_input (const char *args
, struct value
**val
,
2996 gdb::byte_vector
&tags
,
2997 value_print_options
*print_opts
)
2999 /* Fetch the address. */
3000 std::string address_string
= extract_string_maybe_quoted (&args
);
3002 /* Parse the address into a value. */
3003 *val
= process_print_command_args (address_string
.c_str (), print_opts
,
3006 /* Fetch the tag bytes. */
3007 std::string tag_string
= extract_string_maybe_quoted (&args
);
3009 /* Validate the input. */
3010 if (address_string
.empty () || tag_string
.empty ())
3011 error (_("Missing arguments."));
3013 if (tag_string
.length () != 2)
3014 error (_("Error parsing tags argument. The tag should be 2 digits."));
3016 tags
= hex2bin (tag_string
.c_str ());
3019 /* Implement the "memory-tag with-logical-tag" command. */
3022 memory_tag_with_logical_tag_command (const char *args
, int from_tty
)
3024 if (!target_supports_memory_tagging ())
3025 show_memory_tagging_unsupported ();
3027 if (args
== nullptr)
3028 error_no_arg (_("<address> <tag>"));
3030 gdb::byte_vector tags
;
3032 value_print_options print_opts
;
3033 gdbarch
*arch
= current_inferior ()->arch ();
3035 /* Parse the input. */
3036 parse_with_logical_tag_input (args
, &val
, tags
, &print_opts
);
3038 /* Setting the logical tag is just a local operation that does not touch
3039 any memory from the target. Given an input value, we modify the value
3040 to include the appropriate tag.
3042 For this reason we need to cast the argument value to a
3043 (void *) pointer. This is so we have the right type for the gdbarch
3044 hook to manipulate the value and insert the tag.
3046 Otherwise, this would fail if, for example, GDB parsed the argument value
3047 into an int-sized value and the pointer value has a type of greater
3050 /* Cast to (void *). */
3051 val
= value_cast (builtin_type (current_inferior ()->arch ())->builtin_data_ptr
,
3054 /* Length doesn't matter for a logical tag. Pass 0. */
3055 if (!gdbarch_set_memtags (arch
, val
, 0, tags
, memtag_type::logical
))
3056 gdb_printf (_("Could not update the logical tag data.\n"));
3059 /* Always print it in hex format. */
3060 print_opts
.output_format
= 'x';
3061 print_value (val
, print_opts
);
3065 /* Parse ARGS and extract ADDR, LENGTH and TAGS. */
3068 parse_set_allocation_tag_input (const char *args
, struct value
**val
,
3069 size_t *length
, gdb::byte_vector
&tags
)
3071 /* Fetch the address. */
3072 std::string address_string
= extract_string_maybe_quoted (&args
);
3074 /* Parse the address into a value. */
3075 value_print_options print_opts
;
3076 *val
= process_print_command_args (address_string
.c_str (), &print_opts
,
3079 /* Fetch the length. */
3080 std::string length_string
= extract_string_maybe_quoted (&args
);
3082 /* Fetch the tag bytes. */
3083 std::string tags_string
= extract_string_maybe_quoted (&args
);
3085 /* Validate the input. */
3086 if (address_string
.empty () || length_string
.empty () || tags_string
.empty ())
3087 error (_("Missing arguments."));
3090 const char *trailer
= nullptr;
3091 LONGEST parsed_length
= strtoulst (length_string
.c_str (), &trailer
, 10);
3093 if (errno
!= 0 || (trailer
!= nullptr && trailer
[0] != '\0'))
3094 error (_("Error parsing length argument."));
3096 if (parsed_length
<= 0)
3097 error (_("Invalid zero or negative length."));
3099 *length
= parsed_length
;
3101 if (tags_string
.length () % 2)
3102 error (_("Error parsing tags argument. Tags should be 2 digits per byte."));
3104 tags
= hex2bin (tags_string
.c_str ());
3106 /* If the address is not in a region memory mapped with a memory tagging
3107 flag, it is no use trying to access/manipulate its allocation tag. */
3108 if (!gdbarch_tagged_address_p (current_inferior ()->arch (), *val
))
3109 show_addr_not_tagged (value_as_address (*val
));
3112 /* Implement the "memory-tag set-allocation-tag" command.
3113 ARGS should be in the format <address> <length> <tags>. */
3116 memory_tag_set_allocation_tag_command (const char *args
, int from_tty
)
3118 if (!target_supports_memory_tagging ())
3119 show_memory_tagging_unsupported ();
3121 if (args
== nullptr)
3122 error_no_arg (_("<starting address> <length> <tag bytes>"));
3124 gdb::byte_vector tags
;
3128 /* Parse the input. */
3129 parse_set_allocation_tag_input (args
, &val
, &length
, tags
);
3131 if (!gdbarch_set_memtags (current_inferior ()->arch (), val
, length
, tags
,
3132 memtag_type::allocation
))
3133 gdb_printf (_("Could not update the allocation tag(s).\n"));
3135 gdb_printf (_("Allocation tag(s) updated successfully.\n"));
3138 /* Implement the "memory-tag check" command. */
3141 memory_tag_check_command (const char *args
, int from_tty
)
3143 if (!target_supports_memory_tagging ())
3144 show_memory_tagging_unsupported ();
3146 if (args
== nullptr)
3147 error_no_arg (_("address or pointer"));
3149 /* Parse the expression into a value. If the value is an address or
3150 pointer, then check its logical tag against the allocation tag. */
3151 value_print_options print_opts
;
3153 struct value
*val
= process_print_command_args (args
, &print_opts
, true);
3154 gdbarch
*arch
= current_inferior ()->arch ();
3156 /* If the address is not in a region memory mapped with a memory tagging
3157 flag, it is no use trying to access/manipulate its allocation tag. */
3158 if (!gdbarch_tagged_address_p (arch
, val
))
3159 show_addr_not_tagged (value_as_address (val
));
3161 CORE_ADDR addr
= value_as_address (val
);
3163 /* Check if the tag is valid. */
3164 if (!gdbarch_memtag_matches_p (arch
, val
))
3166 value
*tag
= gdbarch_get_memtag (arch
, val
, memtag_type::logical
);
3167 std::string ltag
= gdbarch_memtag_to_string (arch
, tag
);
3169 tag
= gdbarch_get_memtag (arch
, val
, memtag_type::allocation
);
3170 std::string atag
= gdbarch_memtag_to_string (arch
, tag
);
3172 gdb_printf (_("Logical tag (%s) does not match"
3173 " the allocation tag (%s) for address %s.\n"),
3174 ltag
.c_str (), atag
.c_str (),
3175 paddress (current_inferior ()->arch (), addr
));
3180 = gdbarch_get_memtag (current_inferior ()->arch (), val
,
3181 memtag_type::logical
);
3183 = gdbarch_memtag_to_string (current_inferior ()->arch (), tag
);
3185 gdb_printf (_("Memory tags for address %s match (%s).\n"),
3186 paddress (current_inferior ()->arch (), addr
), ltag
.c_str ());
3190 void _initialize_printcmd ();
3192 _initialize_printcmd ()
3194 struct cmd_list_element
*c
;
3196 current_display_number
= -1;
3198 gdb::observers::free_objfile
.attach (clear_dangling_display_expressions
,
3201 add_info ("address", info_address_command
,
3202 _("Describe where symbol SYM is stored.\n\
3203 Usage: info address SYM"));
3205 add_info ("symbol", info_symbol_command
, _("\
3206 Describe what symbol is at location ADDR.\n\
3207 Usage: info symbol ADDR\n\
3208 Only for symbols with fixed locations (global or static scope)."));
3210 c
= add_com ("x", class_vars
, x_command
, _("\
3211 Examine memory: x/FMT ADDRESS.\n\
3212 ADDRESS is an expression for the memory address to examine.\n\
3213 FMT is a repeat count followed by a format letter and a size letter.\n\
3214 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
3215 t(binary), f(float), a(address), i(instruction), c(char), s(string)\n\
3216 and z(hex, zero padded on the left).\n\
3217 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
3218 The specified number of objects of the specified size are printed\n\
3219 according to the format. If a negative number is specified, memory is\n\
3220 examined backward from the address.\n\n\
3221 Defaults for format and size letters are those previously used.\n\
3222 Default count is 1. Default address is following last thing printed\n\
3223 with this command or \"print\"."));
3224 set_cmd_completer_handle_brkchars (c
, display_and_x_command_completer
);
3226 add_info ("display", info_display_command
, _("\
3227 Expressions to display when program stops, with code numbers.\n\
3228 Usage: info display"));
3230 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
3231 Cancel some expressions to be displayed when program stops.\n\
3232 Usage: undisplay [NUM]...\n\
3233 Arguments are the code numbers of the expressions to stop displaying.\n\
3234 No argument means cancel all automatic-display expressions.\n\
3235 \"delete display\" has the same effect as this command.\n\
3236 Do \"info display\" to see current list of code numbers."),
3239 c
= add_com ("display", class_vars
, display_command
, _("\
3240 Print value of expression EXP each time the program stops.\n\
3241 Usage: display[/FMT] EXP\n\
3242 /FMT may be used before EXP as in the \"print\" command.\n\
3243 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
3244 as in the \"x\" command, and then EXP is used to get the address to examine\n\
3245 and examining is done as in the \"x\" command.\n\n\
3246 With no argument, display all currently requested auto-display expressions.\n\
3247 Use \"undisplay\" to cancel display requests previously made."));
3248 set_cmd_completer_handle_brkchars (c
, display_and_x_command_completer
);
3250 add_cmd ("display", class_vars
, enable_display_command
, _("\
3251 Enable some expressions to be displayed when program stops.\n\
3252 Usage: enable display [NUM]...\n\
3253 Arguments are the code numbers of the expressions to resume displaying.\n\
3254 No argument means enable all automatic-display expressions.\n\
3255 Do \"info display\" to see current list of code numbers."), &enablelist
);
3257 add_cmd ("display", class_vars
, disable_display_command
, _("\
3258 Disable some expressions to be displayed when program stops.\n\
3259 Usage: disable display [NUM]...\n\
3260 Arguments are the code numbers of the expressions to stop displaying.\n\
3261 No argument means disable all automatic-display expressions.\n\
3262 Do \"info display\" to see current list of code numbers."), &disablelist
);
3264 add_cmd ("display", class_vars
, undisplay_command
, _("\
3265 Cancel some expressions to be displayed when program stops.\n\
3266 Usage: delete display [NUM]...\n\
3267 Arguments are the code numbers of the expressions to stop displaying.\n\
3268 No argument means cancel all automatic-display expressions.\n\
3269 Do \"info display\" to see current list of code numbers."), &deletelist
);
3271 add_com ("printf", class_vars
, printf_command
, _("\
3272 Formatted printing, like the C \"printf\" function.\n\
3273 Usage: printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
3274 This supports most C printf format specifications, like %s, %d, etc."));
3276 add_com ("output", class_vars
, output_command
, _("\
3277 Like \"print\" but don't put in value history and don't print newline.\n\
3278 Usage: output EXP\n\
3279 This is useful in user-defined commands."));
3281 add_prefix_cmd ("set", class_vars
, set_command
, _("\
3282 Evaluate expression EXP and assign result to variable VAR.\n\
3283 Usage: set VAR = EXP\n\
3284 This uses assignment syntax appropriate for the current language\n\
3285 (VAR = EXP or VAR := EXP for example).\n\
3286 VAR may be a debugger \"convenience\" variable (names starting\n\
3287 with $), a register (a few standard names starting with $), or an actual\n\
3288 variable in the program being debugged. EXP is any valid expression.\n\
3289 Use \"set variable\" for variables with names identical to set subcommands.\n\
3291 With a subcommand, this command modifies parts of the gdb environment.\n\
3292 You can see these environment settings with the \"show\" command."),
3293 &setlist
, 1, &cmdlist
);
3295 /* "call" is the same as "set", but handy for dbx users to call fns. */
3296 c
= add_com ("call", class_vars
, call_command
, _("\
3297 Call a function in the program.\n\
3299 The argument is the function name and arguments, in the notation of the\n\
3300 current working language. The result is printed and saved in the value\n\
3301 history, if it is not void."));
3302 set_cmd_completer_handle_brkchars (c
, print_command_completer
);
3304 cmd_list_element
*set_variable_cmd
3305 = add_cmd ("variable", class_vars
, set_command
, _("\
3306 Evaluate expression EXP and assign result to variable VAR.\n\
3307 Usage: set variable VAR = EXP\n\
3308 This uses assignment syntax appropriate for the current language\n\
3309 (VAR = EXP or VAR := EXP for example).\n\
3310 VAR may be a debugger \"convenience\" variable (names starting\n\
3311 with $), a register (a few standard names starting with $), or an actual\n\
3312 variable in the program being debugged. EXP is any valid expression.\n\
3313 This may usually be abbreviated to simply \"set\"."),
3315 add_alias_cmd ("var", set_variable_cmd
, class_vars
, 0, &setlist
);
3317 const auto print_opts
= make_value_print_options_def_group (nullptr);
3319 static const std::string print_help
= gdb::option::build_help (_("\
3320 Print value of expression EXP.\n\
3321 Usage: print [[OPTION]... --] [/FMT] [EXP]\n\
3326 Note: because this command accepts arbitrary expressions, if you\n\
3327 specify any command option, you must use a double dash (\"--\")\n\
3328 to mark the end of option processing. E.g.: \"print -o -- myobj\".\n\
3330 Variables accessible are those of the lexical environment of the selected\n\
3331 stack frame, plus all those whose scope is global or an entire file.\n\
3333 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
3334 $$NUM refers to NUM'th value back from the last one.\n\
3335 Names starting with $ refer to registers (with the values they would have\n\
3336 if the program were to return to the stack frame now selected, restoring\n\
3337 all registers saved by frames farther in) or else to debugger\n\
3338 \"convenience\" variables (any such name not a known register).\n\
3339 Use assignment expressions to give values to convenience variables.\n\
3341 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
3342 @ is a binary operator for treating consecutive data objects\n\
3343 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
3344 element is FOO, whose second element is stored in the space following\n\
3345 where FOO is stored, etc. FOO must be an expression whose value\n\
3346 resides in memory.\n\
3348 EXP may be preceded with /FMT, where FMT is a format letter\n\
3349 but no count or size letter (see \"x\" command)."),
3352 cmd_list_element
*print_cmd
3353 = add_com ("print", class_vars
, print_command
, print_help
.c_str ());
3354 set_cmd_completer_handle_brkchars (print_cmd
, print_command_completer
);
3355 add_com_alias ("p", print_cmd
, class_vars
, 1);
3356 add_com_alias ("inspect", print_cmd
, class_vars
, 1);
3358 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
3359 &max_symbolic_offset
, _("\
3360 Set the largest offset that will be printed in <SYMBOL+1234> form."), _("\
3361 Show the largest offset that will be printed in <SYMBOL+1234> form."), _("\
3362 Tell GDB to only display the symbolic form of an address if the\n\
3363 offset between the closest earlier symbol and the address is less than\n\
3364 the specified maximum offset. The default is \"unlimited\", which tells GDB\n\
3365 to always print the symbolic form of an address if any symbol precedes\n\
3366 it. Zero is equivalent to \"unlimited\"."),
3368 show_max_symbolic_offset
,
3369 &setprintlist
, &showprintlist
);
3370 add_setshow_boolean_cmd ("symbol-filename", no_class
,
3371 &print_symbol_filename
, _("\
3372 Set printing of source filename and line number with <SYMBOL>."), _("\
3373 Show printing of source filename and line number with <SYMBOL>."), NULL
,
3375 show_print_symbol_filename
,
3376 &setprintlist
, &showprintlist
);
3378 add_com ("eval", no_class
, eval_command
, _("\
3379 Construct a GDB command and then evaluate it.\n\
3380 Usage: eval \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
3381 Convert the arguments to a string as \"printf\" would, but then\n\
3382 treat this string as a command line, and evaluate it."));
3384 /* Memory tagging commands. */
3385 add_prefix_cmd ("memory-tag", class_vars
, memory_tag_command
, _("\
3386 Generic command for printing and manipulating memory tag properties."),
3387 &memory_tag_list
, 0, &cmdlist
);
3388 add_cmd ("print-logical-tag", class_vars
,
3389 memory_tag_print_logical_tag_command
,
3390 ("Print the logical tag from POINTER.\n\
3391 Usage: memory-tag print-logical-tag <POINTER>.\n\
3392 <POINTER> is an expression that evaluates to a pointer.\n\
3393 Print the logical tag contained in POINTER. The tag interpretation is\n\
3394 architecture-specific."),
3396 add_cmd ("print-allocation-tag", class_vars
,
3397 memory_tag_print_allocation_tag_command
,
3398 _("Print the allocation tag for ADDRESS.\n\
3399 Usage: memory-tag print-allocation-tag <ADDRESS>.\n\
3400 <ADDRESS> is an expression that evaluates to a memory address.\n\
3401 Print the allocation tag associated with the memory address ADDRESS.\n\
3402 The tag interpretation is architecture-specific."),
3404 add_cmd ("with-logical-tag", class_vars
, memory_tag_with_logical_tag_command
,
3405 _("Print a POINTER with a specific logical TAG.\n\
3406 Usage: memory-tag with-logical-tag <POINTER> <TAG>\n\
3407 <POINTER> is an expression that evaluates to a pointer.\n\
3408 <TAG> is a sequence of hex bytes that is interpreted by the architecture\n\
3409 as a single memory tag."),
3411 add_cmd ("set-allocation-tag", class_vars
,
3412 memory_tag_set_allocation_tag_command
,
3413 _("Set the allocation tag(s) for a memory range.\n\
3414 Usage: memory-tag set-allocation-tag <ADDRESS> <LENGTH> <TAG_BYTES>\n\
3415 <ADDRESS> is an expression that evaluates to a memory address\n\
3416 <LENGTH> is the number of bytes that is added to <ADDRESS> to calculate\n\
3417 the memory range.\n\
3418 <TAG_BYTES> is a sequence of hex bytes that is interpreted by the\n\
3419 architecture as one or more memory tags.\n\
3420 Sets the tags of the memory range [ADDRESS, ADDRESS + LENGTH)\n\
3423 If the number of tags is greater than or equal to the number of tag granules\n\
3424 in the [ADDRESS, ADDRESS + LENGTH) range, only the tags up to the\n\
3425 number of tag granules are updated.\n\
3427 If the number of tags is less than the number of tag granules, then the\n\
3428 command is a fill operation. The TAG_BYTES are interpreted as a pattern\n\
3429 that gets repeated until the number of tag granules in the memory range\n\
3430 [ADDRESS, ADDRESS + LENGTH) is updated."),
3432 add_cmd ("check", class_vars
, memory_tag_check_command
,
3433 _("Validate a pointer's logical tag against the allocation tag.\n\
3434 Usage: memory-tag check <POINTER>\n\
3435 <POINTER> is an expression that evaluates to a pointer\n\
3436 Fetch the logical and allocation tags for POINTER and compare them\n\
3437 for equality. If the tags do not match, print additional information about\n\
3438 the tag mismatch."),