]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add dwarf2_per_objfile field to dwarf2_cu
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 27 May 2020 15:13:52 +0000 (11:13 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 27 May 2020 15:15:54 +0000 (11:15 -0400)
Subsequent patches will make dwarf2_per_cu_data objfile-independent.
This means that the dwarf2_per_cu_data::dwarf2_per_objfile field must
go.

The code using a dwarf2_cu structure currently accesses the current
dwarf2_per_objfile object through dwarf2_cu->per_cu->dwarf2_per_objfile.
Since it's ok for the dwarf2_cu to know about the current objfile (a
dwarf2_cu is always used in the context of a particular objfile), add a
dwarf2_per_objfile field to dwarf2_cu.  Upcoming patches will gradually
remove uses of dwarf2_per_cu_data::dwarf2_per_objfile in favor of
dwarf2_cu::dwarf2_per_objfile, until the former can be removed.

gdb/ChangeLog:

* dwarf2/read.c (struct dwarf2_cu) <dwarf2_cu>: Add parameter.
<per_objfile>: New member.
(class cutu_reader) <init_tu_and_read_dwo_dies>: Add parameter.
(cutu_reader::init_tu_and_read_dwo_dies): Add parameter, update
call to dwarf2_cu.
(cutu_reader::cutu_reader): Update.
(dwarf2_cu::dwarf2_cu): Add parameter, initialize per_objfile.

Change-Id: I8fd0da7371f65baea1ea7787aad08e10453bc565

gdb/ChangeLog
gdb/dwarf2/read.c

index 76b8d7b7e8d39039b636234d7a72b352d3f8db09..436da4d75c053b03abbcb3ef1df47e0f9ccd7525 100644 (file)
@@ -1,3 +1,13 @@
+2020-05-27  Simon Marchi  <simon.marchi@efficios.com>
+
+       * dwarf2/read.c (struct dwarf2_cu) <dwarf2_cu>: Add parameter.
+       <per_objfile>: New member.
+       (class cutu_reader) <init_tu_and_read_dwo_dies>: Add parameter.
+       (cutu_reader::init_tu_and_read_dwo_dies): Add parameter, update
+       call to dwarf2_cu.
+       (cutu_reader::cutu_reader): Update.
+       (dwarf2_cu::dwarf2_cu): Add parameter, initialize per_objfile.
+
 2020-05-27  Simon Marchi  <simon.marchi@efficios.com>
 
        * dwarf2/read.h (struct dwarf2_per_bfd) <die_type_hash>: Move to
index aa39c883b9b1773efefc05f1b9e0e7df6e8f7475..ef64d13947c693d2e44d75c93e012259820897a4 100644 (file)
@@ -399,7 +399,8 @@ struct delayed_method_info
 /* Internal state when decoding a particular compilation unit.  */
 struct dwarf2_cu
 {
-  explicit dwarf2_cu (struct dwarf2_per_cu_data *per_cu);
+  explicit dwarf2_cu (dwarf2_per_cu_data *per_cu,
+                     dwarf2_per_objfile *per_objfile);
   ~dwarf2_cu ();
 
   DISABLE_COPY_AND_ASSIGN (dwarf2_cu);
@@ -466,6 +467,9 @@ public:
   /* Backlink to our per_cu entry.  */
   struct dwarf2_per_cu_data *per_cu;
 
+  /* The dwarf2_per_objfile that owns this.  */
+  struct dwarf2_per_objfile *per_objfile;
+
   /* How many compilation units ago was this CU last referenced?  */
   int last_used = 0;
 
@@ -928,7 +932,8 @@ public:
   void keep ();
 
 private:
-  void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
+  void init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu,
+                                 dwarf2_per_objfile *per_objfile,
                                  int use_existing_cu);
 
   struct dwarf2_per_cu_data *m_this_cu;
@@ -6888,7 +6893,8 @@ lookup_dwo_unit (struct dwarf2_per_cu_data *this_cu,
    Read a TU directly from a DWO file, bypassing the stub.  */
 
 void
-cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
+cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu,
+                                       dwarf2_per_objfile *per_objfile,
                                        int use_existing_cu)
 {
   struct signatured_type *sig_type;
@@ -6909,7 +6915,7 @@ cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
     {
       /* If !use_existing_cu, this_cu->cu must be NULL.  */
       gdb_assert (this_cu->cu == NULL);
-      m_new_cu.reset (new dwarf2_cu (this_cu));
+      m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile));
     }
 
   /* A future optimization, if needed, would be to use an existing
@@ -6970,7 +6976,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
       /* Narrow down the scope of possibilities to have to understand.  */
       gdb_assert (this_cu->is_debug_types);
       gdb_assert (abbrev_table == NULL);
-      init_tu_and_read_dwo_dies (this_cu, use_existing_cu);
+      init_tu_and_read_dwo_dies (this_cu, dwarf2_per_objfile, use_existing_cu);
       return;
     }
 
@@ -6997,7 +7003,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
     {
       /* If !use_existing_cu, this_cu->cu must be NULL.  */
       gdb_assert (this_cu->cu == NULL);
-      m_new_cu.reset (new dwarf2_cu (this_cu));
+      m_new_cu.reset (new dwarf2_cu (this_cu, dwarf2_per_objfile));
       cu = m_new_cu.get ();
     }
 
@@ -7189,7 +7195,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
   /* This is cheap if the section is already read in.  */
   section->read (objfile);
 
-  m_new_cu.reset (new dwarf2_cu (this_cu));
+  m_new_cu.reset (new dwarf2_cu (this_cu, dwarf2_per_objfile));
 
   begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off);
   info_ptr = read_and_check_comp_unit_head (dwarf2_per_objfile,
@@ -23514,10 +23520,12 @@ run_test ()
 
 #endif /* GDB_SELF_TEST */
 
-/* Initialize dwarf2_cu CU, owned by PER_CU.  */
+/* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE.  */
 
-dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data *per_cu_)
-  : per_cu (per_cu_),
+dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu,
+                     dwarf2_per_objfile *per_objfile)
+  : per_cu (per_cu),
+    per_objfile (per_objfile),
     mark (false),
     has_loclist (false),
     checked_producer (false),