MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / CppcheckSignalHandler

Function CppcheckSignalHandler

cli/signalhandler.cpp:109–297  ·  view source on GitHub ↗

* Entry pointer for signal handlers * It uses functions which are not safe to be called from a signal handler, * (http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04 has a whitelist) * but when ending up here something went terribly wrong anyway. * And all which is left is just printing some information and terminate. */

Source from the content-addressed store, hash-verified

107 * And all which is left is just printing some information and terminate.
108 */
109static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) // cppcheck-suppress constParameterCallback - info can be const
110{
111 const char* typeStr = "";
112 pid_t killid;
113 // TODO: separate these two defines
114#if defined(__linux__) && defined(REG_ERR)
115 const auto* const uc = reinterpret_cast<const ucontext_t*>(context);
116 killid = static_cast<pid_t>(syscall(SYS_gettid));
117 if (uc) {
118 const int type = static_cast<int>(uc->uc_mcontext.gregs[REG_ERR]) & 2;
119 typeStr = (type == 0) ? "reading " : "writing ";
120 }
121#else
122 (void)context;
123 killid = getpid();
124#endif
125
126 const auto it = listofsignals.find(signo);
127 const char * const signame = (it==listofsignals.end()) ? "unknown" : it->second.c_str();
128 bool unexpectedSignal=true; // unexpected indicates program failure
129 bool terminate=true; // exit process/thread
130 const bool isAddressOnStack = IsAddressOnStack(info->si_addr);
131 FILE * const output = signalOutput;
132 switch (signo) {
133 case SIGABRT:
134 fputs("Internal error: cppcheck received signal ", output);
135 fputs(signame, output);
136 fputs(
137#ifdef NDEBUG
138 " - abort\n",
139#else
140 " - abort or assertion\n",
141#endif
142 output);
143 break;
144 case SIGBUS:
145 fputs("Internal error: cppcheck received signal ", output);
146 fputs(signame, output);
147 switch (info->si_code) {
148 case BUS_ADRALN: // invalid address alignment
149 fputs(" - BUS_ADRALN", output);
150 break;
151 case BUS_ADRERR: // nonexistent physical address
152 fputs(" - BUS_ADRERR", output);
153 break;
154 case BUS_OBJERR: // object-specific hardware error
155 fputs(" - BUS_OBJERR", output);
156 break;
157#ifdef BUS_MCEERR_AR
158 case BUS_MCEERR_AR: // Hardware memory error consumed on a machine check;
159 fputs(" - BUS_MCEERR_AR", output);
160 break;
161#endif
162#ifdef BUS_MCEERR_AO
163 case BUS_MCEERR_AO: // Hardware memory error detected in process but not consumed
164 fputs(" - BUS_MCEERR_AO", output);
165 break;
166#endif

Callers

nothing calls this directly

Calls 5

IsAddressOnStackFunction · 0.85
print_stacktraceFunction · 0.85
sigactionClass · 0.85
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected