Skip to content

Commit

Permalink
[REX]: supporting stacktrace output when the compiler(rose-cc, etc) i…
Browse files Browse the repository at this point in the history
…s aborted because

of calling ASSERT_* related mlogging or ROSE_ASSERT/ROSE_ABORT. The
implementation uses boost stacktrace in mlog.C file, but must be enabled
in the configure/building of the whole source tree. To enable it, set
CFLAGS/CXXFLAGS/LDFLAGS for configure, e.g.

   CXXFLAGS="-DBOOST_STACKTRACE_LINK -DREX_STACKTRACE_ABORT_BOOST"
   CFLAGS="-DBOOST_STACKTRACE_LINK -DREX_STACKTRACE_ABORT_BOOST"
   LDFLAGS="-lboost_stacktrace_backtrace"

These compiler and linker lags can be passed to --with-DEBUG, -with-C_DEBUG,
or -with-CXX_DEBUG of the configure, but setting directly via
CFLAGS/CXXFLAGS/LDFLAGS seems to be easier to use.
  • Loading branch information
yanyh15 committed Feb 1, 2023
1 parent 40c2b9d commit 1b62d06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/util/mlog.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <stdio.h>
#include "mlog.h"

#if defined(REX_STACKTRACE_ABORT_BOOST)
#include <boost/stacktrace.hpp>
#endif

int mlogLevel = DEFAULT_MLOG_LEVEL;

/**
Expand Down Expand Up @@ -76,6 +80,9 @@ void mlogAssertFail_C(const char * subject, const char * expr, const char * file
va_end(l);
fflush(mlogFile);
}
#if defined(REX_STACKTRACE_ABORT_BOOST)
std::cerr << boost::stacktrace::stacktrace();
#endif
abort();
}

Expand Down
1 change: 0 additions & 1 deletion src/util/mlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ extern std::string mlogLevelToString_CXX(MLOG_LEVEL_t level);
#define WHEREARG __FILE__,__LINE__, __func__

//C-style API for mandatory fatal/error/warning/debugging mlogging
#define MLOG_FAIL_C(SUBJECT, ...) { mlog_C(MLOG_LEVEL_FAIL, SUBJECT, WHEREARG, __VA_ARGS__); abort();}
#define MLOG_FATAL_C(SUBJECT, ...) mlog_C(MLOG_LEVEL_FATAL, SUBJECT, WHEREARG, __VA_ARGS__)
#define MLOG_ERROR_C(SUBJECT, ...) mlog_C(MLOG_LEVEL_ERROR, SUBJECT, WHEREARG, __VA_ARGS__)
#define MLOG_WARN_C(SUBJECT, ...) mlog_C(MLOG_LEVEL_WARN, SUBJECT, WHEREARG, __VA_ARGS__)
Expand Down

0 comments on commit 1b62d06

Please sign in to comment.