Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] dwarf2: avoid decoding .debug_line for type units
@ 2026-03-18 13:35 Bratislav Filipovic
  2026-04-01 14:54 ` [PING][PATCH] " Filipovic, Bratislav
  2026-04-16 14:10 ` [PATCH] testsuite: ada-valprint-error relocation issue Bratislav Filipovic
  0 siblings, 2 replies; 8+ messages in thread
From: Bratislav Filipovic @ 2026-03-18 13:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: simon.marchi, Bratislav Filipovic

Running gdb.dwarf2/pr13961.exp with clang fails with an internal error:

  gdb/dwarf2/read.c: internal-error: decode_line_header_for_cu:
  Assertion `!cu->per_cu->is_debug_types ()' failed.

pr13961 is a legacy .S test that references a .debug_line label from
both a CU and a TU.  The assembly includes an empty .debug_line section
declaration:

  .section .debug_line,"",%progbits
.Ldebug_line0:

With gcc this results in a dummy (valid, but content-less) .debug_line
header being emitted, so GDB can build a line header and resolve file
indices.  With clang the .debug_line section can be missing/empty,
leaving the line header unset.

During symbol creation, new_symbol may then try to lazily decode the
CU-only line header while processing a type unit, which triggers the
assertion above.

Fix this by only decoding the line header for non-type units.  If no
line header is available, emit a complaint and continue without setting
the symtab rather than attempting CU-only line decoding from a TU.

Tested: gdb.dwarf2/pr13961.exp (CC_FOR_TARGET=clang)
---
 gdb/dwarf2/read.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8b87d58d..2e897e65 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -15484,23 +15484,32 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 	  if (index_cst.has_value ())
 	    {
 	      file_name_index file_index = (file_name_index) *index_cst;
-	      struct file_entry *fe;
 
-	      if (file_cu->line_header == nullptr)
+	      /* Resolve DW_AT_decl_file/DW_AT_call_file.  These attributes are
+		 indices into the file-name table, which lives in the unit's
+		 decoded .debug_line header.
+		 decode_line_header_for_cu is CU-only and asserts on debug_types.
+		 For type units, the TU setup code runs before processing child
+		 DIEs, so if line_header is still nullptr here it means there is no
+		 usable line table for this unit.  */
+	      if (file_cu->line_header == nullptr
+		  && !file_cu->per_cu->is_debug_types ())
 		{
 		  file_and_directory fnd (nullptr, nullptr);
 		  decode_line_header_for_cu (file_cu->dies, file_cu, fnd);
 		}
 
 	      if (file_cu->line_header != nullptr)
-		fe = file_cu->line_header->file_name_at (file_index);
-	      else
-		fe = NULL;
-
-	      if (fe == NULL)
-		complaint (_("file index out of range"));
+		{
+		  if (file_entry *fe
+		      = file_cu->line_header->file_name_at (file_index);
+		      fe != nullptr)
+		    sym->set_symtab (fe->symtab (*file_cu));
+		  else
+		    complaint (_("file index out of range"));
+		}
 	      else
-		sym->set_symtab (fe->symtab (*file_cu));
+		complaint (_("missing .debug_line information to resolve file index"));
 	    }
 	}
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PING][PATCH] dwarf2: avoid decoding .debug_line for type units
  2026-03-18 13:35 [PATCH] dwarf2: avoid decoding .debug_line for type units Bratislav Filipovic
@ 2026-04-01 14:54 ` Filipovic, Bratislav
  2026-04-16 14:10 ` [PATCH] testsuite: ada-valprint-error relocation issue Bratislav Filipovic
  1 sibling, 0 replies; 8+ messages in thread
From: Filipovic, Bratislav @ 2026-04-01 14:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: simon.marchi

[AMD Official Use Only - AMD Internal Distribution Only]

PING
Can someone take a look at this?

Regards Bratislav

-----Original Message-----
From: Filipovic, Bratislav <Bratislav.Filipovic@amd.com>
Sent: Wednesday, March 18, 2026 2:36 PM
To: gdb-patches@sourceware.org
Cc: simon.marchi@efficios.com; Filipovic, Bratislav <Bratislav.Filipovic@amd.com>
Subject: [PATCH] dwarf2: avoid decoding .debug_line for type units

Running gdb.dwarf2/pr13961.exp with clang fails with an internal error:

  gdb/dwarf2/read.c: internal-error: decode_line_header_for_cu:
  Assertion `!cu->per_cu->is_debug_types ()' failed.

pr13961 is a legacy .S test that references a .debug_line label from both a CU and a TU.  The assembly includes an empty .debug_line section
declaration:

  .section .debug_line,"",%progbits
.Ldebug_line0:

With gcc this results in a dummy (valid, but content-less) .debug_line header being emitted, so GDB can build a line header and resolve file indices.  With clang the .debug_line section can be missing/empty, leaving the line header unset.

During symbol creation, new_symbol may then try to lazily decode the CU-only line header while processing a type unit, which triggers the assertion above.

Fix this by only decoding the line header for non-type units.  If no line header is available, emit a complaint and continue without setting the symtab rather than attempting CU-only line decoding from a TU.

Tested: gdb.dwarf2/pr13961.exp (CC_FOR_TARGET=clang)
---
 gdb/dwarf2/read.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8b87d58d..2e897e65 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -15484,23 +15484,32 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
          if (index_cst.has_value ())
            {
              file_name_index file_index = (file_name_index) *index_cst;
-             struct file_entry *fe;

-             if (file_cu->line_header == nullptr)
+             /* Resolve DW_AT_decl_file/DW_AT_call_file.  These attributes are
+                indices into the file-name table, which lives in the unit's
+                decoded .debug_line header.
+                decode_line_header_for_cu is CU-only and asserts on debug_types.
+                For type units, the TU setup code runs before processing child
+                DIEs, so if line_header is still nullptr here it means there is no
+                usable line table for this unit.  */
+             if (file_cu->line_header == nullptr
+                 && !file_cu->per_cu->is_debug_types ())
                {
                  file_and_directory fnd (nullptr, nullptr);
                  decode_line_header_for_cu (file_cu->dies, file_cu, fnd);
                }

              if (file_cu->line_header != nullptr)
-               fe = file_cu->line_header->file_name_at (file_index);
-             else
-               fe = NULL;
-
-             if (fe == NULL)
-               complaint (_("file index out of range"));
+               {
+                 if (file_entry *fe
+                     = file_cu->line_header->file_name_at (file_index);
+                     fe != nullptr)
+                   sym->set_symtab (fe->symtab (*file_cu));
+                 else
+                   complaint (_("file index out of range"));
+               }
              else
-               sym->set_symtab (fe->symtab (*file_cu));
+               complaint (_("missing .debug_line information to resolve file
+index"));
            }
        }

--
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] testsuite: ada-valprint-error relocation issue
  2026-03-18 13:35 [PATCH] dwarf2: avoid decoding .debug_line for type units Bratislav Filipovic
  2026-04-01 14:54 ` [PING][PATCH] " Filipovic, Bratislav
@ 2026-04-16 14:10 ` Bratislav Filipovic
  2026-04-16 15:14   ` Tom de Vries
  1 sibling, 1 reply; 8+ messages in thread
From: Bratislav Filipovic @ 2026-04-16 14:10 UTC (permalink / raw)
  To: gdb-patches; +Cc: simon.marchi

Ping.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] testsuite: ada-valprint-error relocation issue
  2026-04-16 14:10 ` [PATCH] testsuite: ada-valprint-error relocation issue Bratislav Filipovic
@ 2026-04-16 15:14   ` Tom de Vries
  2026-04-20 13:16     ` [PATCH][PING] dwarf2: avoid decoding .debug_line for type units Filipovic, Bratislav
  0 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2026-04-16 15:14 UTC (permalink / raw)
  To: Bratislav Filipovic, gdb-patches; +Cc: simon.marchi

On 4/16/26 4:10 PM, Bratislav Filipovic wrote:
> Ping.

I've pushed this:
...
$ git show -s --pretty=fuller 5ae26f34ef5ac863203d63fffc968d63e823172f
commit 5ae26f34ef5ac863203d63fffc968d63e823172f
Author:     Bratislav Filipovic <bfilipov@amd.com>
AuthorDate: Fri Apr 3 08:11:02 2026 +0200
Commit:     Tom de Vries <tdevries@suse.de>
CommitDate: Fri Apr 3 08:11:02 2026 +0200

     testsuite: ada-valprint-error relocation issue
...
as mentioned here ( 
https://sourceware.org/pipermail/gdb-patches/2026-April/226315.html ).

Thanks,
- Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH][PING] dwarf2: avoid decoding .debug_line for type units
  2026-04-16 15:14   ` Tom de Vries
@ 2026-04-20 13:16     ` Filipovic, Bratislav
  2026-04-23 16:37       ` [PATCH] " Bratislav Filipovic
  0 siblings, 1 reply; 8+ messages in thread
From: Filipovic, Bratislav @ 2026-04-20 13:16 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches; +Cc: simon.marchi

[AMD Official Use Only - AMD Internal Distribution Only]

Hello Tom,

I sent email with wrong subject by mistake, the ping was referring to the original patch in this thread:
https://inbox.sourceware.org/gdb-patches/20260318133618.2805916-1-bfilipov@amd.com/

Regards Bratislav

-----Original Message-----
From: Tom de Vries <tdevries@suse.de>
Sent: Thursday, April 16, 2026 5:15 PM
To: Filipovic, Bratislav <Bratislav.Filipovic@amd.com>; gdb-patches@sourceware.org
Cc: simon.marchi@efficios.com
Subject: Re: [PATCH] testsuite: ada-valprint-error relocation issue

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.


On 4/16/26 4:10 PM, Bratislav Filipovic wrote:
> Ping.

I've pushed this:
...
$ git show -s --pretty=fuller 5ae26f34ef5ac863203d63fffc968d63e823172f
commit 5ae26f34ef5ac863203d63fffc968d63e823172f
Author:     Bratislav Filipovic <bfilipov@amd.com>
AuthorDate: Fri Apr 3 08:11:02 2026 +0200
Commit:     Tom de Vries <tdevries@suse.de>
CommitDate: Fri Apr 3 08:11:02 2026 +0200

     testsuite: ada-valprint-error relocation issue ...
as mentioned here (
https://sourceware.org/pipermail/gdb-patches/2026-April/226315.html ).

Thanks,
- Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] dwarf2: avoid decoding .debug_line for type units
  2026-04-20 13:16     ` [PATCH][PING] dwarf2: avoid decoding .debug_line for type units Filipovic, Bratislav
@ 2026-04-23 16:37       ` Bratislav Filipovic
  2026-04-23 17:42         ` Simon Marchi
  0 siblings, 1 reply; 8+ messages in thread
From: Bratislav Filipovic @ 2026-04-23 16:37 UTC (permalink / raw)
  To: bratislav.filipovic
  Cc: gdb-patches, simon.marchi, tdevries, Bratislav Filipovic

Running gdb.dwarf2/pr13961.exp with clang fails with an internal error:

  gdb/dwarf2/read.c: internal-error: decode_line_header_for_cu:
  Assertion `!cu->per_cu->is_debug_types ()' failed.

pr13961 is a legacy .S test that references a .debug_line label from
both a CU and a TU.  The assembly includes an empty .debug_line section
declaration:

  .section .debug_line,"",%progbits
.Ldebug_line0:

With gcc this results in a dummy (valid, but content-less) .debug_line
header being emitted, so GDB can build a line header and resolve file
indices.  With clang the .debug_line section can be missing/empty,
leaving the line header unset.

During symbol creation, new_symbol may then try to lazily decode the
CU-only line header while processing a type unit, which triggers the
assertion above.

Fix this by only decoding the line header for non-type units.  If no
line header is available, emit a complaint and continue without setting
the symtab rather than attempting CU-only line decoding from a TU.

Tested: gdb.dwarf2/pr13961.exp (CC_FOR_TARGET=clang-23)
---
 gdb/dwarf2/read.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index bc7b8b46d87..655cc753334 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -15430,21 +15430,21 @@ is_ada_import_or_export (dwarf2_cu *cu, const char *name,
 
 static void
 new_symbol_file_line (struct die_info *die, struct dwarf2_cu *cu,
-		      struct symbol *sym)
+                      struct symbol *sym)
 {
   bool inlined_func = (die->tag == DW_TAG_inlined_subroutine);
 
   /* Handle DW_AT_call_line / DW_AT_decl_line.  */
   struct attribute *attr
     = dwarf2_attr (die, inlined_func ? DW_AT_call_line : DW_AT_decl_line,
-		   cu);
+                   cu);
   if (attr != nullptr)
     sym->set_line (attr->unsigned_constant ().value_or (0));
 
   /* Handle DW_AT_call_file / DW_AT_decl_file.  */
   struct dwarf2_cu *file_cu = cu;
   attr = dwarf2_attr (die, inlined_func ? DW_AT_call_file : DW_AT_decl_file,
-		      &file_cu);
+                      &file_cu);
   if (attr == nullptr)
     return;
 
@@ -15452,16 +15452,27 @@ new_symbol_file_line (struct die_info *die, struct dwarf2_cu *cu,
   if (!index_cst.has_value ())
     return;
 
-  if (file_cu->line_header == nullptr)
+  /* decode_line_header_for_cu is CU-only and asserts on debug_types.
+     For type units, the TU setup code runs before processing child DIEs,
+     so if line_header is still nullptr here it means there is no usable
+     line table for this unit.  */
+  if (file_cu->line_header == nullptr
+      && !file_cu->per_cu->is_debug_types ())
     {
       file_and_directory fnd (nullptr, nullptr);
       decode_line_header_for_cu (file_cu->dies, file_cu, fnd);
     }
 
   file_name_index file_index = (file_name_index) *index_cst;
-  struct file_entry *fe = nullptr;
-  if (file_cu->line_header != nullptr)
-    fe = file_cu->line_header->file_name_at (file_index);
+
+  /* Check if we successfully got line_header.  */
+  if (file_cu->line_header == nullptr)
+    {
+      complaint (_("missing .debug_line information to resolve file index"));
+      return;
+    }
+
+  struct file_entry *fe = file_cu->line_header->file_name_at (file_index);
 
   if (fe == nullptr)
     {
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dwarf2: avoid decoding .debug_line for type units
  2026-04-23 16:37       ` [PATCH] " Bratislav Filipovic
@ 2026-04-23 17:42         ` Simon Marchi
  2026-04-27 10:26           ` [FYI] " Filipovic, Bratislav
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2026-04-23 17:42 UTC (permalink / raw)
  To: Bratislav Filipovic, bratislav.filipovic
  Cc: gdb-patches, simon.marchi, tdevries

On 4/23/26 12:37 PM, Bratislav Filipovic wrote:
> Running gdb.dwarf2/pr13961.exp with clang fails with an internal error:
> 
>   gdb/dwarf2/read.c: internal-error: decode_line_header_for_cu:
>   Assertion `!cu->per_cu->is_debug_types ()' failed.
> 
> pr13961 is a legacy .S test that references a .debug_line label from
> both a CU and a TU.  The assembly includes an empty .debug_line section
> declaration:
> 
>   .section .debug_line,"",%progbits
> .Ldebug_line0:
> 
> With gcc this results in a dummy (valid, but content-less) .debug_line
> header being emitted, so GDB can build a line header and resolve file
> indices.  With clang the .debug_line section can be missing/empty,
> leaving the line header unset.
> 
> During symbol creation, new_symbol may then try to lazily decode the
> CU-only line header while processing a type unit, which triggers the
> assertion above.
> 
> Fix this by only decoding the line header for non-type units.  If no
> line header is available, emit a complaint and continue without setting
> the symtab rather than attempting CU-only line decoding from a TU.
> 
> Tested: gdb.dwarf2/pr13961.exp (CC_FOR_TARGET=clang-23)

There are some whitespace issues.  I would suggest setting up pre-commit
and running it:

    $ pre-commit run --all-files
    ...
    check-whitespace.........................................................Failed
    - hook id: check-whitespace
    - exit code: 2

    gdb/dwarf2/read.c:15433: indent with spaces.
    +                      struct symbol *sym)
    gdb/dwarf2/read.c:15440: indent with spaces.
    +                   cu);
    gdb/dwarf2/read.c:15447: indent with spaces.
    +                      &file_cu);


In fact, those warnings are about lines that shouldn't be changed by
this patch.

> @@ -15452,16 +15452,27 @@ new_symbol_file_line (struct die_info *die, struct dwarf2_cu *cu,
>    if (!index_cst.has_value ())
>      return;
>  
> -  if (file_cu->line_header == nullptr)
> +  /* decode_line_header_for_cu is CU-only and asserts on debug_types.
> +     For type units, the TU setup code runs before processing child DIEs,
> +     so if line_header is still nullptr here it means there is no usable
> +     line table for this unit.  */

Just a small suggestion to be more precise and less repetitive:

  /* decode_line_header_for_cu is CU-only and asserts on type units.
     For type units, the line header setup runs before processing child
     DIEs, in method dwarf2_cu::setup_type_unit_groups.  So if
     line_header is still nullptr here it means there is no usable line
     table for this unit.  */

With those fixed, the patch LGTM.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [FYI] dwarf2: avoid decoding .debug_line for type units
  2026-04-23 17:42         ` Simon Marchi
@ 2026-04-27 10:26           ` Filipovic, Bratislav
  0 siblings, 0 replies; 8+ messages in thread
From: Filipovic, Bratislav @ 2026-04-27 10:26 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches, simon.marchi, tdevries

[AMD Official Use Only - AMD Internal Distribution Only]

Thanks Simon. I addressed the comments and pushed to master.

Regards Bratislav

-----Original Message-----
From: Simon Marchi <simark@simark.ca>
Sent: Thursday, April 23, 2026 7:43 PM
To: Filipovic, Bratislav <Bratislav.Filipovic@amd.com>; Filipovic, Bratislav <Bratislav.Filipovic@amd.com>
Cc: gdb-patches@sourceware.org; simon.marchi@efficios.com; tdevries@suse.de
Subject: Re: [PATCH] dwarf2: avoid decoding .debug_line for type units

[Certaines personnes qui ont reçu ce message ne reçoivent pas souvent de courriers de simark@simark.ca. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.


On 4/23/26 12:37 PM, Bratislav Filipovic wrote:
> Running gdb.dwarf2/pr13961.exp with clang fails with an internal error:
>
>   gdb/dwarf2/read.c: internal-error: decode_line_header_for_cu:
>   Assertion `!cu->per_cu->is_debug_types ()' failed.
>
> pr13961 is a legacy .S test that references a .debug_line label from
> both a CU and a TU.  The assembly includes an empty .debug_line
> section
> declaration:
>
>   .section .debug_line,"",%progbits
> .Ldebug_line0:
>
> With gcc this results in a dummy (valid, but content-less) .debug_line
> header being emitted, so GDB can build a line header and resolve file
> indices.  With clang the .debug_line section can be missing/empty,
> leaving the line header unset.
>
> During symbol creation, new_symbol may then try to lazily decode the
> CU-only line header while processing a type unit, which triggers the
> assertion above.
>
> Fix this by only decoding the line header for non-type units.  If no
> line header is available, emit a complaint and continue without
> setting the symtab rather than attempting CU-only line decoding from a TU.
>
> Tested: gdb.dwarf2/pr13961.exp (CC_FOR_TARGET=clang-23)

There are some whitespace issues.  I would suggest setting up pre-commit and running it:

    $ pre-commit run --all-files
    ...
    check-whitespace.........................................................Failed
    - hook id: check-whitespace
    - exit code: 2

    gdb/dwarf2/read.c:15433: indent with spaces.
    +                      struct symbol *sym)
    gdb/dwarf2/read.c:15440: indent with spaces.
    +                   cu);
    gdb/dwarf2/read.c:15447: indent with spaces.
    +                      &file_cu);


In fact, those warnings are about lines that shouldn't be changed by this patch.

> @@ -15452,16 +15452,27 @@ new_symbol_file_line (struct die_info *die, struct dwarf2_cu *cu,
>    if (!index_cst.has_value ())
>      return;
>
> -  if (file_cu->line_header == nullptr)
> +  /* decode_line_header_for_cu is CU-only and asserts on debug_types.
> +     For type units, the TU setup code runs before processing child DIEs,
> +     so if line_header is still nullptr here it means there is no usable
> +     line table for this unit.  */

Just a small suggestion to be more precise and less repetitive:

  /* decode_line_header_for_cu is CU-only and asserts on type units.
     For type units, the line header setup runs before processing child
     DIEs, in method dwarf2_cu::setup_type_unit_groups.  So if
     line_header is still nullptr here it means there is no usable line
     table for this unit.  */

With those fixed, the patch LGTM.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-04-27 10:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-18 13:35 [PATCH] dwarf2: avoid decoding .debug_line for type units Bratislav Filipovic
2026-04-01 14:54 ` [PING][PATCH] " Filipovic, Bratislav
2026-04-16 14:10 ` [PATCH] testsuite: ada-valprint-error relocation issue Bratislav Filipovic
2026-04-16 15:14   ` Tom de Vries
2026-04-20 13:16     ` [PATCH][PING] dwarf2: avoid decoding .debug_line for type units Filipovic, Bratislav
2026-04-23 16:37       ` [PATCH] " Bratislav Filipovic
2026-04-23 17:42         ` Simon Marchi
2026-04-27 10:26           ` [FYI] " Filipovic, Bratislav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox