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

Message ID 20250226165255.25737-2-simon.marchi@efficios.com
State New
Headers
Series [1/2] gdb/dwarf: pass unit length to dwarf2_per_cu_data constructor |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply

Commit Message

Simon Marchi Feb. 26, 2025, 4:52 p.m. UTC
  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(-)
  

Comments

Tom de Vries Feb. 27, 2025, 1:12 p.m. UTC | #1
On 2/26/25 17:52, Simon Marchi wrote:
> 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.
> 

Hi Simon,

I"ve applied the series, and confirmed that gdb.gdb/unittest.exp passes 
again.

LGTM.

Reviewed-By: Tom de Vries <tdevries@suse.de>

Thanks,
- Tom

> 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));
>       };
>
  
Tom de Vries Feb. 27, 2025, 1:15 p.m. UTC | #2
On 2/26/25 17:52, Simon Marchi wrote:
> However, the dummy dwarf2_per_cu_data objects create the in
> dwarf2_find_containing_comp_unit selftests are passed nullptr for those
> parameters.

Hi,

I'm not sure I understand this sentence.

create the in -> created in the ?

Thanks,
- Tom
  
Simon Marchi Feb. 27, 2025, 3:18 p.m. UTC | #3
On 2/27/25 8:15 AM, Tom de Vries wrote:
> On 2/26/25 17:52, Simon Marchi wrote:
>> However, the dummy dwarf2_per_cu_data objects create the in
>> dwarf2_find_containing_comp_unit selftests are passed nullptr for those
>> parameters.
> 
> Hi,
> 
> I'm not sure I understand this sentence.
> 
> create the in -> created in the ?

Oof, yes, thanks.  I pushed the patches with that fixed.

Simon
  

Patch

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));
     };