From a6075d74394a7f0e81d737f74adcff3dc9e037c8 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 30 Aug 2010 11:09:40 +0200 Subject: [PATCH] trap when throwing exceptions while the program is being debugged --- src/libcore/logger.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libcore/logger.cpp b/src/libcore/logger.cpp index 00a3c01f..8b9bdef0 100644 --- a/src/libcore/logger.cpp +++ b/src/libcore/logger.cpp @@ -50,8 +50,17 @@ void Logger::log(ELogLevel level, const Class *theClass, m_appenders[i]->append(level, text); m_mutex->unlock(); } else { -#ifdef MTS_DEBUG_TRAP - __asm__ ("int $3"); +#if defined(__LINUX__) + /* A critical error occurred: trap if we're running in a debugger */ + + char exePath[PATH_MAX]; + pid_t ppid = getppid(); + memset(exePath, 0, PATH_MAX); + if (readlink(formatString("/proc/%i/exe", ppid).c_str(), exePath, PATH_MAX) != -1) { + if (!strcmp(exePath, "/usr/bin/gdb")) { + __asm__ ("int $3"); + } + } #endif throw std::runtime_error(text); }