aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-02-12 11:39:23 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-02-24 16:58:02 +0000
commit19cf757a87d4ad1300f3de1e5c9bcb675e0ef331 (patch)
treee6a5813dee072ee9e1ad696ef125895f66b87419 /gdb
parent02a79309925c71591d825f8fc4e2b79ce0faa45b (diff)
downloadgdb-19cf757a87d4ad1300f3de1e5c9bcb675e0ef331.zip
gdb-19cf757a87d4ad1300f3de1e5c9bcb675e0ef331.tar.gz
gdb-19cf757a87d4ad1300f3de1e5c9bcb675e0ef331.tar.bz2
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) <get_section_table>: Make return type const. * gdb/exec.c (struct exec_target) <get_section_table>: 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) <get_section_table>: Make return type const. (target_section_by_addr): Likewise. (target_get_section_table): Likewise.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog30
-rw-r--r--gdb/bfd-target.c4
-rw-r--r--gdb/exec.c10
-rw-r--r--gdb/exec.h2
-rw-r--r--gdb/ppc64-tdep.c2
-rw-r--r--gdb/record-btrace.c2
-rw-r--r--gdb/remote.c6
-rw-r--r--gdb/s390-tdep.c4
-rw-r--r--gdb/solib-dsbt.c3
-rw-r--r--gdb/solib-svr4.c3
-rw-r--r--gdb/target-debug.h2
-rw-r--r--gdb/target-delegates.c14
-rw-r--r--gdb/target.c17
-rw-r--r--gdb/target.h8
14 files changed, 69 insertions, 38 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 41e480a..e59343b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,35 @@
2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
+ * gdb/bfd-target.c (class target_bfd) <get_section_table>: Make
+ return type const.
+ * gdb/exec.c (struct exec_target) <get_section_table>: 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) <get_section_table>: Make
+ return type const.
+ (target_section_by_addr): Likewise.
+ (target_get_section_table): Likewise.
+
+2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
+
* NEWS: Mention new 'maint info target-sections' command.
* maint.c (maintenance_info_target_sections): New function.
(_initialize_maint_cmds): Register new command.
diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
index 689dbb1..b23cf2c 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 68b3520..1cac5fb 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<mem_range> 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 &current_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 cccc0d0..1119953 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 f8f6099..74873a6 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 ac51ff2..d9cc7a3 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 31c6e17..2c85bdc 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 57ddd54..39c8ee0 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 71245b2..6d21806 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 5d0d380..f8dd419 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 6910338..1cc8256 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 437b19b..69fbc0f 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 06d7b4f..78535b8 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> ((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 52e23b0..66d46e2 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 */