MCPcopy Create free account
hub / github.com/F-Stack/f-stack / logStackTrace

Function logStackTrace

app/redis-6.2.6/src/debug.c:1550–1578  ·  view source on GitHub ↗

Logs the stack trace using the backtrace() call. This function is designed * to be called from signal handlers safely. * The eip argument is optional (can take NULL). * The uplevel argument indicates how many of the calling functions to skip. */

Source from the content-addressed store, hash-verified

1548 * The uplevel argument indicates how many of the calling functions to skip.
1549 */
1550void logStackTrace(void *eip, int uplevel) {
1551 void *trace[100];
1552 int trace_size = 0, fd = openDirectLogFiledes();
1553 char *msg;
1554 uplevel++; /* skip this function */
1555
1556 if (fd == -1) return; /* If we can't log there is anything to do. */
1557
1558 /* Get the stack trace first! */
1559 trace_size = backtrace(trace, 100);
1560
1561 msg = "\n------ STACK TRACE ------\n";
1562 if (write(fd,msg,strlen(msg)) == -1) {/* Avoid warning. */};
1563
1564 if (eip) {
1565 /* Write EIP to the log file*/
1566 msg = "EIP:\n";
1567 if (write(fd,msg,strlen(msg)) == -1) {/* Avoid warning. */};
1568 backtrace_symbols_fd(&eip, 1, fd);
1569 }
1570
1571 /* Write symbols to log file */
1572 msg = "\nBacktrace:\n";
1573 if (write(fd,msg,strlen(msg)) == -1) {/* Avoid warning. */};
1574 backtrace_symbols_fd(trace+uplevel, trace_size-uplevel, fd);
1575
1576 /* Cleanup */
1577 closeDirectLogFiledes(fd);
1578}
1579
1580#endif /* HAVE_BACKTRACE */
1581

Callers 4

_serverAssertFunction · 0.85
_serverPanicFunction · 0.85
sigsegvHandlerFunction · 0.85
watchdogSignalHandlerFunction · 0.85

Calls 3

openDirectLogFiledesFunction · 0.85
closeDirectLogFiledesFunction · 0.85
writeFunction · 0.70

Tested by

no test coverage detected