diff options
author | Tom Tromey <tom@tromey.com> | 2021-03-06 09:26:39 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-03-06 09:26:39 -0700 |
commit | a7308ce01effdd143bfe5e3c7350fa2d5606d12b (patch) | |
tree | 0e10c305165080018d6c81067d0717927c45f473 /gdb/dwarf2 | |
parent | fbedd54644116109834c0e0546e6c32ae3c482f9 (diff) | |
download | gdb-a7308ce01effdd143bfe5e3c7350fa2d5606d12b.zip gdb-a7308ce01effdd143bfe5e3c7350fa2d5606d12b.tar.gz gdb-a7308ce01effdd143bfe5e3c7350fa2d5606d12b.tar.bz2 |
Avoid crash on missing dwz file
If DWARF contains a reference to a "dwz" file, but there is no
.gnu_debugaltlink section, then gdb will crash. This happens because
dwarf2_get_dwz_file will return NULL, but some callers do not expect
this.
This patch changes dwarf2_get_dwz_file so that callers can require a
dwz file. Then, it updates the callers that are attempting to process
references to the dwz file to require one.
This includes a new testcase. The dwarf.exp changes don't handle the
new forms exactly correctly -- they are only handled well enough to
let this test case complete.
gdb/ChangeLog
2021-03-06 Tom Tromey <tom@tromey.com>
* dwarf2/read.h (dwarf2_get_dwz_file): Add 'require' parameter.
* dwarf2/read.c (dwarf2_get_dwz_file): Add 'require' parameter.
(get_abbrev_section_for_cu, read_attribute_value)
(get_debug_line_section): Update.
* dwarf2/macro.c (dwarf_decode_macro_bytes): Update.
gdb/testsuite/ChangeLog
2021-03-06 Tom Tromey <tom@tromey.com>
* lib/dwarf.exp (_handle_DW_FORM): Treat DW_FORM_GNU_ref_alt and
DW_FORM_GNU_strp_alt like DW_FORM_sec_offset.
* gdb.dwarf2/dwznolink.exp: New file.
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r-- | gdb/dwarf2/macro.c | 6 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 14 | ||||
-rw-r--r-- | gdb/dwarf2/read.h | 13 |
3 files changed, 21 insertions, 12 deletions
diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index afe2f91..2ecebe6 100644 --- a/gdb/dwarf2/macro.c +++ b/gdb/dwarf2/macro.c @@ -509,7 +509,8 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, || macinfo_type == DW_MACRO_undef_sup || section_is_dwz) { - dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); + dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, + true); body = dwz->read_string (objfile, str_offset); } @@ -693,7 +694,8 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, if (macinfo_type == DW_MACRO_import_sup) { - dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); + dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, + true); dwz->macro.read (objfile); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e9cd929..65e2047 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2285,7 +2285,7 @@ dwz_search_other_debugdirs (std::string &filename, bfd_byte *buildid, /* See dwarf2read.h. */ struct dwz_file * -dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd) +dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require) { bfd_size_type buildid_len_arg; size_t buildid_len; @@ -2301,7 +2301,11 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd) if (data == NULL) { if (bfd_get_error () == bfd_error_no_error) - return NULL; + { + if (!require) + return nullptr; + error (_("could not read '.gnu_debugaltlink' section")); + } error (_("could not read '.gnu_debugaltlink' section: %s"), bfd_errmsg (bfd_get_error ())); } @@ -6308,7 +6312,7 @@ get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu) dwarf2_per_bfd *per_bfd = this_cu->per_bfd; if (this_cu->is_dwz) - abbrev = &dwarf2_get_dwz_file (per_bfd)->abbrev; + abbrev = &dwarf2_get_dwz_file (per_bfd, true)->abbrev; else abbrev = &per_bfd->abbrev; @@ -20654,7 +20658,7 @@ read_attribute_value (const struct die_reader_specs *reader, /* FALLTHROUGH */ case DW_FORM_GNU_strp_alt: { - dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); + dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true); LONGEST str_offset = cu_header->read_offset (abfd, info_ptr, &bytes_read); @@ -21252,7 +21256,7 @@ get_debug_line_section (struct dwarf2_cu *cu) section = &cu->dwo_unit->dwo_file->sections.line; else if (cu->per_cu->is_dwz) { - dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); + dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true); section = &dwz->line; } diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index c7f6a11..b974fe4 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -633,11 +633,14 @@ struct signatured_type struct dwo_unit *dwo_unit; }; -/* Open the separate '.dwz' debug file, if needed. Return NULL if - there is no .gnu_debugaltlink section in the file. Error if there - is such a section but the file cannot be found. */ - -extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd); +/* Open the separate '.dwz' debug file, if needed. If there is no + .gnu_debugaltlink section in the file, then the result depends on + REQUIRE: if REQUIRE is true, then error; if REQUIRE is false, + return NULL. Always error if there is such a section but the file + cannot be found. */ + +extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, + bool require = false); /* Return the type of the DIE at DIE_OFFSET in the CU named by PER_CU. */ |