From: Andrew Burgess <aburgess@redhat.com>
To: "Sébastien Darche" <sdarche@efficios.com>, simark@simark.ca
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: ensure bp_location::section is set correct to avoid an assert
Date: Mon, 06 Oct 2025 13:11:24 +0100 [thread overview]
Message-ID: <87jz186xhv.fsf@redhat.com> (raw)
In-Reply-To: <6c31b667-db2d-453e-9597-9fe011c4766e@efficios.com>
Sébastien Darche <sdarche@efficios.com> writes:
> On 9/25/25 17:40, Andrew Burgess wrote:
>> Maybe the answer is as simple as moving the .section assignment into the
>> earlier if block, something like:
>>
>> if (is_function && want_start_sal)
>> {
>> sal = find_function_start_sal (func_addr, NULL, self->funfirstline);
>>
>> /* This breakpoint is for the ifunc case, FUNC_ADDR is can be
>> anywhere, in a completely different section to MSYMBOL, or even
>> in a different objfile!
>>
>> TODO: I haven't checked, maybe find_function_start_sal already
>> fills this stuff in for us? Or maybe it could be made too?
>> For now I'm assuming all we have is an address, but this needs
>> checking. */
>> sal.section = find_pc_overlay (func_addr);
>> if (sal.section == nullptr)
>> sal.section = find_pc_section (func_addr);
>> }
>> else
>> {
>> sal.objfile = objfile;
>> sal.msymbol = msymbol;
>> /* Store func_addr, not the minsym's address in case this was an
>> ifunc that hasn't been resolved yet. */
>> if (is_function)
>> sal.pc = func_addr;
>> else
>> sal.pc = msymbol->value_address (objfile);
>> sal.pspace = current_program_space;
>>
>> /* We can assign the section based on MSYMBOL here because the
>> breakpoint is actually being placed at (or near) MSYMBOL. */
>> sal.section = msymbol->obj_section (objfile);
>> }
>>
>
> To answer your question on whether find_function_start_sal does fill
> this for us : it depends. It manages to do it on amd64 but not on amdgpu.
>
> By default, the sal does not contain a valid section. It's only when we
> try to adjust the pc past the prologue (skip_prologue_sal) that a
> section is computed for the pc at the start of the function. If we do
> have a prologue, then we assign that section (symtab.c:3914). If not
> (and that is the case on amdgpu), then we're left with an empty
> sal.section. I would say the behavior is not really consistent.
>
> I would agree it could be made to.
>> Does this look like a valid path forward maybe?
>
> Your solution seems to work for the gnu-ifunc test and fixes the
> regression for gdb.rocm/displaced-stepping.exp - so I'd say it's a good
> aproach. I am not familiar with overlays, so I can't really judge if the
> change would impact how they are handled.
>
> I think it would be best to ensure find_function_start_sal has a
> consistent behavior across architectures. I'll submit a small patch
> which should address this. This would also at least reduce the chance
> for another bug like this to appear somewhere else :
>
Hi,
I'm proposing the patch below. You should double check that this still
addresses the issue you're seeing with the amdgpu target. Given Simon's
concerns, I do wonder if there might still be some issues with this
related to overlay debugging, but without any way to test it, and no
known overlay users, I think we can probably just ignore that for now.
If this fixes your regression, then maybe we should merge this, and
figure any other issues out later?
Thanks,
Andrew
---
commit 6ffea587445eeacf8b2962de6d3b00d6efa98213
Author: Andrew Burgess <aburgess@redhat.com>
Date: Mon Oct 6 10:27:08 2025 +0100
gdb: fixes for setting the section in minsym_found
After this commit:
commit 6f7ad2381ae72aa592ada4a0921265aa3292b1fa
Date: Wed Sep 3 19:57:42 2025 +0100
gdb: ensure bp_location::section is set correct to avoid an assert
Some issues were reported as a result of the bp_location::section
being left as NULL by the call to find_pc_overlay that was
introduced. See this thread:
https://inbox.sourceware.org/gdb-patches/7febb0c1-7bbd-45d5-8ebe-91c34bb4a6ce@efficios.com
The problem was that code_breakpoint::add_location relies on the
section being set in order to deduce the gdbarch. If the section is
not set then the gdbarch is deduced using the breakpoint's gdbarch.
The bug was reported by the ROCm engineers, who have inferiors running
mixed host and GPU code, and so rely on the section being set in order
to establish the correct architecture for a specific address.
During discussion in the above thread Simon pointed out that the
change made in the above commit might not be correct anyway for
overlay debugging (does that even work, or is it used any more?), as
the commit relies on establishing a section by calling
find_pc_overlay. However, when presented with multiple possible
sections, find_pc_overlay cannot know which section to select, and so
just picks one. This could be different from the section of the
minimal_symbol we already had to hand.
This patch I think should (at least) resolve the issues the ROCm
engineers are seeing.
Instead of always calling find_pc_overlay I have moved the section
assignment inside the if/then/else blocks with the following
reasoning.
In the 'else' block, this is the non-function or non-ifunc case, the
address used is based on the msymbol's address, and so should be in
the same section. In this case we can use the msymbol's section.
In the 'if' block things are more complicated. This could be the
ifunc case, in which case func_addr could have been adjusted to a
different section, or even different objfile.
Further, when we call find_function_start_sal, we pass in just an
address, so the SAL being returned isn't going to consider which
overlay section the original msymbol was from, which could cause
problems for overlay debugging maybe?
Anyway, I'm ignoring that for now, as fixing that would be a whole big
thing. So I'm proposing that, if find_function_start_sal returns a
symtab_and_line with a section set, then we use that section.
Otherwise, we can try to figure out a section.
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 2ddc495babf..4d9c5ac26f3 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -4083,13 +4083,16 @@ minsym_found (struct linespec_state *self, struct objfile *objfile,
CORE_ADDR func_addr;
bool is_function = msymbol_is_function (objfile, msymbol, &func_addr);
+ bool is_ifunc = false;
if (is_function)
{
const char *msym_name = msymbol->linkage_name ();
- if (msymbol->type () == mst_text_gnu_ifunc
- || msymbol->type () == mst_data_gnu_ifunc)
+ is_ifunc = (msymbol->type () == mst_text_gnu_ifunc
+ || msymbol->type () == mst_data_gnu_ifunc);
+
+ if (is_ifunc)
want_start_sal = gnu_ifunc_resolve_name (msym_name, &func_addr);
else
want_start_sal = true;
@@ -4098,7 +4101,32 @@ minsym_found (struct linespec_state *self, struct objfile *objfile,
symtab_and_line sal;
if (is_function && want_start_sal)
- sal = find_function_start_sal (func_addr, NULL, self->funfirstline);
+ {
+ sal = find_function_start_sal (func_addr, NULL, self->funfirstline);
+
+ /* If SAL already has a section then we'll use that. If not, then we
+ can try to find a section.
+
+ In the ifunc case though we cannot rely on the section of MSYMBOL,
+ the ifunc target could be in a different section, or even a
+ different objfile, from the original MSYMBOL. For this case, we
+ fall back to looking up a section based on FUNC_ADDR.
+
+ For the non-ifunc case, we can use the section of MSYMBOL, as
+ that's how we filled in FUNC_ADDR, so they should be in the same
+ section. */
+ if (sal.section == nullptr)
+ {
+ if (!is_ifunc)
+ sal.section = msymbol->obj_section (objfile);
+ else
+ {
+ sal.section = find_pc_overlay (func_addr);
+ if (sal.section == nullptr)
+ sal.section = find_pc_section (func_addr);
+ }
+ }
+ }
else
{
sal.objfile = objfile;
@@ -4110,14 +4138,13 @@ minsym_found (struct linespec_state *self, struct objfile *objfile,
else
sal.pc = msymbol->value_address (objfile);
sal.pspace = current_program_space;
- }
- /* Don't use the section from the msymbol, the code above might have
- adjusted FUNC_ADDR, in which case the msymbol's section might not be
- the section containing FUNC_ADDR. It might not even be in the same
- objfile. As the section is primarily to assist with overlay
- debugging, it should reflect the SAL's pc value. */
- sal.section = find_pc_overlay (sal.pc);
+ /* We can assign the section based on MSYMBOL here because the
+ breakpoint is actually being placed at (or near) MSYMBOL. Note,
+ this is not a path where ifunc resolution can have occurred, which
+ could adjust FUNC_ADDR significantly. */
+ sal.section = msymbol->obj_section (objfile);
+ }
if (self->maybe_add_address (objfile->pspace (), sal.pc))
add_sal_to_sals (self, result, &sal, msymbol->natural_name (), false);
next prev parent reply other threads:[~2025-10-06 12:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-04 20:16 Andrew Burgess
2025-09-05 3:10 ` Simon Marchi
2025-09-25 15:16 ` Sébastien Darche
2025-09-25 17:56 ` Andrew Burgess
2025-09-25 21:05 ` Simon Marchi
2025-09-25 21:40 ` Andrew Burgess
2025-09-25 22:30 ` Simon Marchi
2025-10-02 19:40 ` Sébastien Darche
2025-10-06 12:11 ` Andrew Burgess [this message]
2026-02-02 8:49 ` Rohr, Stephan
2026-02-02 18:45 ` Simon Marchi
2026-02-04 11:55 ` Andrew Burgess
2026-02-04 12:59 ` Andrew Burgess
2026-02-04 16:25 ` Rohr, Stephan
2026-02-12 13:10 ` Andrew Burgess
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=87jz186xhv.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=sdarche@efficios.com \
--cc=simark@simark.ca \
/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