跳至主要内容

博文

目前显示的是 十一月, 2020的博文

libunwind查看其他进程的堆栈

 g++ -g3 -o main main.cpp -std=c++11 -lunwind -lunwind-x86_64 -lunwind-ptrace   #include <iostream> #include <libunwind.h> #include <libunwind-ptrace.h> #include <unistd.h> #include <sys/ptrace.h> #include <sys/wait.h> #include <cxxabi.h> #include <cstdio> int wait4stop ( pid_t pid ) { int status = 99 ; do { if ( waitpid ( pid , & status , 0 ) == - 1 || WIFEXITED ( status ) || WIFSIGNALED ( status )) return 0 ; } while ( ! WIFSTOPPED ( status )); return 1 ; } void get_backtrace ( pid_t pid ) { unw_cursor_t cursor , resume_cursor ; unw_context_t context ; unw_word_t ip , sp , off ; unw_addr_space_t addr_space = unw_create_addr_space ( & _UPT_accessors , __BYTE_ORDER__ ); if ( ! addr_space ) std :: cerr << "Failed to create address space" << std :: endl ; unw_getcontext (