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. */
| 1548 | * The uplevel argument indicates how many of the calling functions to skip. |
| 1549 | */ |
| 1550 | void 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 |
no test coverage detected