gdb: z80: Guard against missing symtab in skip_prologue

Message ID 289d2478-6150-4499-a367-426ab9c88a40@gmx.de
State New
Headers
Series gdb: z80: Guard against missing symtab in skip_prologue |

Checks

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

Commit Message

Ronald Hecht June 3, 2026, 12:11 p.m. UTC
  |Hi, this is the patch from PR tdep/34198. It fixes an internal 
segmentation fault in z80_skip_prologue when setting "break main" on 
some Z80 binaries. "break *main" works, which points at the prologue/SAL 
path. Regression-tested manually with the reproducer from the PR. 
Thanks, Ronald https://sourceware.org/bugzilla/show_bug.cgi?id=34198 |
  

Comments

Simon Marchi June 3, 2026, 3:32 p.m. UTC | #1
On 6/3/26 8:11 AM, Ronald Hecht wrote:
> |Hi, this is the patch from PR tdep/34198. It fixes an internal
> segmentation fault in z80_skip_prologue when setting "break main" on
> some Z80 binaries. "break *main" works, which points at the
> prologue/SAL path. Regression-tested manually with the reproducer from
> the PR. Thanks, Ronald
> https://sourceware.org/bugzilla/show_bug.cgi?id=34198 |
> diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
> index f7e207d02ec3..f2e9b09e3b91 100644
> --- a/gdb/z80-tdep.c
> +++ b/gdb/z80-tdep.c
> @@ -495,12 +495,17 @@ z80_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>    if (prologue_end != 0)
>      {
>        struct symtab_and_line prologue_sal = find_sal_for_pc (func_addr, 0);
> -      struct compunit_symtab *compunit = prologue_sal.symtab->compunit ();
> -      const char *debug_format = compunit->debugformat ();
> -
> -      if (debug_format != NULL &&
> -         !strncasecmp ("dwarf", debug_format, strlen("dwarf")))
> -       return std::max (pc, prologue_end);
> +      if (prologue_sal.symtab != nullptr)
> +       {
> +         struct compunit_symtab *compunit = prologue_sal.symtab->compunit ();
> +         if (compunit != nullptr)

symtab->compunit() can't return nullptr, so I wouldn't add this check
(that method should be modified to return a reference, to make it
clear).

The patch looks good otherwise.  Would you be ok with me pushing your
patch with that change?

Simon
  
Ronald Hecht June 4, 2026, 6:58 a.m. UTC | #2
Hi Simon,

yes, that's fine with me. Thanks for cleaning it up and pushing it.

For reference, I attached the adjusted patch with the compunit nullptr 
check removed, matching your suggestion.

Best,
Ronald

On 6/3/26 17:32, Simon Marchi wrote:
> On 6/3/26 8:11 AM, Ronald Hecht wrote:
>> |Hi, this is the patch from PR tdep/34198. It fixes an internal
>> segmentation fault in z80_skip_prologue when setting "break main" on
>> some Z80 binaries. "break *main" works, which points at the
>> prologue/SAL path. Regression-tested manually with the reproducer from
>> the PR. Thanks, Ronald
>> https://sourceware.org/bugzilla/show_bug.cgi?id=34198 |
>> diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
>> index f7e207d02ec3..f2e9b09e3b91 100644
>> --- a/gdb/z80-tdep.c
>> +++ b/gdb/z80-tdep.c
>> @@ -495,12 +495,17 @@ z80_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>>     if (prologue_end != 0)
>>       {
>>         struct symtab_and_line prologue_sal = find_sal_for_pc (func_addr, 0);
>> -      struct compunit_symtab *compunit = prologue_sal.symtab->compunit ();
>> -      const char *debug_format = compunit->debugformat ();
>> -
>> -      if (debug_format != NULL &&
>> -         !strncasecmp ("dwarf", debug_format, strlen("dwarf")))
>> -       return std::max (pc, prologue_end);
>> +      if (prologue_sal.symtab != nullptr)
>> +       {
>> +         struct compunit_symtab *compunit = prologue_sal.symtab->compunit ();
>> +         if (compunit != nullptr)
> symtab->compunit() can't return nullptr, so I wouldn't add this check
> (that method should be modified to return a reference, to make it
> clear).
>
> The patch looks good otherwise.  Would you be ok with me pushing your
> patch with that change?
>
> Simon
  
Simon Marchi June 4, 2026, 7:49 p.m. UTC | #3
On 6/4/26 2:58 AM, Ronald Hecht wrote:
> Hi Simon,
> 
> yes, that's fine with me. Thanks for cleaning it up and pushing it.
> 
> For reference, I attached the adjusted patch with the compunit nullptr check removed, matching your suggestion.
> 
> Best,

Thanks, I used the text from your bug report as a commit message and
pushed the patch.

Simon
  

Patch

From 14a45c8bd64db9c6c41c75bd9a7de2c95935e9f2 Mon Sep 17 00:00:00 2001
From: Ronald Hecht <r.hecht@astech.de>
Date: Wed, 3 Jun 2026 14:05:07 +0200
Subject: [PATCH] gdb: z80: Guard against missing symtab in skip_prologue

Signed-off-by: Ronald Hecht <r.hecht@astech.de>
---
 gdb/z80-tdep.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index f7e207d0..f2e9b09e 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -495,12 +495,17 @@  z80_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
   if (prologue_end != 0)
     {
       struct symtab_and_line prologue_sal = find_sal_for_pc (func_addr, 0);
-      struct compunit_symtab *compunit = prologue_sal.symtab->compunit ();
-      const char *debug_format = compunit->debugformat ();
-
-      if (debug_format != NULL &&
-	  !strncasecmp ("dwarf", debug_format, strlen("dwarf")))
-	return std::max (pc, prologue_end);
+      if (prologue_sal.symtab != nullptr)
+	{
+	  struct compunit_symtab *compunit = prologue_sal.symtab->compunit ();
+	  if (compunit != nullptr)
+	    {
+	      const char *debug_format = compunit->debugformat ();
+	      if (debug_format != nullptr
+		  && !strncasecmp ("dwarf", debug_format, strlen ("dwarf")))
+		return std::max (pc, prologue_end);
+	    }
+	}
     }
 
   return pc;
-- 
2.43.0