gdb: spread a little 'const' through the target_section_table code
authorAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 12 Feb 2021 11:39:23 +0000 (11:39 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 24 Feb 2021 16:58:02 +0000 (16:58 +0000)
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.

14 files changed:
gdb/ChangeLog
gdb/bfd-target.c
gdb/exec.c
gdb/exec.h
gdb/ppc64-tdep.c
gdb/record-btrace.c
gdb/remote.c
gdb/s390-tdep.c
gdb/solib-dsbt.c
gdb/solib-svr4.c
gdb/target-debug.h
gdb/target-delegates.c
gdb/target.c
gdb/target.h

index 41e480ab6d2ff5b4e1be6b1b55480a057dc44cee..e59343bc819807559cf940fc8fc5341e040bf89f 100644 (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.
index 689dbb19e2592c6278bbe9ff1d776d9209ebfc6a..b23cf2cd5ccb63c303db1c43d60903bcdc88c1a4 100644 (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;
index 68b35204068f1852d8e6d1680e7b5412401dc314..1cac5fb5d3d6395f05995b09a99ce1824646f373 100644 (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,
 \f
 
 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.  */
index cccc0d0cfa735d65ee10040157afe77bae11cd1b..1119953dc8fb79ac01a448065b5ff8cc9291fb47 100644 (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.
index f8f60994baed3852005c75feaa531724371d0d59..74873a6999e71b0516029fcfc0964b4d6825e2d7 100644 (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)
index ac51ff2bf49b7f7e138890b2ee98995afe1dcbd4..d9cc7a3b6d89dd14bf4da75ec3d20bb711b6c92a 100644 (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)
index 31c6e17a1c4bd381ca2d0c2f917f482b0d39983e..2c85bdcffbc58db4fcc78cf131f274f655e16225 100644 (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)
            {
index 57ddd540609a069613e5ad7f3f6688bcc0cd0ba4..39c8ee0450ac0088012f3c5078aae4e55c3478a7 100644 (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,
index 71245b26ca29bce53035ab0cb8f48228ddc73072..6d2180603433d0b4b72e6fc84b1ba2b1269b12f9 100644 (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;
index 5d0d3803086a704117395eef59d4b00c14cb941c..f8dd4194e701e2260f1880ea23d25c5557fe12d8 100644 (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;
index 69103388652341f2f7ddee91cd0f93ecaba2ff54..1cc825620954b8f5dee4c59dea715c229845236c 100644 (file)
   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))
index 437b19b8581c636b5b01a393e934155395bff34b..69fbc0f3b23c6bd08ac7e7ef1634e61def34f73e 100644 (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;
 }
index 06d7b4fbf8eb2cfb970d70b6283fd0fd1a57c497..78535b89e581c7dc6eb3945f39ae922bab7b4e11 100644 (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);
index 52e23b05ffd81a9d6a5890cf991ebbef30345715..66d46e2facbc68acb83a88bec95a657e74fa1a43 100644 (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,
-                                              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 */
This page took 0.035991 seconds and 4 git commands to generate.