[binutils-gdb] gdb/dwarf: use (section, offset-in-section) as key for line_header hash
Simon Marchi via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=256fcd3b98f19491c7a80dd4bb0c21122ccb5bcb commit 256fcd3b98f19491c7a80dd4bb0c21122ccb5bcb Author: Simon Marchi <[email protected]> Date: Sat Feb 21 15:07:33 2026 -0500 gdb/dwarf: use (section, offset-in-section) as key for line_header hash 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 <[email protected]> Diff: --- gdb/dwarf2/line-header.c | 8 +++----- gdb/dwarf2/line-header.h | 25 ++++++++++--------------- gdb/dwarf2/read.c | 13 ++++++------- gdb/dwarf2/read.h | 2 +- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c index 3d2563eeb39..f972564f00e 100644 --- a/gdb/dwarf2/line-header.c +++ b/gdb/dwarf2/line-header.c @@ -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. */ diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h index d44213d46dc..6c8d62d6ae2 100644 --- a/gdb/dwarf2/line-header.h +++ b/gdb/dwarf2/line-header.h @@ -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 */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8714d7bb501..fbe0b0bdbec 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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 diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 89b1437a849..5dd7a0993a3 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -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. */