X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/89b3af67bb32e691275bf6fa803d1834b2284115..e2fac8b15b12a7979f72090454d850e612fc5b13:/libkern/gen/OSDebug.cpp?ds=inline diff --git a/libkern/gen/OSDebug.cpp b/libkern/gen/OSDebug.cpp index f464ad889..3690714e8 100644 --- a/libkern/gen/OSDebug.cpp +++ b/libkern/gen/OSDebug.cpp @@ -39,6 +39,8 @@ #include // From bsd's libkern directory #include +#include +extern int etext; __BEGIN_DECLS // From osmfk/kern/thread.h but considered to be private extern vm_offset_t min_valid_stack_address(void); @@ -48,10 +50,39 @@ extern vm_offset_t max_valid_stack_address(void); extern void kmod_dump_log(vm_offset_t *addr, unsigned int cnt); extern addr64_t kvtophys(vm_offset_t va); + __END_DECLS static mutex_t *sOSReportLock = mutex_alloc(0); +/* Use kernel_debug() to log a backtrace */ +void +trace_backtrace(unsigned int debugid, unsigned int debugid2, int size, int data) { + void *bt[16]; + const unsigned cnt = sizeof(bt) / sizeof(bt[0]); + unsigned i; + int found = 0; + + OSBacktrace(bt, cnt); + + /* find first non-kernel frame */ + for (i = 3; i < cnt && bt[i]; i++) { + if (bt[i] > (void*)&etext) { + found = 1; + break; + } + } + /* + * if there are non-kernel frames, only log these + * otherwise, log everything but the first two + */ + if (!found) i=2; + +#define safe_bt(a) (int)(a