public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCHv4] gdb: fix handling of DW_AT_entry_pc of inlined subroutines
Date: Tue, 29 Oct 2024 16:28:30 +0100	[thread overview]
Message-ID: <DU2PR08MB102630C71A6AE0F0002C2C085E44B2@DU2PR08MB10263.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <048adfb0b4dad045ffff2c71825bb2348c49e5ed.1730212638.git.aburgess@redhat.com>

Hi Andrew,

On 10/29/24 15:49, Andrew Burgess wrote:
> In v4:
> 
>   - I still have one failed being reported from Linaro CI,
>     gdb.stabs/gdb11479.exp.  I've been unable to reproduce this
>     failure.  However, on re-reading this patch I did notice that, if
>     the m_entry_pc field was not set then we would still end up giving
>     it a value during relocation, this would result in m_entry_pc
>     holding an address which had been relocated twice.
> 
>     Fixed this by moving the block's address relocation logic into the
>     block class, and only relocating the m_entry_pc variable if it
>     actually has been assigned a value.
> 
> In v3:
> 
>   - Entry PC values are now clamped to the block's start/end range.
>     This was causing failures in the self-tests when GDB was compiled
>     with GCC using default optimisation, as GCC emits an (invalid?)
>     entry-pc which is outside the blocks start/end range.
> 
> In v2:
> 
>   - Don't use std::optional<CORE_ADDR> for block::m_entry_pc, instead
>     just use CORE_ADDR.  This does mean that targets where 0 is a
>     valid code address might run into problems, but those targets
>     likely have plenty of other problems, and I'd rather land this fix
>     than get hung up on this edge case.
> 
>     In the future it might be possible to remove block::m_start and
>     block::m_end as Klaus suggested, but this doesn't look like a
>     simple task.  If we did drop those fields then it might be
>     possible to space a word for some flag bits which would allow us
>     to remove the 0 address special case.
> 
>   - Fixes to the DWARF assembler testcase to handle compiling with
>     '-pie', the Linaro CI exposed these issues.  The changes are
>     pretty minor, mostly using label names rather than addresses when
>     building the DWARF.
> 
> ---
> 
> The entry PC for a DIE, e.g. an inline function, might not be the base
> address of the DIE.  Currently though, in block::entry_pc(), GDB
> always returns the base address (low-pc or the first address of the
> first range) as the entry PC.
> 
> This commit extends the block class to carry the entry PC as a
> separate member variable.  Then the DWARF reader is extended to read
> and set the entry PC for the block.  Now in block::entry_pc(), if the
> entry PC has been set to a specific value, this is the value returned.
> 
> I have not removed the old code in block::entry_pc().  If the specific
> entry PC value was not set then we still fall back on the old approach
> of just returning the base address.  Doing this feels more useful than
> just claiming there is no entry PC.  This should also mean that we
> shouldn't see any change in behaviour for compilers that don't emit
> the DW_AT_entry_pc, or for debug readers (e.g. stabs) that don't set
> the entry PC value within a block.
> 
> The DWARF-5 spec for reading the entry PC is a super-set of the spec
> as found in DWARF-4.  For example, if there is no DW_AT_entry_pc then
> DWARF-4 says to use DW_AT_low_pc while DWARF-5 says to use the base
> address, which is DW_AT_low_pc or the first address in the first range
> specified by DW_AT_ranges if there is no DW_AT_low_pc.
> 
> I have taken the approach of just implementing the DWARF-5 spec for
> everyone.  There doesn't seem to be any benefit to deliberately
> ignoring a ranges based entry PC value for DWARF-4.  If some naughty
> compiler has emitted that, then lets use it.
> 
> Similarly, DWARF-4 says that DW_AT_entry_pc is an address.  DWARF-5
> allows an address or a constant, where the constant is an offset from
> the base address.  I allow both approaches for all DWARF versions.
> There doesn't seem to be any downsides to this approach.
> 
> There was one issue that I ran into when testing this patch.  GCC
> seems to be quite bad at tracking code ranges when the default level
> of optimisation is applied.  As a result I was seeing failures in
> gdb.gdb/python-helper.exp and gdb.gdb/selftest.exp when we debug the
> generated GDB executable.
> 
> What happens is that the DW_AT_entry_pc is given as an entry address
> which is outside of any of the blocks ranges.  Previously we ignored
> the DW_AT_entry_pc and when we later ask for the entry-pc we just
> report the first range's start address.
> 
> After this commit we track the declared entry-pc, which is then what
> we report.
> 
> What this means is that when the user (or DejaGNU) tries to place a
> breakpoint on an inline function, the breakpoint is placed at the
> entry-pc.  Then when GDB stops at this address and tries to figure out
> which block it's in, GDB doesn't think it's actually within the inline
> function that the user asked to stop in.
> 
> In the test I mention about we place a breakpoint within GDB's
> 'captured_main' function.  In the builds I was looked at, this
> function was inline within 'gdb_main', but the DW_AT_entry_pc for the
> 'captured_main' function was not within the declared ranges of
> 'captured_main'.  As a result when the breakpoint was hit, GDB would
> report the inferior as within 'gdb_main' instead of 'captured_main'.
> 

I think you might have hit a case that I mentioned on part 3 of my patch:

    Additionally it may happen that one inline sub-range
    is empty or the inline is completely empty.  But
    filtering that information away is not the right
    solution, since although there is no actual code
    from the inline, it is still possible that variables
    from an inline function can be inspected here.

You probably had the entry_pc pointing to an empty sub-range,
that is usually the lowest address, currently that is filtered
away by the dwarf reader, but part 2+3 change that behavior,
but since I did not try to solve the entry_pc problem completely,
there was no apparent dependency between part 1 and part 2+3.
But probably this is no longer the case, with your patch,
since the checks are more strict, you could try to layer
your entry_pc path over part 2+3.

> For now I propose fixing this by checking the entry-pc against the
> blocks start address.  If the entry-pc is before the start address
> then we move the entry-pc to be the start address.  This effectively
> restores the pre-patch behaviour for this problem case.
> 

I think this plausibilty check is not strict enough, instead of just
checking against the low and hig bounds, you should only accept the
entry_pc value if it is inside the bounds of any of the sub-ranges,
since we have no chance to get the correct behaviour otherwise, and
the previous state is to prefer in that case.


Thanks
Bernd.

  reply	other threads:[~2024-10-29 15:27 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16 15:47 [PATCH] " Andrew Burgess
2024-10-17 20:03 ` Tom Tromey
2024-10-18 10:06   ` Andrew Burgess
2024-10-18 13:57     ` Andrew Burgess
2024-10-18 10:26   ` Gerlicher, Klaus
2024-10-18 13:55     ` Andrew Burgess
2024-10-18 13:53 ` [PATCHv2] " Andrew Burgess
2024-10-28 13:45   ` [PATCHv3] " Andrew Burgess
2024-10-29 14:49     ` [PATCHv4] " Andrew Burgess
2024-10-29 15:28       ` Bernd Edlinger [this message]
2024-10-31 10:57         ` Andrew Burgess
2024-10-31 14:01           ` Bernd Edlinger
2024-10-31 14:56             ` Andrew Burgess
2024-10-29 16:34       ` Bernd Edlinger
2024-10-31 10:59         ` Andrew Burgess
2024-10-31 15:00       ` [PATCHv5] " Andrew Burgess
2024-11-01 18:13         ` Tom Tromey
2024-11-01 20:27         ` Bernd Edlinger
2024-11-05 11:25           ` Andrew Burgess
2024-11-05 15:26             ` Bernd Edlinger
2024-11-05 16:52               ` Andrew Burgess
2024-11-05 19:57                 ` Bernd Edlinger
2024-11-05 11:21         ` [PATCHv6] " Andrew Burgess
2024-11-13 13:49           ` Andrew Burgess
2024-11-13 16:59             ` Andrew Burgess
2024-11-14  9:20               ` Tom de Vries
2024-11-14 19:33                 ` Andrew Burgess
2024-11-15  8:50                   ` Tom de Vries
2024-11-15 10:53                     ` Bernd Edlinger
2024-11-15 14:00                       ` Andrew Burgess
2024-11-15 14:30                         ` Tom de Vries
2024-11-15 16:46                           ` Andrew Burgess
2024-11-15 19:24                           ` Andrew Burgess
2024-11-17 23:52                             ` Bernd Edlinger
2024-11-19  9:29                               ` Andrew Burgess
2024-11-15 17:00                         ` Bernd Edlinger
2024-11-15 13:45                     ` Andrew Burgess
2024-10-29 15:29     ` [PATCHv3] " Sam James
2024-10-31  9:48       ` Andrew Burgess
2024-10-18 14:24 ` [PATCH] " Bernd Edlinger
2024-10-28 13:26   ` 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=DU2PR08MB102630C71A6AE0F0002C2C085E44B2@DU2PR08MB10263.eurprd08.prod.outlook.com \
    --to=bernd.edlinger@hotmail.de \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).