Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 2/2] gdb/dwarf: fix failed assertion in dwarf2_find_containing_comp_unit selftest
Date: Wed, 26 Feb 2025 11:52:32 -0500	[thread overview]
Message-ID: <20250226165255.25737-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20250226165255.25737-1-simon.marchi@efficios.com>

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 create the in
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
---
 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 2b060959c36f..59d79af004ca 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));
     };
 
-- 
2.48.1


  reply	other threads:[~2025-02-26 16:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-26 16:52 [PATCH 1/2] gdb/dwarf: pass unit length to dwarf2_per_cu_data constructor Simon Marchi
2025-02-26 16:52 ` Simon Marchi [this message]
2025-02-27 13:12   ` [PATCH 2/2] gdb/dwarf: fix failed assertion in dwarf2_find_containing_comp_unit selftest Tom de Vries
2025-02-27 13:15   ` Tom de Vries
2025-02-27 15:18     ` Simon Marchi
2025-02-27 13:09 ` [PATCH 1/2] gdb/dwarf: pass unit length to dwarf2_per_cu_data constructor Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250226165255.25737-2-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox