[binutils-gdb] gdb/dwarf: fix failed assertion in dwarf2_find_containing_comp_unit selftest

Simon Marchi simark@sourceware.org
Thu Feb 27 15:17:27 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=661a85884f1399b3d6acd4d4314010c163ae2b23

commit 661a85884f1399b3d6acd4d4314010c163ae2b23
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Wed Feb 26 11:52:32 2025 -0500

    gdb/dwarf: fix failed assertion in dwarf2_find_containing_comp_unit selftest
    
    Commit 2f0521c0d6f6 ("gdb/dwarf: fix signature_type created with nullptr
    section") added some asserts in the dwarf2_per_cu_data constructor to
    verify that the passed dwarf2_per_bfd and dwarf2_section_info are not
    nullptr.  However, the dummy dwarf2_per_cu_data objects created in the
    dwarf2_find_containing_comp_unit selftests are passed nullptr for those
    parameters.
    
    I prefer to keep the asserts in place, as protection for the non-test
    code and as self documentation, so fix this by passing some dummy
    pointers in the test.
    
    Change-Id: Ic7cdc1b976f7506041b651222234eefc998e473a
    Reviewed-By: Tom de Vries <tdevries@suse.de>

Diff:
---
 gdb/dwarf2/read.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2b060959c36..59d79af004c 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -20946,9 +20946,16 @@ namespace find_containing_comp_unit {
 static void
 run_test ()
 {
-  const auto create_dummy_per_cu = [] (sect_offset sect_off, unsigned int length)
+  char dummy_per_bfd;
+  char dummy_section;
+
+  const auto create_dummy_per_cu = [&] (sect_offset sect_off,
+					unsigned int length)
     {
-      return dwarf2_per_cu_data_up (new dwarf2_per_cu_data (nullptr, nullptr,
+      auto per_bfd = reinterpret_cast<dwarf2_per_bfd *> (&dummy_per_bfd);
+      auto section = reinterpret_cast<dwarf2_section_info *> (&dummy_section);
+
+      return dwarf2_per_cu_data_up (new dwarf2_per_cu_data (per_bfd, section,
 							    sect_off, length));
     };


More information about the Gdb-cvs mailing list