[PATCHv2] print stack trace after each syscall

Luca Clementi luca.clementi at gmail.com
Tue Jul 9 05:28:33 UTC 2013


On Mon, Jul 8, 2013 at 3:08 PM, Dmitry V. Levin <ldv at altlinux.org> wrote:
> On Mon, Jul 08, 2013 at 12:24:14AM -0700, Luca Clementi wrote:
> [...]
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -261,6 +261,63 @@ AC_CHECK_MEMBERS([struct sigcontext.sc_hi2],,, [#include <signal.h>
>>  # include <asm/sigcontext.h>
>>  #endif])
>>
>> +
>> +dnl stack trace with libunwind
>> +AC_ARG_WITH([libunwind],
>> +         [AS_HELP_STRING([--with-libunwind],
>> +                         [libunwind is used to display system call stacktrace])],
>> +         [case "${withval}" in
>> +          (yes|no) enable_libunwind=$withval;;
>> +          (*)      enable_libunwind=yes
>> +                   libunwind_CPPFLAGS="${AM_CPPFLAGS} -I${withval}/include"
>> +                   libunwind_LDFLAGS="-L${withval}/lib" ;;
>> +          esac],
>> +         [enable_libunwind=maybe])
>
> If the option is called --with-libunwind, then the options's argument
> variable should be called with_libunwind.

Sorry that's a leftover from previous tests.

> BTW, do you really need this
> libunwind_CPPFLAGS/libunwind_LDFLAGS stuff?  Wouldn't a simple tristate
> (yes|no|check) be enough?

I did it because I thought it was the "standard" (if there is such a
thing) way of using the --with flag.
In this way if you have libunwind compiled libunwind in your own path
you can use only
./configure --with-libunwind=/some/odd/path
instead of having to set both the CPPFLAGS and the LDFLAGS.

I did some testing on Centos6 (where there is no libunwind).

>> +AS_IF([test "x$enable_libunwind" != xno],
>> +     [saved_CPPFLAGS="${CPPFLAGS}"
>> +     CPPFLAGS="${CPPFLAGS} ${libunwind_CPPFLAGS}"
>> +     AC_CHECK_HEADERS([libunwind-ptrace.h libunwind.h])
>> +     CPPFLAGS="${saved_CPPFLAGS}" ])
>> +
>> +if test "x$ac_cv_header_libunwind_ptrace_h" = "xyes" &&
>> +     test "x$ac_cv_header_libunwind_h" = "xyes"; then
>
> If --with-libunwind was given and one of these header files is not
> available, configure should fail.

Good catch, I'll get it fixed.
That's why I have the maybe option above.

>> +     dnl code is taken from ltrace
>> +     case "${host_cpu}" in
>> +             arm*|sa110)         UNWIND_ARCH="arm" ;;
>> +             i?86)               UNWIND_ARCH="x86" ;;
>> +             powerpc)            UNWIND_ARCH="ppc32" ;;
>> +             powerpc64)          UNWIND_ARCH="ppc64" ;;
>> +             mips*)              UNWIND_ARCH="mips" ;;
>> +             *)                  UNWIND_ARCH="${host_cpu}" ;;
>> +     esac
>> +
>> +     saved_LDFLAGS="${LDFLAGS}"
>> +     LDFLAGS="${LDFLAGS} ${libunwind_LDFLAGS}"
>> +     AC_CHECK_LIB([unwind], [backtrace],
>> +                  [libunwind_LIBS="-lunwind"],
>> +                  [AC_MSG_FAILURE([Unable to find libunwind])])
>> +        AC_CHECK_LIB([unwind-generic], [_U${UNWIND_ARCH}_create_addr_space],
>> +                  [libunwind_LIBS="-lunwind-generic $libunwind_LIBS"],
>> +                  [AC_MSG_FAILURE([Unable to find libunwind-generic])],
>> +                  [$libunwind_LIBS])
>> +     AC_CHECK_LIB([unwind-ptrace], [_UPT_create],
>> +                  [libunwind_LIBS="-lunwind-ptrace $libunwind_LIBS"],
>> +                  [AC_MSG_FAILURE([Unable to find libunwind-ptrace])],
>> +                  [$libunwind_LIBS])
>> +     LDFLAGS="${saved_LDFLAGS}"
>
> If --with-libunwind was not given and one of these symbols is not
> available, configure should not fail.

But I enter this "if" block only if I find the headers.
My default is: if no option is given and the headers are found it's
like if you use --with-libunwind (then you can use --with-libunwind=no
to disable that).
Is that wrong?


Luca




More information about the Strace-devel mailing list