1 /* Print values for GNU debugger GDB.
3 Copyright (C) 1986-2021 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. */
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 /* Historically gdb has printed floats by first casting them to a
430 long, and then printing the long. PR cli/16242 suggests changing
431 this to using C-style hex float format.
433 Biased range types and sub-word scalar types must also be handled
434 here; the value is correctly computed by unpack_long. */
435 gdb::byte_vector converted_bytes
;
436 /* Some cases below will unpack the value again. In the biased
437 range case, we want to avoid this, so we store the unpacked value
438 here for possible use later. */
439 gdb::optional
<LONGEST
> val_long
;
440 if (((type
->code () == TYPE_CODE_FLT
441 || is_fixed_point_type (type
))
442 && (options
->format
== 'o'
443 || options
->format
== 'x'
444 || options
->format
== 't'
445 || options
->format
== 'z'
446 || options
->format
== 'd'
447 || options
->format
== 'u'))
448 || (type
->code () == TYPE_CODE_RANGE
&& type
->bounds ()->bias
!= 0)
449 || type
->bit_size_differs_p ())
451 val_long
.emplace (unpack_long (type
, valaddr
));
452 converted_bytes
.resize (TYPE_LENGTH (type
));
453 store_signed_integer (converted_bytes
.data (), TYPE_LENGTH (type
),
454 byte_order
, *val_long
);
455 valaddr
= converted_bytes
.data ();
458 /* Printing a non-float type as 'f' will interpret the data as if it were
459 of a floating-point type of the same length, if that exists. Otherwise,
460 the data is printed as integer. */
461 char format
= options
->format
;
462 if (format
== 'f' && type
->code () != TYPE_CODE_FLT
)
464 type
= float_type_from_length (type
);
465 if (type
->code () != TYPE_CODE_FLT
)
472 print_octal_chars (stream
, valaddr
, len
, byte_order
);
475 print_decimal_chars (stream
, valaddr
, len
, true, byte_order
);
478 print_decimal_chars (stream
, valaddr
, len
, false, byte_order
);
481 if (type
->code () != TYPE_CODE_FLT
)
483 print_decimal_chars (stream
, valaddr
, len
, !type
->is_unsigned (),
489 print_floating (valaddr
, type
, stream
);
493 print_binary_chars (stream
, valaddr
, len
, byte_order
, size
> 0);
496 print_hex_chars (stream
, valaddr
, len
, byte_order
, size
> 0);
499 print_hex_chars (stream
, valaddr
, len
, byte_order
, true);
503 struct value_print_options opts
= *options
;
505 if (!val_long
.has_value ())
506 val_long
.emplace (unpack_long (type
, valaddr
));
509 if (type
->is_unsigned ())
510 type
= builtin_type (gdbarch
)->builtin_true_unsigned_char
;
512 type
= builtin_type (gdbarch
)->builtin_true_char
;
514 value_print (value_from_longest (type
, *val_long
), stream
, &opts
);
520 if (!val_long
.has_value ())
521 val_long
.emplace (unpack_long (type
, valaddr
));
522 print_address (gdbarch
, *val_long
, stream
);
527 error (_("Undefined output format \"%c\"."), format
);
531 /* Specify default address for `x' command.
532 The `info lines' command uses this. */
535 set_next_address (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
537 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
539 next_gdbarch
= gdbarch
;
542 /* Make address available to the user as $_. */
543 set_internalvar (lookup_internalvar ("_"),
544 value_from_pointer (ptr_type
, addr
));
547 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
548 after LEADIN. Print nothing if no symbolic name is found nearby.
549 Optionally also print source file and line number, if available.
550 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
551 or to interpret it as a possible C++ name and convert it back to source
552 form. However note that DO_DEMANGLE can be overridden by the specific
553 settings of the demangle and asm_demangle variables. Returns
554 non-zero if anything was printed; zero otherwise. */
557 print_address_symbolic (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
558 struct ui_file
*stream
,
559 int do_demangle
, const char *leadin
)
561 std::string name
, filename
;
566 if (build_address_symbolic (gdbarch
, addr
, do_demangle
, false, &name
,
567 &offset
, &filename
, &line
, &unmapped
))
570 fputs_filtered (leadin
, stream
);
572 fputs_filtered ("<*", stream
);
574 fputs_filtered ("<", stream
);
575 fputs_styled (name
.c_str (), function_name_style
.style (), stream
);
577 fprintf_filtered (stream
, "%+d", offset
);
579 /* Append source filename and line number if desired. Give specific
580 line # of this addr, if we have it; else line # of the nearest symbol. */
581 if (print_symbol_filename
&& !filename
.empty ())
583 fputs_filtered (line
== -1 ? " in " : " at ", stream
);
584 fputs_styled (filename
.c_str (), file_name_style
.style (), stream
);
586 fprintf_filtered (stream
, ":%d", line
);
589 fputs_filtered ("*>", stream
);
591 fputs_filtered (">", stream
);
596 /* See valprint.h. */
599 build_address_symbolic (struct gdbarch
*gdbarch
,
600 CORE_ADDR addr
, /* IN */
601 bool do_demangle
, /* IN */
602 bool prefer_sym_over_minsym
, /* IN */
603 std::string
*name
, /* OUT */
604 int *offset
, /* OUT */
605 std::string
*filename
, /* OUT */
607 int *unmapped
) /* OUT */
609 struct bound_minimal_symbol msymbol
;
610 struct symbol
*symbol
;
611 CORE_ADDR name_location
= 0;
612 struct obj_section
*section
= NULL
;
613 const char *name_temp
= "";
615 /* Let's say it is mapped (not unmapped). */
618 /* Determine if the address is in an overlay, and whether it is
620 if (overlay_debugging
)
622 section
= find_pc_overlay (addr
);
623 if (pc_in_unmapped_range (addr
, section
))
626 addr
= overlay_mapped_address (addr
, section
);
630 /* Try to find the address in both the symbol table and the minsyms.
631 In most cases, we'll prefer to use the symbol instead of the
632 minsym. However, there are cases (see below) where we'll choose
633 to use the minsym instead. */
635 /* This is defective in the sense that it only finds text symbols. So
636 really this is kind of pointless--we should make sure that the
637 minimal symbols have everything we need (by changing that we could
638 save some memory, but for many debug format--ELF/DWARF or
639 anything/stabs--it would be inconvenient to eliminate those minimal
641 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
642 symbol
= find_pc_sect_function (addr
, section
);
646 /* If this is a function (i.e. a code address), strip out any
647 non-address bits. For instance, display a pointer to the
648 first instruction of a Thumb function as <function>; the
649 second instruction will be <function+2>, even though the
650 pointer is <function+3>. This matches the ISA behavior. */
651 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
653 name_location
= BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (symbol
));
654 if (do_demangle
|| asm_demangle
)
655 name_temp
= symbol
->print_name ();
657 name_temp
= symbol
->linkage_name ();
660 if (msymbol
.minsym
!= NULL
661 && MSYMBOL_HAS_SIZE (msymbol
.minsym
)
662 && MSYMBOL_SIZE (msymbol
.minsym
) == 0
663 && MSYMBOL_TYPE (msymbol
.minsym
) != mst_text
664 && MSYMBOL_TYPE (msymbol
.minsym
) != mst_text_gnu_ifunc
665 && MSYMBOL_TYPE (msymbol
.minsym
) != mst_file_text
)
666 msymbol
.minsym
= NULL
;
668 if (msymbol
.minsym
!= NULL
)
670 /* Use the minsym if no symbol is found.
672 Additionally, use the minsym instead of a (found) symbol if
673 the following conditions all hold:
674 1) The prefer_sym_over_minsym flag is false.
675 2) The minsym address is identical to that of the address under
677 3) The symbol address is not identical to that of the address
678 under consideration. */
679 if (symbol
== NULL
||
680 (!prefer_sym_over_minsym
681 && BMSYMBOL_VALUE_ADDRESS (msymbol
) == addr
682 && name_location
!= addr
))
684 /* If this is a function (i.e. a code address), strip out any
685 non-address bits. For instance, display a pointer to the
686 first instruction of a Thumb function as <function>; the
687 second instruction will be <function+2>, even though the
688 pointer is <function+3>. This matches the ISA behavior. */
689 if (MSYMBOL_TYPE (msymbol
.minsym
) == mst_text
690 || MSYMBOL_TYPE (msymbol
.minsym
) == mst_text_gnu_ifunc
691 || MSYMBOL_TYPE (msymbol
.minsym
) == mst_file_text
692 || MSYMBOL_TYPE (msymbol
.minsym
) == mst_solib_trampoline
)
693 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
696 name_location
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
697 if (do_demangle
|| asm_demangle
)
698 name_temp
= msymbol
.minsym
->print_name ();
700 name_temp
= msymbol
.minsym
->linkage_name ();
703 if (symbol
== NULL
&& msymbol
.minsym
== NULL
)
706 /* If the nearest symbol is too far away, don't print anything symbolic. */
708 /* For when CORE_ADDR is larger than unsigned int, we do math in
709 CORE_ADDR. But when we detect unsigned wraparound in the
710 CORE_ADDR math, we ignore this test and print the offset,
711 because addr+max_symbolic_offset has wrapped through the end
712 of the address space back to the beginning, giving bogus comparison. */
713 if (addr
> name_location
+ max_symbolic_offset
714 && name_location
+ max_symbolic_offset
> name_location
)
717 *offset
= (LONGEST
) addr
- name_location
;
721 if (print_symbol_filename
)
723 struct symtab_and_line sal
;
725 sal
= find_pc_sect_line (addr
, section
, 0);
729 *filename
= symtab_to_filename_for_display (sal
.symtab
);
737 /* Print address ADDR symbolically on STREAM.
738 First print it as a number. Then perhaps print
739 <SYMBOL + OFFSET> after the number. */
742 print_address (struct gdbarch
*gdbarch
,
743 CORE_ADDR addr
, struct ui_file
*stream
)
745 fputs_styled (paddress (gdbarch
, addr
), address_style
.style (), stream
);
746 print_address_symbolic (gdbarch
, addr
, stream
, asm_demangle
, " ");
749 /* Return a prefix for instruction address:
750 "=> " for current instruction, else " ". */
753 pc_prefix (CORE_ADDR addr
)
755 if (has_stack_frames ())
757 struct frame_info
*frame
;
760 frame
= get_selected_frame (NULL
);
761 if (get_frame_pc_if_available (frame
, &pc
) && pc
== addr
)
767 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
768 controls whether to print the symbolic name "raw" or demangled.
769 Return non-zero if anything was printed; zero otherwise. */
772 print_address_demangle (const struct value_print_options
*opts
,
773 struct gdbarch
*gdbarch
, CORE_ADDR addr
,
774 struct ui_file
*stream
, int do_demangle
)
776 if (opts
->addressprint
)
778 fputs_styled (paddress (gdbarch
, addr
), address_style
.style (), stream
);
779 print_address_symbolic (gdbarch
, addr
, stream
, do_demangle
, " ");
783 return print_address_symbolic (gdbarch
, addr
, stream
, do_demangle
, "");
789 /* Find the address of the instruction that is INST_COUNT instructions before
790 the instruction at ADDR.
791 Since some architectures have variable-length instructions, we can't just
792 simply subtract INST_COUNT * INSN_LEN from ADDR. Instead, we use line
793 number information to locate the nearest known instruction boundary,
794 and disassemble forward from there. If we go out of the symbol range
795 during disassembling, we return the lowest address we've got so far and
796 set the number of instructions read to INST_READ. */
799 find_instruction_backward (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
800 int inst_count
, int *inst_read
)
802 /* The vector PCS is used to store instruction addresses within
804 CORE_ADDR loop_start
, loop_end
, p
;
805 std::vector
<CORE_ADDR
> pcs
;
806 struct symtab_and_line sal
;
809 loop_start
= loop_end
= addr
;
811 /* In each iteration of the outer loop, we get a pc range that ends before
812 LOOP_START, then we count and store every instruction address of the range
813 iterated in the loop.
814 If the number of instructions counted reaches INST_COUNT, return the
815 stored address that is located INST_COUNT instructions back from ADDR.
816 If INST_COUNT is not reached, we subtract the number of counted
817 instructions from INST_COUNT, and go to the next iteration. */
821 sal
= find_pc_sect_line (loop_start
, NULL
, 1);
824 /* We reach here when line info is not available. In this case,
825 we print a message and just exit the loop. The return value
826 is calculated after the loop. */
827 printf_filtered (_("No line number information available "
830 print_address (gdbarch
, loop_start
- 1, gdb_stdout
);
831 printf_filtered ("\n");
835 loop_end
= loop_start
;
838 /* This loop pushes instruction addresses in the range from
839 LOOP_START to LOOP_END. */
840 for (p
= loop_start
; p
< loop_end
;)
843 p
+= gdb_insn_length (gdbarch
, p
);
846 inst_count
-= pcs
.size ();
847 *inst_read
+= pcs
.size ();
849 while (inst_count
> 0);
851 /* After the loop, the vector PCS has instruction addresses of the last
852 source line we processed, and INST_COUNT has a negative value.
853 We return the address at the index of -INST_COUNT in the vector for
855 Let's assume the following instruction addresses and run 'x/-4i 0x400e'.
865 find_instruction_backward is called with INST_COUNT = 4 and expected to
866 return 0x4001. When we reach here, INST_COUNT is set to -1 because
867 it was subtracted by 2 (from Line Y) and 3 (from Line X). The value
868 4001 is located at the index 1 of the last iterated line (= Line X),
869 which is simply calculated by -INST_COUNT.
870 The case when the length of PCS is 0 means that we reached an area for
871 which line info is not available. In such case, we return LOOP_START,
872 which was the lowest instruction address that had line info. */
873 p
= pcs
.size () > 0 ? pcs
[-inst_count
] : loop_start
;
875 /* INST_READ includes all instruction addresses in a pc range. Need to
876 exclude the beginning part up to the address we're returning. That
877 is, exclude {0x4000} in the example above. */
879 *inst_read
+= inst_count
;
884 /* Backward read LEN bytes of target memory from address MEMADDR + LEN,
885 placing the results in GDB's memory from MYADDR + LEN. Returns
886 a count of the bytes actually read. */
889 read_memory_backward (struct gdbarch
*gdbarch
,
890 CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
893 int nread
; /* Number of bytes actually read. */
895 /* First try a complete read. */
896 errcode
= target_read_memory (memaddr
, myaddr
, len
);
904 /* Loop, reading one byte at a time until we get as much as we can. */
907 for (nread
= 0; nread
< len
; ++nread
)
909 errcode
= target_read_memory (--memaddr
, --myaddr
, 1);
912 /* The read was unsuccessful, so exit the loop. */
913 printf_filtered (_("Cannot access memory at address %s\n"),
914 paddress (gdbarch
, memaddr
));
922 /* Returns true if X (which is LEN bytes wide) is the number zero. */
925 integer_is_zero (const gdb_byte
*x
, int len
)
929 while (i
< len
&& x
[i
] == 0)
934 /* Find the start address of a string in which ADDR is included.
935 Basically we search for '\0' and return the next address,
936 but if OPTIONS->PRINT_MAX is smaller than the length of a string,
937 we stop searching and return the address to print characters as many as
938 PRINT_MAX from the string. */
941 find_string_backward (struct gdbarch
*gdbarch
,
942 CORE_ADDR addr
, int count
, int char_size
,
943 const struct value_print_options
*options
,
944 int *strings_counted
)
946 const int chunk_size
= 0x20;
949 int chars_to_read
= chunk_size
;
950 int chars_counted
= 0;
951 int count_original
= count
;
952 CORE_ADDR string_start_addr
= addr
;
954 gdb_assert (char_size
== 1 || char_size
== 2 || char_size
== 4);
955 gdb::byte_vector
buffer (chars_to_read
* char_size
);
956 while (count
> 0 && read_error
== 0)
960 addr
-= chars_to_read
* char_size
;
961 chars_read
= read_memory_backward (gdbarch
, addr
, buffer
.data (),
962 chars_to_read
* char_size
);
963 chars_read
/= char_size
;
964 read_error
= (chars_read
== chars_to_read
) ? 0 : 1;
965 /* Searching for '\0' from the end of buffer in backward direction. */
966 for (i
= 0; i
< chars_read
&& count
> 0 ; ++i
, ++chars_counted
)
968 int offset
= (chars_to_read
- i
- 1) * char_size
;
970 if (integer_is_zero (&buffer
[offset
], char_size
)
971 || chars_counted
== options
->print_max
)
973 /* Found '\0' or reached print_max. As OFFSET is the offset to
974 '\0', we add CHAR_SIZE to return the start address of
977 string_start_addr
= addr
+ offset
+ char_size
;
983 /* Update STRINGS_COUNTED with the actual number of loaded strings. */
984 *strings_counted
= count_original
- count
;
988 /* In error case, STRING_START_ADDR is pointing to the string that
989 was last successfully loaded. Rewind the partially loaded string. */
990 string_start_addr
-= chars_counted
* char_size
;
993 return string_start_addr
;
996 /* Examine data at address ADDR in format FMT.
997 Fetch it from memory and print on gdb_stdout. */
1000 do_examine (struct format_data fmt
, struct gdbarch
*gdbarch
, CORE_ADDR addr
)
1005 struct type
*val_type
= NULL
;
1008 struct value_print_options opts
;
1009 int need_to_update_next_address
= 0;
1010 CORE_ADDR addr_rewound
= 0;
1012 format
= fmt
.format
;
1015 next_gdbarch
= gdbarch
;
1016 next_address
= addr
;
1018 /* Instruction format implies fetch single bytes
1019 regardless of the specified size.
1020 The case of strings is handled in decode_format, only explicit
1021 size operator are not changed to 'b'. */
1027 /* Pick the appropriate size for an address. */
1028 if (gdbarch_ptr_bit (next_gdbarch
) == 64)
1030 else if (gdbarch_ptr_bit (next_gdbarch
) == 32)
1032 else if (gdbarch_ptr_bit (next_gdbarch
) == 16)
1035 /* Bad value for gdbarch_ptr_bit. */
1036 internal_error (__FILE__
, __LINE__
,
1037 _("failed internal consistency check"));
1041 val_type
= builtin_type (next_gdbarch
)->builtin_int8
;
1042 else if (size
== 'h')
1043 val_type
= builtin_type (next_gdbarch
)->builtin_int16
;
1044 else if (size
== 'w')
1045 val_type
= builtin_type (next_gdbarch
)->builtin_int32
;
1046 else if (size
== 'g')
1047 val_type
= builtin_type (next_gdbarch
)->builtin_int64
;
1051 struct type
*char_type
= NULL
;
1053 /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char
1054 if type is not found. */
1056 char_type
= builtin_type (next_gdbarch
)->builtin_char16
;
1057 else if (size
== 'w')
1058 char_type
= builtin_type (next_gdbarch
)->builtin_char32
;
1060 val_type
= char_type
;
1063 if (size
!= '\0' && size
!= 'b')
1064 warning (_("Unable to display strings with "
1065 "size '%c', using 'b' instead."), size
);
1067 val_type
= builtin_type (next_gdbarch
)->builtin_int8
;
1076 if (format
== 's' || format
== 'i')
1079 get_formatted_print_options (&opts
, format
);
1083 /* This is the negative repeat count case.
1084 We rewind the address based on the given repeat count and format,
1085 then examine memory from there in forward direction. */
1090 next_address
= find_instruction_backward (gdbarch
, addr
, count
,
1093 else if (format
== 's')
1095 next_address
= find_string_backward (gdbarch
, addr
, count
,
1096 TYPE_LENGTH (val_type
),
1101 next_address
= addr
- count
* TYPE_LENGTH (val_type
);
1104 /* The following call to print_formatted updates next_address in every
1105 iteration. In backward case, we store the start address here
1106 and update next_address with it before exiting the function. */
1107 addr_rewound
= (format
== 's'
1108 ? next_address
- TYPE_LENGTH (val_type
)
1110 need_to_update_next_address
= 1;
1113 /* Whether we need to print the memory tag information for the current
1115 bool print_range_tag
= true;
1116 uint32_t gsize
= gdbarch_memtag_granule_size (gdbarch
);
1118 /* Print as many objects as specified in COUNT, at most maxelts per line,
1119 with the address of the next one at the start of each line. */
1125 CORE_ADDR tag_laddr
= 0, tag_haddr
= 0;
1127 /* Print the memory tag information if requested. */
1128 if (fmt
.print_tags
&& print_range_tag
1129 && target_supports_memory_tagging ())
1131 tag_laddr
= align_down (next_address
, gsize
);
1132 tag_haddr
= align_down (next_address
+ gsize
, gsize
);
1134 struct value
*v_addr
1135 = value_from_ulongest (builtin_type (gdbarch
)->builtin_data_ptr
,
1138 if (gdbarch_tagged_address_p (target_gdbarch (), v_addr
))
1140 /* Fetch the allocation tag. */
1142 = gdbarch_get_memtag (gdbarch
, v_addr
, memtag_type::allocation
);
1144 = gdbarch_memtag_to_string (gdbarch
, tag
);
1148 printf_filtered (_("<Allocation Tag %s for range [%s,%s)>\n"),
1150 paddress (gdbarch
, tag_laddr
),
1151 paddress (gdbarch
, tag_haddr
));
1154 print_range_tag
= false;
1158 fputs_filtered (pc_prefix (next_address
), gdb_stdout
);
1159 print_address (next_gdbarch
, next_address
, gdb_stdout
);
1160 printf_filtered (":");
1165 printf_filtered ("\t");
1166 /* Note that print_formatted sets next_address for the next
1168 last_examine_address
= next_address
;
1170 /* The value to be displayed is not fetched greedily.
1171 Instead, to avoid the possibility of a fetched value not
1172 being used, its retrieval is delayed until the print code
1173 uses it. When examining an instruction stream, the
1174 disassembler will perform its own memory fetch using just
1175 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
1176 the disassembler be modified so that LAST_EXAMINE_VALUE
1177 is left with the byte sequence from the last complete
1178 instruction fetched from memory? */
1180 = release_value (value_at_lazy (val_type
, next_address
));
1182 print_formatted (last_examine_value
.get (), size
, &opts
, gdb_stdout
);
1184 /* Display any branch delay slots following the final insn. */
1185 if (format
== 'i' && count
== 1)
1186 count
+= branch_delay_insns
;
1188 /* Update the tag range based on the current address being
1190 if (tag_haddr
<= next_address
)
1191 print_range_tag
= true;
1193 printf_filtered ("\n");
1196 if (need_to_update_next_address
)
1197 next_address
= addr_rewound
;
1201 validate_format (struct format_data fmt
, const char *cmdname
)
1204 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
1206 error (_("Item count other than 1 is meaningless in \"%s\" command."),
1208 if (fmt
.format
== 'i')
1209 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
1210 fmt
.format
, cmdname
);
1213 /* Parse print command format string into *OPTS and update *EXPP.
1214 CMDNAME should name the current command. */
1217 print_command_parse_format (const char **expp
, const char *cmdname
,
1218 value_print_options
*opts
)
1220 const char *exp
= *expp
;
1222 /* opts->raw value might already have been set by 'set print raw-values'
1223 or by using 'print -raw-values'.
1224 So, do not set opts->raw to 0, only set it to 1 if /r is given. */
1225 if (exp
&& *exp
== '/')
1230 fmt
= decode_format (&exp
, last_format
, 0);
1231 validate_format (fmt
, cmdname
);
1232 last_format
= fmt
.format
;
1234 opts
->format
= fmt
.format
;
1235 opts
->raw
= opts
->raw
|| fmt
.raw
;
1245 /* See valprint.h. */
1248 print_value (value
*val
, const value_print_options
&opts
)
1250 int histindex
= record_latest_value (val
);
1252 annotate_value_history_begin (histindex
, value_type (val
));
1254 printf_filtered ("$%d = ", histindex
);
1256 annotate_value_history_value ();
1258 print_formatted (val
, 0, &opts
, gdb_stdout
);
1259 printf_filtered ("\n");
1261 annotate_value_history_end ();
1264 /* Returns true if memory tags should be validated. False otherwise. */
1267 should_validate_memtags (struct value
*value
)
1269 gdb_assert (value
!= nullptr && value_type (value
) != nullptr);
1271 if (!target_supports_memory_tagging ())
1274 enum type_code code
= value_type (value
)->code ();
1276 /* Skip non-address values. */
1277 if (code
!= TYPE_CODE_PTR
1278 && !TYPE_IS_REFERENCE (value_type (value
)))
1281 /* OK, we have an address value. Check we have a complete value we
1283 if (value_optimized_out (value
)
1284 || !value_entirely_available (value
))
1287 /* We do. Check whether it includes any tags. */
1288 return gdbarch_tagged_address_p (target_gdbarch (), value
);
1291 /* Helper for parsing arguments for print_command_1. */
1293 static struct value
*
1294 process_print_command_args (const char *args
, value_print_options
*print_opts
,
1297 get_user_print_options (print_opts
);
1298 /* Override global settings with explicit options, if any. */
1299 auto group
= make_value_print_options_def_group (print_opts
);
1300 gdb::option::process_options
1301 (&args
, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER
, group
);
1303 print_command_parse_format (&args
, "print", print_opts
);
1305 const char *exp
= args
;
1307 if (exp
!= nullptr && *exp
)
1309 /* VOIDPRINT is true to indicate that we do want to print a void
1310 value, so invert it for parse_expression. */
1311 expression_up expr
= parse_expression (exp
, nullptr, !voidprint
);
1312 return evaluate_expression (expr
.get ());
1315 return access_value_history (0);
1318 /* Implementation of the "print" and "call" commands. */
1321 print_command_1 (const char *args
, int voidprint
)
1323 value_print_options print_opts
;
1325 struct value
*val
= process_print_command_args (args
, &print_opts
, voidprint
);
1327 if (voidprint
|| (val
&& value_type (val
) &&
1328 value_type (val
)->code () != TYPE_CODE_VOID
))
1330 /* If memory tagging validation is on, check if the tag is valid. */
1331 if (print_opts
.memory_tag_violations
)
1335 if (should_validate_memtags (val
)
1336 && !gdbarch_memtag_matches_p (target_gdbarch (), val
))
1338 /* Fetch the logical tag. */
1340 = gdbarch_get_memtag (target_gdbarch (), val
,
1341 memtag_type::logical
);
1343 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
1345 /* Fetch the allocation tag. */
1346 tag
= gdbarch_get_memtag (target_gdbarch (), val
,
1347 memtag_type::allocation
);
1349 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
1351 printf_filtered (_("Logical tag (%s) does not match the "
1352 "allocation tag (%s).\n"),
1353 ltag
.c_str (), atag
.c_str ());
1356 catch (gdb_exception_error
&ex
)
1358 if (ex
.error
== TARGET_CLOSE_ERROR
)
1361 fprintf_filtered (gdb_stderr
,
1362 _("Could not validate memory tag: %s\n"),
1363 ex
.message
->c_str ());
1367 print_value (val
, print_opts
);
1371 /* Called from command completion function to skip over /FMT
1372 specifications, allowing the rest of the line to be completed. Returns
1373 true if the /FMT is at the end of the current line and there is nothing
1374 left to complete, otherwise false is returned.
1376 In either case *ARGS can be updated to point after any part of /FMT that
1379 This function is designed so that trying to complete '/' will offer no
1380 completions, the user needs to insert the format specification
1381 themselves. Trying to complete '/FMT' (where FMT is any non-empty set
1382 of alpha-numeric characters) will cause readline to insert a single
1383 space, setting the user up to enter the expression. */
1386 skip_over_slash_fmt (completion_tracker
&tracker
, const char **args
)
1388 const char *text
= *args
;
1393 tracker
.set_use_custom_word_point (true);
1395 if (text
[1] == '\0')
1397 /* The user tried to complete after typing just the '/' character
1398 of the /FMT string. Step the completer past the '/', but we
1399 don't offer any completions. */
1405 /* The user has typed some characters after the '/', we assume
1406 this is a complete /FMT string, first skip over it. */
1407 text
= skip_to_space (text
);
1411 /* We're at the end of the input string. The user has typed
1412 '/FMT' and asked for a completion. Push an empty
1413 completion string, this will cause readline to insert a
1414 space so the user now has '/FMT '. */
1416 tracker
.add_completion (make_unique_xstrdup (text
));
1420 /* The user has already typed things after the /FMT, skip the
1421 whitespace and return false. Whoever called this function
1422 should then try to complete what comes next. */
1424 text
= skip_spaces (text
);
1428 tracker
.advance_custom_word_point_by (text
- *args
);
1436 /* See valprint.h. */
1439 print_command_completer (struct cmd_list_element
*ignore
,
1440 completion_tracker
&tracker
,
1441 const char *text
, const char * /*word*/)
1443 const auto group
= make_value_print_options_def_group (nullptr);
1444 if (gdb::option::complete_options
1445 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_REQUIRE_DELIMITER
, group
))
1448 if (skip_over_slash_fmt (tracker
, &text
))
1451 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1452 expression_completer (ignore
, tracker
, text
, word
);
1456 print_command (const char *exp
, int from_tty
)
1458 print_command_1 (exp
, true);
1461 /* Same as print, except it doesn't print void results. */
1463 call_command (const char *exp
, int from_tty
)
1465 print_command_1 (exp
, false);
1468 /* Implementation of the "output" command. */
1471 output_command (const char *exp
, int from_tty
)
1475 struct format_data fmt
;
1476 struct value_print_options opts
;
1481 if (exp
&& *exp
== '/')
1484 fmt
= decode_format (&exp
, 0, 0);
1485 validate_format (fmt
, "output");
1486 format
= fmt
.format
;
1489 expression_up expr
= parse_expression (exp
);
1491 val
= evaluate_expression (expr
.get ());
1493 annotate_value_begin (value_type (val
));
1495 get_formatted_print_options (&opts
, format
);
1497 print_formatted (val
, fmt
.size
, &opts
, gdb_stdout
);
1499 annotate_value_end ();
1502 gdb_flush (gdb_stdout
);
1506 set_command (const char *exp
, int from_tty
)
1508 expression_up expr
= parse_expression (exp
);
1510 switch (expr
->op
->opcode ())
1512 case UNOP_PREINCREMENT
:
1513 case UNOP_POSTINCREMENT
:
1514 case UNOP_PREDECREMENT
:
1515 case UNOP_POSTDECREMENT
:
1517 case BINOP_ASSIGN_MODIFY
:
1522 (_("Expression is not an assignment (and might have no effect)"));
1525 evaluate_expression (expr
.get ());
1529 info_symbol_command (const char *arg
, int from_tty
)
1531 struct minimal_symbol
*msymbol
;
1532 struct obj_section
*osect
;
1533 CORE_ADDR addr
, sect_addr
;
1535 unsigned int offset
;
1538 error_no_arg (_("address"));
1540 addr
= parse_and_eval_address (arg
);
1541 for (objfile
*objfile
: current_program_space
->objfiles ())
1542 ALL_OBJFILE_OSECTIONS (objfile
, osect
)
1544 /* Only process each object file once, even if there's a separate
1546 if (objfile
->separate_debug_objfile_backlink
)
1549 sect_addr
= overlay_mapped_address (addr
, osect
);
1551 if (osect
->addr () <= sect_addr
&& sect_addr
< osect
->endaddr ()
1553 = lookup_minimal_symbol_by_pc_section (sect_addr
,
1556 const char *obj_name
, *mapped
, *sec_name
, *msym_name
;
1557 const char *loc_string
;
1560 offset
= sect_addr
- MSYMBOL_VALUE_ADDRESS (objfile
, msymbol
);
1561 mapped
= section_is_mapped (osect
) ? _("mapped") : _("unmapped");
1562 sec_name
= osect
->the_bfd_section
->name
;
1563 msym_name
= msymbol
->print_name ();
1565 /* Don't print the offset if it is zero.
1566 We assume there's no need to handle i18n of "sym + offset". */
1567 std::string string_holder
;
1570 string_holder
= string_printf ("%s + %u", msym_name
, offset
);
1571 loc_string
= string_holder
.c_str ();
1574 loc_string
= msym_name
;
1576 gdb_assert (osect
->objfile
&& objfile_name (osect
->objfile
));
1577 obj_name
= objfile_name (osect
->objfile
);
1579 if (current_program_space
->multi_objfile_p ())
1580 if (pc_in_unmapped_range (addr
, osect
))
1581 if (section_is_overlay (osect
))
1582 printf_filtered (_("%s in load address range of "
1583 "%s overlay section %s of %s\n"),
1584 loc_string
, mapped
, sec_name
, obj_name
);
1586 printf_filtered (_("%s in load address range of "
1587 "section %s of %s\n"),
1588 loc_string
, sec_name
, obj_name
);
1590 if (section_is_overlay (osect
))
1591 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1592 loc_string
, mapped
, sec_name
, obj_name
);
1594 printf_filtered (_("%s in section %s of %s\n"),
1595 loc_string
, sec_name
, obj_name
);
1597 if (pc_in_unmapped_range (addr
, osect
))
1598 if (section_is_overlay (osect
))
1599 printf_filtered (_("%s in load address range of %s overlay "
1601 loc_string
, mapped
, sec_name
);
1604 (_("%s in load address range of section %s\n"),
1605 loc_string
, sec_name
);
1607 if (section_is_overlay (osect
))
1608 printf_filtered (_("%s in %s overlay section %s\n"),
1609 loc_string
, mapped
, sec_name
);
1611 printf_filtered (_("%s in section %s\n"),
1612 loc_string
, sec_name
);
1616 printf_filtered (_("No symbol matches %s.\n"), arg
);
1620 info_address_command (const char *exp
, int from_tty
)
1622 struct gdbarch
*gdbarch
;
1625 struct bound_minimal_symbol msymbol
;
1627 struct obj_section
*section
;
1628 CORE_ADDR load_addr
, context_pc
= 0;
1629 struct field_of_this_result is_a_field_of_this
;
1632 error (_("Argument required."));
1634 sym
= lookup_symbol (exp
, get_selected_block (&context_pc
), VAR_DOMAIN
,
1635 &is_a_field_of_this
).symbol
;
1638 if (is_a_field_of_this
.type
!= NULL
)
1640 printf_filtered ("Symbol \"");
1641 fprintf_symbol_filtered (gdb_stdout
, exp
,
1642 current_language
->la_language
, DMGL_ANSI
);
1643 printf_filtered ("\" is a field of the local class variable ");
1644 if (current_language
->la_language
== language_objc
)
1645 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1647 printf_filtered ("`this'\n");
1651 msymbol
= lookup_bound_minimal_symbol (exp
);
1653 if (msymbol
.minsym
!= NULL
)
1655 struct objfile
*objfile
= msymbol
.objfile
;
1657 gdbarch
= objfile
->arch ();
1658 load_addr
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
1660 printf_filtered ("Symbol \"");
1661 fprintf_symbol_filtered (gdb_stdout
, exp
,
1662 current_language
->la_language
, DMGL_ANSI
);
1663 printf_filtered ("\" is at ");
1664 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1666 printf_filtered (" in a file compiled without debugging");
1667 section
= msymbol
.minsym
->obj_section (objfile
);
1668 if (section_is_overlay (section
))
1670 load_addr
= overlay_unmapped_address (load_addr
, section
);
1671 printf_filtered (",\n -- loaded at ");
1672 fputs_styled (paddress (gdbarch
, load_addr
),
1673 address_style
.style (),
1675 printf_filtered (" in overlay section %s",
1676 section
->the_bfd_section
->name
);
1678 printf_filtered (".\n");
1681 error (_("No symbol \"%s\" in current context."), exp
);
1685 printf_filtered ("Symbol \"");
1686 fprintf_symbol_filtered (gdb_stdout
, sym
->print_name (),
1687 current_language
->la_language
, DMGL_ANSI
);
1688 printf_filtered ("\" is ");
1689 val
= SYMBOL_VALUE (sym
);
1690 if (SYMBOL_OBJFILE_OWNED (sym
))
1691 section
= sym
->obj_section (symbol_objfile (sym
));
1694 gdbarch
= symbol_arch (sym
);
1696 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
1698 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, context_pc
,
1700 printf_filtered (".\n");
1704 switch (SYMBOL_CLASS (sym
))
1707 case LOC_CONST_BYTES
:
1708 printf_filtered ("constant");
1712 printf_filtered ("a label at address ");
1713 load_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1714 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1716 if (section_is_overlay (section
))
1718 load_addr
= overlay_unmapped_address (load_addr
, section
);
1719 printf_filtered (",\n -- loaded at ");
1720 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1722 printf_filtered (" in overlay section %s",
1723 section
->the_bfd_section
->name
);
1728 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
1731 /* GDBARCH is the architecture associated with the objfile the symbol
1732 is defined in; the target architecture may be different, and may
1733 provide additional registers. However, we do not know the target
1734 architecture at this point. We assume the objfile architecture
1735 will contain all the standard registers that occur in debug info
1737 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1739 if (SYMBOL_IS_ARGUMENT (sym
))
1740 printf_filtered (_("an argument in register %s"),
1741 gdbarch_register_name (gdbarch
, regno
));
1743 printf_filtered (_("a variable in register %s"),
1744 gdbarch_register_name (gdbarch
, regno
));
1748 printf_filtered (_("static storage at address "));
1749 load_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1750 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1752 if (section_is_overlay (section
))
1754 load_addr
= overlay_unmapped_address (load_addr
, section
);
1755 printf_filtered (_(",\n -- loaded at "));
1756 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1758 printf_filtered (_(" in overlay section %s"),
1759 section
->the_bfd_section
->name
);
1763 case LOC_REGPARM_ADDR
:
1764 /* Note comment at LOC_REGISTER. */
1765 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1766 printf_filtered (_("address of an argument in register %s"),
1767 gdbarch_register_name (gdbarch
, regno
));
1771 printf_filtered (_("an argument at offset %ld"), val
);
1775 printf_filtered (_("a local variable at frame offset %ld"), val
);
1779 printf_filtered (_("a reference argument at offset %ld"), val
);
1783 printf_filtered (_("a typedef"));
1787 printf_filtered (_("a function at address "));
1788 load_addr
= BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
));
1789 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1791 if (section_is_overlay (section
))
1793 load_addr
= overlay_unmapped_address (load_addr
, section
);
1794 printf_filtered (_(",\n -- loaded at "));
1795 fputs_styled (paddress (gdbarch
, load_addr
), address_style
.style (),
1797 printf_filtered (_(" in overlay section %s"),
1798 section
->the_bfd_section
->name
);
1802 case LOC_UNRESOLVED
:
1804 struct bound_minimal_symbol msym
;
1806 msym
= lookup_bound_minimal_symbol (sym
->linkage_name ());
1807 if (msym
.minsym
== NULL
)
1808 printf_filtered ("unresolved");
1811 section
= msym
.obj_section ();
1814 && (section
->the_bfd_section
->flags
& SEC_THREAD_LOCAL
) != 0)
1816 load_addr
= MSYMBOL_VALUE_RAW_ADDRESS (msym
.minsym
);
1817 printf_filtered (_("a thread-local variable at offset %s "
1818 "in the thread-local storage for `%s'"),
1819 paddress (gdbarch
, load_addr
),
1820 objfile_name (section
->objfile
));
1824 load_addr
= BMSYMBOL_VALUE_ADDRESS (msym
);
1825 printf_filtered (_("static storage at address "));
1826 fputs_styled (paddress (gdbarch
, load_addr
),
1827 address_style
.style (), gdb_stdout
);
1828 if (section_is_overlay (section
))
1830 load_addr
= overlay_unmapped_address (load_addr
, section
);
1831 printf_filtered (_(",\n -- loaded at "));
1832 fputs_styled (paddress (gdbarch
, load_addr
),
1833 address_style
.style (),
1835 printf_filtered (_(" in overlay section %s"),
1836 section
->the_bfd_section
->name
);
1843 case LOC_OPTIMIZED_OUT
:
1844 printf_filtered (_("optimized out"));
1848 printf_filtered (_("of unknown (botched) type"));
1851 printf_filtered (".\n");
1856 x_command (const char *exp
, int from_tty
)
1858 struct format_data fmt
;
1861 fmt
.format
= last_format
? last_format
: 'x';
1862 fmt
.print_tags
= last_print_tags
;
1863 fmt
.size
= last_size
;
1867 /* If there is no expression and no format, use the most recent
1869 if (exp
== nullptr && last_count
> 0)
1870 fmt
.count
= last_count
;
1872 if (exp
&& *exp
== '/')
1874 const char *tmp
= exp
+ 1;
1876 fmt
= decode_format (&tmp
, last_format
, last_size
);
1880 last_count
= fmt
.count
;
1882 /* If we have an expression, evaluate it and use it as the address. */
1884 if (exp
!= 0 && *exp
!= 0)
1886 expression_up expr
= parse_expression (exp
);
1887 /* Cause expression not to be there any more if this command is
1888 repeated with Newline. But don't clobber a user-defined
1889 command's definition. */
1891 set_repeat_arguments ("");
1892 val
= evaluate_expression (expr
.get ());
1893 if (TYPE_IS_REFERENCE (value_type (val
)))
1894 val
= coerce_ref (val
);
1895 /* In rvalue contexts, such as this, functions are coerced into
1896 pointers to functions. This makes "x/i main" work. */
1897 if (value_type (val
)->code () == TYPE_CODE_FUNC
1898 && VALUE_LVAL (val
) == lval_memory
)
1899 next_address
= value_address (val
);
1901 next_address
= value_as_address (val
);
1903 next_gdbarch
= expr
->gdbarch
;
1907 error_no_arg (_("starting display address"));
1909 do_examine (fmt
, next_gdbarch
, next_address
);
1911 /* If the examine succeeds, we remember its size and format for next
1912 time. Set last_size to 'b' for strings. */
1913 if (fmt
.format
== 's')
1916 last_size
= fmt
.size
;
1917 last_format
= fmt
.format
;
1919 /* Remember tag-printing setting. */
1920 last_print_tags
= fmt
.print_tags
;
1922 /* Set a couple of internal variables if appropriate. */
1923 if (last_examine_value
!= nullptr)
1925 /* Make last address examined available to the user as $_. Use
1926 the correct pointer type. */
1927 struct type
*pointer_type
1928 = lookup_pointer_type (value_type (last_examine_value
.get ()));
1929 set_internalvar (lookup_internalvar ("_"),
1930 value_from_pointer (pointer_type
,
1931 last_examine_address
));
1933 /* Make contents of last address examined available to the user
1934 as $__. If the last value has not been fetched from memory
1935 then don't fetch it now; instead mark it by voiding the $__
1937 if (value_lazy (last_examine_value
.get ()))
1938 clear_internalvar (lookup_internalvar ("__"));
1940 set_internalvar (lookup_internalvar ("__"), last_examine_value
.get ());
1944 /* Command completion for the 'display' and 'x' commands. */
1947 display_and_x_command_completer (struct cmd_list_element
*ignore
,
1948 completion_tracker
&tracker
,
1949 const char *text
, const char * /*word*/)
1951 if (skip_over_slash_fmt (tracker
, &text
))
1954 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1955 expression_completer (ignore
, tracker
, text
, word
);
1960 /* Add an expression to the auto-display chain.
1961 Specify the expression. */
1964 display_command (const char *arg
, int from_tty
)
1966 struct format_data fmt
;
1967 struct display
*newobj
;
1968 const char *exp
= arg
;
1979 fmt
= decode_format (&exp
, 0, 0);
1980 if (fmt
.size
&& fmt
.format
== 0)
1982 if (fmt
.format
== 'i' || fmt
.format
== 's')
1993 innermost_block_tracker tracker
;
1994 expression_up expr
= parse_expression (exp
, &tracker
);
1996 newobj
= new display (exp
, std::move (expr
), fmt
,
1997 current_program_space
, tracker
.block ());
1998 all_displays
.emplace_back (newobj
);
2001 do_one_display (newobj
);
2006 /* Clear out the display_chain. Done when new symtabs are loaded,
2007 since this invalidates the types stored in many expressions. */
2012 all_displays
.clear ();
2015 /* Delete the auto-display DISPLAY. */
2018 delete_display (struct display
*display
)
2020 gdb_assert (display
!= NULL
);
2022 auto iter
= std::find_if (all_displays
.begin (),
2023 all_displays
.end (),
2024 [=] (const std::unique_ptr
<struct display
> &item
)
2026 return item
.get () == display
;
2028 gdb_assert (iter
!= all_displays
.end ());
2029 all_displays
.erase (iter
);
2032 /* Call FUNCTION on each of the displays whose numbers are given in
2033 ARGS. DATA is passed unmodified to FUNCTION. */
2036 map_display_numbers (const char *args
,
2037 gdb::function_view
<void (struct display
*)> function
)
2042 error_no_arg (_("one or more display numbers"));
2044 number_or_range_parser
parser (args
);
2046 while (!parser
.finished ())
2048 const char *p
= parser
.cur_tok ();
2050 num
= parser
.get_number ();
2052 warning (_("bad display number at or near '%s'"), p
);
2055 auto iter
= std::find_if (all_displays
.begin (),
2056 all_displays
.end (),
2057 [=] (const std::unique_ptr
<display
> &item
)
2059 return item
->number
== num
;
2061 if (iter
== all_displays
.end ())
2062 printf_unfiltered (_("No display number %d.\n"), num
);
2064 function (iter
->get ());
2069 /* "undisplay" command. */
2072 undisplay_command (const char *args
, int from_tty
)
2076 if (query (_("Delete all auto-display expressions? ")))
2082 map_display_numbers (args
, delete_display
);
2086 /* Display a single auto-display.
2087 Do nothing if the display cannot be printed in the current context,
2088 or if the display is disabled. */
2091 do_one_display (struct display
*d
)
2093 int within_current_scope
;
2098 /* The expression carries the architecture that was used at parse time.
2099 This is a problem if the expression depends on architecture features
2100 (e.g. register numbers), and the current architecture is now different.
2101 For example, a display statement like "display/i $pc" is expected to
2102 display the PC register of the current architecture, not the arch at
2103 the time the display command was given. Therefore, we re-parse the
2104 expression if the current architecture has changed. */
2105 if (d
->exp
!= NULL
&& d
->exp
->gdbarch
!= get_current_arch ())
2116 innermost_block_tracker tracker
;
2117 d
->exp
= parse_expression (d
->exp_string
.c_str (), &tracker
);
2118 d
->block
= tracker
.block ();
2120 catch (const gdb_exception
&ex
)
2122 /* Can't re-parse the expression. Disable this display item. */
2123 d
->enabled_p
= false;
2124 warning (_("Unable to display \"%s\": %s"),
2125 d
->exp_string
.c_str (), ex
.what ());
2132 if (d
->pspace
== current_program_space
)
2133 within_current_scope
= contained_in (get_selected_block (0), d
->block
,
2136 within_current_scope
= 0;
2139 within_current_scope
= 1;
2140 if (!within_current_scope
)
2143 scoped_restore save_display_number
2144 = make_scoped_restore (¤t_display_number
, d
->number
);
2146 annotate_display_begin ();
2147 printf_filtered ("%d", d
->number
);
2148 annotate_display_number_end ();
2149 printf_filtered (": ");
2153 annotate_display_format ();
2155 printf_filtered ("x/");
2156 if (d
->format
.count
!= 1)
2157 printf_filtered ("%d", d
->format
.count
);
2158 printf_filtered ("%c", d
->format
.format
);
2159 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
2160 printf_filtered ("%c", d
->format
.size
);
2161 printf_filtered (" ");
2163 annotate_display_expression ();
2165 puts_filtered (d
->exp_string
.c_str ());
2166 annotate_display_expression_end ();
2168 if (d
->format
.count
!= 1 || d
->format
.format
== 'i')
2169 printf_filtered ("\n");
2171 printf_filtered (" ");
2173 annotate_display_value ();
2180 val
= evaluate_expression (d
->exp
.get ());
2181 addr
= value_as_address (val
);
2182 if (d
->format
.format
== 'i')
2183 addr
= gdbarch_addr_bits_remove (d
->exp
->gdbarch
, addr
);
2184 do_examine (d
->format
, d
->exp
->gdbarch
, addr
);
2186 catch (const gdb_exception_error
&ex
)
2188 fprintf_filtered (gdb_stdout
, _("%p[<error: %s>%p]\n"),
2189 metadata_style
.style ().ptr (), ex
.what (),
2195 struct value_print_options opts
;
2197 annotate_display_format ();
2199 if (d
->format
.format
)
2200 printf_filtered ("/%c ", d
->format
.format
);
2202 annotate_display_expression ();
2204 puts_filtered (d
->exp_string
.c_str ());
2205 annotate_display_expression_end ();
2207 printf_filtered (" = ");
2209 annotate_display_expression ();
2211 get_formatted_print_options (&opts
, d
->format
.format
);
2212 opts
.raw
= d
->format
.raw
;
2218 val
= evaluate_expression (d
->exp
.get ());
2219 print_formatted (val
, d
->format
.size
, &opts
, gdb_stdout
);
2221 catch (const gdb_exception_error
&ex
)
2223 fprintf_styled (gdb_stdout
, metadata_style
.style (),
2224 _("<error: %s>"), ex
.what ());
2227 printf_filtered ("\n");
2230 annotate_display_end ();
2232 gdb_flush (gdb_stdout
);
2235 /* Display all of the values on the auto-display chain which can be
2236 evaluated in the current scope. */
2241 for (auto &d
: all_displays
)
2242 do_one_display (d
.get ());
2245 /* Delete the auto-display which we were in the process of displaying.
2246 This is done when there is an error or a signal. */
2249 disable_display (int num
)
2251 for (auto &d
: all_displays
)
2252 if (d
->number
== num
)
2254 d
->enabled_p
= false;
2257 printf_unfiltered (_("No display number %d.\n"), num
);
2261 disable_current_display (void)
2263 if (current_display_number
>= 0)
2265 disable_display (current_display_number
);
2266 fprintf_unfiltered (gdb_stderr
,
2267 _("Disabling display %d to "
2268 "avoid infinite recursion.\n"),
2269 current_display_number
);
2271 current_display_number
= -1;
2275 info_display_command (const char *ignore
, int from_tty
)
2277 if (all_displays
.empty ())
2278 printf_unfiltered (_("There are no auto-display expressions now.\n"));
2280 printf_filtered (_("Auto-display expressions now in effect:\n\
2281 Num Enb Expression\n"));
2283 for (auto &d
: all_displays
)
2285 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
2287 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
2289 else if (d
->format
.format
)
2290 printf_filtered ("/%c ", d
->format
.format
);
2291 puts_filtered (d
->exp_string
.c_str ());
2292 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
, true))
2293 printf_filtered (_(" (cannot be evaluated in the current context)"));
2294 printf_filtered ("\n");
2298 /* Implementation of both the "disable display" and "enable display"
2299 commands. ENABLE decides what to do. */
2302 enable_disable_display_command (const char *args
, int from_tty
, bool enable
)
2306 for (auto &d
: all_displays
)
2307 d
->enabled_p
= enable
;
2311 map_display_numbers (args
,
2312 [=] (struct display
*d
)
2314 d
->enabled_p
= enable
;
2318 /* The "enable display" command. */
2321 enable_display_command (const char *args
, int from_tty
)
2323 enable_disable_display_command (args
, from_tty
, true);
2326 /* The "disable display" command. */
2329 disable_display_command (const char *args
, int from_tty
)
2331 enable_disable_display_command (args
, from_tty
, false);
2334 /* display_chain items point to blocks and expressions. Some expressions in
2335 turn may point to symbols.
2336 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
2337 obstack_free'd when a shared library is unloaded.
2338 Clear pointers that are about to become dangling.
2339 Both .exp and .block fields will be restored next time we need to display
2340 an item by re-parsing .exp_string field in the new execution context. */
2343 clear_dangling_display_expressions (struct objfile
*objfile
)
2345 struct program_space
*pspace
;
2347 /* With no symbol file we cannot have a block or expression from it. */
2348 if (objfile
== NULL
)
2350 pspace
= objfile
->pspace
;
2351 if (objfile
->separate_debug_objfile_backlink
)
2353 objfile
= objfile
->separate_debug_objfile_backlink
;
2354 gdb_assert (objfile
->pspace
== pspace
);
2357 for (auto &d
: all_displays
)
2359 if (d
->pspace
!= pspace
)
2362 struct objfile
*bl_objf
= nullptr;
2363 if (d
->block
!= nullptr)
2365 bl_objf
= block_objfile (d
->block
);
2366 if (bl_objf
->separate_debug_objfile_backlink
!= nullptr)
2367 bl_objf
= bl_objf
->separate_debug_objfile_backlink
;
2370 if (bl_objf
== objfile
2371 || (d
->exp
!= NULL
&& exp_uses_objfile (d
->exp
.get (), objfile
)))
2380 /* Print the value in stack frame FRAME of a variable specified by a
2381 struct symbol. NAME is the name to print; if NULL then VAR's print
2382 name will be used. STREAM is the ui_file on which to print the
2383 value. INDENT specifies the number of indent levels to print
2384 before printing the variable name.
2386 This function invalidates FRAME. */
2389 print_variable_and_value (const char *name
, struct symbol
*var
,
2390 struct frame_info
*frame
,
2391 struct ui_file
*stream
, int indent
)
2395 name
= var
->print_name ();
2397 fprintf_filtered (stream
, "%*s%ps = ", 2 * indent
, "",
2398 styled_string (variable_name_style
.style (), name
));
2403 struct value_print_options opts
;
2405 /* READ_VAR_VALUE needs a block in order to deal with non-local
2406 references (i.e. to handle nested functions). In this context, we
2407 print variables that are local to this frame, so we can avoid passing
2409 val
= read_var_value (var
, NULL
, frame
);
2410 get_user_print_options (&opts
);
2412 common_val_print_checked (val
, stream
, indent
, &opts
, current_language
);
2414 /* common_val_print invalidates FRAME when a pretty printer calls inferior
2418 catch (const gdb_exception_error
&except
)
2420 fprintf_styled (stream
, metadata_style
.style (),
2421 "<error reading variable %s (%s)>", name
,
2425 fprintf_filtered (stream
, "\n");
2428 /* Subroutine of ui_printf to simplify it.
2429 Print VALUE to STREAM using FORMAT.
2430 VALUE is a C-style string either on the target or
2431 in a GDB internal variable. */
2434 printf_c_string (struct ui_file
*stream
, const char *format
,
2435 struct value
*value
)
2437 const gdb_byte
*str
;
2439 if (value_type (value
)->code () != TYPE_CODE_PTR
2440 && VALUE_LVAL (value
) == lval_internalvar
2441 && c_is_string_type_p (value_type (value
)))
2443 size_t len
= TYPE_LENGTH (value_type (value
));
2445 /* Copy the internal var value to TEM_STR and append a terminating null
2446 character. This protects against corrupted C-style strings that lack
2447 the terminating null char. It also allows Ada-style strings (not
2448 null terminated) to be printed without problems. */
2449 gdb_byte
*tem_str
= (gdb_byte
*) alloca (len
+ 1);
2451 memcpy (tem_str
, value_contents (value
), len
);
2457 CORE_ADDR tem
= value_as_address (value
);;
2462 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2463 fprintf_filtered (stream
, format
, "(null)");
2468 /* This is a %s argument. Find the length of the string. */
2471 for (len
= 0;; len
++)
2476 read_memory (tem
+ len
, &c
, 1);
2481 /* Copy the string contents into a string inside GDB. */
2482 gdb_byte
*tem_str
= (gdb_byte
*) alloca (len
+ 1);
2485 read_memory (tem
, tem_str
, len
);
2491 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2492 fprintf_filtered (stream
, format
, (char *) str
);
2496 /* Subroutine of ui_printf to simplify it.
2497 Print VALUE to STREAM using FORMAT.
2498 VALUE is a wide C-style string on the target or
2499 in a GDB internal variable. */
2502 printf_wide_c_string (struct ui_file
*stream
, const char *format
,
2503 struct value
*value
)
2505 const gdb_byte
*str
;
2507 struct gdbarch
*gdbarch
= value_type (value
)->arch ();
2508 struct type
*wctype
= lookup_typename (current_language
,
2509 "wchar_t", NULL
, 0);
2510 int wcwidth
= TYPE_LENGTH (wctype
);
2512 if (VALUE_LVAL (value
) == lval_internalvar
2513 && c_is_string_type_p (value_type (value
)))
2515 str
= value_contents (value
);
2516 len
= TYPE_LENGTH (value_type (value
));
2520 CORE_ADDR tem
= value_as_address (value
);
2525 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2526 fprintf_filtered (stream
, format
, "(null)");
2531 /* This is a %s argument. Find the length of the string. */
2532 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2533 gdb_byte
*buf
= (gdb_byte
*) alloca (wcwidth
);
2535 for (len
= 0;; len
+= wcwidth
)
2538 read_memory (tem
+ len
, buf
, wcwidth
);
2539 if (extract_unsigned_integer (buf
, wcwidth
, byte_order
) == 0)
2543 /* Copy the string contents into a string inside GDB. */
2544 gdb_byte
*tem_str
= (gdb_byte
*) alloca (len
+ wcwidth
);
2547 read_memory (tem
, tem_str
, len
);
2548 memset (&tem_str
[len
], 0, wcwidth
);
2552 auto_obstack output
;
2554 convert_between_encodings (target_wide_charset (gdbarch
),
2557 &output
, translit_char
);
2558 obstack_grow_str0 (&output
, "");
2561 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2562 fprintf_filtered (stream
, format
, obstack_base (&output
));
2566 /* Subroutine of ui_printf to simplify it.
2567 Print VALUE, a floating point value, to STREAM using FORMAT. */
2570 printf_floating (struct ui_file
*stream
, const char *format
,
2571 struct value
*value
, enum argclass argclass
)
2573 /* Parameter data. */
2574 struct type
*param_type
= value_type (value
);
2575 struct gdbarch
*gdbarch
= param_type
->arch ();
2577 /* Determine target type corresponding to the format string. */
2578 struct type
*fmt_type
;
2582 fmt_type
= builtin_type (gdbarch
)->builtin_double
;
2584 case long_double_arg
:
2585 fmt_type
= builtin_type (gdbarch
)->builtin_long_double
;
2587 case dec32float_arg
:
2588 fmt_type
= builtin_type (gdbarch
)->builtin_decfloat
;
2590 case dec64float_arg
:
2591 fmt_type
= builtin_type (gdbarch
)->builtin_decdouble
;
2593 case dec128float_arg
:
2594 fmt_type
= builtin_type (gdbarch
)->builtin_declong
;
2597 gdb_assert_not_reached ("unexpected argument class");
2600 /* To match the traditional GDB behavior, the conversion is
2601 done differently depending on the type of the parameter:
2603 - if the parameter has floating-point type, it's value
2604 is converted to the target type;
2606 - otherwise, if the parameter has a type that is of the
2607 same size as a built-in floating-point type, the value
2608 bytes are interpreted as if they were of that type, and
2609 then converted to the target type (this is not done for
2610 decimal floating-point argument classes);
2612 - otherwise, if the source value has an integer value,
2613 it's value is converted to the target type;
2615 - otherwise, an error is raised.
2617 In either case, the result of the conversion is a byte buffer
2618 formatted in the target format for the target type. */
2620 if (fmt_type
->code () == TYPE_CODE_FLT
)
2622 param_type
= float_type_from_length (param_type
);
2623 if (param_type
!= value_type (value
))
2624 value
= value_from_contents (param_type
, value_contents (value
));
2627 value
= value_cast (fmt_type
, value
);
2629 /* Convert the value to a string and print it. */
2631 = target_float_to_string (value_contents (value
), fmt_type
, format
);
2632 fputs_filtered (str
.c_str (), stream
);
2635 /* Subroutine of ui_printf to simplify it.
2636 Print VALUE, a target pointer, to STREAM using FORMAT. */
2639 printf_pointer (struct ui_file
*stream
, const char *format
,
2640 struct value
*value
)
2642 /* We avoid the host's %p because pointers are too
2643 likely to be the wrong size. The only interesting
2644 modifier for %p is a width; extract that, and then
2645 handle %p as glibc would: %#x or a literal "(nil)". */
2649 #ifdef PRINTF_HAS_LONG_LONG
2650 long long val
= value_as_long (value
);
2652 long val
= value_as_long (value
);
2655 fmt
= (char *) alloca (strlen (format
) + 5);
2657 /* Copy up to the leading %. */
2662 int is_percent
= (*p
== '%');
2677 /* Copy any width or flags. Only the "-" flag is valid for pointers
2678 -- see the format_pieces constructor. */
2679 while (*p
== '-' || (*p
>= '0' && *p
< '9'))
2682 gdb_assert (*p
== 'p' && *(p
+ 1) == '\0');
2685 #ifdef PRINTF_HAS_LONG_LONG
2692 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2693 fprintf_filtered (stream
, fmt
, val
);
2701 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2702 fprintf_filtered (stream
, fmt
, "(nil)");
2707 /* printf "printf format string" ARG to STREAM. */
2710 ui_printf (const char *arg
, struct ui_file
*stream
)
2712 const char *s
= arg
;
2713 std::vector
<struct value
*> val_args
;
2716 error_no_arg (_("format-control string and values to print"));
2718 s
= skip_spaces (s
);
2720 /* A format string should follow, enveloped in double quotes. */
2722 error (_("Bad format string, missing '\"'."));
2724 format_pieces
fpieces (&s
);
2727 error (_("Bad format string, non-terminated '\"'."));
2729 s
= skip_spaces (s
);
2731 if (*s
!= ',' && *s
!= 0)
2732 error (_("Invalid argument syntax"));
2736 s
= skip_spaces (s
);
2741 const char *current_substring
;
2744 for (auto &&piece
: fpieces
)
2745 if (piece
.argclass
!= literal_piece
)
2748 /* Now, parse all arguments and evaluate them.
2749 Store the VALUEs in VAL_ARGS. */
2756 val_args
.push_back (parse_to_comma_and_eval (&s1
));
2763 if (val_args
.size () != nargs_wanted
)
2764 error (_("Wrong number of arguments for specified format-string"));
2766 /* Now actually print them. */
2768 for (auto &&piece
: fpieces
)
2770 current_substring
= piece
.string
;
2771 switch (piece
.argclass
)
2774 printf_c_string (stream
, current_substring
, val_args
[i
]);
2776 case wide_string_arg
:
2777 printf_wide_c_string (stream
, current_substring
, val_args
[i
]);
2781 struct gdbarch
*gdbarch
= value_type (val_args
[i
])->arch ();
2782 struct type
*wctype
= lookup_typename (current_language
,
2783 "wchar_t", NULL
, 0);
2784 struct type
*valtype
;
2785 const gdb_byte
*bytes
;
2787 valtype
= value_type (val_args
[i
]);
2788 if (TYPE_LENGTH (valtype
) != TYPE_LENGTH (wctype
)
2789 || valtype
->code () != TYPE_CODE_INT
)
2790 error (_("expected wchar_t argument for %%lc"));
2792 bytes
= value_contents (val_args
[i
]);
2794 auto_obstack output
;
2796 convert_between_encodings (target_wide_charset (gdbarch
),
2798 bytes
, TYPE_LENGTH (valtype
),
2799 TYPE_LENGTH (valtype
),
2800 &output
, translit_char
);
2801 obstack_grow_str0 (&output
, "");
2804 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2805 fprintf_filtered (stream
, current_substring
,
2806 obstack_base (&output
));
2811 #ifdef PRINTF_HAS_LONG_LONG
2813 long long val
= value_as_long (val_args
[i
]);
2816 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2817 fprintf_filtered (stream
, current_substring
, val
);
2822 error (_("long long not supported in printf"));
2826 int val
= value_as_long (val_args
[i
]);
2829 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2830 fprintf_filtered (stream
, current_substring
, val
);
2836 long val
= value_as_long (val_args
[i
]);
2839 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2840 fprintf_filtered (stream
, current_substring
, val
);
2846 size_t val
= value_as_long (val_args
[i
]);
2849 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2850 fprintf_filtered (stream
, current_substring
, val
);
2854 /* Handles floating-point values. */
2856 case long_double_arg
:
2857 case dec32float_arg
:
2858 case dec64float_arg
:
2859 case dec128float_arg
:
2860 printf_floating (stream
, current_substring
, val_args
[i
],
2864 printf_pointer (stream
, current_substring
, val_args
[i
]);
2867 /* Print a portion of the format string that has no
2868 directives. Note that this will not include any
2869 ordinary %-specs, but it might include "%%". That is
2870 why we use printf_filtered and not puts_filtered here.
2871 Also, we pass a dummy argument because some platforms
2872 have modified GCC to include -Wformat-security by
2873 default, which will warn here if there is no
2876 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
2877 fprintf_filtered (stream
, current_substring
, 0);
2881 internal_error (__FILE__
, __LINE__
,
2882 _("failed internal consistency check"));
2884 /* Maybe advance to the next argument. */
2885 if (piece
.argclass
!= literal_piece
)
2891 /* Implement the "printf" command. */
2894 printf_command (const char *arg
, int from_tty
)
2896 ui_printf (arg
, gdb_stdout
);
2897 reset_terminal_style (gdb_stdout
);
2899 gdb_stdout
->flush ();
2902 /* Implement the "eval" command. */
2905 eval_command (const char *arg
, int from_tty
)
2909 ui_printf (arg
, &stb
);
2911 std::string expanded
= insert_user_defined_cmd_args (stb
.c_str ());
2913 execute_command (expanded
.c_str (), from_tty
);
2916 /* Convenience function for error checking in memory-tag commands. */
2919 show_addr_not_tagged (CORE_ADDR address
)
2921 error (_("Address %s not in a region mapped with a memory tagging flag."),
2922 paddress (target_gdbarch (), address
));
2925 /* Convenience function for error checking in memory-tag commands. */
2928 show_memory_tagging_unsupported (void)
2930 error (_("Memory tagging not supported or disabled by the current"
2934 /* Implement the "memory-tag" prefix command. */
2937 memory_tag_command (const char *arg
, int from_tty
)
2939 help_list (memory_tag_list
, "memory-tag ", all_commands
, gdb_stdout
);
2942 /* Helper for print-logical-tag and print-allocation-tag. */
2945 memory_tag_print_tag_command (const char *args
, enum memtag_type tag_type
)
2947 if (args
== nullptr)
2948 error_no_arg (_("address or pointer"));
2950 /* Parse args into a value. If the value is a pointer or an address,
2951 then fetch the logical or allocation tag. */
2952 value_print_options print_opts
;
2954 struct value
*val
= process_print_command_args (args
, &print_opts
, true);
2956 /* If the address is not in a region memory mapped with a memory tagging
2957 flag, it is no use trying to access/manipulate its allocation tag.
2959 It is OK to manipulate the logical tag though. */
2960 if (tag_type
== memtag_type::allocation
2961 && !gdbarch_tagged_address_p (target_gdbarch (), val
))
2962 show_addr_not_tagged (value_as_address (val
));
2964 struct value
*tag_value
2965 = gdbarch_get_memtag (target_gdbarch (), val
, tag_type
);
2966 std::string tag
= gdbarch_memtag_to_string (target_gdbarch (), tag_value
);
2969 printf_filtered (_("%s tag unavailable.\n"),
2971 == memtag_type::logical
? "Logical" : "Allocation");
2973 struct value
*v_tag
= process_print_command_args (tag
.c_str (),
2976 print_opts
.output_format
= 'x';
2977 print_value (v_tag
, print_opts
);
2980 /* Implement the "memory-tag print-logical-tag" command. */
2983 memory_tag_print_logical_tag_command (const char *args
, int from_tty
)
2985 if (!target_supports_memory_tagging ())
2986 show_memory_tagging_unsupported ();
2988 memory_tag_print_tag_command (args
, memtag_type::logical
);
2991 /* Implement the "memory-tag print-allocation-tag" command. */
2994 memory_tag_print_allocation_tag_command (const char *args
, int from_tty
)
2996 if (!target_supports_memory_tagging ())
2997 show_memory_tagging_unsupported ();
2999 memory_tag_print_tag_command (args
, memtag_type::allocation
);
3002 /* Parse ARGS and extract ADDR and TAG.
3003 ARGS should have format <expression> <tag bytes>. */
3006 parse_with_logical_tag_input (const char *args
, struct value
**val
,
3007 gdb::byte_vector
&tags
,
3008 value_print_options
*print_opts
)
3010 /* Fetch the address. */
3011 std::string address_string
= extract_string_maybe_quoted (&args
);
3013 /* Parse the address into a value. */
3014 *val
= process_print_command_args (address_string
.c_str (), print_opts
,
3017 /* Fetch the tag bytes. */
3018 std::string tag_string
= extract_string_maybe_quoted (&args
);
3020 /* Validate the input. */
3021 if (address_string
.empty () || tag_string
.empty ())
3022 error (_("Missing arguments."));
3024 if (tag_string
.length () != 2)
3025 error (_("Error parsing tags argument. The tag should be 2 digits."));
3027 tags
= hex2bin (tag_string
.c_str ());
3030 /* Implement the "memory-tag with-logical-tag" command. */
3033 memory_tag_with_logical_tag_command (const char *args
, int from_tty
)
3035 if (!target_supports_memory_tagging ())
3036 show_memory_tagging_unsupported ();
3038 if (args
== nullptr)
3039 error_no_arg (_("<address> <tag>"));
3041 gdb::byte_vector tags
;
3043 value_print_options print_opts
;
3045 /* Parse the input. */
3046 parse_with_logical_tag_input (args
, &val
, tags
, &print_opts
);
3048 /* Setting the logical tag is just a local operation that does not touch
3049 any memory from the target. Given an input value, we modify the value
3050 to include the appropriate tag.
3052 For this reason we need to cast the argument value to a
3053 (void *) pointer. This is so we have the right type for the gdbarch
3054 hook to manipulate the value and insert the tag.
3056 Otherwise, this would fail if, for example, GDB parsed the argument value
3057 into an int-sized value and the pointer value has a type of greater
3060 /* Cast to (void *). */
3061 val
= value_cast (builtin_type (target_gdbarch ())->builtin_data_ptr
,
3064 /* Length doesn't matter for a logical tag. Pass 0. */
3065 if (!gdbarch_set_memtags (target_gdbarch (), val
, 0, tags
,
3066 memtag_type::logical
))
3067 printf_filtered (_("Could not update the logical tag data.\n"));
3070 /* Always print it in hex format. */
3071 print_opts
.output_format
= 'x';
3072 print_value (val
, print_opts
);
3076 /* Parse ARGS and extract ADDR, LENGTH and TAGS. */
3079 parse_set_allocation_tag_input (const char *args
, struct value
**val
,
3080 size_t *length
, gdb::byte_vector
&tags
)
3082 /* Fetch the address. */
3083 std::string address_string
= extract_string_maybe_quoted (&args
);
3085 /* Parse the address into a value. */
3086 value_print_options print_opts
;
3087 *val
= process_print_command_args (address_string
.c_str (), &print_opts
,
3090 /* Fetch the length. */
3091 std::string length_string
= extract_string_maybe_quoted (&args
);
3093 /* Fetch the tag bytes. */
3094 std::string tags_string
= extract_string_maybe_quoted (&args
);
3096 /* Validate the input. */
3097 if (address_string
.empty () || length_string
.empty () || tags_string
.empty ())
3098 error (_("Missing arguments."));
3101 const char *trailer
= nullptr;
3102 LONGEST parsed_length
= strtoulst (length_string
.c_str (), &trailer
, 10);
3104 if (errno
!= 0 || (trailer
!= nullptr && trailer
[0] != '\0'))
3105 error (_("Error parsing length argument."));
3107 if (parsed_length
<= 0)
3108 error (_("Invalid zero or negative length."));
3110 *length
= parsed_length
;
3112 if (tags_string
.length () % 2)
3113 error (_("Error parsing tags argument. Tags should be 2 digits per byte."));
3115 tags
= hex2bin (tags_string
.c_str ());
3117 /* If the address is not in a region memory mapped with a memory tagging
3118 flag, it is no use trying to access/manipulate its allocation tag. */
3119 if (!gdbarch_tagged_address_p (target_gdbarch (), *val
))
3120 show_addr_not_tagged (value_as_address (*val
));
3123 /* Implement the "memory-tag set-allocation-tag" command.
3124 ARGS should be in the format <address> <length> <tags>. */
3127 memory_tag_set_allocation_tag_command (const char *args
, int from_tty
)
3129 if (!target_supports_memory_tagging ())
3130 show_memory_tagging_unsupported ();
3132 if (args
== nullptr)
3133 error_no_arg (_("<starting address> <length> <tag bytes>"));
3135 gdb::byte_vector tags
;
3139 /* Parse the input. */
3140 parse_set_allocation_tag_input (args
, &val
, &length
, tags
);
3142 if (!gdbarch_set_memtags (target_gdbarch (), val
, length
, tags
,
3143 memtag_type::allocation
))
3144 printf_filtered (_("Could not update the allocation tag(s).\n"));
3146 printf_filtered (_("Allocation tag(s) updated successfully.\n"));
3149 /* Implement the "memory-tag check" command. */
3152 memory_tag_check_command (const char *args
, int from_tty
)
3154 if (!target_supports_memory_tagging ())
3155 show_memory_tagging_unsupported ();
3157 if (args
== nullptr)
3158 error (_("Argument required (address or pointer)"));
3160 /* Parse the expression into a value. If the value is an address or
3161 pointer, then check its logical tag against the allocation tag. */
3162 value_print_options print_opts
;
3164 struct value
*val
= process_print_command_args (args
, &print_opts
, true);
3166 /* If the address is not in a region memory mapped with a memory tagging
3167 flag, it is no use trying to access/manipulate its allocation tag. */
3168 if (!gdbarch_tagged_address_p (target_gdbarch (), val
))
3169 show_addr_not_tagged (value_as_address (val
));
3171 CORE_ADDR addr
= value_as_address (val
);
3173 /* Check if the tag is valid. */
3174 if (!gdbarch_memtag_matches_p (target_gdbarch (), val
))
3177 = gdbarch_get_memtag (target_gdbarch (), val
, memtag_type::logical
);
3179 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
3181 tag
= gdbarch_get_memtag (target_gdbarch (), val
,
3182 memtag_type::allocation
);
3184 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
3186 printf_filtered (_("Logical tag (%s) does not match"
3187 " the allocation tag (%s) for address %s.\n"),
3188 ltag
.c_str (), atag
.c_str (),
3189 paddress (target_gdbarch (), addr
));
3194 = gdbarch_get_memtag (target_gdbarch (), val
, memtag_type::logical
);
3196 = gdbarch_memtag_to_string (target_gdbarch (), tag
);
3198 printf_filtered (_("Memory tags for address %s match (%s).\n"),
3199 paddress (target_gdbarch (), addr
), ltag
.c_str ());
3203 void _initialize_printcmd ();
3205 _initialize_printcmd ()
3207 struct cmd_list_element
*c
;
3209 current_display_number
= -1;
3211 gdb::observers::free_objfile
.attach (clear_dangling_display_expressions
,
3214 add_info ("address", info_address_command
,
3215 _("Describe where symbol SYM is stored.\n\
3216 Usage: info address SYM"));
3218 add_info ("symbol", info_symbol_command
, _("\
3219 Describe what symbol is at location ADDR.\n\
3220 Usage: info symbol ADDR\n\
3221 Only for symbols with fixed locations (global or static scope)."));
3223 c
= add_com ("x", class_vars
, x_command
, _("\
3224 Examine memory: x/FMT ADDRESS.\n\
3225 ADDRESS is an expression for the memory address to examine.\n\
3226 FMT is a repeat count followed by a format letter and a size letter.\n\
3227 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
3228 t(binary), f(float), a(address), i(instruction), c(char), s(string)\n\
3229 and z(hex, zero padded on the left).\n\
3230 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
3231 The specified number of objects of the specified size are printed\n\
3232 according to the format. If a negative number is specified, memory is\n\
3233 examined backward from the address.\n\n\
3234 Defaults for format and size letters are those previously used.\n\
3235 Default count is 1. Default address is following last thing printed\n\
3236 with this command or \"print\"."));
3237 set_cmd_completer_handle_brkchars (c
, display_and_x_command_completer
);
3239 add_info ("display", info_display_command
, _("\
3240 Expressions to display when program stops, with code numbers.\n\
3241 Usage: info display"));
3243 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
3244 Cancel some expressions to be displayed when program stops.\n\
3245 Usage: undisplay [NUM]...\n\
3246 Arguments are the code numbers of the expressions to stop displaying.\n\
3247 No argument means cancel all automatic-display expressions.\n\
3248 \"delete display\" has the same effect as this command.\n\
3249 Do \"info display\" to see current list of code numbers."),
3252 c
= add_com ("display", class_vars
, display_command
, _("\
3253 Print value of expression EXP each time the program stops.\n\
3254 Usage: display[/FMT] EXP\n\
3255 /FMT may be used before EXP as in the \"print\" command.\n\
3256 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
3257 as in the \"x\" command, and then EXP is used to get the address to examine\n\
3258 and examining is done as in the \"x\" command.\n\n\
3259 With no argument, display all currently requested auto-display expressions.\n\
3260 Use \"undisplay\" to cancel display requests previously made."));
3261 set_cmd_completer_handle_brkchars (c
, display_and_x_command_completer
);
3263 add_cmd ("display", class_vars
, enable_display_command
, _("\
3264 Enable some expressions to be displayed when program stops.\n\
3265 Usage: enable display [NUM]...\n\
3266 Arguments are the code numbers of the expressions to resume displaying.\n\
3267 No argument means enable all automatic-display expressions.\n\
3268 Do \"info display\" to see current list of code numbers."), &enablelist
);
3270 add_cmd ("display", class_vars
, disable_display_command
, _("\
3271 Disable some expressions to be displayed when program stops.\n\
3272 Usage: disable display [NUM]...\n\
3273 Arguments are the code numbers of the expressions to stop displaying.\n\
3274 No argument means disable all automatic-display expressions.\n\
3275 Do \"info display\" to see current list of code numbers."), &disablelist
);
3277 add_cmd ("display", class_vars
, undisplay_command
, _("\
3278 Cancel some expressions to be displayed when program stops.\n\
3279 Usage: delete display [NUM]...\n\
3280 Arguments are the code numbers of the expressions to stop displaying.\n\
3281 No argument means cancel all automatic-display expressions.\n\
3282 Do \"info display\" to see current list of code numbers."), &deletelist
);
3284 add_com ("printf", class_vars
, printf_command
, _("\
3285 Formatted printing, like the C \"printf\" function.\n\
3286 Usage: printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
3287 This supports most C printf format specifications, like %s, %d, etc."));
3289 add_com ("output", class_vars
, output_command
, _("\
3290 Like \"print\" but don't put in value history and don't print newline.\n\
3291 Usage: output EXP\n\
3292 This is useful in user-defined commands."));
3294 add_prefix_cmd ("set", class_vars
, set_command
, _("\
3295 Evaluate expression EXP and assign result to variable VAR.\n\
3296 Usage: set VAR = EXP\n\
3297 This uses assignment syntax appropriate for the current language\n\
3298 (VAR = EXP or VAR := EXP for example).\n\
3299 VAR may be a debugger \"convenience\" variable (names starting\n\
3300 with $), a register (a few standard names starting with $), or an actual\n\
3301 variable in the program being debugged. EXP is any valid expression.\n\
3302 Use \"set variable\" for variables with names identical to set subcommands.\n\
3304 With a subcommand, this command modifies parts of the gdb environment.\n\
3305 You can see these environment settings with the \"show\" command."),
3306 &setlist
, 1, &cmdlist
);
3308 add_com ("assign", class_vars
, set_command
, _("\
3309 Evaluate expression EXP and assign result to variable VAR.\n\
3310 Usage: assign VAR = EXP\n\
3311 This uses assignment syntax appropriate for the current language\n\
3312 (VAR = EXP or VAR := EXP for example).\n\
3313 VAR may be a debugger \"convenience\" variable (names starting\n\
3314 with $), a register (a few standard names starting with $), or an actual\n\
3315 variable in the program being debugged. EXP is any valid expression.\n\
3316 Use \"set variable\" for variables with names identical to set subcommands.\n\
3317 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
3318 You can see these environment settings with the \"show\" command."));
3320 /* "call" is the same as "set", but handy for dbx users to call fns. */
3321 c
= add_com ("call", class_vars
, call_command
, _("\
3322 Call a function in the program.\n\
3324 The argument is the function name and arguments, in the notation of the\n\
3325 current working language. The result is printed and saved in the value\n\
3326 history, if it is not void."));
3327 set_cmd_completer_handle_brkchars (c
, print_command_completer
);
3329 cmd_list_element
*set_variable_cmd
3330 = add_cmd ("variable", class_vars
, set_command
, _("\
3331 Evaluate expression EXP and assign result to variable VAR.\n\
3332 Usage: set variable VAR = EXP\n\
3333 This uses assignment syntax appropriate for the current language\n\
3334 (VAR = EXP or VAR := EXP for example).\n\
3335 VAR may be a debugger \"convenience\" variable (names starting\n\
3336 with $), a register (a few standard names starting with $), or an actual\n\
3337 variable in the program being debugged. EXP is any valid expression.\n\
3338 This may usually be abbreviated to simply \"set\"."),
3340 add_alias_cmd ("var", set_variable_cmd
, class_vars
, 0, &setlist
);
3342 const auto print_opts
= make_value_print_options_def_group (nullptr);
3344 static const std::string print_help
= gdb::option::build_help (_("\
3345 Print value of expression EXP.\n\
3346 Usage: print [[OPTION]... --] [/FMT] [EXP]\n\
3351 Note: because this command accepts arbitrary expressions, if you\n\
3352 specify any command option, you must use a double dash (\"--\")\n\
3353 to mark the end of option processing. E.g.: \"print -o -- myobj\".\n\
3355 Variables accessible are those of the lexical environment of the selected\n\
3356 stack frame, plus all those whose scope is global or an entire file.\n\
3358 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
3359 $$NUM refers to NUM'th value back from the last one.\n\
3360 Names starting with $ refer to registers (with the values they would have\n\
3361 if the program were to return to the stack frame now selected, restoring\n\
3362 all registers saved by frames farther in) or else to debugger\n\
3363 \"convenience\" variables (any such name not a known register).\n\
3364 Use assignment expressions to give values to convenience variables.\n\
3366 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
3367 @ is a binary operator for treating consecutive data objects\n\
3368 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
3369 element is FOO, whose second element is stored in the space following\n\
3370 where FOO is stored, etc. FOO must be an expression whose value\n\
3371 resides in memory.\n\
3373 EXP may be preceded with /FMT, where FMT is a format letter\n\
3374 but no count or size letter (see \"x\" command)."),
3377 cmd_list_element
*print_cmd
3378 = add_com ("print", class_vars
, print_command
, print_help
.c_str ());
3379 set_cmd_completer_handle_brkchars (print_cmd
, print_command_completer
);
3380 add_com_alias ("p", print_cmd
, class_vars
, 1);
3381 add_com_alias ("inspect", print_cmd
, class_vars
, 1);
3383 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
3384 &max_symbolic_offset
, _("\
3385 Set the largest offset that will be printed in <SYMBOL+1234> form."), _("\
3386 Show the largest offset that will be printed in <SYMBOL+1234> form."), _("\
3387 Tell GDB to only display the symbolic form of an address if the\n\
3388 offset between the closest earlier symbol and the address is less than\n\
3389 the specified maximum offset. The default is \"unlimited\", which tells GDB\n\
3390 to always print the symbolic form of an address if any symbol precedes\n\
3391 it. Zero is equivalent to \"unlimited\"."),
3393 show_max_symbolic_offset
,
3394 &setprintlist
, &showprintlist
);
3395 add_setshow_boolean_cmd ("symbol-filename", no_class
,
3396 &print_symbol_filename
, _("\
3397 Set printing of source filename and line number with <SYMBOL>."), _("\
3398 Show printing of source filename and line number with <SYMBOL>."), NULL
,
3400 show_print_symbol_filename
,
3401 &setprintlist
, &showprintlist
);
3403 add_com ("eval", no_class
, eval_command
, _("\
3404 Construct a GDB command and then evaluate it.\n\
3405 Usage: eval \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
3406 Convert the arguments to a string as \"printf\" would, but then\n\
3407 treat this string as a command line, and evaluate it."));
3409 /* Memory tagging commands. */
3410 add_prefix_cmd ("memory-tag", class_vars
, memory_tag_command
, _("\
3411 Generic command for printing and manipulating memory tag properties."),
3412 &memory_tag_list
, 0, &cmdlist
);
3413 add_cmd ("print-logical-tag", class_vars
,
3414 memory_tag_print_logical_tag_command
,
3415 ("Print the logical tag from POINTER.\n\
3416 Usage: memory-tag print-logical-tag <POINTER>.\n\
3417 <POINTER> is an expression that evaluates to a pointer.\n\
3418 Print the logical tag contained in POINTER. The tag interpretation is\n\
3419 architecture-specific."),
3421 add_cmd ("print-allocation-tag", class_vars
,
3422 memory_tag_print_allocation_tag_command
,
3423 _("Print the allocation tag for ADDRESS.\n\
3424 Usage: memory-tag print-allocation-tag <ADDRESS>.\n\
3425 <ADDRESS> is an expression that evaluates to a memory address.\n\
3426 Print the allocation tag associated with the memory address ADDRESS.\n\
3427 The tag interpretation is architecture-specific."),
3429 add_cmd ("with-logical-tag", class_vars
, memory_tag_with_logical_tag_command
,
3430 _("Print a POINTER with a specific logical TAG.\n\
3431 Usage: memory-tag with-logical-tag <POINTER> <TAG>\n\
3432 <POINTER> is an expression that evaluates to a pointer.\n\
3433 <TAG> is a sequence of hex bytes that is interpreted by the architecture\n\
3434 as a single memory tag."),
3436 add_cmd ("set-allocation-tag", class_vars
,
3437 memory_tag_set_allocation_tag_command
,
3438 _("Set the allocation tag(s) for a memory range.\n\
3439 Usage: memory-tag set-allocation-tag <ADDRESS> <LENGTH> <TAG_BYTES>\n\
3440 <ADDRESS> is an expression that evaluates to a memory address\n\
3441 <LENGTH> is the number of bytes that is added to <ADDRESS> to calculate\n\
3442 the memory range.\n\
3443 <TAG_BYTES> is a sequence of hex bytes that is interpreted by the\n\
3444 architecture as one or more memory tags.\n\
3445 Sets the tags of the memory range [ADDRESS, ADDRESS + LENGTH)\n\
3448 If the number of tags is greater than or equal to the number of tag granules\n\
3449 in the [ADDRESS, ADDRESS + LENGTH) range, only the tags up to the\n\
3450 number of tag granules are updated.\n\
3452 If the number of tags is less than the number of tag granules, then the\n\
3453 command is a fill operation. The TAG_BYTES are interpreted as a pattern\n\
3454 that gets repeated until the number of tag granules in the memory range\n\
3455 [ADDRESS, ADDRESS + LENGTH) is updated."),
3457 add_cmd ("check", class_vars
, memory_tag_check_command
,
3458 _("Validate a pointer's logical tag against the allocation tag.\n\
3459 Usage: memory-tag check <POINTER>\n\
3460 <POINTER> is an expression that evaluates to a pointer\n\
3461 Fetch the logical and allocation tags for POINTER and compare them\n\
3462 for equality. If the tags do not match, print additional information about\n\
3463 the tag mismatch."),