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

Pedro Alves <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha,gmane.comp.gdb.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.