This is the mail archive of the
mailing list for the GDB project.
Re: Bug in gdb.block_for_pc documentation?
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: Roman Popov <ripopov at gmail dot com>
- Cc: gdb at sourceware dot org
- Date: Fri, 22 Dec 2017 16:57:45 -0500
- Subject: Re: Bug in gdb.block_for_pc documentation?
- Authentication-results: sourceware.org; auth=none
- References: <CAATAM3H4ExzcrVCuPjKng72Omhfqz90ZvVDvNmmOKwYQStehLw@mail.gmail.com>
On 2017-12-21 20:15, Roman Popov wrote:
Looks like there is a bug in docs:
*"Function: gdb.block_for_pc (pc)*
*Return the innermost gdb.Block containing the given pc value. If the
cannot be found for the pc value specified, the function will return
Instead of returning None it throws runtime exception:
RuntimeError: Cannot locate object file for block.
Thanks for reporting. The corresponding code is here:
There are two failure cases, as far as I can see
1) We can't find a compilation unit for the given pc -> we throw an
2) We can find a compilation unit for the given pc, but can't find a
corresponding block -> we return None
It's easy to trigger 1), you just call block_for_pc with a bad random
address. I don't know how to trigger 2). You would have to pass a pc
covered by a compilation unit, but not covered by a block, not sure when
Now we have two choices, either we adapt the documentation to match the
reality, which easy. Or we change the code to match the documentation,
which is harder because we risk breaking user scripts.
I don't really like the current situation, because the exception thrown,
RuntimeError, is very generic. So if one uses "except RuntimeError" to
catch the case where block_for_pc fails, they risk catching other
things, like RecursionError, which derives from RuntimeError. Returning
None, as the documentation suggests, would make more sense to me...