Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Craig Blackmore <craig.blackmore@embecosm.com>,
	gdb-patches@sourceware.org
Cc: Craig Blackmore <craig.blackmore@embecosm.com>,
	Simon Cook <simon.cook@embecosm.com>
Subject: Re: [PATCH] Add missing null pointer check in get_sal_arch
Date: Fri, 31 Jul 2026 14:54:53 +0100	[thread overview]
Message-ID: <87ldarmfgy.fsf@redhat.com> (raw)
In-Reply-To: <20260729150617.3502554-1-craig.blackmore@embecosm.com>

Craig Blackmore <craig.blackmore@embecosm.com> writes:

> This fixes a GDB crash when trying to set a breakpoint on a function in
> an ELF where there is both no .text section and the first section within
> the ELF is not allocatable.
>
> Co-authored-by: Simon Cook <simon.cook@embecosm.com>
> ---
>  gdb/breakpoint.c                        |  2 +-
>  gdb/testsuite/gdb.base/bp-non-alloc.c   | 21 +++++++++++++++
>  gdb/testsuite/gdb.base/bp-non-alloc.exp | 36 +++++++++++++++++++++++++
>  gdb/testsuite/gdb.base/bp-non-alloc.ld  | 35 ++++++++++++++++++++++++
>  4 files changed, 93 insertions(+), 1 deletion(-)
>  create mode 100644 gdb/testsuite/gdb.base/bp-non-alloc.c
>  create mode 100644 gdb/testsuite/gdb.base/bp-non-alloc.exp
>  create mode 100644 gdb/testsuite/gdb.base/bp-non-alloc.ld
>
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index ca600a845e5..7df63856278 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -7764,7 +7764,7 @@ set_breakpoint_location_function (struct bp_location *loc)
>  struct gdbarch *
>  get_sal_arch (struct symtab_and_line sal)
>  {
> -  if (sal.section != nullptr)
> +  if (sal.section != nullptr && sal.section->objfile != nullptr)
>      return sal.section->objfile->arch ();
>    if (sal.symtab != nullptr)
>      return sal.symtab->compunit ().objfile ()->arch ();
> diff --git a/gdb/testsuite/gdb.base/bp-non-alloc.c b/gdb/testsuite/gdb.base/bp-non-alloc.c
> new file mode 100644
> index 00000000000..2eb9f523887
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/bp-non-alloc.c
> @@ -0,0 +1,21 @@
> +/* Copyright (C) 2026 Free Software Foundation, Inc.
> +
> +   This file is part of GDB.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +int main ()
> +{
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/bp-non-alloc.exp b/gdb/testsuite/gdb.base/bp-non-alloc.exp
> new file mode 100644
> index 00000000000..7758a591fa7
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/bp-non-alloc.exp
> @@ -0,0 +1,36 @@
> +# Copyright (C) 2026 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# For an ELF that has no section called ".text" and the first section is
> +# non-alloc, test that a breakpoint can be set on a function.  This previously
> +# caused GDB to crash due to a missing null pointer check.
> +
> +require is_elf_target
> +
> +global srcdir
> +global subdir
> +
> +standard_testfile
> +
> +set linker_script $srcdir/$subdir/$testfile.ld

Isn't a test with a custom linker script, especially one that's placing
text sections going to be architecture specific?  I would have expected
this to be a gdb.arch/ test?

If this does work more widely then maybe a list of the targets it has
been confirmed to work on would be good.

You can push a `try` branch to sourceware into your username namespace,
e.g. I could push to 'aburgess/try-my-awesome-fix' and the sourceware CI
will spot this branch, run its tests, and email you the results.  The
key is the 'try-' part of the branch name.  Though thinking about it,
I'm not sure if it runs all tests, or just a subset, I guess you'd have
to "try" it and find out.

Thanks,
Andrew


> +
> +set options "debug ldscript=-Wl,-T${linker_script}"
> +if {[build_executable "failed to prepare" $testfile $srcfile $options]} {
> +    return -1
> +}
> +
> +clean_restart $testfile
> +
> +gdb_test "break main" "Breakpoint .* at .*"
> diff --git a/gdb/testsuite/gdb.base/bp-non-alloc.ld b/gdb/testsuite/gdb.base/bp-non-alloc.ld
> new file mode 100644
> index 00000000000..6a8ad57af18
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/bp-non-alloc.ld
> @@ -0,0 +1,35 @@
> +/* Copyright (C) 2026 Free Software Foundation, Inc.
> +
> +   This file is part of GDB.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +   This linker script is used to produce an executable that starts with a
> +   non-allocatable section and does not contain a `.text` section.  */
> +
> +MEMORY
> +{
> +  DATA (rw) : ORIGIN = 0x8000000, LENGTH = 0x10000
> +  TEXT (rx) : ORIGIN = LENGTH (DATA), LENGTH = 0x10000
> +}
> +
> +SECTIONS
> +{
> +  .my_non_alloc_sec (INFO) : { . = . + 0x10; }
> +  .text.all : { *(.text) } > TEXT
> +  .data : { *(.data) } > DATA
> +  _edata = .;
> +  .bss : { *(.bss) } > DATA
> +  _end = .;
> +}
> -- 
> 2.43.0


  parent reply	other threads:[~2026-07-31 13:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 15:06 Craig Blackmore
2026-07-31 13:27 ` Tom de Vries
2026-08-21  9:51   ` Craig Blackmore
2026-07-31 13:54 ` Andrew Burgess [this message]
2026-08-21 10:09   ` Craig Blackmore
2026-07-31 14:31 ` Andrew Burgess
2026-07-31 15:27   ` Andrew Burgess
2026-08-21 10:25     ` Craig Blackmore

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=87ldarmfgy.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=craig.blackmore@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.cook@embecosm.com \
    /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