add stacktrace message

Former-commit-id: 5be1620629ce8de7f419bc001f18d22d6eb4fa8a
This commit is contained in:
malavan 2021-07-19 23:17:18 +00:00
parent fe2292f111
commit a269f35002

View File

@ -1612,15 +1612,23 @@ void safe_write(int fd, const void *pv, ssize_t cb)
*/
void logStackTrace(void * eip, int uplevel) {
(void)eip;//UNUSED
const char *msg;
int fd = openDirectLogFiledes();
if (fd == -1) return; /* If we can't log there is anything to do. */
msg = "\n------ STACK TRACE ------\n";
if (write(fd,msg,strlen(msg)) == -1) {/* Avoid warning. */};
unw_cursor_t cursor;
unw_context_t context;
unw_getcontext(&context);
unw_init_local(&cursor, &context);
/* Write symbols to log file */
msg = "\nBacktrace:\n";
if (write(fd,msg,strlen(msg)) == -1) {/* Avoid warning. */};
for (int i = 0; i < uplevel; i++) {
unw_step(&cursor);
}