10VirtualBase::~VirtualBase() noexcept
23 auto it = m2d.find (mangled_identifier);
28 char *malloced_result = abi::__cxa_demangle (mangled_identifier, NULL, NULL, &status);
29 if (malloced_result && !status) {
31 auto it = m2d.find (mangled_identifier);
32 if (it != m2d.end()) {
33 free (malloced_result);
36 m2d[mangled_identifier] = malloced_result;
37 return malloced_result;
39 return mangled_identifier;
46 bool allow_ptrace =
true;
47#if 0 && defined (__linux__)
49 const char *
const ptrace_scope =
"/proc/sys/kernel/yama/ptrace_scope";
50 int fd =
open (ptrace_scope, 0);
52 if (
read (fd, b, 8) > 0)
53 allow_ptrace = b[0] ==
'0';
59 const char *
const usr_bin_lldb =
"/usr/bin/lldb";
60 if (
access (usr_bin_lldb, X_OK) == 0) {
62 "%s -Q -x --batch -p %u "
64 usr_bin_lldb, gettid());
67 const char *
const usr_bin_gdb =
"/usr/bin/gdb";
68 if (
access (usr_bin_gdb, X_OK) == 0) {
70 "%s -q -n --nx -p %u --batch "
71 "-iex 'set auto-load python-scripts off' "
72 "-iex 'set script-extension off' "
73 "-ex 'set print address off' "
75 "-ex 'thread apply all backtrace 99' "
77 usr_bin_gdb, gettid());
85has_debug_key (
const char *
const debugkeys,
const char *
const key)
87 if (!debugkeys)
return false;
88 const auto l =
strlen (key);
89 const auto d =
strstr (debugkeys, key);
90 return d && (d == debugkeys || d[-1] ==
':') && (d[l] == 0 || d[l] ==
':');
110assertion_fatal (
const char *msg,
const char *file,
int line,
const char *func)
noexcept
118static void assertion_abort (
const char *msg,
const char *file,
int line,
const char *func)
noexcept ASE_NORETURN;
125 if (file && line > 0 && func)
127 else if (file && line > 0)
129 else if (file || func)
132 m +=
"assertion unreachable\n";
135 m +=
"assertion failed: ";
143 const char *
const d =
getenv (
"ASE_DEBUG");
147#if (defined __i386__ || defined __x86_64__)
148 __asm__ __volatile__ (
"int $03");
152 }
else if (has_debug_key (d,
"backtrace")) {
154 if (!gdb_cmd.
empty()) {
160 assertion_abort (msg, file, line, func);
169assertion_abort (
const char *msg,
const char *file,
int line,
const char *func)
noexcept
171#if defined (_ASSERT_H_DECLS) && defined(__GLIBC__)
173 __assert_fail (msg && msg[0] ? msg :
"assertion unreachable\n", file, line, func);
The Anklang C++ API namespace.
void assertion_failed(const char *msg, const char *file, int line, const char *func) noexcept
Print instructive message, handle "breakpoint", "backtrace" and "fatal-warnings" in $ASE_DEBUG.
void assertion_fatal(const char *msg, const char *file, int line, const char *func) noexcept
Print a debug message via assertion_failed() and abort the program.
void perror_die(const std::string &msg) noexcept
Issue a warning about an assertion error.
const char * string_demangle_cxx(const char *mangled_identifier) noexcept
Demangle identifier via libcc.
std::string backtrace_command()
Find GDB and construct command line.
bool assertion_failed_fatal
Global flag to force aborting on assertion warnings.