MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / stackDump

Method stackDump

global.cpp:1221–1295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1219
1220
1221void Global::stackDump(int max) {
1222// Windows Check
1223#ifndef _WIN32
1224
1225 void *array[30];
1226 size_t size;
1227 QLOG_ERROR() << "***** Dumping stack *****";
1228
1229 // get void*'s for all entries on the stack
1230 size = backtrace(array, 30);
1231 char **messages = backtrace_symbols(array, size);
1232
1233 if (max > 0)
1234 size = max+1; // We add one here because we always skip the first thing on the stack (this function).
1235 for (size_t i = 1; i < size && messages != NULL; ++i)
1236 {
1237 char *mangled_name = 0, *offset_begin = 0, *offset_end = 0;
1238
1239 // find parantheses and +address offset surrounding mangled name
1240 for (char *p = messages[i]; *p; ++p)
1241 {
1242 if (*p == '(')
1243 {
1244 mangled_name = p;
1245 }
1246 else if (*p == '+')
1247 {
1248 offset_begin = p;
1249 }
1250 else if (*p == ')')
1251 {
1252 offset_end = p;
1253 break;
1254 }
1255 }
1256
1257 // if the line could be processed, attempt to demangle the symbol
1258 if (mangled_name && offset_begin && offset_end &&
1259 mangled_name < offset_begin)
1260 {
1261 *mangled_name++ = '\0';
1262 *offset_begin++ = '\0';
1263 *offset_end++ = '\0';
1264
1265 int status;
1266 char * real_name = abi::__cxa_demangle(mangled_name, 0, 0, &status);
1267
1268 // if demangling is successful, output the demangled function name
1269 if (status == 0)
1270 {
1271 QLOG_ERROR() << "[bt]: (" << i << ") " << messages[i] << " : "
1272 << real_name << "+" << offset_begin << offset_end;
1273
1274 }
1275 // otherwise, output the mangled function name
1276 else
1277 {
1278 QLOG_ERROR() << "[bt]: (" << i << ") " << messages[i] << " : "

Callers 1

execMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected