On 14.06.2012 03:54, Paul Pluzhnikov wrote:
On Wed, Jun 13, 2012 at 9:18 AM, Carsten Edenfeld<[email protected]> wrote:
I am trying to use the libunwind library for getting a callstack while my
application crashes with a segmentation fault signal.
But, if the app crashes, I do not get a correct callstack, but always this
output:
_ZL13check_sys_sigi
__restore_rt
If I am using the unwind code without a (forced) exception, but instead
directly calling the following function, everything works as expected:
I don't see anything immediately wrong with your code, and it is expected
to work (and does work here).
Please post a complete compilable test case, and also tell us what OS, what
processor, which version of libunwind and which version of GCC you are using.
One other possibly useful test is to run the program under GDB, set a
breakpoint on show_backtrace, wait for SIGSEGV and continue with "signal
SIGSEGV". At that point you should hit the breakpoint in GDB. What does
the GDB backtrace command show?
Hi,
Thanks for the answers.
I have now attached a repro case, which outputs the same results here. I
have also forgotten to post a perhaps relevant function in my last mail
(if you want to have a direct look at it without compiling...):
static sighandler_t sys_signal_add (int sig_nr, sighandler_t signalhandler)
{
struct sigaction add_sig;
if (sigaction (sig_nr, NULL, &add_sig) < 0) return SIG_ERR;
add_sig.sa_handler = signalhandler;
sigaddset (&add_sig.sa_mask, sig_nr);
add_sig.sa_flags = SA_RESTART;
if (sigaction (sig_nr, &add_sig, NULL) < 0) return SIG_ERR;
return add_sig.sa_handler;
}
I am using gcc 4.6.2 on a x64 suse 12.1 system with libunwind version
0.98.6-39.1.2, QT Version 4.7.4 and Kernel Version 3.1.10-1.9-desktop
#1 SMP PREEMPT Thu Apr 5 18:48:38 UTC 2012 (4a97ec8) x86_64 x86_64
x86_64 GNU/Linux
If I am just running my executable with gdb, I got the following output:
(Interestingly, the given callstack here is also the correct one.)
GNU gdb (GDB) SUSE (7.3-41.1.2)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-suse-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/carsten/ExceptionRepro/ExceptionRepro...done.
(gdb) run
Starting program: /home/carsten/ExceptionRepro/ExceptionRepro
Missing separate debuginfo for /lib64/ld-linux-x86-64.so.2
Try: zypper install -C
"debuginfo(build-id)=f20c99249f5a5776e1377d3bd728502e3f455a3f"
Missing separate debuginfo for /lib64/libunwind.so.7
Try: zypper install -C
"debuginfo(build-id)=b3dfa390276ecba7fe44ecd6683e19da371abfd0"
Missing separate debuginfo for /usr/lib64/libunwind-x86_64.so.7
Try: zypper install -C
"debuginfo(build-id)=1ac98809fd83cb317bf422528aafd29a0ae63444"
Missing separate debuginfo for /lib64/libpthread.so.0
Try: zypper install -C
"debuginfo(build-id)=1f368f83b776815033caab6e389d7030bba4593e"
[Thread debugging using libthread_db enabled]
Missing separate debuginfo for /usr/lib64/libstdc++.so.6
Try: zypper install -C
"debuginfo(build-id)=9642fa8658fd6cc04fd33d55ad2d95658bb7360b"
Missing separate debuginfo for /lib64/libm.so.6
Try: zypper install -C
"debuginfo(build-id)=8ee6418257efac9e7fbadc657c30c62e0a002d57"
Missing separate debuginfo for /lib64/libgcc_s.so.1
Try: zypper install -C
"debuginfo(build-id)=04626951231c50274a41cb283a3a41208ac47efe"
Missing separate debuginfo for /lib64/libc.so.6
Try: zypper install -C
"debuginfo(build-id)=7b169b1db50384b70e3e4b4884cd56432d5de796"
Missing separate debuginfo for /lib64/libz.so.1
Try: zypper install -C
"debuginfo(build-id)=f5011618a4da73cd48cd503403ef6c6bc6b16fc8"
Missing separate debuginfo for /lib64/libdl.so.2
Try: zypper install -C
"debuginfo(build-id)=8d32fdb9682242cc2ebc1d9e6d717c6eaa51714e"
Missing separate debuginfo for /usr/lib64/libgthread-2.0.so.0
Try: zypper install -C
"debuginfo(build-id)=726132cc660b46e6762990c41610a991e033d798"
Missing separate debuginfo for /lib64/librt.so.1
Try: zypper install -C
"debuginfo(build-id)=b38afcf428f2107c56c0939b59ef737a5571348c"
Missing separate debuginfo for /usr/lib64/libglib-2.0.so.0
Try: zypper install -C
"debuginfo(build-id)=1684af5007b4586de35609d69c79676b57fdd3e2"
Missing separate debuginfo for /lib64/libpcre.so.0
Try: zypper install -C
"debuginfo(build-id)=fd3d7de0c30920f167970d38874643e0ae4ac637"
Missing separate debuginfo for /usr/lib64/gconv/UTF-16.so
Try: zypper install -C
"debuginfo(build-id)=da190967b4f242573065a61fcbaa066d238305fb"
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400b6f in main ()
(gdb)
Not sure, how I should debug the program with gdb though as you have
described it.
If I am entering ...
'gdb ExceptionRepro'
'break show_backtrace()'
'run'
...I am already getting the exception and thus are not able to
"wait for SIGSEGV and continue with "signal SIGSEGV"
as the signal is already being handled at this position ?
Thanks and Regards,
Carsten Edenfeld
#-------------------------------------------------
#
# Project created by QtCreator 2012-06-14T11:55:50
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = ExceptionRepro
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
LIBS += -lunwind \
-lunwind-x86_64
# -lSegFault \
#include <QCoreApplication>
#include "libunwind.h"
#include <stdio.h>
#include <sys/sysinfo.h>
#include <signal.h>
void show_backtrace (void)
{
char name[256];
unw_cursor_t cursor;
unw_word_t ip, sp, offp;
unw_context_t uc;
unw_getcontext(&uc);
if ( unw_init_local(&cursor, &uc) != 0)
{
return;
}
while (unw_step(&cursor) > 0)
{
char file[256];
int line = 0;
name[0] = '\0';
int iResult = unw_get_proc_name(&cursor, name, 256, &offp);
if ( iResult != UNW_ESUCCESS )
{
return;
}
unw_get_reg(&cursor, UNW_REG_IP, &ip);
unw_get_reg(&cursor, UNW_REG_SP, &sp);
printf ("%s ip = %lx, sp = %lx\n", name, (long) ip, (long) sp);
}
}
static sighandler_t sys_signal_add (int sig_nr, sighandler_t signalhandler)
{
struct sigaction add_sig;
if (sigaction (sig_nr, NULL, &add_sig) < 0) return SIG_ERR;
add_sig.sa_handler = signalhandler;
sigaddset (&add_sig.sa_mask, sig_nr);
add_sig.sa_flags = SA_RESTART;
if (sigaction (sig_nr, &add_sig, NULL) < 0) return SIG_ERR;
return add_sig.sa_handler;
}
static void check_sys_sig ( int sig_nr )
{
show_backtrace();
raise (SIGKILL);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
sys_signal_add (SIGSEGV, check_sys_sig);
*(int *)0=0;
return a.exec();
}
#############################################################################
# Makefile for building: ExceptionRepro
# Generated by qmake (2.01a) (Qt 4.8.1) on: Thu Jun 14 11:57:02 2012
# Project: ExceptionRepro.pro
# Template: app
# Command: /usr/bin/qmake -spec /usr/share/qt4/mkspecs/linux-g++ -o Makefile
ExceptionRepro.pro
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore
-I/usr/include -I.
LINK = g++
LFLAGS = -Wl,-O1
LIBS = $(SUBLIBS) -L/usr/lib64 -lunwind -lunwind-x86_64 -lQtCore
-L/usr/lib64 -lpthread
AR = ar cqs
RANLIB =
QMAKE = /usr/bin/qmake
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
SED = sed
COPY_FILE = $(COPY)
COPY_DIR = $(COPY) -r
STRIP = strip
INSTALL_FILE = install -m 644 -p
INSTALL_DIR = $(COPY_DIR)
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
####### Output directory
OBJECTS_DIR = ./
####### Files
SOURCES = main.cpp
OBJECTS = main.o
DIST = /usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/common/gcc-base.conf \
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
/usr/share/qt4/mkspecs/common/g++-base.conf \
/usr/share/qt4/mkspecs/common/g++-unix.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/release.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/qt.prf \
/usr/share/qt4/mkspecs/features/unix/thread.prf \
/usr/share/qt4/mkspecs/features/moc.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
/usr/share/qt4/mkspecs/features/yacc.prf \
/usr/share/qt4/mkspecs/features/lex.prf \
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
ExceptionRepro.pro
QMAKE_TARGET = ExceptionRepro
DESTDIR =
TARGET = ExceptionRepro
first: all
####### Implicit rules
.SUFFIXES: .o .c .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
####### Build rules
all: Makefile $(TARGET)
$(TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
Makefile: ExceptionRepro.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf
/usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/common/gcc-base.conf \
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
/usr/share/qt4/mkspecs/common/g++-base.conf \
/usr/share/qt4/mkspecs/common/g++-unix.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/release.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/qt.prf \
/usr/share/qt4/mkspecs/features/unix/thread.prf \
/usr/share/qt4/mkspecs/features/moc.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
/usr/share/qt4/mkspecs/features/yacc.prf \
/usr/share/qt4/mkspecs/features/lex.prf \
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
/usr/lib64/libQtCore.prl
$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -o Makefile
ExceptionRepro.pro
/usr/share/qt4/mkspecs/common/unix.conf:
/usr/share/qt4/mkspecs/common/linux.conf:
/usr/share/qt4/mkspecs/common/gcc-base.conf:
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf:
/usr/share/qt4/mkspecs/common/g++-base.conf:
/usr/share/qt4/mkspecs/common/g++-unix.conf:
/usr/share/qt4/mkspecs/qconfig.pri:
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri:
/usr/share/qt4/mkspecs/features/qt_functions.prf:
/usr/share/qt4/mkspecs/features/qt_config.prf:
/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
/usr/share/qt4/mkspecs/features/default_pre.prf:
/usr/share/qt4/mkspecs/features/release.prf:
/usr/share/qt4/mkspecs/features/default_post.prf:
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf:
/usr/share/qt4/mkspecs/features/warn_on.prf:
/usr/share/qt4/mkspecs/features/qt.prf:
/usr/share/qt4/mkspecs/features/unix/thread.prf:
/usr/share/qt4/mkspecs/features/moc.prf:
/usr/share/qt4/mkspecs/features/resources.prf:
/usr/share/qt4/mkspecs/features/uic.prf:
/usr/share/qt4/mkspecs/features/yacc.prf:
/usr/share/qt4/mkspecs/features/lex.prf:
/usr/share/qt4/mkspecs/features/include_source_dir.prf:
/usr/lib64/libQtCore.prl:
qmake: FORCE
@$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -o Makefile
ExceptionRepro.pro
dist:
@$(CHK_DIR_EXISTS) .tmp/ExceptionRepro1.0.0 || $(MKDIR)
.tmp/ExceptionRepro1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/ExceptionRepro1.0.0/ &&
$(COPY_FILE) --parents main.cpp .tmp/ExceptionRepro1.0.0/ && (cd `dirname
.tmp/ExceptionRepro1.0.0` && $(TAR) ExceptionRepro1.0.0.tar ExceptionRepro1.0.0
&& $(COMPRESS) ExceptionRepro1.0.0.tar) && $(MOVE) `dirname
.tmp/ExceptionRepro1.0.0`/ExceptionRepro1.0.0.tar.gz . && $(DEL_FILE) -r
.tmp/ExceptionRepro1.0.0
clean:compiler_clean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Sub-libraries
distclean: clean
-$(DEL_FILE) $(TARGET)
-$(DEL_FILE) Makefile
check: first
mocclean: compiler_moc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
compiler_moc_header_make_all:
compiler_moc_header_clean:
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean:
####### Compile
main.o: main.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:
_______________________________________________
Libunwind-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/libunwind-devel