aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-02-04 17:27:54 +0200
committerRiccardo Spagni <ric@spagni.net>2017-02-04 17:27:54 +0200
commit5da4650cba43520e91b002513312a1c6613d6e04 (patch)
treee2dbe7a3deaee4e95ea649bb011f02b6baa25c0f /src
parentMerge pull request #1672 (diff)
parentUse easylogging++'s stack trace facility where possible (diff)
downloadmonero-5da4650cba43520e91b002513312a1c6613d6e04.tar.xz
Merge pull request #1671
cd34fc65 Use easylogging++'s stack trace facility where possible (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/common/stack_trace.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp
index 99e4bda2c..67065aae7 100644
--- a/src/common/stack_trace.cpp
+++ b/src/common/stack_trace.cpp
@@ -26,11 +26,17 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#if !defined __GNUC__ || defined __MINGW32__ || defined __MINGW64__
+#define USE_UNWIND
+#endif
+
#include "common/stack_trace.h"
#include "misc_log_ex.h"
+#ifdef USE_UNWIND
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <cxxabi.h>
+#endif
#ifndef STATICLIB
#include <dlfcn.h>
#endif
@@ -99,6 +105,7 @@ void set_stack_trace_log(const std::string &log)
void log_stack_trace(const char *msg)
{
+#ifdef USE_UNWIND
unw_context_t ctx;
unw_cursor_t cur;
unw_word_t ip, off;
@@ -106,10 +113,13 @@ void log_stack_trace(const char *msg)
char sym[512], *dsym;
int status;
const char *log = stack_trace_log.empty() ? NULL : stack_trace_log.c_str();
+#endif
if (msg)
ST_LOG(msg);
ST_LOG("Unwound call stack:");
+
+#ifdef USE_UNWIND
if (unw_getcontext(&ctx) < 0) {
ST_LOG("Failed to create unwind context");
return;
@@ -138,6 +148,15 @@ void log_stack_trace(const char *msg)
ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off);
free(dsym);
}
+#else
+ std::stringstream ss;
+ ss << el::base::debug::StackTrace();
+ std::vector<std::string> lines;
+ std::string s = ss.str();
+ boost::split(lines, s, boost::is_any_of("\n"));
+ for (const auto &line: lines)
+ ST_LOG(line);
+#endif
}
} // namespace tools