-
-
Save ArnCarveris/09982554d454f9460790029e79e7e7ce to your computer and use it in GitHub Desktop.
Revisions
-
bdash created this gist
Oct 20, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ // c++ -framework Foundation -std=c++14 -o dladdr-lambda-test dladdr-lambda-test.mm #import <Foundation/Foundation.h> #include <cxxabi.h> #include <dlfcn.h> #include <execinfo.h> @interface MyObject : NSObject @end @implementation MyObject + (void)doStuff { [] { void* callstack[128]; int i, frames = backtrace(callstack, 128); for (i = 0; i < frames; ++i) { if ((intptr_t)callstack[i] == 1) continue; const char* mangledName; const char* demangledName; Dl_info info; if (dladdr(callstack[i], &info) && info.dli_sname) mangledName = info.dli_sname; if (mangledName) demangledName = abi::__cxa_demangle(mangledName, nullptr, nullptr, nullptr); if (mangledName || demangledName) printf("0x%016lx %s + %ld\n", (intptr_t)callstack[i], demangledName ? demangledName : mangledName, (intptr_t)callstack[i] - (intptr_t)info.dli_saddr); else printf("?\n"); } }(); } @end int main(int argc, char** argv) { [MyObject doStuff]; }