diff options
author | Luis Machado <luis.machado@linaro.org> | 2020-06-15 15:50:55 -0300 |
---|---|---|
committer | Luis Machado <luis.machado@linaro.org> | 2021-03-24 14:59:19 -0300 |
commit | bef382e61aeff32e46ce987e2af9b7c636dcf038 (patch) | |
tree | 02de46a5bda21cd0e3ee49f49594acc86c2d83dc /gdb/valprint.c | |
parent | 362a07001900888b37d54523aa010806bd754e18 (diff) | |
download | gdb-bef382e61aeff32e46ce987e2af9b7c636dcf038.zip gdb-bef382e61aeff32e46ce987e2af9b7c636dcf038.tar.gz gdb-bef382e61aeff32e46ce987e2af9b7c636dcf038.tar.bz2 |
Extend "x" and "print" commands to support memory tagging
Extend the "x" and "print" commands to make use of memory tagging
functionality, if supported by the architecture.
The "print" command will point out any possible tag mismatches it finds
when dealing with pointers, in case such a pointer is tagged. No additional
modifiers are needed.
Suppose we have a pointer "p" with value 0x1234 (logical tag 0x0) and that we
have an allocation tag of 0x1 for that particular area of memory. This is the
expected output:
(gdb) p/x p
Logical tag (0x0) does not match the allocation tag (0x1).
$1 = 0x1234
The "x" command has a new 'm' modifier that will enable displaying of
allocation tags alongside the data dump. It will display one allocation
tag per line.
AArch64 has a tag granule of 16 bytes, which means we can have one tag for
every 16 bytes of memory. In this case, this is what the "x" command will
display with the new 'm' modifier:
(gdb) x/32bxm p
<Allocation Tag 0x1 for range [0x1230,0x1240)>
0x1234: 0x01 0x02 0x00 0x00 0x00 0x00 0x00 0x00
0x123c: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
<Allocation Tag 0x1 for range [0x1240,0x1250)>
0x1244: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x124c: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
(gdb) x/4gxm a
<Allocation Tag 0x1 for range [0x1230,0x1240)>
0x1234: 0x0000000000000201 0x0000000000000000
<Allocation Tag 0x1 for range [0x1240,0x1250)>
0x1244: 0x0000000000000000 0x0000000000000000
gdb/ChangeLog:
2021-03-24 Luis Machado <luis.machado@linaro.org>
* printcmd.c (decode_format): Handle the 'm' modifier.
(do_examine): Display allocation tags when required/supported.
(should_validate_memtags): New function.
(print_command_1): Display memory tag mismatches.
* valprint.c (show_memory_tag_violations): New function.
(value_print_option_defs): Add new option "memory-tag-violations".
(user_print_options) <memory_tag_violations>: Initialize to 1.
* valprint.h (struct format_data) <print_tags>: New field.
(value_print_options) <memory_tag_violations>: New field.
gdb/testsuite/ChangeLog:
2021-03-24 Luis Machado <luis.machado@linaro.org>
* gdb.base/options.exp: Adjust for new print options.
* gdb.base/with.exp: Likewise.
Diffstat (limited to 'gdb/valprint.c')
-rw-r--r-- | gdb/valprint.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c index 340a329..c089ee2 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -110,6 +110,7 @@ struct value_print_options user_print_options = 10, /* repeat_count_threshold */ 0, /* output_format */ 0, /* format */ + 1, /* memory_tag_violations */ 0, /* stop_print_at_null */ 0, /* print_array_indexes */ 0, /* deref_ref */ @@ -203,6 +204,17 @@ show_repeat_count_threshold (struct ui_file *file, int from_tty, value); } +/* If nonzero, prints memory tag violations for pointers. */ + +static void +show_memory_tag_violations (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, + _("Printing of memory tag violations is %s.\n"), + value); +} + /* If nonzero, stops printing of char arrays at first null. */ static void @@ -3024,6 +3036,17 @@ Use \"unlimited\" to print the complete structure.") }, boolean_option_def { + "memory-tag-violations", + [] (value_print_options *opt) { return &opt->memory_tag_violations; }, + show_memory_tag_violations, /* show_cmd_cb */ + N_("Set printing of memory tag violations for pointers."), + N_("Show printing of memory tag violations for pointers."), + N_("Issue a warning when the printed value is a pointer\n\ +whose logical tag doesn't match the allocation tag of the memory\n\ +location it points to."), + }, + + boolean_option_def { "null-stop", [] (value_print_options *opt) { return &opt->stop_print_at_null; }, show_stop_print_at_null, /* show_cmd_cb */ |