diff options
author | Luis Machado <luis.machado@linaro.org> | 2020-06-19 17:36:14 -0300 |
---|---|---|
committer | Luis Machado <luis.machado@linaro.org> | 2021-03-24 14:47:52 -0300 |
commit | c193949e75809a656b99c8408e5b29504aec436a (patch) | |
tree | e8adec412217398f1684fe69a4a26d63f3be7046 /gdb/gdbarch.c | |
parent | dbe692af2d1814100748b18a5dd70214e8611107 (diff) | |
download | gdb-c193949e75809a656b99c8408e5b29504aec436a.zip gdb-c193949e75809a656b99c8408e5b29504aec436a.tar.gz gdb-c193949e75809a656b99c8408e5b29504aec436a.tar.bz2 |
New gdbarch memory tagging hooks
We need some new gdbarch hooks to help us manipulate memory tags without having
to have GDB call the target methods directly.
This patch adds the following hooks:
gdbarch_memtag_to_string
--
Returns a printable string corresponding to the tag.
gdbarch_tagged_address_p
--
Checks if a particular address is protected with memory tagging.
gdbarch_memtag_matches_p
--
Checks if the logical tag of a pointer and the allocation tag from the address
the pointer points to matches.
gdbarch_set_memtags:
--
Sets either the allocation tag or the logical tag for a particular value.
gdbarch_get_memtag:
--
Gets either the allocation tag or the logical tag for a particular value.
gdbarch_memtag_granule_size
--
Sets the memory tag granule size, which represents the number of bytes a
particular allocation tag covers. For example, this is 16 bytes for
AArch64's MTE.
I've used struct value as opposed to straight CORE_ADDR so other architectures
can use the infrastructure without having to rely on a particular type for
addresses/pointers. Some architecture may use pointers of 16 bytes that don't
fit in a CORE_ADDR, for example.
gdb/ChangeLog:
2021-03-24 Luis Machado <luis.machado@linaro.org>
* arch-utils.c (default_memtag_to_string, default_tagged_address_p)
(default_memtag_matches_p, default_set_memtags)
(default_get_memtag): New functions.
* arch-utils.h (default_memtag_to_string, default_tagged_address_p)
(default_memtag_matches_p, default_set_memtags)
(default_get_memtag): New prototypes.
* gdbarch.c: Regenerate.
* gdbarch.h: Regenerate.
* gdbarch.sh (memtag_to_string, tagged_address_p, memtag_matches_p)
(set_memtags, get_memtag, memtag_granule_size): New gdbarch hooks.
(enum memtag_type): New enum.
Diffstat (limited to 'gdb/gdbarch.c')
-rw-r--r-- | gdb/gdbarch.c | 139 |
1 files changed, 138 insertions, 1 deletions
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 8fa3cba..23509ba 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -253,6 +253,12 @@ struct gdbarch gdbarch_convert_from_func_ptr_addr_ftype *convert_from_func_ptr_addr; gdbarch_addr_bits_remove_ftype *addr_bits_remove; int significant_addr_bit; + gdbarch_memtag_to_string_ftype *memtag_to_string; + gdbarch_tagged_address_p_ftype *tagged_address_p; + gdbarch_memtag_matches_p_ftype *memtag_matches_p; + gdbarch_set_memtags_ftype *set_memtags; + gdbarch_get_memtag_ftype *get_memtag; + CORE_ADDR memtag_granule_size; gdbarch_software_single_step_ftype *software_single_step; gdbarch_single_step_through_delay_ftype *single_step_through_delay; gdbarch_print_insn_ftype *print_insn; @@ -433,6 +439,11 @@ gdbarch_alloc (const struct gdbarch_info *info, gdbarch->stabs_argument_has_addr = default_stabs_argument_has_addr; gdbarch->convert_from_func_ptr_addr = convert_from_func_ptr_addr_identity; gdbarch->addr_bits_remove = core_addr_identity; + gdbarch->memtag_to_string = default_memtag_to_string; + gdbarch->tagged_address_p = default_tagged_address_p; + gdbarch->memtag_matches_p = default_memtag_matches_p; + gdbarch->set_memtags = default_set_memtags; + gdbarch->get_memtag = default_get_memtag; gdbarch->print_insn = default_print_insn; gdbarch->skip_trampoline_code = generic_skip_trampoline_code; gdbarch->skip_solib_resolver = generic_skip_solib_resolver; @@ -626,6 +637,12 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of convert_from_func_ptr_addr, invalid_p == 0 */ /* Skip verify of addr_bits_remove, invalid_p == 0 */ /* Skip verify of significant_addr_bit, invalid_p == 0 */ + /* Skip verify of memtag_to_string, invalid_p == 0 */ + /* Skip verify of tagged_address_p, invalid_p == 0 */ + /* Skip verify of memtag_matches_p, invalid_p == 0 */ + /* Skip verify of set_memtags, invalid_p == 0 */ + /* Skip verify of get_memtag, invalid_p == 0 */ + /* Skip verify of memtag_granule_size, invalid_p == 0 */ /* Skip verify of software_single_step, has predicate. */ /* Skip verify of single_step_through_delay, has predicate. */ /* Skip verify of print_insn, invalid_p == 0 */ @@ -1089,6 +1106,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: get_longjmp_target = <%s>\n", host_address_to_string (gdbarch->get_longjmp_target)); fprintf_unfiltered (file, + "gdbarch_dump: get_memtag = <%s>\n", + host_address_to_string (gdbarch->get_memtag)); + fprintf_unfiltered (file, "gdbarch_dump: get_pc_address_flags = <%s>\n", host_address_to_string (gdbarch->get_pc_address_flags)); fprintf_unfiltered (file, @@ -1218,6 +1238,15 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: memory_remove_breakpoint = <%s>\n", host_address_to_string (gdbarch->memory_remove_breakpoint)); fprintf_unfiltered (file, + "gdbarch_dump: memtag_granule_size = %s\n", + core_addr_to_string_nz (gdbarch->memtag_granule_size)); + fprintf_unfiltered (file, + "gdbarch_dump: memtag_matches_p = <%s>\n", + host_address_to_string (gdbarch->memtag_matches_p)); + fprintf_unfiltered (file, + "gdbarch_dump: memtag_to_string = <%s>\n", + host_address_to_string (gdbarch->memtag_to_string)); + fprintf_unfiltered (file, "gdbarch_dump: num_pseudo_regs = %s\n", plongest (gdbarch->num_pseudo_regs)); fprintf_unfiltered (file, @@ -1371,6 +1400,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: sdb_reg_to_regnum = <%s>\n", host_address_to_string (gdbarch->sdb_reg_to_regnum)); fprintf_unfiltered (file, + "gdbarch_dump: set_memtags = <%s>\n", + host_address_to_string (gdbarch->set_memtags)); + fprintf_unfiltered (file, "gdbarch_dump: short_bit = %s\n", plongest (gdbarch->short_bit)); fprintf_unfiltered (file, @@ -1479,6 +1511,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: syscalls_info = %s\n", host_address_to_string (gdbarch->syscalls_info)); fprintf_unfiltered (file, + "gdbarch_dump: tagged_address_p = <%s>\n", + host_address_to_string (gdbarch->tagged_address_p)); + fprintf_unfiltered (file, "gdbarch_dump: target_desc = %s\n", host_address_to_string (gdbarch->target_desc)); fprintf_unfiltered (file, @@ -3283,6 +3318,108 @@ set_gdbarch_significant_addr_bit (struct gdbarch *gdbarch, gdbarch->significant_addr_bit = significant_addr_bit; } +std::string +gdbarch_memtag_to_string (struct gdbarch *gdbarch, struct value *tag) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->memtag_to_string != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_memtag_to_string called\n"); + return gdbarch->memtag_to_string (gdbarch, tag); +} + +void +set_gdbarch_memtag_to_string (struct gdbarch *gdbarch, + gdbarch_memtag_to_string_ftype memtag_to_string) +{ + gdbarch->memtag_to_string = memtag_to_string; +} + +bool +gdbarch_tagged_address_p (struct gdbarch *gdbarch, struct value *address) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->tagged_address_p != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_tagged_address_p called\n"); + return gdbarch->tagged_address_p (gdbarch, address); +} + +void +set_gdbarch_tagged_address_p (struct gdbarch *gdbarch, + gdbarch_tagged_address_p_ftype tagged_address_p) +{ + gdbarch->tagged_address_p = tagged_address_p; +} + +bool +gdbarch_memtag_matches_p (struct gdbarch *gdbarch, struct value *address) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->memtag_matches_p != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_memtag_matches_p called\n"); + return gdbarch->memtag_matches_p (gdbarch, address); +} + +void +set_gdbarch_memtag_matches_p (struct gdbarch *gdbarch, + gdbarch_memtag_matches_p_ftype memtag_matches_p) +{ + gdbarch->memtag_matches_p = memtag_matches_p; +} + +bool +gdbarch_set_memtags (struct gdbarch *gdbarch, struct value *address, size_t length, const gdb::byte_vector &tags, memtag_type tag_type) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->set_memtags != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_set_memtags called\n"); + return gdbarch->set_memtags (gdbarch, address, length, tags, tag_type); +} + +void +set_gdbarch_set_memtags (struct gdbarch *gdbarch, + gdbarch_set_memtags_ftype set_memtags) +{ + gdbarch->set_memtags = set_memtags; +} + +struct value * +gdbarch_get_memtag (struct gdbarch *gdbarch, struct value *address, memtag_type tag_type) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->get_memtag != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_get_memtag called\n"); + return gdbarch->get_memtag (gdbarch, address, tag_type); +} + +void +set_gdbarch_get_memtag (struct gdbarch *gdbarch, + gdbarch_get_memtag_ftype get_memtag) +{ + gdbarch->get_memtag = get_memtag; +} + +CORE_ADDR +gdbarch_memtag_granule_size (struct gdbarch *gdbarch) +{ + gdb_assert (gdbarch != NULL); + /* Skip verify of memtag_granule_size, invalid_p == 0 */ + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_memtag_granule_size called\n"); + return gdbarch->memtag_granule_size; +} + +void +set_gdbarch_memtag_granule_size (struct gdbarch *gdbarch, + CORE_ADDR memtag_granule_size) +{ + gdbarch->memtag_granule_size = memtag_granule_size; +} + bool gdbarch_software_single_step_p (struct gdbarch *gdbarch) { @@ -5314,7 +5451,7 @@ struct gdbarch_data_registry struct gdbarch_data_registration *registrations; }; -static struct gdbarch_data_registry gdbarch_data_registry = +struct gdbarch_data_registry gdbarch_data_registry = { 0, NULL, }; |