This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC PATCH 0/3] Pretty-printing for errno
- From: Siddhesh Poyarekar <siddhesh at gotplt dot org>
- To: Zack Weinberg <zackw at panix dot com>, Pedro Alves <palves at redhat dot com>
- Cc: Phil Muldoon <pmuldoon at redhat dot com>, GNU C Library <libc-alpha at sourceware dot org>, gdb at sourceware dot org, Joseph Myers <joseph at codesourcery dot com>, Florian Weimer <fweimer at redhat dot com>, Tom Tromey <tom at tromey dot com>
- Date: Sat, 1 Jul 2017 20:05:18 +0530
- Subject: Re: [RFC PATCH 0/3] Pretty-printing for errno
- Authentication-results: sourceware.org; auth=none
- References: <20170622224456.1358-1-zackw@panix.com> <b2e7bc3b-d914-37ec-0215-2937949a848c@redhat.com> <3a7946e9-d178-f878-9774-64ff44bcf5df@redhat.com> <9490d183-a57b-b336-3131-6580e4773818@redhat.com> <be8d9730-96c5-79fa-b9bc-2afc02a17ddf@redhat.com> <CAKCAbMgAwZOG95hpAAAVYJd4SP6j3aAahOf=WWedjNJkj7_JsA@mail.gmail.com> <2f28f69b-406f-65e5-40e1-ae65632ea4f0@redhat.com> <CAKCAbMj8Rf374bss0ct+H+XMOu_o+_WWR2mQ-s8fb4-3_d7GjA@mail.gmail.com>
On Friday 30 June 2017 10:57 PM, Zack Weinberg wrote:
> The _primary_ goal of the glibc patches is to trigger a pretty-printer
> when someone does
>
> (gdb) p errno
>
> with no further adornment. Since pretty-printers are keyed by type
> (and since people do store errno codes in other places than errno),
> this involves a type 'error_t' (and its implementation-namespace alias
> '__error_t'), but if we can't get 'p errno' to work, we're probably
> not going to bother.
>
> In all currently-supported configurations, this is glibc's definition of errno:
>
> extern int *__errno_location (void) __THROW __attribute__ ((__const__));
> #define errno (*__errno_location ())
>
> (__THROW is a macro expanding to 'throw ()' when compiling C++.)
>
> The patches change that to
>
> extern __error_t *__errno_location (void) __THROW __attribute__ ((__const__));
>
> which should be sufficient to get the pretty-printing happening. But
> obviously that's only going to work if GDB actually knows that the
> return type of __errno_location is __error_t*, and it doesn't seem to,
> *even when debug information for the definition is available*:
>
> $ gdb /lib/x86_64-linux-gnu/libc.so.6
> GNU gdb (Debian 7.12-6) 7.12.0.20161007-git
> ...
>
> Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols
> from /usr/lib/debug/.build-id/cc/80584889db7a969292959a46c718a2b1500702.debug...done.
> done.
> (gdb) ptype __errno_location
> type = int ()
> (gdb) p __errno_location
> $1 = {<text variable, no debug info>} 0x20590 <__GI___errno_location>
>
> ... a suspicion occurs...
>
> (gdb) ptype __GI___errno_location
> type = int *(void)
> (gdb) p __GI___errno_location
> $2 = {int *(void)} 0x20590 <__GI___errno_location>
>
> ... so I guess this is a problem with the __GI_ indirection, which
> *may* be a thing we can resolve on our end. I don't fully understand
> that stuff.
>
> Still, It Would Be Nice™ if you _didn't_ have to have the debug
> symbols for libc.so installed for this to work. Probably a lot of
> people think you only need those if you are debugging libc itself.
The __GI_* alias is an internal alias of __errno_location and I've seen
this before with other symbols, where a function address resolves to the
internal alias instead of the public one in gdb as well as other places
like objdump. It might make sense to turn this around, but I suspect
there may be a reason for it that I am unaware of.
Siddhesh