This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bug in gdb.block_for_pc documentation?

On 2017-12-21 20:15, Roman Popov wrote:
Hi all,
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 block cannot be found for the pc value specified, the function will return None."*

Instead of returning None it throws runtime exception:

RuntimeError: Cannot locate object file for block.


Thanks for reporting.  The corresponding code is here:;a=blob;f=gdb/python/py-block.c;h=840c842e85a3161685af3c1df2ecadbb16422979;hb=HEAD#l368

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 exception 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 that happens.

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...


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]