]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: use (section, offset-in-section) as key for line_header hash
authorSimon Marchi <simon.marchi@efficios.com>
Sat, 21 Feb 2026 20:07:33 +0000 (15:07 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Tue, 10 Mar 2026 17:35:26 +0000 (13:35 -0400)
Similar to the previous patch, use the (section, offset-in-section)
tuple as the key to uniquely identify a line table header.  Currently,
line_header objects are hashed based on the (offset-in-section, is-dwz)
tuple.

This removes the last instances of "offset_in_dwz" parameters, which I
never really liked, as they were oddly specific.  Specifying the section
does the same job in a more generic way.

Change-Id: Ia4666f68111ce2210dc58f716eff37cf913eeeb9
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/line-header.c
gdb/dwarf2/line-header.h
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index 3d2563eeb397ddbbeaedf6ee1486f3db22ac893f..f972564f00ea07b2f41be1e4743c24be11e2547e 100644 (file)
@@ -253,15 +253,16 @@ read_formatted_entries (dwarf2_per_objfile *per_objfile, bfd *abfd,
 /* See line-header.h.  */
 
 line_header_up
-dwarf_decode_line_header (sect_offset sect_off, bool is_dwz,
+dwarf_decode_line_header (section_and_offset sect_and_offset,
                          dwarf2_per_objfile *per_objfile,
-                         struct dwarf2_section_info *section,
                          const unit_head *cu_header, const char *comp_dir)
 {
   const gdb_byte *line_ptr;
   unsigned int bytes_read, offset_size;
   int i;
   const char *cur_dir, *cur_file;
+  const dwarf2_section_info *section = sect_and_offset.section;
+  sect_offset sect_off = sect_and_offset.offset;
 
   bfd *abfd = section->get_bfd_owner ();
 
@@ -275,9 +276,6 @@ dwarf_decode_line_header (sect_offset sect_off, bool is_dwz,
 
   line_header_up lh (new line_header (comp_dir));
 
-  lh->sect_off = sect_off;
-  lh->offset_in_dwz = is_dwz;
-
   line_ptr = section->buffer + to_underlying (sect_off);
 
   /* Read in the header.  */
index d44213d46dcce6f88c0da4fab41dc65f9eaf924c..6c8d62d6ae2566962d691eb04186b8b126e3b4c3 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef GDB_DWARF2_LINE_HEADER_H
 #define GDB_DWARF2_LINE_HEADER_H
 
-#include "dwarf2/types.h"
+#include "dwarf2/section.h"
 
 struct dwarf2_per_objfile;
 struct dwarf2_cu;
@@ -89,14 +89,13 @@ struct line_header
      unit in the context of which we are reading this line header, or nullptr
      if unknown or not applicable.  */
   explicit line_header (const char *comp_dir)
-    : offset_in_dwz {}, m_comp_dir (comp_dir)
+    : m_comp_dir (comp_dir)
   {}
 
   /* This constructor should only be used to create line_header instances to do
      hash table lookups.  */
-  line_header (sect_offset sect_off, bool offset_in_dwz)
-    : sect_off (sect_off),
-      offset_in_dwz (offset_in_dwz)
+  line_header (section_and_offset sect_and_offset)
+    : sect_and_offset (sect_and_offset)
   {}
 
   /* Add an entry to the include directory table.  */
@@ -157,11 +156,8 @@ struct line_header
   const std::vector<file_entry> &file_names () const
   { return m_file_names; }
 
-  /* Offset of line number information in .debug_line section.  */
-  sect_offset sect_off {};
-
-  /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile.  */
-  unsigned offset_in_dwz : 1; /* Can't initialize bitfields in-class.  */
+  /* Section containing this line header, and its offset into that section.  */
+  section_and_offset sect_and_offset;
 
   unsigned short version {};
   unsigned char minimum_instruction_length {};
@@ -219,7 +215,7 @@ file_entry::include_dir (const line_header *lh) const
   return lh->include_dir_at (d_index);
 }
 
-/* Read the statement program header starting at SECT_OFF in SECTION.
+/* Read the statement program header starting at SECT_AND_OFFSET.
    Return line_header.  Returns nullptr if there is a problem reading
    the header, e.g., if it has a version we don't understand.
 
@@ -227,9 +223,8 @@ file_entry::include_dir (const line_header *lh) const
    the returned object point into the dwarf line section buffer,
    and must not be freed.  */
 
-extern line_header_up dwarf_decode_line_header
-  (sect_offset sect_off, bool is_dwz, dwarf2_per_objfile *per_objfile,
-   struct dwarf2_section_info *section, const struct unit_head *cu_header,
-   const char *comp_dir);
+extern line_header_up dwarf_decode_line_header (
+  section_and_offset sect_and_offset, dwarf2_per_objfile *per_objfile,
+  const struct unit_head *cu_header, const char *comp_dir);
 
 #endif /* GDB_DWARF2_LINE_HEADER_H */
index 8714d7bb501c02e893836961668970e65d03bcac..fbe0b0bdbeceed4fc4344a41607b358376357d80 100644 (file)
@@ -1034,7 +1034,7 @@ dwarf2_per_objfile::relocate (unrelocated_addr addr)
 static hashval_t
 line_header_hash (const struct line_header *ofs)
 {
-  return to_underlying (ofs->sect_off) ^ ofs->offset_in_dwz;
+  return section_and_offset_hash () (ofs->sect_and_offset);
 }
 
 /* Hash function for htab_create_alloc_ex for line_header_hash.  */
@@ -1055,8 +1055,8 @@ line_header_eq_voidp (const void *item_lhs, const void *item_rhs)
   const struct line_header *ofs_lhs = (const struct line_header *) item_lhs;
   const struct line_header *ofs_rhs = (const struct line_header *) item_rhs;
 
-  return (ofs_lhs->sect_off == ofs_rhs->sect_off
-         && ofs_lhs->offset_in_dwz == ofs_rhs->offset_in_dwz);
+  return section_and_offset_eq () (ofs_lhs->sect_and_offset,
+                                  ofs_rhs->sect_and_offset);
 }
 
 /* See declaration.  */
@@ -5803,7 +5803,7 @@ decode_line_header_for_cu (struct die_info *die, struct dwarf2_cu *cu,
     }
 
   void **slot;
-  line_header line_header_local (line_offset, cu->per_cu->is_dwz ());
+  line_header line_header_local ({ get_debug_line_section (cu), line_offset });
   hashval_t line_header_local_hash = line_header_hash (&line_header_local);
   if (per_objfile->line_header_hash != NULL)
     {
@@ -15307,9 +15307,8 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu,
       return 0;
     }
 
-  return dwarf_decode_line_header (sect_off, cu->per_cu->is_dwz (),
-                                  per_objfile, section, &cu->header,
-                                  comp_dir);
+  return dwarf_decode_line_header ({ section, sect_off }, per_objfile,
+                                  &cu->header, comp_dir);
 }
 
 static void
index 89b1437a849d6d684911d75f7e30fdb3575e3a5c..5dd7a0993a363c1abf7f55ff42b3e9a480e56d2b 100644 (file)
@@ -951,7 +951,7 @@ struct dwarf2_per_objfile
   gdb::unordered_map<per_cu_and_offset, type *, per_cu_and_offset_hash>
     die_type_hash;
 
-  /* Table containing line_header indexed by offset and offset_in_dwz.  */
+  /* Table containing line_header indexed by (section, offset-in-section).  */
   htab_up line_header_hash;
 
   /* The CU containing the m_builder in scope.  */