1 /* Print values for GNU debugger GDB.
3 Copyright (C) 1986-2022 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"
36 #include "symfile.h" /* for overlay functions */
37 #include "objfiles.h" /* ditto */
38 #include "completer.h" /* for completion functions */
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"
55 #include "gdbsupport/gdb_optional.h"
56 #include "safe-ctype.h"
57 #include "gdbsupport/rsp-low.h"
59 /* Chain containing all defined memory-tag subcommands. */
61 static struct cmd_list_element
*memory_tag_list
;
63 /* Last specified output format. */
65 static char last_format
= 0;
67 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
69 static char last_size
= 'w';
71 /* Last specified count for the 'x' command. */
73 static int last_count
;
75 /* Last specified tag-printing option. */
77 static bool last_print_tags
= false;
79 /* Default address to examine next, and associated architecture. */
81 static struct gdbarch
*next_gdbarch
;
82 static CORE_ADDR next_address
;
84 /* Number of delay instructions following current disassembled insn. */
86 static int branch_delay_insns
;
88 /* Last address examined. */
90 static CORE_ADDR last_examine_address
;
92 /* Contents of last address examined.
93 This is not valid past the end of the `x' command! */
95 static value_ref_ptr last_examine_value
;
97 /* Largest offset between a symbolic value and an address, that will be
98 printed as `0x1234 <symbol+offset>'. */
100 static unsigned int max_symbolic_offset
= UINT_MAX
;
102 show_max_symbolic_offset (struct ui_file
*file
, int from_tty
,
103 struct cmd_list_element
*c
, const char *value
)
105 fprintf_filtered (file
,
106 _("The largest offset that will be "
107 "printed in <symbol+1234> form is %s.\n"),
111 /* Append the source filename and linenumber of the symbol when
112 printing a symbolic value as `<symbol at filename:linenum>' if set. */
113 static bool print_symbol_filename
= false;
115 show_print_symbol_filename (struct ui_file
*file
, int from_tty
,
116 struct cmd_list_element
*c
, const char *value
)
118 fprintf_filtered (file
, _("Printing of source filename and "
119 "line number with <symbol> is %s.\n"),
123 /* Number of auto-display expression currently being displayed.
124 So that we can disable it if we get a signal within it.
125 -1 when not doing one. */
127 static int current_display_number
;
129 /* Last allocated display number. */
131 static int display_number
;
135 display (const char *exp_string_
, expression_up
&&exp_
,
136 const struct format_data
&format_
, struct program_space
*pspace_
,
137 const struct block
*block_
)
138 : exp_string (exp_string_
),
139 exp (std::move (exp_
)),
140 number (++display_number
),
148 /* The expression as the user typed it. */
149 std::string exp_string
;
151 /* Expression to be evaluated and displayed. */
154 /* Item number of this auto-display item. */
157 /* Display format specified. */
158 struct format_data format
;
160 /* Program space associated with `block'. */
161 struct program_space
*pspace
;
163 /* Innermost block required by this expression when evaluated. */
164 const struct block
*block
;
166 /* Status of this display (enabled or disabled). */
170 /* Expressions whose values should be displayed automatically each
171 time the program stops. */
173 static std::vector
<std::unique_ptr
<struct display
>> all_displays
;
175 /* Prototypes for local functions. */
177 static void do_one_display (struct display
*);
180 /* Decode a format specification. *STRING_PTR should point to it.
181 OFORMAT and OSIZE are used as defaults for the format and size
182 if none are given in the format specification.
183 If OSIZE is zero, then the size field of the returned value
184 should be set only if a size is explicitly specified by the
186 The structure returned describes all the data
187 found in the specification. In addition, *STRING_PTR is advanced
188 past the specification and past all whitespace following it. */
190 static struct format_data
191 decode_format (const char **string_ptr
, int oformat
, int osize
)
193 struct format_data val
;
194 const char *p
= *string_ptr
;
200 val
.print_tags
= false;
207 if (*p
>= '0' && *p
<= '9')
208 val
.count
*= atoi (p
);
209 while (*p
>= '0' && *p
<= '9')
212 /* Now process size or format letters that follow. */
216 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
225 val
.print_tags
= true;
228 else if (*p
>= 'a' && *p
<= 'z')
234 *string_ptr
= skip_spaces (p
);
236 /* Set defaults for format and size if not specified. */
237 if (val
.format
== '?')
241 /* Neither has been specified. */
242 val
.format
= oformat
;
246 /* If a size is specified, any format makes a reasonable
247 default except 'i'. */
248 val
.format
= oformat
== 'i' ? 'x' : oformat
;
250 else if (val
.size
== '?')
254 /* Pick the appropriate size for an address. This is deferred
255 until do_examine when we know the actual architecture to use.
256 A special size value of 'a' is used to indicate this case. */
257 val
.size
= osize
? 'a' : osize
;
260 /* Floating point has to be word or giantword. */
261 if (osize
== 'w' || osize
== 'g')
264 /* Default it to giantword if the last used size is not
266 val
.size
= osize
? 'g' : osize
;
269 /* Characters default to one byte. */
270 val
.size
= osize
? 'b' : osize
;
273 /* Display strings with byte size chars unless explicitly
279 /* The default is the size most recently specified. */
286 /* Print value VAL on stream according to OPTIONS.
287 Do not end with a newline.
288 SIZE is the letter for the size of datum being printed.
289 This is used to pad hex numbers so they line up. SIZE is 0
290 for print / output and set for examine. */
293 print_formatted (struct value
*val
, int size
,
294 const struct value_print_options
*options
,
295 struct ui_file
*stream
)
297 struct type
*type
= check_typedef (value_type (val
));
298 int len
= TYPE_LENGTH (type
);
300 if (VALUE_LVAL (val
) == lval_memory
)
301 next_address
= value_address (val
) + len
;
305 switch (options
->format
)
309 struct type
*elttype
= value_type (val
);
311 next_address
= (value_address (val
)
312 + val_print_string (elttype
, NULL
,
313 value_address (val
), -1,
314 stream
, options
) * len
);
319 /* We often wrap here if there are long symbolic names. */
320 stream
->wrap_here (4);
321 next_address
= (value_address (val
)
322 + gdb_print_insn (type
->arch (),
323 value_address (val
), stream
,
324 &branch_delay_insns
));
329 if (options
->format
== 0 || options
->format
== 's'
330 || type
->code () == TYPE_CODE_VOID
331 || type
->code () == TYPE_CODE_REF
332 || type
->code () == TYPE_CODE_ARRAY
333 || type
->code () == TYPE_CODE_STRING
334 || type
->code () == TYPE_CODE_STRUCT
335 || type
->code () == TYPE_CODE_UNION
336 || type
->code () == TYPE_CODE_NAMESPACE
)
337 value_print (val
, stream
, options
);
339 /* User specified format, so don't look to the type to tell us
341 value_print_scalar_formatted (val
, options
, size
, stream
);
344 /* Return builtin floating point type of same length as TYPE.
345 If no such type is found, return TYPE itself. */
347 float_type_from_length (struct type
*type
)
349 struct gdbarch
*gdbarch
= type
->arch ();
350 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
352 if (TYPE_LENGTH (type
) == TYPE_LENGTH (builtin
->builtin_float
))
353 type
= builtin
->builtin_float
;
354 else if (TYPE_LENGTH (type
) == TYPE_LENGTH (builtin
->builtin_double
))
355 type
= builtin
->builtin_double
;
356 else if (TYPE_LENGTH (type
) == TYPE_LENGTH (builtin
->builtin_long_double
))
357 type
= builtin
->builtin_long_double
;
362 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
363 according to OPTIONS and SIZE on STREAM. Formats s and i are not
364 supported at this level. */
367 print_scalar_formatted (const gdb_byte
*valaddr
, struct type
*type
,
368 const struct value_print_options
*options
,
369 int size
, struct ui_file
*stream
)
371 struct gdbarch
*gdbarch
= type
->arch ();
372 unsigned int len
= TYPE_LENGTH (type
);
373 enum bfd_endian byte_order
= type_byte_order (type
);
375 /* String printing should go through val_print_scalar_formatted. */
376 gdb_assert (options
->format
!= 's');
378 /* If the value is a pointer, and pointers and addresses are not the
379 same, then at this point, the value's length (in target bytes) is
380 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
381 if (type
->code () == TYPE_CODE_PTR
)
382 len
= gdbarch_addr_bit (gdbarch
) / TARGET_CHAR_BIT
;
384 /* If we are printing it as unsigned, truncate it in case it is actually
385 a negative signed value (e.g. "print/u (short)-1" should print 65535
386 (if shorts are 16 bits) instead of 4294967295). */
387 if (options
->format
!= 'c'
388 && (options
->format
!= 'd' || type
->is_unsigned ()))
390 if (len
< TYPE_LENGTH (type
) && byte_order
== BFD_ENDIAN_BIG
)
391 valaddr
+= TYPE_LENGTH (type
) - len
;
394 /* Allow LEN == 0, and in this case, don't assume that VALADDR is
396 const gdb_byte zero
= 0;
403 if (size
!= 0 && (options
->format
== 'x' || options
->format
== 't'))
405 /* Truncate to fit. */
422 error (_("Undefined output size \"%c\"."), size
);
424 if (newlen
< len
&& byte_order
== BFD_ENDIAN_BIG
)
425 valaddr
+= len
- newlen
;
429 /* Biased range types and sub-word scalar types must be handled
430 here; the value is correctly computed by unpack_long. */
431 gdb::byte_vector converted_bytes
;
432 /* Some cases below will unpack the value again. In the biased
433 range case, we want to avoid this, so we store the unpacked value
434 here for possible use later. */
435 gdb::optional
<LONGEST
> val_long
;
436 if ((is_fixed_point_type (type
)
437 && (options
->format
== 'o'
438 || options
->format
== 'x'
439 || options
->format
== 't'
440 || options
->format
== 'z'
441 || options
->format
== 'd'
442 || options
->format
== 'u'))
443 || (type
->code () == TYPE_CODE_RANGE
&& type
->bounds ()->bias
!= 0)
444 || type
->bit_size_differs_p ())
446 val_long
.emplace (unpack_long (type
, valaddr
));
447 converted_bytes
.resize (TYPE_LENGTH (type
));
448 store_signed_integer (converted_bytes
.data (), TYPE_LENGTH (type
),
449 byte_order
, *val_long
);
450 valaddr
= converted_bytes
.data ();
453 /* Printing a non-float type as 'f' will interpret the data as if it were
454 of a floating-point type of the same length, if that exists. Otherwise,
455 the data is printed as integer. */
456 char format
= options
->format
;
457 if (format
== 'f' && type
->code () != TYPE_CODE_FLT
)
459 type
= float_type_from_length (type
);
460 if (type
->code () != TYPE_CODE_FLT
)
467 print_octal_chars (stream
, valaddr
, len
, byte_order
);
470 print_decimal_chars (stream
, valaddr
, len
, true, byte_order
);
473 print_decimal_chars (stream
, valaddr
, len
, false, byte_order
);
476 if (type
->code () != TYPE_CODE_FLT
)
478 print_decimal_chars (stream
, valaddr
, len
, !type
->is_unsigned (),
484 print_floating (valaddr
, type
, stream
);
488 print_binary_chars (stream
, valaddr
, len
, byte_order
, size
> 0);
491 print_hex_chars (stream
, valaddr
, len
, byte_order
, size
> 0);
494 print_hex_chars (stream
, valaddr
, len
, byte_order
, true);
498 struct value_print_options opts
= *options
;
500 if (!val_long
.has_value ())
501 val_long
.emplace (unpack_long (type
, valaddr
));
504 if (type
->is_unsigned ())
505 type
= builtin_type (gdbarch
)->builtin_true_unsigned_char
;
507 type
= builtin_type (gdbarch
)->builtin_true_char
;
509 value_print (value_from_longest (type
, *val_long
), stream
, &opts
);
515 if (!val_long
.has_value ())
516 val_long
.emplace (unpack_long (type
, valaddr
));
517 print_address (gdbarch
, *val_long
, stream
);
522 error (_("Undefined output format \"%c\"."), format
);
526 /* Specify default address for `x' command.
527 The `info lines' command uses this. */
530 set_next_address (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
532 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
534 next_gdbarch
= gdbarch
;
537 /* Make address available to the user as $_. */
538 set_internalvar (lookup_internalvar ("_"),
539 value_from_pointer (ptr_type
, addr
));
542 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
543 after LEADIN. Print nothing if no symbolic name is found nearby.
544 Optionally also print source file and line number, if available.
545 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
546 or to interpret it as a possible C++ name and convert it back to source
547 form. However note that DO_DEMANGLE can be overridden by the specific
548 settings of the demangle and asm_demangle variables. Returns
549 non-zero if anything was printed; zero otherwise. */
552 print_address_symbolic (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
553 struct ui_file
*stream
,
554 int do_demangle
, const char *leadin
)
556 std::string name
, filename
;
561 if (build_address_symbolic (gdbarch
, addr
, do_demangle
, false, &name
,
562 &offset
, &filename
, &line
, &unmapped
))
565 fputs_filtered (leadin
, stream
);
567 fputs_filtered ("<*", stream
);
569 fputs_filtered ("<", stream
);
570 fputs_styled (name
.c_str (), function_name_style
.style (), stream
);
572 fprintf_filtered (stream
, "%+d", offset
);
574 /* Append source filename and line number if desired. Give specific
575 line # of this addr, if we have it; else line # of the nearest symbol. */
576 if (print_symbol_filename
&& !filename
.empty ())
578 fputs_filtered (line
== -1 ? " in " : " at ", stream
);
579 fputs_styled (filename
.c_str (), file_name_style
.style (), stream
);
581 fprintf_filtered (stream
, ":%d", line
);
584 fputs_filtered ("*>", stream
);
586 fputs_filtered (">", stream
);
591 /* See valprint.h. */
594 build_address_symbolic (struct gdbarch
*gdbarch
,
595 CORE_ADDR addr
, /* IN */
596 bool do_demangle
, /* IN */
597 bool prefer_sym_over_minsym
, /* IN */
598 std::string
*name
, /* OUT */
599 int *offset
, /* OUT */
600 std::string
*filename
, /* OUT */
602 int *unmapped
) /* OUT */
604 struct bound_minimal_symbol msymbol
;
605 struct symbol
*symbol
;
606 CORE_ADDR name_location
= 0;
607 struct obj_section
*section
= NULL
;
608 const char *name_temp
= "";
610 /* Let's say it is mapped (not unmapped). */
613 /* Determine if the address is in an overlay, and whether it is
615 if (overlay_debugging
)
617 section
= find_pc_overlay (addr
);
618 if (pc_in_unmapped_range (addr
, section
))
621 addr
= overlay_mapped_address (addr
, section
);
625 /* Try to find the address in both the symbol table and the minsyms.
626 In most cases, we'll prefer to use the symbol instead of the
627 minsym. However, there are cases (see below) where we'll choose
628 to use the minsym instead. */
630 /* This is defective in the sense that it only finds text symbols. So
631 really this is kind of pointless--we should make sure that the
632 minimal symbols have everything we need (by changing that we could
633 save some memory, but for many debug format--ELF/DWARF or
634 anything/stabs--it would be inconvenient to eliminate those minimal
636 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
637 symbol
= find_pc_sect_function (addr
, section
);
641 /* If this is a function (i.e. a code address), strip out any
642 non-address bits. For instance, display a pointer to the
643 first instruction of a Thumb function as <function>; the
644 second instruction will be <function+2>, even though the
645 pointer is <function+3>. This matches the ISA behavior. */
646 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
648 name_location
= BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (symbol
));
649 if (do_demangle
|| asm_demangle
)
650 name_temp
= symbol
->print_name ();
652 name_temp
= symbol
->linkage_name ();
655 if (msymbol
.minsym
!= NULL
656 && MSYMBOL_HAS_SIZE (msymbol
.minsym
)
657 && MSYMBOL_SIZE (msymbol
.minsym
) == 0
658 && MSYMBOL_TYPE (msymbol
.minsym
) != mst_text
659 && MSYMBOL_TYPE (msymbol
.minsym
) != mst_text_gnu_ifunc
660 && MSYMBOL_TYPE (msymbol
.minsym
) != mst_file_text
)
661 msymbol
.minsym
= NULL
;
663 if (msymbol
.minsym
!= NULL
)
665 /* Use the minsym if no symbol is found.
667 Additionally, use the minsym instead of a (found) symbol if
668 the following conditions all hold:
669 1) The prefer_sym_over_minsym flag is false.
670 2) The minsym address is identical to that of the address under
672 3) The symbol address is not identical to that of the address
673 under consideration. */
674 if (symbol
== NULL
||
675 (!prefer_sym_over_minsym
676 && BMSYMBOL_VALUE_ADDRESS (msymbol
) == addr
677 && name_location
!= addr
))
679 /* If this is a function (i.e. a code address), strip out any
680 non-address bits. For instance, display a pointer to the
681 first instruction of a Thumb function as <function>; the
682 second instruction will be <function+2>, even though the
683 pointer is <function+3>. This matches the ISA behavior. */
684 if (MSYMBOL_TYPE (msymbol
.minsym
) == mst_text
685 || MSYMBOL_TYPE (msymbol
.minsym
) == mst_text_gnu_ifunc
686 || MSYMBOL_TYPE (msymbol
.minsym
) == mst_file_text
687 || MSYMBOL_TYPE (msymbol
.minsym
) == mst_solib_trampoline
)
688 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
691 name_location
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
692 if (do_demangle
|| asm_demangle
)
693 name_temp
= msymbol
.minsym
->print_name ();
695 name_temp
= msymbol
.minsym
->linkage_name ();
698 if (symbol
== NULL
&& msymbol
.minsym
== NULL
)
701 /* If the nearest symbol is too far away, don't print anything symbolic. */
703 /* For when CORE_ADDR is larger than unsigned int, we do math in
704 CORE_ADDR. But when we detect unsigned wraparound in the
705 CORE_ADDR math, we ignore this test and print the offset,
706 because addr+max_symbolic_offset has wrapped through the end
707 of the address space back to the beginning, giving bogus comparison. */
708 if (addr
> name_location
+ max_symbolic_offset
709 && name_location
+ max_symbolic_offset
> name_location
)
712 *offset
= (LONGEST
) addr
- name_location
;
716 if (print_symbol_filename
)
718 struct symtab_and_line sal
;
720 sal
= find_pc_sect_line (addr
, section
, 0);
724 *filename
= symtab_to_filename_for_display (sal
.symtab
);
732 /* Print address ADDR symbolically on STREAM.
733 First print it as a number. Then perhaps print
734 <SYMBOL + OFFSET> after the number. */
737 print_address (struct gdbarch
*gdbarch
,
738 CORE_ADDR addr
, struct ui_file
*stream
)
740 fputs_styled (paddress (gdbarch
, addr
), address_style
.style (), stream
);
741 print_address_symbolic (gdbarch
, addr
, stream
, asm_demangle
, " ");
744 /* Return a prefix for instruction address:
745 "=> " for current instruction, else " ". */
748 pc_prefix (CORE_ADDR addr
)
750 if (has_stack_frames ())
752 struct frame_info
*frame
;
755 frame
= get_selected_frame (NULL
);
756 if (get_frame_pc_if_available (frame
, &pc
) && pc
== addr
)
762 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
763 controls whether to print the symbolic name "raw" or demangled.
764 Return non-zero if anything was printed; zero otherwise. */
767 print_address_demangle (const struct value_print_options
*opts
,
768 struct gdbarch
*gdbarch
, CORE_ADDR addr
,
769 struct ui_file
*stream
, int do_demangle
)
771 if (opts
->addressprint
)
773 fputs_styled (paddress (gdbarch
, addr
), address_style
.style (), stream
);
774 print_address_symbolic (gdbarch
, addr
, stream
, do_demangle
, " ");
778 return print_address_symbolic (gdbarch
, addr
, stream
, do_demangle
, "");
784 /* Find the address of the instruction that is INST_COUNT instructions before
785 the instruction at ADDR.
786 Since some architectures have variable-length instructions, we can't just
787 simply subtract INST_COUNT * INSN_LEN from ADDR. Instead, we use line
788 number information to locate the nearest known instruction boundary,
789 and disassemble forward from there. If we go out of the symbol range
790 during disassembling, we return the lowest address we've got so far and
791 set the number of instructions read to INST_READ. */
794 find_instruction_backward (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
795 int inst_count
, int *inst_read
)
797 /* The vector PCS is used to store instruction addresses within
799 CORE_ADDR loop_start
, loop_end
, p
;
800 std::vector
<CORE_ADDR
> pcs
;
801 struct symtab_and_line sal
;
804 loop_start
= loop_end
= addr
;
806 /* In each iteration of the outer loop, we get a pc range that ends before
807 LOOP_START, then we count and store every instruction address of the range
808 iterated in the loop.
809 If the number of instructions counted reaches INST_COUNT, return the
810 stored address that is located INST_COUNT instructions back from ADDR.
811 If INST_COUNT is not reached, we subtract the number of counted
812 instructions from INST_COUNT, and go to the next iteration. */
816 sal
= find_pc_sect_line (loop_start
, NULL
, 1);
819 /* We reach here when line info is not available. In this case,
820 we print a message and just exit the loop. The return value
821 is calculated after the loop. */
822 printf_filtered (_("No line number information available "
824 gdb_stdout
->wrap_here (2);
825 print_address (gdbarch
, loop_start
- 1, gdb_stdout
);
826 printf_filtered ("\n");
830 loop_end
= loop_start
;
833 /* This loop pushes instruction addresses in the range from
834 LOOP_START to LOOP_END. */
835 for (p
= loop_start
; p
< loop_end
;)
838 p
+= gdb_insn_length (gdbarch
, p
);
841 inst_count
-= pcs
.size ();
842 *inst_read
+= pcs
.size ();
844 while (inst_count
> 0);
846 /* After the loop, the vector PCS has instruction addresses of the last
847 source line we processed, and INST_COUNT has a negative value.
848 We return the address at the index of -INST_COUNT in the vector for
850 Let's assume the following instruction addresses and run 'x/-4i 0x400e'.
860 find_instruction_backward is called with INST_COUNT = 4 and expected to
861 return 0x4001. When we reach here, INST_COUNT is set to -1 because
862 it was subtracted by 2 (from Line Y) and 3 (from Line X). The value
863 4001 is located at the index 1 of the last iterated line (= Line X),
864 which is simply calculated by -INST_COUNT.
865 The case when the length of PCS is 0 means that we reached an area for
866 which line info is not available. In such case, we return LOOP_START,
867 which was the lowest instruction address that had line info. */
868 p
= pcs
.size () > 0 ? pcs
[-inst_count
] : loop_start
;
870 /* INST_READ includes all instruction addresses in a pc range. Need to
871 exclude the beginning part up to the address we're returning. That
872 is, exclude {0x4000} in the example above. */
874 *inst_read
+= inst_count
;
879 /* Backward read LEN bytes of target memory from address MEMADDR + LEN,
880 placing the results in GDB's memory from MYADDR + LEN. Returns
881 a count of the bytes actually read. */
884 read_memory_backward (struct gdbarch
*gdbarch
,
885 CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
888 int nread
; /* Number of bytes actually read. */
890 /* First try a complete read. */
891 errcode
= target_read_memory (memaddr
, myaddr
, len
);
899 /* Loop, reading one byte at a time until we get as much as we can. */
902 for (nread
= 0; nread
< len
; ++nread
)
904 errcode
= target_read_memory (--memaddr
, --myaddr
, 1);
907 /* The read was unsuccessful, so exit the loop. */
908 printf_filtered (_("Cannot access memory at address %s\n"),
909 paddress (gdbarch
, memaddr
));
917 /* Returns true if X (which is LEN bytes wide) is the number zero. */
920 integer_is_zero (const gdb_byte
*x
, int len
)
924 while (i
< len
&& x
[i
] == 0)
929 /* Find the start address of a string in which ADDR is included.
930 Basically we search for '\0' and return the next address,
931 but if OPTIONS->PRINT_MAX is smaller than the length of a string,
932 we stop searching and return the address to print characters as many as
933 PRINT_MAX from the string. */
936 find_string_backward (struct gdbarch
*gdbarch
,
937 CORE_ADDR addr
, int count
, int char_size
,
938 const struct value_print_options
*options
,
939 int *strings_counted
)
941 const int chunk_size
= 0x20;
944 int chars_to_read
= chunk_size
;
945 int chars_counted
= 0;
946 int count_original
= count
;
947 CORE_ADDR string_start_addr
= addr
;
949 gdb_assert (char_size
== 1 || char_size
== 2 || char_size
== 4);
950 gdb::byte_vector
buffer (chars_to_read
* char_size
);
951 while (count
> 0 && read_error
== 0)
955 addr
-= chars_to_read
* char_size
;
956 chars_read
= read_memory_backward (gdbarch
, addr
, buffer
.data (),
957 chars_to_read
* char_size
);
958 chars_read
/= char_size
;
959 read_error
= (chars_read
== chars_to_read
) ? 0 : 1;
960 /* Searching for '\0' from the end of buffer in backward direction. */
961 for (i
= 0; i
< chars_read
&& count
> 0 ; ++i
, ++chars_counted
)
963 int offset
= (chars_to_read
- i
- 1) * char_size
;
965 if (integer_is_zero (&buffer
[offset
], char_size
)
966 || chars_counted
== options
->print_max
)
968 /* Found '\0' or reached print_max. As OFFSET is the offset to
969 '\0', we add CHAR_SIZE to return the start address of
972 string_start_addr
= addr
+ offset
+ char_size
;
978 /* Update STRINGS_COUNTED with the actual number of loaded strings. */
979 *strings_counted
= count_original
- count
;
983 /* In error case, STRING_START_ADDR is pointing to the string that
984 was last successfully loaded. Rewind the partially loaded string. */
985 string_start_addr
-= chars_counted
* char_size
;
988 return string_start_addr
;
991 /* Examine data at address ADDR in format FMT.
992 Fetch it from memory and print on gdb_stdout. */
995 do_examine (struct format_data fmt
, struct gdbarch
*gdbarch
, CORE_ADDR addr
)
1000 struct type
*val_type
= NULL
;
1003 struct value_print_options opts
;
1004 int need_to_update_next_address
= 0;
1005 CORE_ADDR addr_rewound
= 0;
1007 format
= fmt
.format
;
1010 next_gdbarch
= gdbarch
;
1011 next_address
= addr
;
1013 /* Instruction format implies fetch single bytes
1014 regardless of the specified size.
1015 The case of strings is handled in decode_format, only explicit
1016 size operator are not changed to 'b'. */
1022 /* Pick the appropriate size for an address. */
1023 if (gdbarch_ptr_bit (next_gdbarch
) == 64)
1025 else if (gdbarch_ptr_bit (next_gdbarch
) == 32)
1027 else if (gdbarch_ptr_bit (next_gdbarch
) == 16)
1030 /* Bad value for gdbarch_ptr_bit. */
1031 internal_error (__FILE__
, __LINE__
,
1032 _("failed internal consistency check"));
1036 val_type
= builtin_type (next_gdbarch
)->builtin_int8
;
1037 else if (size
== 'h')
1038 val_type
= builtin_type (next_gdbarch
)->builtin_int16
;
1039 else if (size
== 'w')
1040 val_type
= builtin_type (next_gdbarch
)->builtin_int32
;
1041 else if (size
== 'g')
1042 val_type
= builtin_type (next_gdbarch
)->builtin_int64
;
1046 struct type
*char_type
= NULL
;
1048 /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char
1049 if type is not found. */
1051 char_type
= builtin_type (next_gdbarch
)->builtin_char16
;
1052 else if (size
== 'w')
1053 char_type
= builtin_type (next_gdbarch
)->builtin_char32
;
1055 val_type
= char_type
;
1058 if (size
!= '\0' && size
!= 'b')
1059 warning (_("Unable to display strings with "
1060 "size '%c', using 'b' instead."), size
);
1062 val_type
= builtin_type (next_gdbarch
)->builtin_int8
;
1071 if (format
== 's' || format
== 'i')
1074 get_formatted_print_options (&opts
, format
);
1078 /* This is the negative repeat count case.
1079 We rewind the address based on the given repeat count and format,
1080 then examine memory from there in forward direction. */
1085 next_address
= find_instruction_backward (gdbarch
, addr
, count
,
1088 else if (format
== 's')
1090 next_address
= find_string_backward (gdbarch
, addr
, count
,
1091 TYPE_LENGTH (val_type
),
1096 next_address
= addr
- count
* TYPE_LENGTH (val_type
);
1099 /* The following call to print_formatted updates next_address in every
1100 iteration. In backward case, we store the start address here
1101 and update next_address with it before exiting the function. */
1102 addr_rewound
= (format
== 's'
1103 ? next_address
- TYPE_LENGTH (val_type
)
1105 need_to_update_next_address
= 1;
1108 /* Whether we need to print the memory tag information for the current
1110 bool print_range_tag
= true;
1111 uint32_t gsize
= gdbarch_memtag_granule_size (gdbarch
);
1113 /* Print as many objects as specified in COUNT, at most maxelts per line,
1114 with the address of the next one at the start of each line. */
1120 CORE_ADDR tag_laddr
= 0, tag_haddr
= 0;
1122 /* Print the memory tag information if requested. */
1123 if (fmt
.print_tags
&& print_range_tag
1124 && target_supports_memory_tagging ())
1126 tag_laddr
= align_down (next_address
, gsize
);
1127 tag_haddr
= align_down (next_address
+ gsize
, gsize
);
1129 struct value
*v_addr
1130 = value_from_ulongest (builtin_type (gdbarch
)->builtin_data_ptr
,
1133 if (gdbarch_tagged_address_p (target_gdbarch (), v_addr
))
1135 /* Fetch the allocation tag. */
1137 = gdbarch_get_memtag (gdbarch
, v_addr
, memtag_type::allocation
);
1139 = gdbarch_memtag_to_string (gdbarch
, tag
);
1143 printf_filtered (_("<Allocation Tag %s for range [%s,%s)>\n"),
1145 paddress (gdbarch
, tag_laddr
),
1146 paddress (gdbarch
, tag_haddr
));
1149 print_range_tag
= false;
1153 puts_filtered (pc_prefix (next_address
));
1154 print_address (next_gdbarch
, next_address
, gdb_stdout
);
1155 printf_filtered (":");
1160 printf_filtered ("\t");
1161 /* Note that print_formatted sets next_address for the next
1163 last_examine_address
= next_address
;
1165 /* The value to be displayed is not fetched greedily.
1166 Instead, to avoid the possibility of a fetched value not
1167 being used, its retrieval is delayed until the print code
1168 uses it. When examining an instruction stream, the
1169 disassembler will perform its own memory fetch using just
1170 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
1171 the disassembler be modified so that LAST_EXAMINE_VALUE
1172 is left with the byte sequence from the last complete
1173 instruction fetched from memory? */
1175 = release_value (value_at_lazy (val_type
, next_address
));
1177 print_formatted (last_examine_value
.get (), size
, &opts
, gdb_stdout
);
1179 /* Display any branch delay slots following the final insn. */
1180 if (format
== 'i' && count
== 1)
1181 count
+= branch_delay_insns
;
1183 /* Update the tag range based on the current address being
1185 if (tag_haddr
<= next_address
)
1186 print_range_tag
= true;
1188 printf_filtered ("\n");
1191 if (need_to_update_next_address
)
1192 next_address
= addr_rewound
;
1196 validate_format (struct format_data fmt
, const char *cmdname
)
1199 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
1201 error (_("Item count other than 1 is meaningless in \"%s\" command."),
1203 if (fmt
.format
== 'i')
1204 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
1205 fmt
.format
, cmdname
);
1208 /* Parse print command format string into *OPTS and update *EXPP.
1209 CMDNAME should name the current command. */
1212 print_command_parse_format (const char **expp
, const char *cmdname
,
1213 value_print_options
*opts
)
1215 const char *exp
= *expp
;
1217 /* opts->raw value might already have been set by 'set print raw-values'
1218 or by using 'print -raw-values'.
1219 So, do not set opts->raw to 0, only set it to 1 if /r is given. */
1220 if (exp
&& *exp
== '/')
1225 fmt
= decode_format (&exp
, last_format
, 0);
1226 validate_format (fmt
, cmdname
);
1227 last_format
= fmt
.format
;
1229 opts
->format
= fmt
.format
;
1230 opts
->raw
= opts
->raw
|| fmt
.raw
;
1240 /* See valprint.h. */
1243 print_value (value
*val
, const value_print_options
&opts
)
1245 int histindex
= record_latest_value (val
);
1247 annotate_value_history_begin (histindex
, value_type (val
));
1249 printf_filtered ("$%d = ", histindex
);
1251 annotate_value_history_value ();
1253 print_formatted (val
, 0, &opts
, gdb_stdout
);
1254 printf_filtered ("\n");
1256 annotate_value_history_end ();
1259 /* Returns true if memory tags should be validated. False otherwise. */
1262 should_validate_memtags (struct value
*value
)
1264 gdb_assert (value
!= nullptr && value_type (value
) != nullptr);
1266 if (!target_supports_memory_tagging ())
1269 enum type_code code
= value_type (value
)->code ();
1271 /* Skip non-address values. */
1272 if (code
!= TYPE_CODE_PTR
1273 && !TYPE_IS_REFERENCE (value_type (value
)))
1276 /* OK, we have an address value. Check we have a complete value we
1278 if (value_optimized_out (value
)
1279 || !value_entirely_available (value
))
1282 /* We do. Check whether it includes any tags. */
1283 return gdbarch_tagged_address_p (target_gdbarch (), value
);
1286 /* Helper for parsing arguments for print_command_1. */
1288 static struct value
*
1289 process_print_command_args (const char *args
, value_print_options
*print_opts
,
1292 get_user_print_options (print_opts
);
1293 /* Override global settings with explicit options, if any. */
1294 auto group
= make_value_print_options_def_group (print_opts
);
1295 gdb::option::process_options
1296 (&args
, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER
, group
);
1298 print_command_parse_format (&args
, "print", print_opts
);
1300 const char *exp
= args
;
1302 if (exp
!= nullptr && *exp
)
1304 /* VOIDPRINT is true to indicate that we do want to print a void
1305 value, so invert it for parse_expression. */
1306 expression_up expr
= parse_expression (exp
, nullptr, !voidprint
);
1307 return evaluate_expression (expr
.get ());
1310 return access_value_history (0);
1313 /* Implementation of the "print" and "call" commands. */
1316 print_command_1 (const char *args
, int voidprint
)
1318 value_print_options print_opts
;
1320 struct value
*val
= process_print_command_args (args
, &print_opts
, voidprint
);
1322 if (voidprint
|| (val
&& value_type (val
) &&
1323 value_type (val
)->code () != TYPE_CODE_VOID
))
1325 /* If memory tagging validation is on, check if the tag is valid. */
1326 if (print_opts
.memory_tag_violations
)
1330 if (should_validate_memtags (val
)
1331 && !gdbarch_memtag_matches_p (target_gdbarch (), val
))
1333 /* Fetch the logical tag. */
1335 = gdbarch_get_memtag (target_gdbarch (), val
,
1336 memtag_type::logical
);
1338 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
1340 /* Fetch the allocation tag. */
1341 tag
= gdbarch_get_memtag (target_gdbarch (), val
,
1342 memtag_type::allocation
);
1344 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
1346 printf_filtered (_("Logical tag (%s) does not match the "
1347 "allocation tag (%s).\n"),
1348 ltag
.c_str (), atag
.c_str ());
1351 catch (gdb_exception_error
&ex
)
1353 if (ex
.error
== TARGET_CLOSE_ERROR
)
1356 fprintf_filtered (gdb_stderr
,
1357 _("Could not validate memory tag: %s\n"),
1358 ex
.message
->c_str ());
1362 print_value (val
, print_opts
);
1366 /* Called from command completion function to skip over /FMT
1367 specifications, allowing the rest of the line to be completed. Returns
1368 true if the /FMT is at the end of the current line and there is nothing
1369 left to complete, otherwise false is returned.
1371 In either case *ARGS can be updated to point after any part of /FMT that
1374 This function is designed so that trying to complete '/' will offer no
1375 completions, the user needs to insert the format specification
1376 themselves. Trying to complete '/FMT' (where FMT is any non-empty set
1377 of alpha-numeric characters) will cause readline to insert a single
1378 space, setting the user up to enter the expression. */
1381 skip_over_slash_fmt (completion_tracker
&tracker
, const char **args
)
1383 const char *text
= *args
;
1388 tracker
.set_use_custom_word_point (true);
1390 if (text
[1] == '\0')
1392 /* The user tried to complete after typing just the '/' character
1393 of the /FMT string. Step the completer past the '/', but we
1394 don't offer any completions. */
1400 /* The user has typed some characters after the '/', we assume
1401 this is a complete /FMT string, first skip over it. */
1402 text
= skip_to_space (text
);
1406 /* We're at the end of the input string. The user has typed
1407 '/FMT' and asked for a completion. Push an empty
1408 completion string, this will cause readline to insert a
1409 space so the user now has '/FMT '. */
1411 tracker
.add_completion (make_unique_xstrdup (text
));
1415 /* The user has already typed things after the /FMT, skip the
1416 whitespace and return false. Whoever called this function
1417 should then try to complete what comes next. */
1419 text
= skip_spaces (text
);
1423 tracker
.advance_custom_word_point_by (text
- *args
);
1431 /* See valprint.h. */
1434 print_command_completer (struct cmd_list_element
*ignore
,
1435 completion_tracker
&tracker
,
1436 const char *text
, const char * /*word*/)
1438 const auto group
= make_value_print_options_def_group (nullptr);
1439 if (gdb::option::complete_options
1440 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER
, group
))
1443 if (skip_over_slash_fmt (tracker
, &text
))
1446 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1447 expression_completer (ignore
, tracker
, text
, word
);
1451 print_command (const char *exp
, int from_tty
)
1453 print_command_1 (exp
, true);
1456 /* Same as print, except it doesn't print void results. */
1458 call_command (const char *exp
, int from_tty
)
1460 print_command_1 (exp
, false);
1463 /* Implementation of the "output" command. */
1466 output_command (const char *exp
, int from_tty
)
1470 struct format_data fmt
;
1471 struct value_print_options opts
;
1476 if (exp
&& *exp
== '/')
1479 fmt
= decode_format (&exp
, 0, 0);
1480 validate_format (fmt
, "output");
1481 format
= fmt
.format
;
1484 expression_up expr
= parse_expression (exp
);
1486 val
= evaluate_expression (expr
.get ());
1488 annotate_value_begin (value_type (val
));
1490 get_formatted_print_options (&opts
, format
);
1492 print_formatted (val
, fmt
.size
, &opts
, gdb_stdout
);
1494 annotate_value_end ();
1496 gdb_stdout
->wrap_here (0);
1497 gdb_flush (gdb_stdout
);
1501 set_command (const char *exp
, int from_tty
)
1503 expression_up expr
= parse_expression (exp
);
1505 switch (expr
->op
->opcode ())
1507 case UNOP_PREINCREMENT
:
1508 case UNOP_POSTINCREMENT
:
1509 case UNOP_PREDECREMENT
:
1510 case UNOP_POSTDECREMENT
:
1512 case BINOP_ASSIGN_MODIFY
:
1517 (_("Expression is not an assignment (and might have no effect)"));
1520 evaluate_expression (expr
.get ());
1524 info_symbol_command (const char *arg
, int from_tty
)
1526 struct minimal_symbol
*msymbol
;
1527 struct obj_section
*osect
;
1528 CORE_ADDR addr
, sect_addr
;
1530 unsigned int offset
;
1533 error_no_arg (_("address"));
1535 addr
= parse_and_eval_address (arg
);
1536 for (objfile
*objfile
: current_program_space
->objfiles ())
1537 ALL_OBJFILE_OSECTIONS (objfile
, osect
)
1539 /* Only process each object file once, even if there's a separate
1541 if (objfile
->separate_debug_objfile_backlink
)
1544 sect_addr
= overlay_mapped_address (addr
, osect
);
1546 if (osect
->addr () <= sect_addr
&& sect_addr
< osect
->endaddr ()
1548 = lookup_minimal_symbol_by_pc_section (sect_addr
,
1551 const char *obj_name
, *mapped
, *sec_name
, *msym_name
;
1552 const char *loc_string
;
1555 offset
= sect_addr
- MSYMBOL_VALUE_ADDRESS (objfile
, msymbol
);
1556 mapped
= section_is_mapped (osect
) ? _("mapped") : _("unmapped");
1557 sec_name
= osect
->the_bfd_section
->name
;
1558 msym_name
= msymbol
->print_name ();
1560 /* Don't print the offset if it is zero.
1561 We assume there's no need to handle i18n of "sym + offset". */
1562 std::string string_holder
;
1565 string_holder
= string_printf ("%s + %u", msym_name
, offset
);
1566 loc_string
= string_holder
.c_str ();
1569 loc_string
= msym_name
;
1571 gdb_assert (osect
->objfile
&& objfile_name (osect
->objfile
));
1572 obj_name
= objfile_name (osect
->objfile
);
1574 if (current_program_space
->multi_objfile_p ())
1575 if (pc_in_unmapped_range (addr
, osect
))
1576 if (section_is_overlay (osect
))
1577 printf_filtered (_("%s in load address range of "
1578 "%s overlay section %s of %s\n"),
1579 loc_string
, mapped
, sec_name
, obj_name
);
1581 printf_filtered (_("%s in load address range of "
1582 "section %s of %s\n"),
1583 loc_string
, sec_name
, obj_name
);
1585 if (section_is_overlay (osect
))
1586 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1587 loc_string
, mapped
, sec_name
, obj_name
);
1589 printf_filtered (_("%s in section %s of %s\n"),
1590 loc_string
, sec_name
, obj_name
);
1592 if (pc_in_unmapped_range (addr
, osect
))
1593 if (section_is_overlay (osect
))
1594 printf_filtered (_("%s in load address range of %s overlay "
1596 loc_string
, mapped
, sec_name
);
1599 (_("%s in load address range of section %s\n"),
1600 loc_string
, sec_name
);
1602 if (section_is_overlay (osect
))
1603 printf_filtered (_("%s in %s overlay section %s\n"),
1604 loc_string
, mapped
, sec_name
);
1606 printf_filtered (_("%s in section %s\n"),
1607 loc_string
, sec_name
);
1611 printf_filtered (_("No symbol matches %s.\n"), arg
);
1615 info_address_command (const char *exp
, int from_tty
)
1617 struct gdbarch
*gdbarch
;
1620 struct bound_minimal_symbol msymbol
;
1622 struct obj_section
*section
;
1623 CORE_ADDR load_addr
, context_pc
= 0;
1624 struct field_of_this_result is_a_field_of_this
;
1627 error (_("Argument required."));
1629 sym
= lookup_symbol (exp
, get_selected_block (&context_pc
), VAR_DOMAIN
,
1630 &is_a_field_of_this
).symbol
;
1633 if (is_a_field_of_this
.type
!= NULL
)
1635 printf_filtered ("Symbol \"");
1636 fprintf_symbol_filtered (gdb_stdout
, exp
,
1637 current_language
->la_language
, DMGL_ANSI
);
1638 printf_filtered ("\" is a field of the local class variable ");
1639 if (current_language
->la_language
== language_objc
)
1640 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1642 printf_filtered ("`this'\n");
1646 msymbol
= lookup_bound_minimal_symbol (exp
);
1648 if (msymbol
.minsym
!= NULL
)
1650 struct objfile
*objfile
= msymbol
.objfile
;
1652 gdbarch
= objfile
->arch ();
1653 load_addr
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
1655 printf_filtered ("Symbol \"");
1656 fprintf_symbol_filtered (gdb_stdout
, exp
,
1657 current_language
->la_language
, DMGL_ANSI
);
1658 printf_filtered ("\" is at ");
1659 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1661 printf_filtered (" in a file compiled without debugging");
1662 section
= msymbol
.minsym
->obj_section (objfile
);
1663 if (section_is_overlay (section
))
1665 load_addr
= overlay_unmapped_address (load_addr
, section
);
1666 printf_filtered (",\n -- loaded at ");
1667 fputs_styled (paddress (gdbarch
, load_addr
),
1668 address_style
.style (),
1670 printf_filtered (" in overlay section %s",
1671 section
->the_bfd_section
->name
);
1673 printf_filtered (".\n");
1676 error (_("No symbol \"%s\" in current context."), exp
);
1680 printf_filtered ("Symbol \"");
1681 puts_filtered (sym
->print_name ());
1682 printf_filtered ("\" is ");
1683 val
= SYMBOL_VALUE (sym
);
1684 if (sym
->is_objfile_owned ())
1685 section
= sym
->obj_section (symbol_objfile (sym
));
1688 gdbarch
= symbol_arch (sym
);
1690 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
1692 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, context_pc
,
1694 printf_filtered (".\n");
1698 switch (sym
->aclass ())
1701 case LOC_CONST_BYTES
:
1702 printf_filtered ("constant");
1706 printf_filtered ("a label at address ");
1707 load_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1708 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1710 if (section_is_overlay (section
))
1712 load_addr
= overlay_unmapped_address (load_addr
, section
);
1713 printf_filtered (",\n -- loaded at ");
1714 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1716 printf_filtered (" in overlay section %s",
1717 section
->the_bfd_section
->name
);
1722 gdb_assert_not_reached ("LOC_COMPUTED variable missing a method");
1725 /* GDBARCH is the architecture associated with the objfile the symbol
1726 is defined in; the target architecture may be different, and may
1727 provide additional registers. However, we do not know the target
1728 architecture at this point. We assume the objfile architecture
1729 will contain all the standard registers that occur in debug info
1731 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1733 if (sym
->is_argument ())
1734 printf_filtered (_("an argument in register %s"),
1735 gdbarch_register_name (gdbarch
, regno
));
1737 printf_filtered (_("a variable in register %s"),
1738 gdbarch_register_name (gdbarch
, regno
));
1742 printf_filtered (_("static storage at address "));
1743 load_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1744 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1746 if (section_is_overlay (section
))
1748 load_addr
= overlay_unmapped_address (load_addr
, section
);
1749 printf_filtered (_(",\n -- loaded at "));
1750 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1752 printf_filtered (_(" in overlay section %s"),
1753 section
->the_bfd_section
->name
);
1757 case LOC_REGPARM_ADDR
:
1758 /* Note comment at LOC_REGISTER. */
1759 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1760 printf_filtered (_("address of an argument in register %s"),
1761 gdbarch_register_name (gdbarch
, regno
));
1765 printf_filtered (_("an argument at offset %ld"), val
);
1769 printf_filtered (_("a local variable at frame offset %ld"), val
);
1773 printf_filtered (_("a reference argument at offset %ld"), val
);
1777 printf_filtered (_("a typedef"));
1781 printf_filtered (_("a function at address "));
1782 load_addr
= BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
));
1783 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1785 if (section_is_overlay (section
))
1787 load_addr
= overlay_unmapped_address (load_addr
, section
);
1788 printf_filtered (_(",\n -- loaded at "));
1789 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1791 printf_filtered (_(" in overlay section %s"),
1792 section
->the_bfd_section
->name
);
1796 case LOC_UNRESOLVED
:
1798 struct bound_minimal_symbol msym
;
1800 msym
= lookup_bound_minimal_symbol (sym
->linkage_name ());
1801 if (msym
.minsym
== NULL
)
1802 printf_filtered ("unresolved");
1805 section
= msym
.obj_section ();
1808 && (section
->the_bfd_section
->flags
& SEC_THREAD_LOCAL
) != 0)
1810 load_addr
= MSYMBOL_VALUE_RAW_ADDRESS (msym
.minsym
);
1811 printf_filtered (_("a thread-local variable at offset %s "
1812 "in the thread-local storage for `%s'"),
1813 paddress (gdbarch
, load_addr
),
1814 objfile_name (section
->objfile
));
1818 load_addr
= BMSYMBOL_VALUE_ADDRESS (msym
);
1819 printf_filtered (_("static storage at address "));
1820 fputs_styled (paddress (gdbarch
, load_addr
),
1821 address_style
.style (), gdb_stdout
);
1822 if (section_is_overlay (section
))
1824 load_addr
= overlay_unmapped_address (load_addr
, section
);
1825 printf_filtered (_(",\n -- loaded at "));
1826 fputs_styled (paddress (gdbarch
, load_addr
),
1827 address_style
.style (),
1829 printf_filtered (_(" in overlay section %s"),
1830 section
->the_bfd_section
->name
);
1837 case LOC_OPTIMIZED_OUT
:
1838 printf_filtered (_("optimized out"));
1842 printf_filtered (_("of unknown (botched) type"));
1845 printf_filtered (".\n");
1850 x_command (const char *exp
, int from_tty
)
1852 struct format_data fmt
;
1855 fmt
.format
= last_format
? last_format
: 'x';
1856 fmt
.print_tags
= last_print_tags
;
1857 fmt
.size
= last_size
;
1861 /* If there is no expression and no format, use the most recent
1863 if (exp
== nullptr && last_count
> 0)
1864 fmt
.count
= last_count
;
1866 if (exp
&& *exp
== '/')
1868 const char *tmp
= exp
+ 1;
1870 fmt
= decode_format (&tmp
, last_format
, last_size
);
1874 last_count
= fmt
.count
;
1876 /* If we have an expression, evaluate it and use it as the address. */
1878 if (exp
!= 0 && *exp
!= 0)
1880 expression_up expr
= parse_expression (exp
);
1881 /* Cause expression not to be there any more if this command is
1882 repeated with Newline. But don't clobber a user-defined
1883 command's definition. */
1885 set_repeat_arguments ("");
1886 val
= evaluate_expression (expr
.get ());
1887 if (TYPE_IS_REFERENCE (value_type (val
)))
1888 val
= coerce_ref (val
);
1889 /* In rvalue contexts, such as this, functions are coerced into
1890 pointers to functions. This makes "x/i main" work. */
1891 if (value_type (val
)->code () == TYPE_CODE_FUNC
1892 && VALUE_LVAL (val
) == lval_memory
)
1893 next_address
= value_address (val
);
1895 next_address
= value_as_address (val
);
1897 next_gdbarch
= expr
->gdbarch
;
1901 error_no_arg (_("starting display address"));
1903 do_examine (fmt
, next_gdbarch
, next_address
);
1905 /* If the examine succeeds, we remember its size and format for next
1906 time. Set last_size to 'b' for strings. */
1907 if (fmt
.format
== 's')
1910 last_size
= fmt
.size
;
1911 last_format
= fmt
.format
;
1913 /* Remember tag-printing setting. */
1914 last_print_tags
= fmt
.print_tags
;
1916 /* Set a couple of internal variables if appropriate. */
1917 if (last_examine_value
!= nullptr)
1919 /* Make last address examined available to the user as $_. Use
1920 the correct pointer type. */
1921 struct type
*pointer_type
1922 = lookup_pointer_type (value_type (last_examine_value
.get ()));
1923 set_internalvar (lookup_internalvar ("_"),
1924 value_from_pointer (pointer_type
,
1925 last_examine_address
));
1927 /* Make contents of last address examined available to the user
1928 as $__. If the last value has not been fetched from memory
1929 then don't fetch it now; instead mark it by voiding the $__
1931 if (value_lazy (last_examine_value
.get ()))
1932 clear_internalvar (lookup_internalvar ("__"));
1934 set_internalvar (lookup_internalvar ("__"), last_examine_value
.get ());
1938 /* Command completion for the 'display' and 'x' commands. */
1941 display_and_x_command_completer (struct cmd_list_element
*ignore
,
1942 completion_tracker
&tracker
,
1943 const char *text
, const char * /*word*/)
1945 if (skip_over_slash_fmt (tracker
, &text
))
1948 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1949 expression_completer (ignore
, tracker
, text
, word
);
1954 /* Add an expression to the auto-display chain.
1955 Specify the expression. */
1958 display_command (const char *arg
, int from_tty
)
1960 struct format_data fmt
;
1961 struct display
*newobj
;
1962 const char *exp
= arg
;
1973 fmt
= decode_format (&exp
, 0, 0);
1974 if (fmt
.size
&& fmt
.format
== 0)
1976 if (fmt
.format
== 'i' || fmt
.format
== 's')
1987 innermost_block_tracker tracker
;
1988 expression_up expr
= parse_expression (exp
, &tracker
);
1990 newobj
= new display (exp
, std::move (expr
), fmt
,
1991 current_program_space
, tracker
.block ());
1992 all_displays
.emplace_back (newobj
);
1995 do_one_display (newobj
);
2000 /* Clear out the display_chain. Done when new symtabs are loaded,
2001 since this invalidates the types stored in many expressions. */
2006 all_displays
.clear ();
2009 /* Delete the auto-display DISPLAY. */
2012 delete_display (struct display
*display
)
2014 gdb_assert (display
!= NULL
);
2016 auto iter
= std::find_if (all_displays
.begin (),
2017 all_displays
.end (),
2018 [=] (const std::unique_ptr
<struct display
> &item
)
2020 return item
.get () == display
;
2022 gdb_assert (iter
!= all_displays
.end ());
2023 all_displays
.erase (iter
);
2026 /* Call FUNCTION on each of the displays whose numbers are given in
2027 ARGS. DATA is passed unmodified to FUNCTION. */
2030 map_display_numbers (const char *args
,
2031 gdb::function_view
<void (struct display
*)> function
)
2036 error_no_arg (_("one or more display numbers"));
2038 number_or_range_parser
parser (args
);
2040 while (!parser
.finished ())
2042 const char *p
= parser
.cur_tok ();
2044 num
= parser
.get_number ();
2046 warning (_("bad display number at or near '%s'"), p
);
2049 auto iter
= std::find_if (all_displays
.begin (),
2050 all_displays
.end (),
2051 [=] (const std::unique_ptr
<display
> &item
)
2053 return item
->number
== num
;
2055 if (iter
== all_displays
.end ())
2056 printf_filtered (_("No display number %d.\n"), num
);
2058 function (iter
->get ());
2063 /* "undisplay" command. */
2066 undisplay_command (const char *args
, int from_tty
)
2070 if (query (_("Delete all auto-display expressions? ")))
2076 map_display_numbers (args
, delete_display
);
2080 /* Display a single auto-display.
2081 Do nothing if the display cannot be printed in the current context,
2082 or if the display is disabled. */
2085 do_one_display (struct display
*d
)
2087 int within_current_scope
;
2092 /* The expression carries the architecture that was used at parse time.
2093 This is a problem if the expression depends on architecture features
2094 (e.g. register numbers), and the current architecture is now different.
2095 For example, a display statement like "display/i $pc" is expected to
2096 display the PC register of the current architecture, not the arch at
2097 the time the display command was given. Therefore, we re-parse the
2098 expression if the current architecture has changed. */
2099 if (d
->exp
!= NULL
&& d
->exp
->gdbarch
!= get_current_arch ())
2110 innermost_block_tracker tracker
;
2111 d
->exp
= parse_expression (d
->exp_string
.c_str (), &tracker
);
2112 d
->block
= tracker
.block ();
2114 catch (const gdb_exception
&ex
)
2116 /* Can't re-parse the expression. Disable this display item. */
2117 d
->enabled_p
= false;
2118 warning (_("Unable to display \"%s\": %s"),
2119 d
->exp_string
.c_str (), ex
.what ());
2126 if (d
->pspace
== current_program_space
)
2127 within_current_scope
= contained_in (get_selected_block (0), d
->block
,
2130 within_current_scope
= 0;
2133 within_current_scope
= 1;
2134 if (!within_current_scope
)
2137 scoped_restore save_display_number
2138 = make_scoped_restore (¤t_display_number
, d
->number
);
2140 annotate_display_begin ();
2141 printf_filtered ("%d", d
->number
);
2142 annotate_display_number_end ();
2143 printf_filtered (": ");
2147 annotate_display_format ();
2149 printf_filtered ("x/");
2150 if (d
->format
.count
!= 1)
2151 printf_filtered ("%d", d
->format
.count
);
2152 printf_filtered ("%c", d
->format
.format
);
2153 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
2154 printf_filtered ("%c", d
->format
.size
);
2155 printf_filtered (" ");
2157 annotate_display_expression ();
2159 puts_filtered (d
->exp_string
.c_str ());
2160 annotate_display_expression_end ();
2162 if (d
->format
.count
!= 1 || d
->format
.format
== 'i')
2163 printf_filtered ("\n");
2165 printf_filtered (" ");
2167 annotate_display_value ();
2174 val
= evaluate_expression (d
->exp
.get ());
2175 addr
= value_as_address (val
);
2176 if (d
->format
.format
== 'i')
2177 addr
= gdbarch_addr_bits_remove (d
->exp
->gdbarch
, addr
);
2178 do_examine (d
->format
, d
->exp
->gdbarch
, addr
);
2180 catch (const gdb_exception_error
&ex
)
2182 printf_filtered (_("%p[<error: %s>%p]\n"),
2183 metadata_style
.style ().ptr (), ex
.what (),
2189 struct value_print_options opts
;
2191 annotate_display_format ();
2193 if (d
->format
.format
)
2194 printf_filtered ("/%c ", d
->format
.format
);
2196 annotate_display_expression ();
2198 puts_filtered (d
->exp_string
.c_str ());
2199 annotate_display_expression_end ();
2201 printf_filtered (" = ");
2203 annotate_display_expression ();
2205 get_formatted_print_options (&opts
, d
->format
.format
);
2206 opts
.raw
= d
->format
.raw
;
2212 val
= evaluate_expression (d
->exp
.get ());
2213 print_formatted (val
, d
->format
.size
, &opts
, gdb_stdout
);
2215 catch (const gdb_exception_error
&ex
)
2217 fprintf_styled (gdb_stdout
, metadata_style
.style (),
2218 _("<error: %s>"), ex
.what ());
2221 printf_filtered ("\n");
2224 annotate_display_end ();
2226 gdb_flush (gdb_stdout
);
2229 /* Display all of the values on the auto-display chain which can be
2230 evaluated in the current scope. */
2235 for (auto &d
: all_displays
)
2236 do_one_display (d
.get ());
2239 /* Delete the auto-display which we were in the process of displaying.
2240 This is done when there is an error or a signal. */
2243 disable_display (int num
)
2245 for (auto &d
: all_displays
)
2246 if (d
->number
== num
)
2248 d
->enabled_p
= false;
2251 printf_filtered (_("No display number %d.\n"), num
);
2255 disable_current_display (void)
2257 if (current_display_number
>= 0)
2259 disable_display (current_display_number
);
2260 fprintf_unfiltered (gdb_stderr
,
2261 _("Disabling display %d to "
2262 "avoid infinite recursion.\n"),
2263 current_display_number
);
2265 current_display_number
= -1;
2269 info_display_command (const char *ignore
, int from_tty
)
2271 if (all_displays
.empty ())
2272 printf_filtered (_("There are no auto-display expressions now.\n"));
2274 printf_filtered (_("Auto-display expressions now in effect:\n\
2275 Num Enb Expression\n"));
2277 for (auto &d
: all_displays
)
2279 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
2281 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
2283 else if (d
->format
.format
)
2284 printf_filtered ("/%c ", d
->format
.format
);
2285 puts_filtered (d
->exp_string
.c_str ());
2286 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
, true))
2287 printf_filtered (_(" (cannot be evaluated in the current context)"));
2288 printf_filtered ("\n");
2292 /* Implementation of both the "disable display" and "enable display"
2293 commands. ENABLE decides what to do. */
2296 enable_disable_display_command (const char *args
, int from_tty
, bool enable
)
2300 for (auto &d
: all_displays
)
2301 d
->enabled_p
= enable
;
2305 map_display_numbers (args
,
2306 [=] (struct display
*d
)
2308 d
->enabled_p
= enable
;
2312 /* The "enable display" command. */
2315 enable_display_command (const char *args
, int from_tty
)
2317 enable_disable_display_command (args
, from_tty
, true);
2320 /* The "disable display" command. */
2323 disable_display_command (const char *args
, int from_tty
)
2325 enable_disable_display_command (args
, from_tty
, false);
2328 /* display_chain items point to blocks and expressions. Some expressions in
2329 turn may point to symbols.
2330 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
2331 obstack_free'd when a shared library is unloaded.
2332 Clear pointers that are about to become dangling.
2333 Both .exp and .block fields will be restored next time we need to display
2334 an item by re-parsing .exp_string field in the new execution context. */
2337 clear_dangling_display_expressions (struct objfile
*objfile
)
2339 struct program_space
*pspace
;
2341 /* With no symbol file we cannot have a block or expression from it. */
2342 if (objfile
== NULL
)
2344 pspace
= objfile
->pspace
;
2345 if (objfile
->separate_debug_objfile_backlink
)
2347 objfile
= objfile
->separate_debug_objfile_backlink
;
2348 gdb_assert (objfile
->pspace
== pspace
);
2351 for (auto &d
: all_displays
)
2353 if (d
->pspace
!= pspace
)
2356 struct objfile
*bl_objf
= nullptr;
2357 if (d
->block
!= nullptr)
2359 bl_objf
= block_objfile (d
->block
);
2360 if (bl_objf
->separate_debug_objfile_backlink
!= nullptr)
2361 bl_objf
= bl_objf
->separate_debug_objfile_backlink
;
2364 if (bl_objf
== objfile
2365 || (d
->exp
!= NULL
&& exp_uses_objfile (d
->exp
.get (), objfile
)))
2374 /* Print the value in stack frame FRAME of a variable specified by a
2375 struct symbol. NAME is the name to print; if NULL then VAR's print
2376 name will be used. STREAM is the ui_file on which to print the
2377 value. INDENT specifies the number of indent levels to print
2378 before printing the variable name.
2380 This function invalidates FRAME. */
2383 print_variable_and_value (const char *name
, struct symbol
*var
,
2384 struct frame_info
*frame
,
2385 struct ui_file
*stream
, int indent
)
2389 name
= var
->print_name ();
2391 fprintf_filtered (stream
, "%*s%ps = ", 2 * indent
, "",
2392 styled_string (variable_name_style
.style (), name
));
2397 struct value_print_options opts
;
2399 /* READ_VAR_VALUE needs a block in order to deal with non-local
2400 references (i.e. to handle nested functions). In this context, we
2401 print variables that are local to this frame, so we can avoid passing
2403 val
= read_var_value (var
, NULL
, frame
);
2404 get_user_print_options (&opts
);
2406 common_val_print_checked (val
, stream
, indent
, &opts
, current_language
);
2408 /* common_val_print invalidates FRAME when a pretty printer calls inferior
2412 catch (const gdb_exception_error
&except
)
2414 fprintf_styled (stream
, metadata_style
.style (),
2415 "<error reading variable %s (%s)>", name
,
2419 fprintf_filtered (stream
, "\n");
2422 /* Subroutine of ui_printf to simplify it.
2423 Print VALUE to STREAM using FORMAT.
2424 VALUE is a C-style string either on the target or
2425 in a GDB internal variable. */
2428 printf_c_string (struct ui_file
*stream
, const char *format
,
2429 struct value
*value
)
2431 const gdb_byte
*str
;
2433 if (value_type (value
)->code () != TYPE_CODE_PTR
2434 && VALUE_LVAL (value
) == lval_internalvar
2435 && c_is_string_type_p (value_type (value
)))
2437 size_t len
= TYPE_LENGTH (value_type (value
));
2439 /* Copy the internal var value to TEM_STR and append a terminating null
2440 character. This protects against corrupted C-style strings that lack
2441 the terminating null char. It also allows Ada-style strings (not
2442 null terminated) to be printed without problems. */
2443 gdb_byte
*tem_str
= (gdb_byte
*) alloca (len
+ 1);
2445 memcpy (tem_str
, value_contents (value
).data (), len
);
2451 CORE_ADDR tem
= value_as_address (value
);;
2456 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2457 fprintf_filtered (stream
, format
, "(null)");
2462 /* This is a %s argument. Find the length of the string. */
2465 for (len
= 0;; len
++)
2470 read_memory (tem
+ len
, &c
, 1);
2475 /* Copy the string contents into a string inside GDB. */
2476 gdb_byte
*tem_str
= (gdb_byte
*) alloca (len
+ 1);
2479 read_memory (tem
, tem_str
, len
);
2485 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2486 fprintf_filtered (stream
, format
, (char *) str
);
2490 /* Subroutine of ui_printf to simplify it.
2491 Print VALUE to STREAM using FORMAT.
2492 VALUE is a wide C-style string on the target or
2493 in a GDB internal variable. */
2496 printf_wide_c_string (struct ui_file
*stream
, const char *format
,
2497 struct value
*value
)
2499 const gdb_byte
*str
;
2501 struct gdbarch
*gdbarch
= value_type (value
)->arch ();
2502 struct type
*wctype
= lookup_typename (current_language
,
2503 "wchar_t", NULL
, 0);
2504 int wcwidth
= TYPE_LENGTH (wctype
);
2506 if (VALUE_LVAL (value
) == lval_internalvar
2507 && c_is_string_type_p (value_type (value
)))
2509 str
= value_contents (value
).data ();
2510 len
= TYPE_LENGTH (value_type (value
));
2514 CORE_ADDR tem
= value_as_address (value
);
2519 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2520 fprintf_filtered (stream
, format
, "(null)");
2525 /* This is a %s argument. Find the length of the string. */
2526 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2527 gdb_byte
*buf
= (gdb_byte
*) alloca (wcwidth
);
2529 for (len
= 0;; len
+= wcwidth
)
2532 read_memory (tem
+ len
, buf
, wcwidth
);
2533 if (extract_unsigned_integer (buf
, wcwidth
, byte_order
) == 0)
2537 /* Copy the string contents into a string inside GDB. */
2538 gdb_byte
*tem_str
= (gdb_byte
*) alloca (len
+ wcwidth
);
2541 read_memory (tem
, tem_str
, len
);
2542 memset (&tem_str
[len
], 0, wcwidth
);
2546 auto_obstack output
;
2548 convert_between_encodings (target_wide_charset (gdbarch
),
2551 &output
, translit_char
);
2552 obstack_grow_str0 (&output
, "");
2555 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2556 fprintf_filtered (stream
, format
, obstack_base (&output
));
2560 /* Subroutine of ui_printf to simplify it.
2561 Print VALUE, a floating point value, to STREAM using FORMAT. */
2564 printf_floating (struct ui_file
*stream
, const char *format
,
2565 struct value
*value
, enum argclass argclass
)
2567 /* Parameter data. */
2568 struct type
*param_type
= value_type (value
);
2569 struct gdbarch
*gdbarch
= param_type
->arch ();
2571 /* Determine target type corresponding to the format string. */
2572 struct type
*fmt_type
;
2576 fmt_type
= builtin_type (gdbarch
)->builtin_double
;
2578 case long_double_arg
:
2579 fmt_type
= builtin_type (gdbarch
)->builtin_long_double
;
2581 case dec32float_arg
:
2582 fmt_type
= builtin_type (gdbarch
)->builtin_decfloat
;
2584 case dec64float_arg
:
2585 fmt_type
= builtin_type (gdbarch
)->builtin_decdouble
;
2587 case dec128float_arg
:
2588 fmt_type
= builtin_type (gdbarch
)->builtin_declong
;
2591 gdb_assert_not_reached ("unexpected argument class");
2594 /* To match the traditional GDB behavior, the conversion is
2595 done differently depending on the type of the parameter:
2597 - if the parameter has floating-point type, it's value
2598 is converted to the target type;
2600 - otherwise, if the parameter has a type that is of the
2601 same size as a built-in floating-point type, the value
2602 bytes are interpreted as if they were of that type, and
2603 then converted to the target type (this is not done for
2604 decimal floating-point argument classes);
2606 - otherwise, if the source value has an integer value,
2607 it's value is converted to the target type;
2609 - otherwise, an error is raised.
2611 In either case, the result of the conversion is a byte buffer
2612 formatted in the target format for the target type. */
2614 if (fmt_type
->code () == TYPE_CODE_FLT
)
2616 param_type
= float_type_from_length (param_type
);
2617 if (param_type
!= value_type (value
))
2618 value
= value_from_contents (param_type
,
2619 value_contents (value
).data ());
2622 value
= value_cast (fmt_type
, value
);
2624 /* Convert the value to a string and print it. */
2626 = target_float_to_string (value_contents (value
).data (), fmt_type
, format
);
2627 fputs_filtered (str
.c_str (), stream
);
2630 /* Subroutine of ui_printf to simplify it.
2631 Print VALUE, a target pointer, to STREAM using FORMAT. */
2634 printf_pointer (struct ui_file
*stream
, const char *format
,
2635 struct value
*value
)
2637 /* We avoid the host's %p because pointers are too
2638 likely to be the wrong size. The only interesting
2639 modifier for %p is a width; extract that, and then
2640 handle %p as glibc would: %#x or a literal "(nil)". */
2644 #ifdef PRINTF_HAS_LONG_LONG
2645 long long val
= value_as_long (value
);
2647 long val
= value_as_long (value
);
2650 fmt
= (char *) alloca (strlen (format
) + 5);
2652 /* Copy up to the leading %. */
2657 int is_percent
= (*p
== '%');
2672 /* Copy any width or flags. Only the "-" flag is valid for pointers
2673 -- see the format_pieces constructor. */
2674 while (*p
== '-' || (*p
>= '0' && *p
< '9'))
2677 gdb_assert (*p
== 'p' && *(p
+ 1) == '\0');
2680 #ifdef PRINTF_HAS_LONG_LONG
2687 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2688 fprintf_filtered (stream
, fmt
, val
);
2696 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2697 fprintf_filtered (stream
, fmt
, "(nil)");
2702 /* printf "printf format string" ARG to STREAM. */
2705 ui_printf (const char *arg
, struct ui_file
*stream
)
2707 const char *s
= arg
;
2708 std::vector
<struct value
*> val_args
;
2711 error_no_arg (_("format-control string and values to print"));
2713 s
= skip_spaces (s
);
2715 /* A format string should follow, enveloped in double quotes. */
2717 error (_("Bad format string, missing '\"'."));
2719 format_pieces
fpieces (&s
);
2722 error (_("Bad format string, non-terminated '\"'."));
2724 s
= skip_spaces (s
);
2726 if (*s
!= ',' && *s
!= 0)
2727 error (_("Invalid argument syntax"));
2731 s
= skip_spaces (s
);
2736 const char *current_substring
;
2739 for (auto &&piece
: fpieces
)
2740 if (piece
.argclass
!= literal_piece
)
2743 /* Now, parse all arguments and evaluate them.
2744 Store the VALUEs in VAL_ARGS. */
2751 val_args
.push_back (parse_to_comma_and_eval (&s1
));
2758 if (val_args
.size () != nargs_wanted
)
2759 error (_("Wrong number of arguments for specified format-string"));
2761 /* Now actually print them. */
2763 for (auto &&piece
: fpieces
)
2765 current_substring
= piece
.string
;
2766 switch (piece
.argclass
)
2769 printf_c_string (stream
, current_substring
, val_args
[i
]);
2771 case wide_string_arg
:
2772 printf_wide_c_string (stream
, current_substring
, val_args
[i
]);
2776 struct gdbarch
*gdbarch
= value_type (val_args
[i
])->arch ();
2777 struct type
*wctype
= lookup_typename (current_language
,
2778 "wchar_t", NULL
, 0);
2779 struct type
*valtype
;
2780 const gdb_byte
*bytes
;
2782 valtype
= value_type (val_args
[i
]);
2783 if (TYPE_LENGTH (valtype
) != TYPE_LENGTH (wctype
)
2784 || valtype
->code () != TYPE_CODE_INT
)
2785 error (_("expected wchar_t argument for %%lc"));
2787 bytes
= value_contents (val_args
[i
]).data ();
2789 auto_obstack output
;
2791 convert_between_encodings (target_wide_charset (gdbarch
),
2793 bytes
, TYPE_LENGTH (valtype
),
2794 TYPE_LENGTH (valtype
),
2795 &output
, translit_char
);
2796 obstack_grow_str0 (&output
, "");
2799 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2800 fprintf_filtered (stream
, current_substring
,
2801 obstack_base (&output
));
2806 #ifdef PRINTF_HAS_LONG_LONG
2808 long long val
= value_as_long (val_args
[i
]);
2811 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2812 fprintf_filtered (stream
, current_substring
, val
);
2817 error (_("long long not supported in printf"));
2821 int val
= value_as_long (val_args
[i
]);
2824 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2825 fprintf_filtered (stream
, current_substring
, val
);
2831 long val
= value_as_long (val_args
[i
]);
2834 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2835 fprintf_filtered (stream
, current_substring
, val
);
2841 size_t val
= value_as_long (val_args
[i
]);
2844 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2845 fprintf_filtered (stream
, current_substring
, val
);
2849 /* Handles floating-point values. */
2851 case long_double_arg
:
2852 case dec32float_arg
:
2853 case dec64float_arg
:
2854 case dec128float_arg
:
2855 printf_floating (stream
, current_substring
, val_args
[i
],
2859 printf_pointer (stream
, current_substring
, val_args
[i
]);
2862 /* Print a portion of the format string that has no
2863 directives. Note that this will not include any
2864 ordinary %-specs, but it might include "%%". That is
2865 why we use printf_filtered and not puts_filtered here.
2866 Also, we pass a dummy argument because some platforms
2867 have modified GCC to include -Wformat-security by
2868 default, which will warn here if there is no
2871 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2872 fprintf_filtered (stream
, current_substring
, 0);
2876 internal_error (__FILE__
, __LINE__
,
2877 _("failed internal consistency check"));
2879 /* Maybe advance to the next argument. */
2880 if (piece
.argclass
!= literal_piece
)
2886 /* Implement the "printf" command. */
2889 printf_command (const char *arg
, int from_tty
)
2891 ui_printf (arg
, gdb_stdout
);
2892 reset_terminal_style (gdb_stdout
);
2893 gdb_stdout
->wrap_here (0);
2894 gdb_stdout
->flush ();
2897 /* Implement the "eval" command. */
2900 eval_command (const char *arg
, int from_tty
)
2904 ui_printf (arg
, &stb
);
2906 std::string expanded
= insert_user_defined_cmd_args (stb
.c_str ());
2908 execute_command (expanded
.c_str (), from_tty
);
2911 /* Convenience function for error checking in memory-tag commands. */
2914 show_addr_not_tagged (CORE_ADDR address
)
2916 error (_("Address %s not in a region mapped with a memory tagging flag."),
2917 paddress (target_gdbarch (), address
));
2920 /* Convenience function for error checking in memory-tag commands. */
2923 show_memory_tagging_unsupported (void)
2925 error (_("Memory tagging not supported or disabled by the current"
2929 /* Implement the "memory-tag" prefix command. */
2932 memory_tag_command (const char *arg
, int from_tty
)
2934 help_list (memory_tag_list
, "memory-tag ", all_commands
, gdb_stdout
);
2937 /* Helper for print-logical-tag and print-allocation-tag. */
2940 memory_tag_print_tag_command (const char *args
, enum memtag_type tag_type
)
2942 if (args
== nullptr)
2943 error_no_arg (_("address or pointer"));
2945 /* Parse args into a value. If the value is a pointer or an address,
2946 then fetch the logical or allocation tag. */
2947 value_print_options print_opts
;
2949 struct value
*val
= process_print_command_args (args
, &print_opts
, true);
2951 /* If the address is not in a region memory mapped with a memory tagging
2952 flag, it is no use trying to access/manipulate its allocation tag.
2954 It is OK to manipulate the logical tag though. */
2955 if (tag_type
== memtag_type::allocation
2956 && !gdbarch_tagged_address_p (target_gdbarch (), val
))
2957 show_addr_not_tagged (value_as_address (val
));
2959 struct value
*tag_value
2960 = gdbarch_get_memtag (target_gdbarch (), val
, tag_type
);
2961 std::string tag
= gdbarch_memtag_to_string (target_gdbarch (), tag_value
);
2964 printf_filtered (_("%s tag unavailable.\n"),
2966 == memtag_type::logical
? "Logical" : "Allocation");
2968 struct value
*v_tag
= process_print_command_args (tag
.c_str (),
2971 print_opts
.output_format
= 'x';
2972 print_value (v_tag
, print_opts
);
2975 /* Implement the "memory-tag print-logical-tag" command. */
2978 memory_tag_print_logical_tag_command (const char *args
, int from_tty
)
2980 if (!target_supports_memory_tagging ())
2981 show_memory_tagging_unsupported ();
2983 memory_tag_print_tag_command (args
, memtag_type::logical
);
2986 /* Implement the "memory-tag print-allocation-tag" command. */
2989 memory_tag_print_allocation_tag_command (const char *args
, int from_tty
)
2991 if (!target_supports_memory_tagging ())
2992 show_memory_tagging_unsupported ();
2994 memory_tag_print_tag_command (args
, memtag_type::allocation
);
2997 /* Parse ARGS and extract ADDR and TAG.
2998 ARGS should have format <expression> <tag bytes>. */
3001 parse_with_logical_tag_input (const char *args
, struct value
**val
,
3002 gdb::byte_vector
&tags
,
3003 value_print_options
*print_opts
)
3005 /* Fetch the address. */
3006 std::string address_string
= extract_string_maybe_quoted (&args
);
3008 /* Parse the address into a value. */
3009 *val
= process_print_command_args (address_string
.c_str (), print_opts
,
3012 /* Fetch the tag bytes. */
3013 std::string tag_string
= extract_string_maybe_quoted (&args
);
3015 /* Validate the input. */
3016 if (address_string
.empty () || tag_string
.empty ())
3017 error (_("Missing arguments."));
3019 if (tag_string
.length () != 2)
3020 error (_("Error parsing tags argument. The tag should be 2 digits."));
3022 tags
= hex2bin (tag_string
.c_str ());
3025 /* Implement the "memory-tag with-logical-tag" command. */
3028 memory_tag_with_logical_tag_command (const char *args
, int from_tty
)
3030 if (!target_supports_memory_tagging ())
3031 show_memory_tagging_unsupported ();
3033 if (args
== nullptr)
3034 error_no_arg (_("<address> <tag>"));
3036 gdb::byte_vector tags
;
3038 value_print_options print_opts
;
3040 /* Parse the input. */
3041 parse_with_logical_tag_input (args
, &val
, tags
, &print_opts
);
3043 /* Setting the logical tag is just a local operation that does not touch
3044 any memory from the target. Given an input value, we modify the value
3045 to include the appropriate tag.
3047 For this reason we need to cast the argument value to a
3048 (void *) pointer. This is so we have the right type for the gdbarch
3049 hook to manipulate the value and insert the tag.
3051 Otherwise, this would fail if, for example, GDB parsed the argument value
3052 into an int-sized value and the pointer value has a type of greater
3055 /* Cast to (void *). */
3056 val
= value_cast (builtin_type (target_gdbarch ())->builtin_data_ptr
,
3059 /* Length doesn't matter for a logical tag. Pass 0. */
3060 if (!gdbarch_set_memtags (target_gdbarch (), val
, 0, tags
,
3061 memtag_type::logical
))
3062 printf_filtered (_("Could not update the logical tag data.\n"));
3065 /* Always print it in hex format. */
3066 print_opts
.output_format
= 'x';
3067 print_value (val
, print_opts
);
3071 /* Parse ARGS and extract ADDR, LENGTH and TAGS. */
3074 parse_set_allocation_tag_input (const char *args
, struct value
**val
,
3075 size_t *length
, gdb::byte_vector
&tags
)
3077 /* Fetch the address. */
3078 std::string address_string
= extract_string_maybe_quoted (&args
);
3080 /* Parse the address into a value. */
3081 value_print_options print_opts
;
3082 *val
= process_print_command_args (address_string
.c_str (), &print_opts
,
3085 /* Fetch the length. */
3086 std::string length_string
= extract_string_maybe_quoted (&args
);
3088 /* Fetch the tag bytes. */
3089 std::string tags_string
= extract_string_maybe_quoted (&args
);
3091 /* Validate the input. */
3092 if (address_string
.empty () || length_string
.empty () || tags_string
.empty ())
3093 error (_("Missing arguments."));
3096 const char *trailer
= nullptr;
3097 LONGEST parsed_length
= strtoulst (length_string
.c_str (), &trailer
, 10);
3099 if (errno
!= 0 || (trailer
!= nullptr && trailer
[0] != '\0'))
3100 error (_("Error parsing length argument."));
3102 if (parsed_length
<= 0)
3103 error (_("Invalid zero or negative length."));
3105 *length
= parsed_length
;
3107 if (tags_string
.length () % 2)
3108 error (_("Error parsing tags argument. Tags should be 2 digits per byte."));
3110 tags
= hex2bin (tags_string
.c_str ());
3112 /* If the address is not in a region memory mapped with a memory tagging
3113 flag, it is no use trying to access/manipulate its allocation tag. */
3114 if (!gdbarch_tagged_address_p (target_gdbarch (), *val
))
3115 show_addr_not_tagged (value_as_address (*val
));
3118 /* Implement the "memory-tag set-allocation-tag" command.
3119 ARGS should be in the format <address> <length> <tags>. */
3122 memory_tag_set_allocation_tag_command (const char *args
, int from_tty
)
3124 if (!target_supports_memory_tagging ())
3125 show_memory_tagging_unsupported ();
3127 if (args
== nullptr)
3128 error_no_arg (_("<starting address> <length> <tag bytes>"));
3130 gdb::byte_vector tags
;
3134 /* Parse the input. */
3135 parse_set_allocation_tag_input (args
, &val
, &length
, tags
);
3137 if (!gdbarch_set_memtags (target_gdbarch (), val
, length
, tags
,
3138 memtag_type::allocation
))
3139 printf_filtered (_("Could not update the allocation tag(s).\n"));
3141 printf_filtered (_("Allocation tag(s) updated successfully.\n"));
3144 /* Implement the "memory-tag check" command. */
3147 memory_tag_check_command (const char *args
, int from_tty
)
3149 if (!target_supports_memory_tagging ())
3150 show_memory_tagging_unsupported ();
3152 if (args
== nullptr)
3153 error (_("Argument required (address or pointer)"));
3155 /* Parse the expression into a value. If the value is an address or
3156 pointer, then check its logical tag against the allocation tag. */
3157 value_print_options print_opts
;
3159 struct value
*val
= process_print_command_args (args
, &print_opts
, true);
3161 /* If the address is not in a region memory mapped with a memory tagging
3162 flag, it is no use trying to access/manipulate its allocation tag. */
3163 if (!gdbarch_tagged_address_p (target_gdbarch (), val
))
3164 show_addr_not_tagged (value_as_address (val
));
3166 CORE_ADDR addr
= value_as_address (val
);
3168 /* Check if the tag is valid. */
3169 if (!gdbarch_memtag_matches_p (target_gdbarch (), val
))
3172 = gdbarch_get_memtag (target_gdbarch (), val
, memtag_type::logical
);
3174 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
3176 tag
= gdbarch_get_memtag (target_gdbarch (), val
,
3177 memtag_type::allocation
);
3179 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
3181 printf_filtered (_("Logical tag (%s) does not match"
3182 " the allocation tag (%s) for address %s.\n"),
3183 ltag
.c_str (), atag
.c_str (),
3184 paddress (target_gdbarch (), addr
));
3189 = gdbarch_get_memtag (target_gdbarch (), val
, memtag_type::logical
);
3191 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
3193 printf_filtered (_("Memory tags for address %s match (%s).\n"),
3194 paddress (target_gdbarch (), addr
), ltag
.c_str ());
3198 void _initialize_printcmd ();
3200 _initialize_printcmd ()
3202 struct cmd_list_element
*c
;
3204 current_display_number
= -1;
3206 gdb::observers::free_objfile
.attach (clear_dangling_display_expressions
,
3209 add_info ("address", info_address_command
,
3210 _("Describe where symbol SYM is stored.\n\
3211 Usage: info address SYM"));
3213 add_info ("symbol", info_symbol_command
, _("\
3214 Describe what symbol is at location ADDR.\n\
3215 Usage: info symbol ADDR\n\
3216 Only for symbols with fixed locations (global or static scope)."));
3218 c
= add_com ("x", class_vars
, x_command
, _("\
3219 Examine memory: x/FMT ADDRESS.\n\
3220 ADDRESS is an expression for the memory address to examine.\n\
3221 FMT is a repeat count followed by a format letter and a size letter.\n\
3222 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
3223 t(binary), f(float), a(address), i(instruction), c(char), s(string)\n\
3224 and z(hex, zero padded on the left).\n\
3225 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
3226 The specified number of objects of the specified size are printed\n\
3227 according to the format. If a negative number is specified, memory is\n\
3228 examined backward from the address.\n\n\
3229 Defaults for format and size letters are those previously used.\n\
3230 Default count is 1. Default address is following last thing printed\n\
3231 with this command or \"print\"."));
3232 set_cmd_completer_handle_brkchars (c
, display_and_x_command_completer
);
3234 add_info ("display", info_display_command
, _("\
3235 Expressions to display when program stops, with code numbers.\n\
3236 Usage: info display"));
3238 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
3239 Cancel some expressions to be displayed when program stops.\n\
3240 Usage: undisplay [NUM]...\n\
3241 Arguments are the code numbers of the expressions to stop displaying.\n\
3242 No argument means cancel all automatic-display expressions.\n\
3243 \"delete display\" has the same effect as this command.\n\
3244 Do \"info display\" to see current list of code numbers."),
3247 c
= add_com ("display", class_vars
, display_command
, _("\
3248 Print value of expression EXP each time the program stops.\n\
3249 Usage: display[/FMT] EXP\n\
3250 /FMT may be used before EXP as in the \"print\" command.\n\
3251 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
3252 as in the \"x\" command, and then EXP is used to get the address to examine\n\
3253 and examining is done as in the \"x\" command.\n\n\
3254 With no argument, display all currently requested auto-display expressions.\n\
3255 Use \"undisplay\" to cancel display requests previously made."));
3256 set_cmd_completer_handle_brkchars (c
, display_and_x_command_completer
);
3258 add_cmd ("display", class_vars
, enable_display_command
, _("\
3259 Enable some expressions to be displayed when program stops.\n\
3260 Usage: enable display [NUM]...\n\
3261 Arguments are the code numbers of the expressions to resume displaying.\n\
3262 No argument means enable all automatic-display expressions.\n\
3263 Do \"info display\" to see current list of code numbers."), &enablelist
);
3265 add_cmd ("display", class_vars
, disable_display_command
, _("\
3266 Disable some expressions to be displayed when program stops.\n\
3267 Usage: disable display [NUM]...\n\
3268 Arguments are the code numbers of the expressions to stop displaying.\n\
3269 No argument means disable all automatic-display expressions.\n\
3270 Do \"info display\" to see current list of code numbers."), &disablelist
);
3272 add_cmd ("display", class_vars
, undisplay_command
, _("\
3273 Cancel some expressions to be displayed when program stops.\n\
3274 Usage: delete display [NUM]...\n\
3275 Arguments are the code numbers of the expressions to stop displaying.\n\
3276 No argument means cancel all automatic-display expressions.\n\
3277 Do \"info display\" to see current list of code numbers."), &deletelist
);
3279 add_com ("printf", class_vars
, printf_command
, _("\
3280 Formatted printing, like the C \"printf\" function.\n\
3281 Usage: printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
3282 This supports most C printf format specifications, like %s, %d, etc."));
3284 add_com ("output", class_vars
, output_command
, _("\
3285 Like \"print\" but don't put in value history and don't print newline.\n\
3286 Usage: output EXP\n\
3287 This is useful in user-defined commands."));
3289 add_prefix_cmd ("set", class_vars
, set_command
, _("\
3290 Evaluate expression EXP and assign result to variable VAR.\n\
3291 Usage: set VAR = EXP\n\
3292 This uses assignment syntax appropriate for the current language\n\
3293 (VAR = EXP or VAR := EXP for example).\n\
3294 VAR may be a debugger \"convenience\" variable (names starting\n\
3295 with $), a register (a few standard names starting with $), or an actual\n\
3296 variable in the program being debugged. EXP is any valid expression.\n\
3297 Use \"set variable\" for variables with names identical to set subcommands.\n\
3299 With a subcommand, this command modifies parts of the gdb environment.\n\
3300 You can see these environment settings with the \"show\" command."),
3301 &setlist
, 1, &cmdlist
);
3303 add_com ("assign", class_vars
, set_command
, _("\
3304 Evaluate expression EXP and assign result to variable VAR.\n\
3305 Usage: assign VAR = EXP\n\
3306 This uses assignment syntax appropriate for the current language\n\
3307 (VAR = EXP or VAR := EXP for example).\n\
3308 VAR may be a debugger \"convenience\" variable (names starting\n\
3309 with $), a register (a few standard names starting with $), or an actual\n\
3310 variable in the program being debugged. EXP is any valid expression.\n\
3311 Use \"set variable\" for variables with names identical to set subcommands.\n\
3312 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
3313 You can see these environment settings with the \"show\" command."));
3315 /* "call" is the same as "set", but handy for dbx users to call fns. */
3316 c
= add_com ("call", class_vars
, call_command
, _("\
3317 Call a function in the program.\n\
3319 The argument is the function name and arguments, in the notation of the\n\
3320 current working language. The result is printed and saved in the value\n\
3321 history, if it is not void."));
3322 set_cmd_completer_handle_brkchars (c
, print_command_completer
);
3324 cmd_list_element
*set_variable_cmd
3325 = add_cmd ("variable", class_vars
, set_command
, _("\
3326 Evaluate expression EXP and assign result to variable VAR.\n\
3327 Usage: set variable VAR = EXP\n\
3328 This uses assignment syntax appropriate for the current language\n\
3329 (VAR = EXP or VAR := EXP for example).\n\
3330 VAR may be a debugger \"convenience\" variable (names starting\n\
3331 with $), a register (a few standard names starting with $), or an actual\n\
3332 variable in the program being debugged. EXP is any valid expression.\n\
3333 This may usually be abbreviated to simply \"set\"."),
3335 add_alias_cmd ("var", set_variable_cmd
, class_vars
, 0, &setlist
);
3337 const auto print_opts
= make_value_print_options_def_group (nullptr);
3339 static const std::string print_help
= gdb::option::build_help (_("\
3340 Print value of expression EXP.\n\
3341 Usage: print [[OPTION]... --] [/FMT] [EXP]\n\
3346 Note: because this command accepts arbitrary expressions, if you\n\
3347 specify any command option, you must use a double dash (\"--\")\n\
3348 to mark the end of option processing. E.g.: \"print -o -- myobj\".\n\
3350 Variables accessible are those of the lexical environment of the selected\n\
3351 stack frame, plus all those whose scope is global or an entire file.\n\
3353 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
3354 $$NUM refers to NUM'th value back from the last one.\n\
3355 Names starting with $ refer to registers (with the values they would have\n\
3356 if the program were to return to the stack frame now selected, restoring\n\
3357 all registers saved by frames farther in) or else to debugger\n\
3358 \"convenience\" variables (any such name not a known register).\n\
3359 Use assignment expressions to give values to convenience variables.\n\
3361 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
3362 @ is a binary operator for treating consecutive data objects\n\
3363 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
3364 element is FOO, whose second element is stored in the space following\n\
3365 where FOO is stored, etc. FOO must be an expression whose value\n\
3366 resides in memory.\n\
3368 EXP may be preceded with /FMT, where FMT is a format letter\n\
3369 but no count or size letter (see \"x\" command)."),
3372 cmd_list_element
*print_cmd
3373 = add_com ("print", class_vars
, print_command
, print_help
.c_str ());
3374 set_cmd_completer_handle_brkchars (print_cmd
, print_command_completer
);
3375 add_com_alias ("p", print_cmd
, class_vars
, 1);
3376 add_com_alias ("inspect", print_cmd
, class_vars
, 1);
3378 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
3379 &max_symbolic_offset
, _("\
3380 Set the largest offset that will be printed in <SYMBOL+1234> form."), _("\
3381 Show the largest offset that will be printed in <SYMBOL+1234> form."), _("\
3382 Tell GDB to only display the symbolic form of an address if the\n\
3383 offset between the closest earlier symbol and the address is less than\n\
3384 the specified maximum offset. The default is \"unlimited\", which tells GDB\n\
3385 to always print the symbolic form of an address if any symbol precedes\n\
3386 it. Zero is equivalent to \"unlimited\"."),
3388 show_max_symbolic_offset
,
3389 &setprintlist
, &showprintlist
);
3390 add_setshow_boolean_cmd ("symbol-filename", no_class
,
3391 &print_symbol_filename
, _("\
3392 Set printing of source filename and line number with <SYMBOL>."), _("\
3393 Show printing of source filename and line number with <SYMBOL>."), NULL
,
3395 show_print_symbol_filename
,
3396 &setprintlist
, &showprintlist
);
3398 add_com ("eval", no_class
, eval_command
, _("\
3399 Construct a GDB command and then evaluate it.\n\
3400 Usage: eval \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
3401 Convert the arguments to a string as \"printf\" would, but then\n\
3402 treat this string as a command line, and evaluate it."));
3404 /* Memory tagging commands. */
3405 add_prefix_cmd ("memory-tag", class_vars
, memory_tag_command
, _("\
3406 Generic command for printing and manipulating memory tag properties."),
3407 &memory_tag_list
, 0, &cmdlist
);
3408 add_cmd ("print-logical-tag", class_vars
,
3409 memory_tag_print_logical_tag_command
,
3410 ("Print the logical tag from POINTER.\n\
3411 Usage: memory-tag print-logical-tag <POINTER>.\n\
3412 <POINTER> is an expression that evaluates to a pointer.\n\
3413 Print the logical tag contained in POINTER. The tag interpretation is\n\
3414 architecture-specific."),
3416 add_cmd ("print-allocation-tag", class_vars
,
3417 memory_tag_print_allocation_tag_command
,
3418 _("Print the allocation tag for ADDRESS.\n\
3419 Usage: memory-tag print-allocation-tag <ADDRESS>.\n\
3420 <ADDRESS> is an expression that evaluates to a memory address.\n\
3421 Print the allocation tag associated with the memory address ADDRESS.\n\
3422 The tag interpretation is architecture-specific."),
3424 add_cmd ("with-logical-tag", class_vars
, memory_tag_with_logical_tag_command
,
3425 _("Print a POINTER with a specific logical TAG.\n\
3426 Usage: memory-tag with-logical-tag <POINTER> <TAG>\n\
3427 <POINTER> is an expression that evaluates to a pointer.\n\
3428 <TAG> is a sequence of hex bytes that is interpreted by the architecture\n\
3429 as a single memory tag."),
3431 add_cmd ("set-allocation-tag", class_vars
,
3432 memory_tag_set_allocation_tag_command
,
3433 _("Set the allocation tag(s) for a memory range.\n\
3434 Usage: memory-tag set-allocation-tag <ADDRESS> <LENGTH> <TAG_BYTES>\n\
3435 <ADDRESS> is an expression that evaluates to a memory address\n\
3436 <LENGTH> is the number of bytes that is added to <ADDRESS> to calculate\n\
3437 the memory range.\n\
3438 <TAG_BYTES> is a sequence of hex bytes that is interpreted by the\n\
3439 architecture as one or more memory tags.\n\
3440 Sets the tags of the memory range [ADDRESS, ADDRESS + LENGTH)\n\
3443 If the number of tags is greater than or equal to the number of tag granules\n\
3444 in the [ADDRESS, ADDRESS + LENGTH) range, only the tags up to the\n\
3445 number of tag granules are updated.\n\
3447 If the number of tags is less than the number of tag granules, then the\n\
3448 command is a fill operation. The TAG_BYTES are interpreted as a pattern\n\
3449 that gets repeated until the number of tag granules in the memory range\n\
3450 [ADDRESS, ADDRESS + LENGTH) is updated."),
3452 add_cmd ("check", class_vars
, memory_tag_check_command
,
3453 _("Validate a pointer's logical tag against the allocation tag.\n\
3454 Usage: memory-tag check <POINTER>\n\
3455 <POINTER> is an expression that evaluates to a pointer\n\
3456 Fetch the logical and allocation tags for POINTER and compare them\n\
3457 for equality. If the tags do not match, print additional information about\n\
3458 the tag mismatch."),