From 19cf757a87d4ad1300f3de1e5c9bcb675e0ef331 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Fri, 12 Feb 2021 11:39:23 +0000 Subject: [PATCH] gdb: spread a little 'const' through the target_section_table code The code to access the target section table can be made more const, so lets do that. There should be no user visible changes after this commit. gdb/ChangeLog: * gdb/bfd-target.c (class target_bfd) : Make return type const. * gdb/exec.c (struct exec_target) : Likewise. (section_table_read_available_memory): Make local const. (exec_target::xfer_partial): Make local const. (print_section_info): Make parameter const. * gdb/exec.h (print_section_info): Likewise. * gdb/ppc64-tdep.c (ppc64_convert_from_func_ptr_addr): Make local const. * gdb/record-btrace.c (record_btrace_target::xfer_partial): Likewise. * gdb/remote.c (remote_target::remote_xfer_live_readonly_partial): Likewise. * gdb/s390-tdep.c (s390_load): Likewise. * gdb/solib-dsbt.c (scan_dyntag): Likewise. * gdb/solib-svr4.c (scan_dyntag): Likewise. * gdb/target-debug.h (target_debug_print_target_section_table_p): Rename to... (target_debug_print_const_target_section_table_p): ...this. * gdb/target-delegates.c: Regenerate. * gdb/target.c (target_get_section_table): Make return type const. (target_section_by_addr): Likewise. Also make some locals const. (memory_xfer_partial_1): Make some locals const. * gdb/target.h (struct target_ops) : Make return type const. (target_section_by_addr): Likewise. (target_get_section_table): Likewise. --- gdb/ChangeLog | 30 ++++++++++++++++++++++++++++++ gdb/bfd-target.c | 4 ++-- gdb/exec.c | 10 +++++----- gdb/exec.h | 2 +- gdb/ppc64-tdep.c | 2 +- gdb/record-btrace.c | 2 +- gdb/remote.c | 6 +++--- gdb/s390-tdep.c | 4 ++-- gdb/solib-dsbt.c | 3 ++- gdb/solib-svr4.c | 3 ++- gdb/target-debug.h | 2 +- gdb/target-delegates.c | 14 +++++++------- gdb/target.c | 17 ++++++++--------- gdb/target.h | 8 ++++---- 14 files changed, 69 insertions(+), 38 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 41e480ab6d2..e59343bc819 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,33 @@ +2021-02-24 Andrew Burgess + + * gdb/bfd-target.c (class target_bfd) : Make + return type const. + * gdb/exec.c (struct exec_target) : Likewise. + (section_table_read_available_memory): Make local const. + (exec_target::xfer_partial): Make local const. + (print_section_info): Make parameter const. + * gdb/exec.h (print_section_info): Likewise. + * gdb/ppc64-tdep.c (ppc64_convert_from_func_ptr_addr): Make local + const. + * gdb/record-btrace.c (record_btrace_target::xfer_partial): + Likewise. + * gdb/remote.c (remote_target::remote_xfer_live_readonly_partial): + Likewise. + * gdb/s390-tdep.c (s390_load): Likewise. + * gdb/solib-dsbt.c (scan_dyntag): Likewise. + * gdb/solib-svr4.c (scan_dyntag): Likewise. + * gdb/target-debug.h (target_debug_print_target_section_table_p): + Rename to... + (target_debug_print_const_target_section_table_p): ...this. + * gdb/target-delegates.c: Regenerate. + * gdb/target.c (target_get_section_table): Make return type const. + (target_section_by_addr): Likewise. Also make some locals const. + (memory_xfer_partial_1): Make some locals const. + * gdb/target.h (struct target_ops) : Make + return type const. + (target_section_by_addr): Likewise. + (target_get_section_table): Likewise. + 2021-02-24 Andrew Burgess * NEWS: Mention new 'maint info target-sections' command. diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c index 689dbb19e25..b23cf2cd5cc 100644 --- a/gdb/bfd-target.c +++ b/gdb/bfd-target.c @@ -50,7 +50,7 @@ public: ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override; - target_section_table *get_section_table () override; + const target_section_table *get_section_table () override; private: /* The BFD we're wrapping. */ @@ -82,7 +82,7 @@ target_bfd::xfer_partial (target_object object, } } -target_section_table * +const target_section_table * target_bfd::get_section_table () { return &m_table; diff --git a/gdb/exec.c b/gdb/exec.c index 68b35204068..1cac5fb5d3d 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -75,7 +75,7 @@ struct exec_target final : public target_ops const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override; - target_section_table *get_section_table () override; + const target_section_table *get_section_table () override; void files_info () override; bool has_memory () override; @@ -775,7 +775,7 @@ enum target_xfer_status section_table_read_available_memory (gdb_byte *readbuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { - target_section_table *table = target_get_section_table (&exec_ops); + const target_section_table *table = target_get_section_table (&exec_ops); std::vector available_memory = section_table_available_memory (offset, len, *table); @@ -884,7 +884,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf, return TARGET_XFER_EOF; /* We can't help. */ } -target_section_table * +const target_section_table * exec_target::get_section_table () { return ¤t_program_space->target_sections; @@ -896,7 +896,7 @@ exec_target::xfer_partial (enum target_object object, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { - target_section_table *table = get_section_table (); + const target_section_table *table = target_get_section_table (this); if (object == TARGET_OBJECT_MEMORY) return section_table_xfer_memory_partial (readbuf, writebuf, @@ -908,7 +908,7 @@ exec_target::xfer_partial (enum target_object object, void -print_section_info (target_section_table *t, bfd *abfd) +print_section_info (const target_section_table *t, bfd *abfd) { struct gdbarch *gdbarch = gdbarch_from_bfd (abfd); /* FIXME: 16 is not wide enough when gdbarch_addr_bit > 64. */ diff --git a/gdb/exec.h b/gdb/exec.h index cccc0d0cfa7..1119953dc8f 100644 --- a/gdb/exec.h +++ b/gdb/exec.h @@ -96,7 +96,7 @@ extern void exec_set_section_address (const char *, int, CORE_ADDR); special cased --- it's filename is omitted; if it is the executable file, its entry point is printed. */ -extern void print_section_info (target_section_table *table, +extern void print_section_info (const target_section_table *table, bfd *abfd); /* Helper function that attempts to open the symbol file at EXEC_FILE_HOST. diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c index f8f60994bae..74873a6999e 100644 --- a/gdb/ppc64-tdep.c +++ b/gdb/ppc64-tdep.c @@ -561,7 +561,7 @@ ppc64_convert_from_func_ptr_addr (struct gdbarch *gdbarch, struct target_ops *targ) { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - struct target_section *s = target_section_by_addr (targ, addr); + const struct target_section *s = target_section_by_addr (targ, addr); /* Check if ADDR points to a function descriptor. */ if (s && strcmp (s->the_bfd_section->name, ".opd") == 0) diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index ac51ff2bf49..d9cc7a3b6d8 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -1439,7 +1439,7 @@ record_btrace_target::xfer_partial (enum target_object object, { case TARGET_OBJECT_MEMORY: { - struct target_section *section; + const struct target_section *section; /* We do not allow writing memory in general. */ if (writebuf != NULL) diff --git a/gdb/remote.c b/gdb/remote.c index 31c6e17a1c4..2c85bdcffbc 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -9044,7 +9044,7 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf, int unit_size, ULONGEST *xfered_len) { - struct target_section *secp; + const struct target_section *secp; secp = target_section_by_addr (this, memaddr); if (secp != NULL @@ -9052,8 +9052,8 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf, { ULONGEST memend = memaddr + len; - target_section_table *table = target_get_section_table (this); - for (target_section &p : *table) + const target_section_table *table = target_get_section_table (this); + for (const target_section &p : *table) { if (memaddr >= p.addr) { diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index 57ddd540609..39c8ee0450a 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -684,8 +684,8 @@ s390_load (struct s390_prologue_data *data, we're analyzing the code to unwind past that frame. */ if (pv_is_constant (addr)) { - struct target_section *secp; - secp = target_section_by_addr (current_top_target (), addr.k); + const struct target_section *secp + = target_section_by_addr (current_top_target (), addr.k); if (secp != NULL && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY)) return pv_constant (read_memory_integer (addr.k, size, diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c index 71245b26ca2..6d218060343 100644 --- a/gdb/solib-dsbt.c +++ b/gdb/solib-dsbt.c @@ -424,7 +424,8 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr) return 0; bool found = false; - for (target_section &target_section : current_program_space->target_sections) + for (const target_section &target_section + : current_program_space->target_sections) if (sect == target_section.the_bfd_section) { dyn_addr = target_section.addr; diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 5d0d3803086..f8dd4194e70 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -610,7 +610,8 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr, return 0; bool found = false; - for (target_section &target_section : current_program_space->target_sections) + for (const target_section &target_section + : current_program_space->target_sections) if (sect == target_section.the_bfd_section) { dyn_addr = target_section.addr; diff --git a/gdb/target-debug.h b/gdb/target-debug.h index 69103388652..1cc82562095 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -104,7 +104,7 @@ target_debug_do_print (host_address_to_string (X)) #define target_debug_print_struct_ui_file_p(X) \ target_debug_do_print (host_address_to_string (X)) -#define target_debug_print_target_section_table_p(X) \ +#define target_debug_print_const_target_section_table_p(X) \ target_debug_do_print (host_address_to_string (X)) #define target_debug_print_void_p(X) \ target_debug_do_print (host_address_to_string (X)) diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 437b19b8581..69fbc0f3b23 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -77,7 +77,7 @@ struct dummy_target : public target_ops void rcmd (const char *arg0, struct ui_file *arg1) override; char *pid_to_exec_file (int arg0) override; void log_command (const char *arg0) override; - target_section_table *get_section_table () override; + const target_section_table *get_section_table () override; thread_control_capabilities get_thread_control_capabilities () override; bool attach_no_wait () override; bool can_async_p () override; @@ -248,7 +248,7 @@ struct debug_target : public target_ops void rcmd (const char *arg0, struct ui_file *arg1) override; char *pid_to_exec_file (int arg0) override; void log_command (const char *arg0) override; - target_section_table *get_section_table () override; + const target_section_table *get_section_table () override; thread_control_capabilities get_thread_control_capabilities () override; bool attach_no_wait () override; bool can_async_p () override; @@ -2021,27 +2021,27 @@ debug_target::log_command (const char *arg0) fputs_unfiltered (")\n", gdb_stdlog); } -target_section_table * +const target_section_table * target_ops::get_section_table () { return this->beneath ()->get_section_table (); } -target_section_table * +const target_section_table * dummy_target::get_section_table () { return NULL; } -target_section_table * +const target_section_table * debug_target::get_section_table () { - target_section_table * result; + const target_section_table * result; fprintf_unfiltered (gdb_stdlog, "-> %s->get_section_table (...)\n", this->beneath ()->shortname ()); result = this->beneath ()->get_section_table (); fprintf_unfiltered (gdb_stdlog, "<- %s->get_section_table (", this->beneath ()->shortname ()); fputs_unfiltered (") = ", gdb_stdlog); - target_debug_print_target_section_table_p (result); + target_debug_print_const_target_section_table_p (result); fputs_unfiltered ("\n", gdb_stdlog); return result; } diff --git a/gdb/target.c b/gdb/target.c index 06d7b4fbf8e..78535b89e58 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -812,7 +812,7 @@ target_read_string (CORE_ADDR memaddr, int len, int *bytes_read) return gdb::unique_xmalloc_ptr ((char *) buffer.release ()); } -target_section_table * +const target_section_table * target_get_section_table (struct target_ops *target) { return target->get_section_table (); @@ -820,15 +820,15 @@ target_get_section_table (struct target_ops *target) /* Find a section containing ADDR. */ -struct target_section * +const struct target_section * target_section_by_addr (struct target_ops *target, CORE_ADDR addr) { - target_section_table *table = target_get_section_table (target); + const target_section_table *table = target_get_section_table (target); if (table == NULL) return NULL; - for (target_section &secp : *table) + for (const target_section &secp : *table) { if (addr >= secp.addr && addr < secp.endaddr) return &secp; @@ -965,7 +965,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object, if (pc_in_unmapped_range (memaddr, section)) { - target_section_table *table = target_get_section_table (ops); + const target_section_table *table = target_get_section_table (ops); const char *section_name = section->the_bfd_section->name; memaddr = overlay_mapped_address (memaddr, section); @@ -984,13 +984,12 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object, /* Try the executable files, if "trust-readonly-sections" is set. */ if (readbuf != NULL && trust_readonly) { - struct target_section *secp; - - secp = target_section_by_addr (ops, memaddr); + const struct target_section *secp + = target_section_by_addr (ops, memaddr); if (secp != NULL && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY)) { - target_section_table *table = target_get_section_table (ops); + const target_section_table *table = target_get_section_table (ops); return section_table_xfer_memory_partial (readbuf, writebuf, memaddr, len, xfered_len, *table); diff --git a/gdb/target.h b/gdb/target.h index 52e23b05ffd..66d46e2facb 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -687,7 +687,7 @@ struct target_ops TARGET_DEFAULT_RETURN (NULL); virtual void log_command (const char *) TARGET_DEFAULT_IGNORE (); - virtual target_section_table *get_section_table () + virtual const target_section_table *get_section_table () TARGET_DEFAULT_RETURN (NULL); /* Provide default values for all "must have" methods. */ @@ -2427,13 +2427,13 @@ extern CORE_ADDR target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset); /* Return the "section" containing the specified address. */ -struct target_section *target_section_by_addr (struct target_ops *target, - CORE_ADDR addr); +const struct target_section *target_section_by_addr (struct target_ops *target, + CORE_ADDR addr); /* Return the target section table this target (or the targets beneath) currently manipulate. */ -extern target_section_table *target_get_section_table +extern const target_section_table *target_get_section_table (struct target_ops *target); /* From mem-break.c */ -- 2.30.2