From: John Baldwin Date: Thu, 28 Jul 2022 23:54:21 +0000 (-0700) Subject: Add gdbarch methods for printing capabilities. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf3398cb057eb90e06d0679f90aac9e4026587bf;p=thirdparty%2Fbinutils-gdb.git Add gdbarch methods for printing capabilities. gdbarch_print_cap prints a full capability in either verbose or compat forms. gdbarch_print_cap_attributes prints just the metadata such as bounds and permissions of a capability without the address. --- diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index b0a10b5e2a6..e81c4596a3b 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -1107,6 +1107,24 @@ default_set_cap_tag_from_address (struct gdbarch *gdbarch, return; } +/* See arch-utils.h. */ + +void +default_print_cap (struct gdbarch *gdbarch, const gdb_byte *contents, bool tag, + bool compact, struct ui_file *stream) +{ + return; +} + +/* See arch-utils.h. */ + +void +default_print_cap_attributes (struct gdbarch *gdbarch, const gdb_byte *contents, + bool tag, struct ui_file *stream) +{ + return; +} + /* Static function declarations */ static void alloc_gdbarch_data (struct gdbarch *); diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h index 334ab5f7287..c665b0b6869 100644 --- a/gdb/arch-utils.h +++ b/gdb/arch-utils.h @@ -308,4 +308,15 @@ extern bool default_get_cap_tag_from_address (struct gdbarch *gdbarch, /* Default implementation of gdbarch_set_cap_tag_from_address. */ extern void default_set_cap_tag_from_address (struct gdbarch *gdbarch, CORE_ADDR addr, bool tag); + +/* Default implementation of gdbarch_print_cap_attributes. */ +extern void default_print_cap (struct gdbarch *gdbarch, + const gdb_byte *contents, bool tag, bool compact, + struct ui_file *stream); + +/* Default implementation of gdbarch_print_cap_attributes. */ +extern void default_print_cap_attributes (struct gdbarch *gdbarch, + const gdb_byte *contents, bool tag, + struct ui_file *stream); + #endif /* ARCH_UTILS_H */ diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py index 44eac608b48..2ce2162734f 100644 --- a/gdb/gdbarch-components.py +++ b/gdb/gdbarch-components.py @@ -1045,6 +1045,38 @@ Set the tag from a capability stored at address ADDR to TAG. invalid=False, ) +Method( + comment=""" +Print value of a capability containing CONTENTS and TAG to STREAM. +""", + type="void", + name="print_cap", + params=[ + ("const gdb_byte *", "contents"), + ("bool", "tag"), + ("bool", "compact"), + ("struct ui_file *", "stream"), + ], + predefault="default_print_cap", + invalid=False, +) + +Method( + comment=""" +Print additional attributes for a capability containing CONTENTS and +TAG to STREAM. +""", + type="void", + name="print_cap_attributes", + params=[ + ("const gdb_byte *", "contents"), + ("bool", "tag"), + ("struct ui_file *", "stream"), + ], + predefault="default_print_cap_attributes", + invalid=False, +) + Function( comment=""" Fetch the target specific address used to represent a load module. diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index 2be9b2bc378..5593da3ce81 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -559,6 +559,19 @@ typedef void (gdbarch_set_cap_tag_from_address_ftype) (struct gdbarch *gdbarch, extern void gdbarch_set_cap_tag_from_address (struct gdbarch *gdbarch, CORE_ADDR addr, bool tag); extern void set_gdbarch_set_cap_tag_from_address (struct gdbarch *gdbarch, gdbarch_set_cap_tag_from_address_ftype *set_cap_tag_from_address); +/* Print value of a capability containing CONTENTS and TAG to STREAM. */ + +typedef void (gdbarch_print_cap_ftype) (struct gdbarch *gdbarch, const gdb_byte *contents, bool tag, bool compact, struct ui_file *stream); +extern void gdbarch_print_cap (struct gdbarch *gdbarch, const gdb_byte *contents, bool tag, bool compact, struct ui_file *stream); +extern void set_gdbarch_print_cap (struct gdbarch *gdbarch, gdbarch_print_cap_ftype *print_cap); + +/* Print additional attributes for a capability containing CONTENTS and + TAG to STREAM. */ + +typedef void (gdbarch_print_cap_attributes_ftype) (struct gdbarch *gdbarch, const gdb_byte *contents, bool tag, struct ui_file *stream); +extern void gdbarch_print_cap_attributes (struct gdbarch *gdbarch, const gdb_byte *contents, bool tag, struct ui_file *stream); +extern void set_gdbarch_print_cap_attributes (struct gdbarch *gdbarch, gdbarch_print_cap_attributes_ftype *print_cap_attributes); + /* Fetch the target specific address used to represent a load module. */ extern bool gdbarch_fetch_tls_load_module_address_p (struct gdbarch *gdbarch); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index ae9335c71ba..cdd7f76e657 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -132,6 +132,8 @@ struct gdbarch gdbarch_remote_register_number_ftype *remote_register_number; gdbarch_get_cap_tag_from_address_ftype *get_cap_tag_from_address; gdbarch_set_cap_tag_from_address_ftype *set_cap_tag_from_address; + gdbarch_print_cap_ftype *print_cap; + gdbarch_print_cap_attributes_ftype *print_cap_attributes; gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address; gdbarch_get_thread_local_address_ftype *get_thread_local_address; CORE_ADDR frame_args_skip; @@ -330,6 +332,8 @@ gdbarch_alloc (const struct gdbarch_info *info, gdbarch->remote_register_number = default_remote_register_number; gdbarch->get_cap_tag_from_address = default_get_cap_tag_from_address; gdbarch->set_cap_tag_from_address = default_set_cap_tag_from_address; + gdbarch->print_cap = default_print_cap; + gdbarch->print_cap_attributes = default_print_cap_attributes; gdbarch->unwind_pc = default_unwind_pc; gdbarch->unwind_sp = default_unwind_sp; gdbarch->stabs_argument_has_addr = default_stabs_argument_has_addr; @@ -497,6 +501,8 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of remote_register_number, invalid_p == 0 */ /* Skip verify of get_cap_tag_from_address, invalid_p == 0 */ /* Skip verify of set_cap_tag_from_address, invalid_p == 0 */ + /* Skip verify of print_cap, invalid_p == 0 */ + /* Skip verify of print_cap_attributes, invalid_p == 0 */ /* Skip verify of fetch_tls_load_module_address, has predicate. */ /* Skip verify of get_thread_local_address, has predicate. */ /* Skip verify of frame_args_skip, invalid_p == 0 */ @@ -952,6 +958,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) fprintf_filtered (file, "gdbarch_dump: set_cap_tag_from_address = <%s>\n", host_address_to_string (gdbarch->set_cap_tag_from_address)); + fprintf_filtered (file, + "gdbarch_dump: print_cap = <%s>\n", + host_address_to_string (gdbarch->print_cap)); + fprintf_filtered (file, + "gdbarch_dump: print_cap_attributes = <%s>\n", + host_address_to_string (gdbarch->print_cap_attributes)); fprintf_filtered (file, "gdbarch_dump: gdbarch_fetch_tls_load_module_address_p() = %d\n", gdbarch_fetch_tls_load_module_address_p (gdbarch)); @@ -3026,6 +3038,40 @@ set_gdbarch_set_cap_tag_from_address (struct gdbarch *gdbarch, gdbarch->set_cap_tag_from_address = set_cap_tag_from_address; } +void +gdbarch_print_cap (struct gdbarch *gdbarch, const gdb_byte *contents, bool tag, bool compact, struct ui_file *stream) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->print_cap != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_print_cap called\n"); + gdbarch->print_cap (gdbarch, contents, tag, compact, stream); +} + +void +set_gdbarch_print_cap (struct gdbarch *gdbarch, + gdbarch_print_cap_ftype print_cap) +{ + gdbarch->print_cap = print_cap; +} + +void +gdbarch_print_cap_attributes (struct gdbarch *gdbarch, const gdb_byte *contents, bool tag, struct ui_file *stream) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->print_cap_attributes != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_print_cap_attributes called\n"); + gdbarch->print_cap_attributes (gdbarch, contents, tag, stream); +} + +void +set_gdbarch_print_cap_attributes (struct gdbarch *gdbarch, + gdbarch_print_cap_attributes_ftype print_cap_attributes) +{ + gdbarch->print_cap_attributes = print_cap_attributes; +} + bool gdbarch_fetch_tls_load_module_address_p (struct gdbarch *gdbarch) {