added libunwind interface support for stack frame backtracing
This commit is contained in:
@ -28,6 +28,9 @@ else
|
||||
LIBADD_LIB_COMMON += $(DL_LIBS)
|
||||
endif
|
||||
|
||||
if ENABLE_LIBUNWIND
|
||||
LIBADD_LIB_COMMON += $(UNWIND_LIBS)
|
||||
endif
|
||||
|
||||
pkgincludedir = $(includedir)
|
||||
pkglibdir = $(libdir)
|
||||
|
@ -90,15 +90,16 @@ build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
@ENABLE_LIBLTDL_TRUE@am__append_1 = $(LTDL_LIBS)
|
||||
@ENABLE_LIBLTDL_FALSE@am__append_2 = $(DL_LIBS)
|
||||
@ENABLE_STATIC_MODULE_TRUE@am__append_3 = -lhcl-arr -lhcl-dic \
|
||||
@ENABLE_LIBUNWIND_TRUE@am__append_3 = $(UNWIND_LIBS)
|
||||
@ENABLE_STATIC_MODULE_TRUE@am__append_4 = -lhcl-arr -lhcl-dic \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ -lhcl-str
|
||||
@ENABLE_STATIC_MODULE_TRUE@am__append_4 = $(abs_builddir)/../mod/libhcl-arr.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@am__append_5 = $(abs_builddir)/../mod/libhcl-arr.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-dic.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-str.la
|
||||
bin_PROGRAMS = hcl$(EXEEXT) $(am__EXEEXT_1)
|
||||
@ENABLE_HCLEX_TRUE@am__append_5 = libhclex.la
|
||||
@ENABLE_HCLEX_TRUE@am__append_6 = hcl-c.h hcl-s.h hcl-tmr.h hcl-xutl.h hcl-json.h
|
||||
@ENABLE_HCLEX_TRUE@am__append_7 = hcls hclc hclj
|
||||
@ENABLE_HCLEX_TRUE@am__append_6 = libhclex.la
|
||||
@ENABLE_HCLEX_TRUE@am__append_7 = hcl-c.h hcl-s.h hcl-tmr.h hcl-xutl.h hcl-json.h
|
||||
@ENABLE_HCLEX_TRUE@am__append_8 = hcls hclc hclj
|
||||
subdir = lib
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
|
||||
@ -148,8 +149,9 @@ LTLIBRARIES = $(pkglib_LTLIBRARIES)
|
||||
am__DEPENDENCIES_1 =
|
||||
@ENABLE_LIBLTDL_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
@ENABLE_LIBLTDL_FALSE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
|
||||
am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
|
||||
$(am__DEPENDENCIES_3)
|
||||
@ENABLE_LIBUNWIND_TRUE@am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1)
|
||||
am__DEPENDENCIES_5 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
|
||||
$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4)
|
||||
am_libhcl_la_OBJECTS = libhcl_la-bigint.lo libhcl_la-comp.lo \
|
||||
libhcl_la-debug.lo libhcl_la-decode.lo libhcl_la-dic.lo \
|
||||
libhcl_la-err.lo libhcl_la-exec.lo libhcl_la-gc.lo \
|
||||
@ -370,6 +372,7 @@ SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
UNICOWS_LIBS = @UNICOWS_LIBS@
|
||||
UNWIND_LIBS = @UNWIND_LIBS@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
@ -417,7 +420,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
@ -441,10 +443,11 @@ CPPFLAGS_ALL_COMMON = \
|
||||
##################################################
|
||||
CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON)
|
||||
LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined
|
||||
LIBADD_LIB_COMMON = $(LIBM) $(am__append_1) $(am__append_2)
|
||||
LIBADD_LIB_COMMON = $(LIBM) $(am__append_1) $(am__append_2) \
|
||||
$(am__append_3)
|
||||
pkginclude_HEADERS = hcl.h hcl-cmn.h hcl-opt.h hcl-rbt.h hcl-utl.h \
|
||||
$(am__append_6)
|
||||
pkglib_LTLIBRARIES = libhcl.la $(am__append_5)
|
||||
$(am__append_7)
|
||||
pkglib_LTLIBRARIES = libhcl.la $(am__append_6)
|
||||
libhcl_la_SOURCES = \
|
||||
hcl.h \
|
||||
hcl-cmn.h \
|
||||
@ -478,8 +481,8 @@ libhcl_la_SOURCES = \
|
||||
|
||||
libhcl_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||
libhcl_la_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||
libhcl_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_3)
|
||||
libhcl_la_DEPENDENCIES = $(am__append_4)
|
||||
libhcl_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_4)
|
||||
libhcl_la_DEPENDENCIES = $(am__append_5)
|
||||
hcl_SOURCES = main.c
|
||||
hcl_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||
hcl_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||
|
59
lib/err.c
59
lib/err.c
@ -26,6 +26,10 @@
|
||||
|
||||
#include "hcl-prv.h"
|
||||
|
||||
#if defined(HCL_ENABLE_LIBUNWIND)
|
||||
# include <libunwind.h>
|
||||
#endif
|
||||
|
||||
static hcl_ooch_t errstr_0[] = {'n','o',' ','e','r','r','o','r','\0'};
|
||||
static hcl_ooch_t errstr_1[] = {'g','e','n','e','r','i','c',' ','e','r','r','o','r','\0'};
|
||||
static hcl_ooch_t errstr_2[] = {'n','o','t',' ','i','m','p','l','e','m','e','n','t','e','d','\0'};
|
||||
@ -472,22 +476,45 @@ void hcl_setsynerrufmt (hcl_t* hcl, hcl_synerrnum_t num, const hcl_ioloc_t* loc,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* ASSERTION FAILURE HANDLERsemaphore heap full
|
||||
* STACK FRAME BACKTRACE
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
void hcl_assertfailed (hcl_t* hcl, const hcl_bch_t* expr, const hcl_bch_t* file, hcl_oow_t line)
|
||||
#if defined(HCL_ENABLE_LIBUNWIND)
|
||||
static void backtrace_stack_frames (hcl_t* hcl)
|
||||
{
|
||||
unw_cursor_t cursor;
|
||||
unw_context_t context;
|
||||
|
||||
unw_getcontext(&context);
|
||||
unw_init_local(&cursor, &context);
|
||||
|
||||
int n=0;
|
||||
while (unw_step(&cursor))
|
||||
{
|
||||
unw_word_t ip, sp, off;
|
||||
|
||||
unw_get_reg (&cursor, UNW_REG_IP, &ip);
|
||||
unw_get_reg (&cursor, UNW_REG_SP, &sp);
|
||||
|
||||
char symbol[256];
|
||||
|
||||
if (!unw_get_proc_name(&cursor, symbol, HCL_COUNTOF(symbol), &off))
|
||||
{
|
||||
hcl_copy_bcstr (symbol, "<unknown>");
|
||||
}
|
||||
|
||||
hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_DEBUG,
|
||||
"#%-2d 0x%016p p=0x%016p %s + 0x%zu\n",
|
||||
++n, (void*)ip, (void*)sp, symbol, (hcl_oow_t)off);
|
||||
}
|
||||
}
|
||||
#elif defined(HAVE_BACKTRACE)
|
||||
static void backtrace_stack_frames (hcl_t* hcl)
|
||||
{
|
||||
#if defined(HAVE_BACKTRACE)
|
||||
void* btarray[128];
|
||||
hcl_oow_t btsize;
|
||||
char** btsyms;
|
||||
#endif
|
||||
|
||||
hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_FATAL, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line);
|
||||
|
||||
#if defined(HAVE_BACKTRACE)
|
||||
btsize = backtrace (btarray, HCL_COUNTOF(btarray));
|
||||
btsyms = backtrace_symbols (btarray, btsize);
|
||||
if (btsyms)
|
||||
@ -501,8 +528,22 @@ void hcl_assertfailed (hcl_t* hcl, const hcl_bch_t* expr, const hcl_bch_t* file,
|
||||
}
|
||||
free (btsyms);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void backtrace_stack_frames (hcl_t* hcl)
|
||||
{
|
||||
/* do nothing. not supported */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* ASSERTION FAILURE HANDLERsemaphore heap full
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
void hcl_assertfailed (hcl_t* hcl, const hcl_bch_t* expr, const hcl_bch_t* file, hcl_oow_t line)
|
||||
{
|
||||
hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_FATAL, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line);
|
||||
backtrace_stack_frames (hcl);
|
||||
|
||||
#if defined(_WIN32)
|
||||
ExitProcess (249);
|
||||
|
@ -81,6 +81,9 @@
|
||||
/* Define to 1 if you have the `isatty' function. */
|
||||
#undef HAVE_ISATTY
|
||||
|
||||
/* Define to 1 if you have the <libunwind.h> header file. */
|
||||
#undef HAVE_LIBUNWIND_H
|
||||
|
||||
/* Define to 1 if you have the `log10q' function. */
|
||||
#undef HAVE_LOG10Q
|
||||
|
||||
@ -213,6 +216,9 @@
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* libunwind is available */
|
||||
#undef HAVE_UNWIND_LIB
|
||||
|
||||
/* Define to 1 if you have the `usleep' function. */
|
||||
#undef HAVE_USLEEP
|
||||
|
||||
@ -264,6 +270,9 @@
|
||||
/* use libltdl when loading a dynamic module */
|
||||
#undef HCL_ENABLE_LIBLTDL
|
||||
|
||||
/* use libunwind for backtracing stack frames */
|
||||
#undef HCL_ENABLE_LIBUNWIND
|
||||
|
||||
/* link modules statically into the main library */
|
||||
#undef HCL_ENABLE_STATIC_MODULE
|
||||
|
||||
|
Reference in New Issue
Block a user