diff --git a/moo/Makefile.in b/moo/Makefile.in index 2105b34..9e029b0 100644 --- a/moo/Makefile.in +++ b/moo/Makefile.in @@ -355,7 +355,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -586,7 +585,7 @@ distdir: $(DISTFILES) ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir - tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz $(am__post_remove_distdir) dist-bzip2: distdir @@ -612,7 +611,7 @@ dist-shar: distdir @echo WARNING: "Support for shar distribution archives is" \ "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 - shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz + shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir @@ -630,7 +629,7 @@ dist dist-all: distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lz*) \ @@ -640,7 +639,7 @@ distcheck: dist *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac diff --git a/moo/configure b/moo/configure index f68671d..f6da54c 100755 --- a/moo/configure +++ b/moo/configure @@ -657,6 +657,8 @@ ENABLE_MOD_FFI_FALSE ENABLE_MOD_FFI_TRUE ENABLE_MOD_CON_FALSE ENABLE_MOD_CON_TRUE +ENABLE_LIBUNWIND_FALSE +ENABLE_LIBUNWIND_TRUE ENABLE_LIBLTDL_FALSE ENABLE_LIBLTDL_TRUE ENABLE_STATIC_MODULE_FALSE @@ -787,7 +789,6 @@ infodir docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -826,6 +827,7 @@ enable_cxx enable_dynamic_module enable_static_module enable_libltdl +enable_libunwind enable_mod_con enable_mod_ffi enable_mod_sck @@ -883,7 +885,6 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1136,15 +1137,6 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1282,7 +1274,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1435,7 +1427,6 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1495,6 +1486,7 @@ Optional Features: --enable-static-module build modules statically into the main library(default. no) --enable-libltdl use libltdl(default. no) + --enable-libunwind use libunwind(default. no) --enable-mod-con enable mod/con (default. yes) --enable-mod-ffi enable mod/ffi (default. yes) --enable-mod-sck enable mod/sck (default. yes) @@ -21528,6 +21520,34 @@ else fi +# Check whether --enable-libunwind was given. +if test "${enable_libunwind+set}" = set; then : + enableval=$enable_libunwind; enable_libunwind_is=$enableval +else + enable_libunwind_is=no + +fi + +if test "x${enable_libunwind_is}" = "xyes" +then + if test "x${ac_cv_header_unwind_h}" = "xyes" -a "${UNWIND_LIBS}" != "" + then + +$as_echo "#define MOO_ENABLE_LIBUNWIND /**/" >>confdefs.h + + else + enable_libunwind_is="no" + fi +fi + if test "x${enable_libunwind_is}" = "xyes"; then + ENABLE_LIBUNWIND_TRUE= + ENABLE_LIBUNWIND_FALSE='#' +else + ENABLE_LIBUNWIND_TRUE='#' + ENABLE_LIBUNWIND_FALSE= +fi + + # Check whether --enable-mod-con was given. if test "${enable_mod_con+set}" = set; then : enableval=$enable_mod_con; enable_mod_con_is=$enableval @@ -21814,6 +21834,10 @@ if test -z "${ENABLE_LIBLTDL_TRUE}" && test -z "${ENABLE_LIBLTDL_FALSE}"; then as_fn_error $? "conditional \"ENABLE_LIBLTDL\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${ENABLE_LIBUNWIND_TRUE}" && test -z "${ENABLE_LIBUNWIND_FALSE}"; then + as_fn_error $? "conditional \"ENABLE_LIBUNWIND\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${ENABLE_MOD_CON_TRUE}" && test -z "${ENABLE_MOD_CON_FALSE}"; then as_fn_error $? "conditional \"ENABLE_MOD_CON\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 diff --git a/moo/configure.ac b/moo/configure.ac index e38f824..6818112 100644 --- a/moo/configure.ac +++ b/moo/configure.ac @@ -737,6 +737,23 @@ then fi AM_CONDITIONAL(ENABLE_LIBLTDL, test "x${enable_libltdl_is}" = "xyes") +dnl ===== enable-libunwind ===== +AC_ARG_ENABLE([libunwind], + [AS_HELP_STRING([--enable-libunwind],[use libunwind(default. no)])], + enable_libunwind_is=$enableval, + enable_libunwind_is=no +) +if test "x${enable_libunwind_is}" = "xyes" +then + if test "x${ac_cv_header_unwind_h}" = "xyes" -a "${UNWIND_LIBS}" != "" + then + AC_DEFINE([MOO_ENABLE_LIBUNWIND],[],[use libunwind for backtracing stack frames]) + else + enable_libunwind_is="no" + fi +fi +AM_CONDITIONAL(ENABLE_LIBUNWIND, test "x${enable_libunwind_is}" = "xyes") + dnl ===== enable-mod-con ===== AC_ARG_ENABLE([mod-con], [AS_HELP_STRING([--enable-mod-con],[enable mod/con (default. yes)])], diff --git a/moo/lib/Makefile.am b/moo/lib/Makefile.am index 29d7e25..3ca7c34 100644 --- a/moo/lib/Makefile.am +++ b/moo/lib/Makefile.am @@ -27,6 +27,10 @@ else LIBADD_LIB_COMMON += $(DL_LIBS) endif +if ENABLE_LIBUNWIND +LIBADD_LIB_COMMON += $(UNWIND_LIBS) +endif + if WIN32 # you must adjust the value of DEFAULT_MODPOSTFIX according # to the first number in -version-info above diff --git a/moo/lib/Makefile.in b/moo/lib/Makefile.in index b09dd70..b67f6e6 100644 --- a/moo/lib/Makefile.in +++ b/moo/lib/Makefile.in @@ -90,29 +90,30 @@ build_triplet = @build@ host_triplet = @host@ @ENABLE_LIBLTDL_TRUE@am__append_1 = $(LTDL_LIBS) @ENABLE_LIBLTDL_FALSE@am__append_2 = $(DL_LIBS) +@ENABLE_LIBUNWIND_TRUE@am__append_3 = $(UNWIND_LIBS) # you must adjust the value of DEFAULT_MODPOSTFIX according # to the first number in -version-info above -@WIN32_TRUE@am__append_3 = -DMOO_DEFAULT_MODPREFIX=\"libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"-1\" -@WIN32_FALSE@am__append_4 = -DMOO_DEFAULT_MODPREFIX=\"$(libdir)/libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"\" -@ENABLE_STATIC_MODULE_TRUE@am__append_5 = -lmoo-stdio +@WIN32_TRUE@am__append_4 = -DMOO_DEFAULT_MODPREFIX=\"libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"-1\" +@WIN32_FALSE@am__append_5 = -DMOO_DEFAULT_MODPREFIX=\"$(libdir)/libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"\" +@ENABLE_STATIC_MODULE_TRUE@am__append_6 = -lmoo-stdio @ENABLE_STATIC_MODULE_FALSE@libmoo_la_DEPENDENCIES = \ -@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_4) \ +@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_5) \ @ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) \ @ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) \ @ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) \ @ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) \ @ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) -@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_6 = -lmoo-con -@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_7 = $(abs_builddir)/../mod/libmoo-con.la -@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_8 = -lmoo-ffi -@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_9 = $(abs_builddir)/../mod/libmoo-ffi.la -@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_10 = -lmoo-sck -@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_11 = $(abs_builddir)/../mod/libmoo-sck.la -@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_12 = -lmoo-x11 -@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_13 = $(abs_builddir)/../mod/libmoo-x11.la +@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_7 = -lmoo-con +@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_8 = $(abs_builddir)/../mod/libmoo-con.la +@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_9 = -lmoo-ffi +@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_10 = $(abs_builddir)/../mod/libmoo-ffi.la +@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_11 = -lmoo-sck +@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_12 = $(abs_builddir)/../mod/libmoo-sck.la +@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_13 = -lmoo-x11 +@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_14 = $(abs_builddir)/../mod/libmoo-x11.la bin_PROGRAMS = moo$(EXEEXT) -@ENABLE_STATIC_MODULE_FALSE@moo_DEPENDENCIES = $(am__DEPENDENCIES_4) \ +@ENABLE_STATIC_MODULE_FALSE@moo_DEPENDENCIES = $(am__DEPENDENCIES_5) \ @ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) subdir = lib ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -163,8 +164,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_libmoo_la_OBJECTS = libmoo_la-bigint.lo libmoo_la-comp.lo \ libmoo_la-debug.lo libmoo_la-decode.lo libmoo_la-dic.lo \ libmoo_la-err.lo libmoo_la-exec.lo libmoo_la-logfmt.lo \ @@ -398,7 +400,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -420,10 +421,11 @@ CPPFLAGS_ALL_COMMON = \ ################################################## # MAIN LIBRARY ################################################## -CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON) $(am__append_3) \ - $(am__append_4) +CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON) $(am__append_4) \ + $(am__append_5) 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 = \ moo.h \ moo-bct.h \ @@ -467,12 +469,12 @@ libmoo_la_SOURCES = \ libmoo_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) libmoo_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) -libmoo_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_5) \ - $(am__append_6) $(am__append_8) $(am__append_10) \ - $(am__append_12) +libmoo_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_6) \ + $(am__append_7) $(am__append_9) $(am__append_11) \ + $(am__append_13) @ENABLE_STATIC_MODULE_TRUE@libmoo_la_DEPENDENCIES = $(abs_builddir)/../mod/libmoo-stdio.la \ -@ENABLE_STATIC_MODULE_TRUE@ $(am__append_7) $(am__append_9) \ -@ENABLE_STATIC_MODULE_TRUE@ $(am__append_11) $(am__append_13) +@ENABLE_STATIC_MODULE_TRUE@ $(am__append_8) $(am__append_10) \ +@ENABLE_STATIC_MODULE_TRUE@ $(am__append_12) $(am__append_14) moo_SOURCES = main.c moo_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) moo_LDFLAGS = $(LDFLAGS_LIB_COMMON) diff --git a/moo/lib/err.c b/moo/lib/err.c index ae06395..667e12c 100644 --- a/moo/lib/err.c +++ b/moo/lib/err.c @@ -26,6 +26,9 @@ #include "moo-prv.h" +#if defined(MOO_ENABLE_LIBUNWIND) +# include +#endif /* BEGIN: GENERATED WITH generr.moo */ @@ -466,21 +469,44 @@ void moo_setsynerr (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, con #endif /* -------------------------------------------------------------------------- - * ASSERTION FAILURE HANDLERsemaphore heap full + * STACK FRAME BACKTRACE * -------------------------------------------------------------------------- */ - -void moo_assertfailed (moo_t* moo, const moo_bch_t* expr, const moo_bch_t* file, moo_oow_t line) +#if defined(MOO_ENABLE_LIBUNWIND) +void backtrace_stack_frames (moo_t* moo) +{ + 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, MOO_COUNTOF(symbol), &off)) + { + moo_copy_bcstr (symbol, ""); + } + + moo_logbfmt (moo, MOO_LOG_UNTYPED | MOO_LOG_DEBUG, + "#%-2d 0x%016p p=0x%016p %s + 0x%zu\n", + ++n, (void*)ip, (void*)sp, symbol, (moo_oow_t)off); + } +} +#elif defined(HAVE_BACKTRACE) +void backtrace_stack_frames (moo_t* moo) { -#if defined(HAVE_BACKTRACE) void* btarray[128]; moo_oow_t btsize; char** btsyms; -#endif - moo_logbfmt (moo, MOO_LOG_UNTYPED | MOO_LOG_FATAL, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line); - - -#if defined(HAVE_BACKTRACE) btsize = backtrace (btarray, MOO_COUNTOF(btarray)); btsyms = backtrace_symbols (btarray, btsize); if (btsyms) @@ -494,8 +520,23 @@ void moo_assertfailed (moo_t* moo, const moo_bch_t* expr, const moo_bch_t* file, } free (btsyms); } +} +#else +void backtrace_stack_frames (moo_t* moo) +{ + /* do nothing. not supported */ +} #endif +/* -------------------------------------------------------------------------- + * ASSERTION FAILURE HANDLER + * -------------------------------------------------------------------------- */ + + +void moo_assertfailed (moo_t* moo, const moo_bch_t* expr, const moo_bch_t* file, moo_oow_t line) +{ + moo_logbfmt (moo, MOO_LOG_UNTYPED | MOO_LOG_FATAL, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line); + backtrace_stack_frames (moo); #if defined(_WIN32) ExitProcess (249); diff --git a/moo/lib/exec.c b/moo/lib/exec.c index d60cfc9..c608349 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -1841,7 +1841,7 @@ static moo_pfrc_t pf_dump (moo_t* moo, moo_ooi_t nargs) return MOO_PF_SUCCESS; } -static void log_char_object (moo_t* moo, moo_oow_t mask, moo_oop_char_t msg) +static void log_char_object (moo_t* moo, moo_log_masks_t mask, moo_oop_char_t msg) { moo_ooi_t n; moo_oow_t rem; @@ -3354,7 +3354,7 @@ static moo_pfrc_t pf_strlen (moo_t* moo, moo_ooi_t nargs) static moo_pfrc_t pf_system_log (moo_t* moo, moo_ooi_t nargs) { moo_oop_t msg, level; - moo_oow_t mask; + moo_log_masks_t mask; moo_ooi_t k; MOO_ASSERT (moo, nargs >= 2); diff --git a/moo/lib/logfmt.c b/moo/lib/logfmt.c index 98a4d64..c441468 100644 --- a/moo/lib/logfmt.c +++ b/moo/lib/logfmt.c @@ -129,15 +129,15 @@ static moo_uch_t uch_nullstr[] = { '(','n','u','l','l', ')','\0' }; static moo_bch_t bch_nullstr[] = { '(','n','u','l','l', ')','\0' }; typedef int (*moo_fmtout_putch_t) ( - moo_t* moo, - moo_oow_t mask, - moo_ooch_t c, - moo_oow_t len + moo_t* moo, + moo_log_masks_t mask, + moo_ooch_t c, + moo_oow_t len ); typedef int (*moo_fmtout_putcs_t) ( moo_t* moo, - moo_oow_t mask, + moo_log_masks_t mask, const moo_ooch_t* ptr, moo_oow_t len ); @@ -146,7 +146,7 @@ typedef struct moo_fmtout_t moo_fmtout_t; struct moo_fmtout_t { moo_oow_t count; /* out */ - moo_oow_t mask; /* in */ + moo_log_masks_t mask; /* in */ moo_fmtout_putch_t putch; /* in */ moo_fmtout_putcs_t putcs; /* in */ }; @@ -184,7 +184,7 @@ static moo_bch_t* sprintn_upper (moo_bch_t* nbuf, moo_uintmax_t num, int base, m } /* ------------------------------------------------------------------------- */ -static int put_ooch (moo_t* moo, moo_oow_t mask, moo_ooch_t ch, moo_oow_t len) +static int put_ooch (moo_t* moo, moo_log_masks_t mask, moo_ooch_t ch, moo_oow_t len) { /* this is not equivalent to put_oocs(moo,mask,&ch, 1); * this function is to emit a single character multiple times */ @@ -281,7 +281,7 @@ redo: return 1; /* success */ } -static int put_oocs (moo_t* moo, moo_oow_t mask, const moo_ooch_t* ptr, moo_oow_t len) +static int put_oocs (moo_t* moo, moo_log_masks_t mask, const moo_ooch_t* ptr, moo_oow_t len) { moo_oow_t rem; @@ -374,9 +374,9 @@ redo: /* ------------------------------------------------------------------------- */ -typedef moo_ooi_t (*outbfmt_t) (moo_t* moo, moo_oow_t mask, const moo_bch_t* fmt, ...); +typedef moo_ooi_t (*outbfmt_t) (moo_t* moo, moo_log_masks_t mask, const moo_bch_t* fmt, ...); -static int print_object (moo_t* moo, moo_oow_t mask, moo_oop_t oop, outbfmt_t outbfmt) +static int print_object (moo_t* moo, moo_log_masks_t mask, moo_oop_t oop, outbfmt_t outbfmt) { if (oop == moo->_nil) { @@ -612,7 +612,7 @@ static int _logufmtv (moo_t* moo, const moo_uch_t* fmt, moo_fmtout_t* data, va_l return __logufmtv (moo, fmt, data, ap, moo_logbfmt); } -moo_ooi_t moo_logbfmt (moo_t* moo, moo_oow_t mask, const moo_bch_t* fmt, ...) +moo_ooi_t moo_logbfmt (moo_t* moo, moo_log_masks_t mask, const moo_bch_t* fmt, ...) { int x; va_list ap; @@ -645,7 +645,7 @@ moo_ooi_t moo_logbfmt (moo_t* moo, moo_oow_t mask, const moo_bch_t* fmt, ...) return (x <= -1)? -1: fo.count; } -moo_ooi_t moo_logufmt (moo_t* moo, moo_oow_t mask, const moo_uch_t* fmt, ...) +moo_ooi_t moo_logufmt (moo_t* moo, moo_log_masks_t mask, const moo_uch_t* fmt, ...) { int x; va_list ap; @@ -679,7 +679,7 @@ moo_ooi_t moo_logufmt (moo_t* moo, moo_oow_t mask, const moo_uch_t* fmt, ...) * ERROR MESSAGE FORMATTING * -------------------------------------------------------------------------- */ -static int put_errch (moo_t* moo, moo_oow_t mask, moo_ooch_t ch, moo_oow_t len) +static int put_errch (moo_t* moo, moo_log_masks_t mask, moo_ooch_t ch, moo_oow_t len) { moo_oow_t max; @@ -698,7 +698,7 @@ static int put_errch (moo_t* moo, moo_oow_t mask, moo_ooch_t ch, moo_oow_t len) return 1; /* success */ } -static int put_errcs (moo_t* moo, moo_oow_t mask, const moo_ooch_t* ptr, moo_oow_t len) +static int put_errcs (moo_t* moo, moo_log_masks_t mask, const moo_ooch_t* ptr, moo_oow_t len) { moo_oow_t max; @@ -715,7 +715,7 @@ static int put_errcs (moo_t* moo, moo_oow_t mask, const moo_ooch_t* ptr, moo_oow } -static moo_ooi_t __errbfmtv (moo_t* moo, moo_oow_t mask, const moo_bch_t* fmt, ...); +static moo_ooi_t __errbfmtv (moo_t* moo, moo_log_masks_t mask, const moo_bch_t* fmt, ...); static int _errbfmtv (moo_t* moo, const moo_bch_t* fmt, moo_fmtout_t* data, va_list ap) { @@ -727,7 +727,7 @@ static int _errufmtv (moo_t* moo, const moo_uch_t* fmt, moo_fmtout_t* data, va_l return __logufmtv (moo, fmt, data, ap, __errbfmtv); } -static moo_ooi_t __errbfmtv (moo_t* moo, moo_oow_t mask, const moo_bch_t* fmt, ...) +static moo_ooi_t __errbfmtv (moo_t* moo, moo_log_masks_t mask, const moo_bch_t* fmt, ...) { va_list ap; moo_fmtout_t fo; diff --git a/moo/lib/main.c b/moo/lib/main.c index 6e13b06..7c91e60 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -214,7 +214,7 @@ struct xtn_t int vm_running; int logfd; - int logmask; + moo_log_masks_t logmask; int logfd_istty; struct @@ -657,7 +657,7 @@ static void flush_log (moo_t* moo, int fd) } } -static void log_write (moo_t* moo, unsigned int mask, const moo_ooch_t* msg, moo_oow_t len) +static void log_write (moo_t* moo, moo_log_masks_t mask, const moo_ooch_t* msg, moo_oow_t len) { moo_bch_t buf[256]; moo_oow_t ucslen, bcslen, msgidx; @@ -2213,7 +2213,7 @@ static int handle_logopt (moo_t* moo, const moo_bch_t* str) xtn_t* xtn = moo_getxtn (moo); moo_bch_t* xstr = (moo_bch_t*)str; moo_bch_t* cm, * flt; - unsigned int logmask; + moo_log_masks_t logmask; cm = moo_find_bchar_in_bcstr (xstr, ','); if (cm) @@ -2299,7 +2299,7 @@ static int handle_dbgopt (moo_t* moo, const moo_bch_t* str) xtn_t* xtn = moo_getxtn (moo); const moo_bch_t* cm, * flt; moo_oow_t len; - unsigned int trait, dbgopt = 0; + moo_traits_t trait, dbgopt = 0; cm = str - 1; do @@ -2467,7 +2467,7 @@ int main (int argc, char* argv[]) } { - unsigned int trait = 0; + moo_traits_t trait = 0; /*trait |= MOO_NOGC;*/ trait |= MOO_AWAIT_PROCS; diff --git a/moo/lib/moo-cfg.h.in b/moo/lib/moo-cfg.h.in index eb1d52f..bb31d38 100644 --- a/moo/lib/moo-cfg.h.in +++ b/moo/lib/moo-cfg.h.in @@ -303,6 +303,9 @@ /* use libltdl when loading a dynamic module */ #undef MOO_ENABLE_LIBLTDL +/* use libunwind for backtracing stack frames */ +#undef MOO_ENABLE_LIBUNWIND + /* build mod/con */ #undef MOO_ENABLE_MOD_CON diff --git a/moo/lib/moo.c b/moo/lib/moo.c index 936df69..7e24b6b 100644 --- a/moo/lib/moo.c +++ b/moo/lib/moo.c @@ -291,14 +291,14 @@ int moo_setoption (moo_t* moo, moo_option_t id, const void* value) switch (id) { case MOO_TRAIT: - moo->option.trait = *(const unsigned int*)value; + moo->option.trait = *(moo_traits_t*)value; #if defined(MOO_BUILD_DEBUG) moo->option.karatsuba_cutoff = ((moo->option.trait & MOO_DEBUG_BIGINT)? MOO_KARATSUBA_CUTOFF_DEBUG: MOO_KARATSUBA_CUTOFF); #endif return 0; case MOO_LOG_MASK: - moo->option.log_mask = *(const unsigned int*)value; + moo->option.log_mask = *(moo_log_masks_t*)value; return 0; case MOO_LOG_MAXCAPA: @@ -353,11 +353,11 @@ int moo_getoption (moo_t* moo, moo_option_t id, void* value) switch (id) { case MOO_TRAIT: - *(unsigned int*)value = moo->option.trait; + *(moo_traits_t*)value = moo->option.trait; return 0; case MOO_LOG_MASK: - *(unsigned int*)value = moo->option.log_mask; + *(moo_log_masks_t*)value = moo->option.log_mask; return 0; case MOO_LOG_MAXCAPA: diff --git a/moo/lib/moo.h b/moo/lib/moo.h index e46702a..c606474 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -115,19 +115,21 @@ typedef enum moo_option_dflval_t moo_option_dflval_t; enum moo_trait_t { #if defined(MOO_BUILD_DEBUG) - MOO_DEBUG_GC = (1 << 0), - MOO_DEBUG_BIGINT = (1 << 1), + MOO_DEBUG_GC = (1u << 0), + MOO_DEBUG_BIGINT = (1u << 1), #endif /* perform no garbage collection when the heap is full. * you still can use moo_gc() explicitly. */ - MOO_NOGC = (1 << 8), + MOO_NOGC = (1u << 8), /* wait for running process when exiting from the main method */ - MOO_AWAIT_PROCS = (1 << 9) + MOO_AWAIT_PROCS = (1u << 9) }; typedef enum moo_trait_t moo_trait_t; +typedef unsigned int moo_traits_t; + typedef struct moo_obj_t moo_obj_t; typedef struct moo_obj_t* moo_oop_t; @@ -916,6 +918,81 @@ struct moo_heap_t moo_uint8_t* ptr; /* next allocation pointer */ }; +/* ========================================================================= + * MOO VM LOGGING + * ========================================================================= */ + +enum moo_log_mask_t +{ + MOO_LOG_DEBUG = (1u << 0), + MOO_LOG_INFO = (1u << 1), + MOO_LOG_WARN = (1u << 2), + MOO_LOG_ERROR = (1u << 3), + MOO_LOG_FATAL = (1u << 4), + + MOO_LOG_UNTYPED = (1u << 6), /* only to be used by MOO_DEBUGx() and MOO_INFOx() */ + MOO_LOG_COMPILER = (1u << 7), + MOO_LOG_VM = (1u << 8), + MOO_LOG_MNEMONIC = (1u << 9), /* bytecode mnemonic */ + MOO_LOG_GC = (1u << 10), + MOO_LOG_IC = (1u << 11), /* instruction cycle, fetch-decode-execute */ + MOO_LOG_PRIMITIVE = (1u << 12), + MOO_LOG_APP = (1u << 13), /* moo applications, set by moo logging primitive */ + + MOO_LOG_ALL_LEVELS = (MOO_LOG_DEBUG | MOO_LOG_INFO | MOO_LOG_WARN | MOO_LOG_ERROR | MOO_LOG_FATAL), + MOO_LOG_ALL_TYPES = (MOO_LOG_UNTYPED | MOO_LOG_COMPILER | MOO_LOG_VM | MOO_LOG_MNEMONIC | MOO_LOG_GC | MOO_LOG_IC | MOO_LOG_PRIMITIVE | MOO_LOG_APP), + + + MOO_LOG_STDOUT = (1u << 14), /* write log messages to stdout without timestamp. MOO_LOG_STDOUT wins over MOO_LOG_STDERR. */ + MOO_LOG_STDERR = (1u << 15) /* write log messages to stderr without timestamp. */ + +}; +typedef enum moo_log_mask_t moo_log_mask_t; + +typedef unsigned int moo_log_masks_t; + +/* all bits must be set to get enabled */ +#define MOO_LOG_ENABLED(moo,mask) (((moo)->option.log_mask & (mask)) == (mask)) + +#define MOO_LOG0(moo,mask,fmt) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt); } while(0) +#define MOO_LOG1(moo,mask,fmt,a1) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1); } while(0) +#define MOO_LOG2(moo,mask,fmt,a1,a2) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2); } while(0) +#define MOO_LOG3(moo,mask,fmt,a1,a2,a3) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3); } while(0) +#define MOO_LOG4(moo,mask,fmt,a1,a2,a3,a4) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3, a4); } while(0) +#define MOO_LOG5(moo,mask,fmt,a1,a2,a3,a4,a5) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3, a4, a5); } while(0) +#define MOO_LOG6(moo,mask,fmt,a1,a2,a3,a4,a5,a6) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3, a4, a5, a6); } while(0) + +#if defined(MOO_BUILD_RELEASE) + /* [NOTE] + * get rid of debugging message totally regardless of + * the log mask in the release build. + */ +# define MOO_DEBUG0(moo,fmt) +# define MOO_DEBUG1(moo,fmt,a1) +# define MOO_DEBUG2(moo,fmt,a1,a2) +# define MOO_DEBUG3(moo,fmt,a1,a2,a3) +# define MOO_DEBUG4(moo,fmt,a1,a2,a3,a4) +# define MOO_DEBUG5(moo,fmt,a1,a2,a3,a4,a5) +# define MOO_DEBUG6(moo,fmt,a1,a2,a3,a4,a5,a6) +#else +# define MOO_DEBUG0(moo,fmt) MOO_LOG0(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt) +# define MOO_DEBUG1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1) +# define MOO_DEBUG2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2) +# define MOO_DEBUG3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3) +# define MOO_DEBUG4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4) +# define MOO_DEBUG5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5) +# define MOO_DEBUG6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5, a6) +#endif + +#define MOO_INFO0(moo,fmt) MOO_LOG0(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt) +#define MOO_INFO1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1) +#define MOO_INFO2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2) +#define MOO_INFO3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3) +#define MOO_INFO4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4) +#define MOO_INFO5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5) +#define MOO_INFO6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5, a6) + + /* ========================================================================= * VIRTUAL MACHINE PRIMITIVES * ========================================================================= */ @@ -932,7 +1009,7 @@ typedef void (*moo_free_heap_t) ( typedef void (*moo_log_write_t) ( moo_t* moo, - moo_oow_t mask, + moo_log_masks_t mask, const moo_ooch_t* msg, moo_oow_t len ); @@ -1235,8 +1312,8 @@ struct moo_t struct { - unsigned int trait; - unsigned int log_mask; + moo_traits_t trait; + moo_log_masks_t log_mask; moo_oow_t log_maxcapa; moo_oow_t dfl_symtab_size; moo_oow_t dfl_sysdic_size; @@ -1260,8 +1337,8 @@ struct moo_t moo_ooch_t* ptr; moo_oow_t len; moo_oow_t capa; - int last_mask; - int default_type_mask; + moo_log_masks_t last_mask; + moo_log_masks_t default_type_mask; } log; /* ========================= */ @@ -1477,79 +1554,6 @@ struct moo_t #define MOO_STACK_SETRETTOERRNUM(moo,nargs) MOO_STACK_SETRET(moo, nargs, MOO_ERROR_TO_OOP(moo->errnum)) #define MOO_STACK_SETRETTOERROR(moo,nargs,ec) MOO_STACK_SETRET(moo, nargs, MOO_ERROR_TO_OOP(ec)) -/* ========================================================================= - * MOO VM LOGGING - * ========================================================================= */ - -enum moo_log_mask_t -{ - MOO_LOG_DEBUG = (1 << 0), - MOO_LOG_INFO = (1 << 1), - MOO_LOG_WARN = (1 << 2), - MOO_LOG_ERROR = (1 << 3), - MOO_LOG_FATAL = (1 << 4), - - MOO_LOG_UNTYPED = (1 << 6), /* only to be used by MOO_DEBUGx() and MOO_INFOx() */ - MOO_LOG_COMPILER = (1 << 7), - MOO_LOG_VM = (1 << 8), - MOO_LOG_MNEMONIC = (1 << 9), /* bytecode mnemonic */ - MOO_LOG_GC = (1 << 10), - MOO_LOG_IC = (1 << 11), /* instruction cycle, fetch-decode-execute */ - MOO_LOG_PRIMITIVE = (1 << 12), - MOO_LOG_APP = (1 << 13), /* moo applications, set by moo logging primitive */ - - MOO_LOG_ALL_LEVELS = (MOO_LOG_DEBUG | MOO_LOG_INFO | MOO_LOG_WARN | MOO_LOG_ERROR | MOO_LOG_FATAL), - MOO_LOG_ALL_TYPES = (MOO_LOG_UNTYPED | MOO_LOG_COMPILER | MOO_LOG_VM | MOO_LOG_MNEMONIC | MOO_LOG_GC | MOO_LOG_IC | MOO_LOG_PRIMITIVE | MOO_LOG_APP), - - - MOO_LOG_STDOUT = (1 << 14), /* write log messages to stdout without timestamp. MOO_LOG_STDOUT wins over MOO_LOG_STDERR. */ - MOO_LOG_STDERR = (1 << 15) /* write log messages to stderr without timestamp. */ - -}; -typedef enum moo_log_mask_t moo_log_mask_t; - -/* all bits must be set to get enabled */ -#define MOO_LOG_ENABLED(moo,mask) (((moo)->option.log_mask & (mask)) == (mask)) - -#define MOO_LOG0(moo,mask,fmt) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt); } while(0) -#define MOO_LOG1(moo,mask,fmt,a1) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1); } while(0) -#define MOO_LOG2(moo,mask,fmt,a1,a2) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2); } while(0) -#define MOO_LOG3(moo,mask,fmt,a1,a2,a3) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3); } while(0) -#define MOO_LOG4(moo,mask,fmt,a1,a2,a3,a4) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3, a4); } while(0) -#define MOO_LOG5(moo,mask,fmt,a1,a2,a3,a4,a5) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3, a4, a5); } while(0) -#define MOO_LOG6(moo,mask,fmt,a1,a2,a3,a4,a5,a6) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3, a4, a5, a6); } while(0) - -#if defined(MOO_BUILD_RELEASE) - /* [NOTE] - * get rid of debugging message totally regardless of - * the log mask in the release build. - */ -# define MOO_DEBUG0(moo,fmt) -# define MOO_DEBUG1(moo,fmt,a1) -# define MOO_DEBUG2(moo,fmt,a1,a2) -# define MOO_DEBUG3(moo,fmt,a1,a2,a3) -# define MOO_DEBUG4(moo,fmt,a1,a2,a3,a4) -# define MOO_DEBUG5(moo,fmt,a1,a2,a3,a4,a5) -# define MOO_DEBUG6(moo,fmt,a1,a2,a3,a4,a5,a6) -#else -# define MOO_DEBUG0(moo,fmt) MOO_LOG0(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt) -# define MOO_DEBUG1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1) -# define MOO_DEBUG2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2) -# define MOO_DEBUG3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3) -# define MOO_DEBUG4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4) -# define MOO_DEBUG5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5) -# define MOO_DEBUG6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_DEBUG | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5, a6) -#endif - -#define MOO_INFO0(moo,fmt) MOO_LOG0(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt) -#define MOO_INFO1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1) -#define MOO_INFO2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2) -#define MOO_INFO3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3) -#define MOO_INFO4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4) -#define MOO_INFO5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5) -#define MOO_INFO6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_INFO | MOO_LOG_UNTYPED, fmt, a1, a2, a3, a4, a5, a6) - - /* ========================================================================= * MOO ASSERTION * ========================================================================= */ @@ -2187,14 +2191,14 @@ MOO_EXPORT moo_bch_t* moo_dupbchars ( MOO_EXPORT moo_ooi_t moo_logbfmt ( moo_t* moo, - moo_oow_t mask, + moo_log_mask_t mask, const moo_bch_t* fmt, ... ); MOO_EXPORT moo_ooi_t moo_logufmt ( moo_t* moo, - moo_oow_t mask, + moo_log_mask_t mask, const moo_uch_t* fmt, ... ); diff --git a/moo/mod/Makefile.in b/moo/mod/Makefile.in index 0902ff8..b74f889 100644 --- a/moo/mod/Makefile.in +++ b/moo/mod/Makefile.in @@ -424,7 +424,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@