Re: [RFC PATCH 0/3] Pretty-printing for errno

Pedro Alves
2017-07-01T11:56:38Z

On 06/30/2017 07:11 PM, Pedro Alves wrote:
> On 06/30/2017 06:27 PM, Zack Weinberg wrote:
>

>>> One dirty way around it would be for the printer to
>>> re-define the errno macro (using to cast __errno_location to
>>> the correct type before calling it, I guess:
>>>
>>> (gdb) macro define errno *(*(__error_t *(*) (void)) __errno_location) ()
>>>
>>> That's make "errno" available when you compile with levels
>>> lower than -g3, too.
>>
>> Hmm. How would one do that from inside Python?
>
> There's no direct Python API, I believe. You'd just call the CLI
> command directly, with gdb.execute.
>
> xmethods sounds like something that maybe might be useful here:
> https://sourceware.org/gdb/onlinedocs/gdb/Xmethods-In-Python.html
> though from the docs it sounds like you can only replace class
> methods, not free functions, currently. Not sure, have never written any.

BTW, it'd be very nice if the printer could replace
the "#define errno *__errno_location()" with an alternative
implementation that would avoid the function call, so that
"print errno":

#1 - would also work when debugging core dumps

#2 - is just plain safer. Having gdb call functions in
the inferior always carries the risk of corrupting an
already corrupt inferior even more.

Thanks,
Pedro Alves