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.
This commit is contained in:
Andrew Burgess 2021-02-12 11:39:23 +00:00
parent 02a7930992
commit 19cf757a87
14 changed files with 69 additions and 38 deletions

View File

@ -1,3 +1,33 @@
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.

View File

@ -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;

View File

@ -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. */

View File

@ -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.

View File

@ -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)

View File

@ -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)

View File

@ -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)
{

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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))

View File

@ -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;
}

View File

@ -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);

View File

@ -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,
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 */