[PATCH 0/9] using libdw as an alternative unwinder

Mark Wielaard mark at klomp.org
Sat Mar 17 01:15:32 UTC 2018


On Tue, Mar 13, 2018 at 08:46:15PM +0300, Dmitry V. Levin wrote:
> On Wed, Mar 14, 2018 at 02:28:05AM +0900, Masatake YAMATO wrote:
> > If both unwinders(libunwind and libdw) are linked to strace, you can
> > choose one with -klibunwind or -klibdw option.
> > 
> > Example output:
> > 
> >     [yamato at master]~/var/strace% ./strace  -e open -klibunwind ls > /dev/null
> >     open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
> >      > /usr/lib64/libc-2.26.so(_nl_load_locale_from_archive+0x433) [0x2e333]
> >      > /usr/lib64/libc-2.26.so(_nl_find_locale+0xf4) [0x2cef4]
> >      > /usr/lib64/libc-2.26.so(setlocale+0x1ee) [0x2c6de]
> [...]
> >     [yamato at master]~/var/strace% ./strace  -e open -klibdw ls > /dev/null
> >     open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
> >      > /usr/lib64/libc-2.26.so(_nl_load_locale_from_archive+0x433) [0x2e333]
> >      > /usr/lib64/libc-2.26.so(_nl_find_locale+0xf3) [0x2cef3]
> >      > /usr/lib64/libc-2.26.so(setlocale+0x1ed) [0x2c6dd]
> 
> I wonder where does this off-by-one difference come from?
> They cannot be both correct at the same time, can they?

I haven't looked at the libunwind based code. But the libdw based
code takes care of not just reporting the "return address" found
by the unwinding, but to use the (probable) calling address.
See the part where it corrects the pc if it is not an "activation"
(aka, initial frame or signal frame). Normally this doesn't really
matter that much except when at the end of a (no return) function.
Because then the "return" address might be beyond the current
function and you would report the wrong symbol. In theory the
unwind/return address calculation also could be slightly
different depending on whether you start from the calling vs the
return address. I believe what the libdw based code does is correct.
Masatake has an example where the backtrace goes through a no-return
exit function where the libunwind based one is wrong and the libdw
one is correct.

Cheers,

Mark


More information about the Strace-devel mailing list