Skip to content

Commit ab02595

Browse files
committed
Improve debug output in case of SIGABRT (add hint about assertion) and small refactoring
1 parent e8cccf8 commit ab02595

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static const Signalmap_t listofsignals = make_container< Signalmap_t > ()
347347
static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
348348
{
349349
int type = -1;
350-
pid_t killid = getpid();
350+
pid_t killid;
351351
#if defined(__linux__) && defined(REG_ERR)
352352
const ucontext_t* const uc = reinterpret_cast<const ucontext_t*>(context);
353353
killid = (pid_t) syscall(SYS_gettid);
@@ -356,21 +356,28 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
356356
}
357357
#else
358358
UNUSED(context);
359+
killid = getpid();
359360
#endif
360361

361362
const Signalmap_t::const_iterator it=listofsignals.find(signo);
362363
const char * const signame = (it==listofsignals.end()) ? "unknown" : it->second.c_str();
363364
bool printCallstack=true; // try to print a callstack?
364-
bool lowMem=false; // was low-memory condition detected?
365-
bool unexpectedSignal=true; // unexpected indicates things didn't go as they should...
365+
bool lowMem=false; // was low-memory condition detected? Be careful then! Avoid allocating much more memory then.
366+
bool unexpectedSignal=true; // unexpected indicates program failure
366367
bool terminate=true; // exit process/thread
367368
const bool isAddressOnStack = IsAddressOnStack(info->si_addr);
368369
FILE* output = CppCheckExecutor::getExceptionOutput();
369370
switch (signo) {
370371
case SIGABRT:
371372
fputs("Internal error: cppcheck received signal ", output);
372373
fputs(signame, output);
373-
fputs(" - out of memory?\n", output);
374+
fputs(
375+
#ifdef NDEBUG
376+
" - out of memory?\n",
377+
#else
378+
" - out of memory or assertion?\n",
379+
#endif
380+
output);
374381
lowMem=true; // educated guess
375382
break;
376383
case SIGBUS:

0 commit comments

Comments
 (0)