g++ -Wall test_backtrace.cpp -O0 -g -ggdb -rdynamic -o test_backtrace.exe -DUSING_LIBUNWIND -lunwind -lunwind-x86_64
clang++ -Wall test_backtrace.cpp -O0 -g -ggdb -rdynamic -o test_backtrace.exe -DUSING_LIBUNWIND -lunwind -lunwind-x86_64
命令和输出:
./test_backtrace.exe
Frame #00: (print_trace()+0x17) [0x400c30]
Frame #01: (func1(int)+0x2c) [0x400e80]
Frame #02: (func1(int)+0x22) [0x400e80]
Frame #03: (func1(int)+0x22) [0x400e80]
Frame #04: (func1(int)+0x22) [0x400e80]
Frame #05: (func1(int)+0x22) [0x400e80]
Frame #06: (func1(int)+0x22) [0x400e80]
Frame #07: (functor2::func2(int)+0x49) [0x401040]
Frame #08: (functor2::func2(int)+0x37) [0x401040]
Frame #09: (functor3::func3(int)+0x3d) [0x400ff0]
Frame #10: (functor3::func3(int)+0x27) [0x400ff0]
Frame #11: (functor4::operator()(int)+0x49) [0x400fa0]
Frame #12: (functor4::operator()(int)+0x37) [0x400fa0]
Frame #13: (func5(int)+0x3d) [0x400f00]
Frame #14: (func5(int)+0x27) [0x400f00]
Frame #15: (func6(int)+0x39) [0x400ec0]
Frame #16: (func6(int)+0x27) [0x400ec0]
Frame #17: (main+0x3f) [0x400f50]
Frame #18: (__libc_start_main+0xf0) [0x7f2d3cf50740]
Frame #19: (_start+0x29) [0x400b30]
Frame #20: (+0x29) [0x0]
All frames.
g++ -Wall test_backtrace.cpp -O0 -g -ggdb -rdynamic -o test_backtrace.exe
clang++ -Wall test_backtrace.cpp -O0 -g -ggdb -rdynamic -o test_backtrace.exe
命令和输出:
./test_backtrace.exe
Frame #00: (print_trace()+0x1c) [0x4013ec]
Frame #01: (func1(int)+0x2c) [0x4019dc]
Frame #02: (func1(int)+0x22) [0x4019d2]
Frame #03: (func1(int)+0x22) [0x4019d2]
Frame #04: (func1(int)+0x22) [0x4019d2]
Frame #05: (func1(int)+0x22) [0x4019d2]
Frame #06: (func1(int)+0x22) [0x4019d2]
Frame #07: (functor2::func2(int)+0x49) [0x402189]
Frame #08: (functor2::func2(int)+0x37) [0x402177]
Frame #09: (functor3::func3(int)+0x3d) [0x40212d]
Frame #10: (functor3::func3(int)+0x27) [0x402117]
Frame #11: (functor4::operator()(int)+0x49) [0x4020e9]
Frame #12: (functor4::operator()(int)+0x37) [0x4020d7]
Frame #13: () [0x401a6d]
Frame #14: () [0x401a57]
Frame #15: (func6(int)+0x39) [0x401a29]
Frame #16: (func6(int)+0x27) [0x401a17]
Frame #17: (main+0x3f) [0x401abf]
Frame #18: (__libc_start_main+0xf0) [0x7f7ffc390830]
Frame #19: (_start+0x29) [0x4012f9]
g++ -Wall test_backtrace.cpp -O0 -g -ggdb -o test_backtrace.exe
clang++ -Wall test_backtrace.cpp -O0 -g -ggdb -o test_backtrace.exe
命令和输出:
./test_backtrace.exe | eval 'while read -r line || [[ -n "$line" ]]; do ADDR=${line/*[}; ADDR=${ADDR%]*}; echo "${line}"; echo " $(addr2line -Cfpe ./test_backtrace.exe $ADDR)"; done'
Frame #00: () [0x40167a]
print_trace() at /mnt/d/workspace/test/test_backtrace.cpp:474
Frame #01: () [0x4019dc]
func1(int) at /mnt/d/workspace/test/test_backtrace.cpp:493 (discriminator 1)
Frame #02: () [0x4019d2]
func1(int) at /mnt/d/workspace/test/test_backtrace.cpp:489
Frame #03: () [0x4019d2]
func1(int) at /mnt/d/workspace/test/test_backtrace.cpp:489
Frame #04: () [0x4019d2]
func1(int) at /mnt/d/workspace/test/test_backtrace.cpp:489
Frame #05: () [0x4019d2]
func1(int) at /mnt/d/workspace/test/test_backtrace.cpp:489
Frame #06: () [0x4019d2]
func1(int) at /mnt/d/workspace/test/test_backtrace.cpp:489
Frame #07: () [0x402189]
functor2::func2(int) at /mnt/d/workspace/test/test_backtrace.cpp:503
Frame #08: () [0x402177]
functor2::func2(int) at /mnt/d/workspace/test/test_backtrace.cpp:500
Frame #09: () [0x40212d]
functor3::func3(int) at /mnt/d/workspace/test/test_backtrace.cpp:515
Frame #10: () [0x402117]
functor3::func3(int) at /mnt/d/workspace/test/test_backtrace.cpp:511
Frame #11: () [0x4020e9]
functor4::operator()(int) at /mnt/d/workspace/test/test_backtrace.cpp:525
Frame #12: () [0x4020d7]
functor4::operator()(int) at /mnt/d/workspace/test/test_backtrace.cpp:522
Frame #13: () [0x401a6d]
func5(int) at /mnt/d/workspace/test/test_backtrace.cpp:535
Frame #14: () [0x401a57]
func5(int) at /mnt/d/workspace/test/test_backtrace.cpp:531
Frame #15: () [0x401a29]
func6(int) at /mnt/d/workspace/test/test_backtrace.cpp:543
Frame #16: () [0x401a17]
func6(int) at /mnt/d/workspace/test/test_backtrace.cpp:540
Frame #17: () [0x401abf]
main at /mnt/d/workspace/test/test_backtrace.cpp:550
Frame #18: () [0x7f3c44f90830]
?? ??:0
Frame #19: () [0x4012f9]
_start at ??:?
Frame #20: () [0x0]
?? ??:0
cl /nologo /W4 /DEBUG /Zi test_backtrace.cpp
命令和输出:
test_backtrace.exe
Frame 00: (print_trace) [0x00007FF6C75768F0]
Frame 01: (func1) [0x00007FF6C7576EE0]
Frame 02: (func1) [0x00007FF6C7576EE0]
Frame 03: (func1) [0x00007FF6C7576EE0]
Frame 04: (func1) [0x00007FF6C7576EE0]
Frame 05: (func1) [0x00007FF6C7576EE0]
Frame 06: (func1) [0x00007FF6C7576EE0]
Frame 07: (functor2::func2) [0x00007FF6C7578850]
Frame 08: (functor2::func2) [0x00007FF6C7578850]
Frame 09: (functor3::func3) [0x00007FF6C75788A0]
Frame 10: (functor3::func3) [0x00007FF6C75788A0]
Frame 11: (functor4::operator()) [0x00007FF6C7577D20]
Frame 12: (functor4::operator()) [0x00007FF6C7577D20]
Frame 13: (func5) [0x00007FF6C7576F10]
Frame 14: (func5) [0x00007FF6C7576F10]
Frame 15: (func6) [0x00007FF6C7576F50]
Frame 16: (func6) [0x00007FF6C7576F50]
Frame 17: (main) [0x00007FF6C7576F90]
Frame 18: (__scrt_common_main_seh) [0x00007FF6C757A078]
Frame 19: (BaseThreadInitThunk) [0x00007FFCAA081FD0]
Frame 20: (RtlUserThreadStart) [0x00007FFCAC64EF90]
cl /nologo /W4 /DEBUG /Zi test_backtrace.cpp
命令和输出:
test_backtrace.exe
Frame 00: (test_backtrace!print_trace) [0x00007FF6C7576921]
Frame 01: (test_backtrace!func1) [0x00007FF6C7576F03]
Frame 02: (test_backtrace!func1) [0x00007FF6C7576EFC]
Frame 03: (test_backtrace!func1) [0x00007FF6C7576EFC]
Frame 04: (test_backtrace!func1) [0x00007FF6C7576EFC]
Frame 05: (test_backtrace!func1) [0x00007FF6C7576EFC]
Frame 06: (test_backtrace!func1) [0x00007FF6C7576EFC]
Frame 07: (test_backtrace!functor2::func2) [0x00007FF6C7578889]
Frame 08: (test_backtrace!functor2::func2) [0x00007FF6C757887A]
Frame 09: (test_backtrace!functor3::func3) [0x00007FF6C75788D4]
Frame 10: (test_backtrace!functor3::func3) [0x00007FF6C75788C0]
Frame 11: (test_backtrace!functor4::operator()) [0x00007FF6C7577D59]
Frame 12: (test_backtrace!functor4::operator()) [0x00007FF6C7577D4A]
Frame 13: (test_backtrace!func5) [0x00007FF6C7576F44]
Frame 14: (test_backtrace!func5) [0x00007FF6C7576F30]
Frame 15: (test_backtrace!func6) [0x00007FF6C7576F7F]
Frame 16: (test_backtrace!func6) [0x00007FF6C7576F70]
Frame 17: (test_backtrace!main) [0x00007FF6C7576FD0]
Frame 18: (test_backtrace!__scrt_common_main_seh) [0x00007FF6C757A188]
Frame 19: (KERNEL32!BaseThreadInitThunk) [0x00007FFCAA081FE4]
Frame 20: (ntdll!RtlUserThreadStart) [0x00007FFCAC64EFB1]
g++ test_backtrace.cpp -O0 -g -ggdb -o test_backtrace.exe -ldbghelp -ldbgeng -Wall -DUSING_GNU_UNWIND=0
clang++ test_backtrace.cpp -O0 -g -ggdb -o test_backtrace.exe -ldbghelp -ldbgeng -Wall -DUSING_GNU_UNWIND=0
命令和输出:
./test_backtrace.exe | eval 'while read -r line || [[ -n "$line" ]]; do ADDR=${line/*[}; ADDR=${ADDR%]*}; echo "${line}"; echo " $(addr2line -Cfpe ./test_backtrace.exe $ADDR)"; done'
Frame 00: () [0x00000000004015b4]
print_trace() 于 D:\workspace\test/test_backtrace.cpp:176
Frame 01: () [0x000000000040163b]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:353
Frame 02: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 03: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 04: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 05: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 06: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 07: () [0x000000000040189d]
functor2::func2(int) 于 D:\workspace\test/test_backtrace.cpp:363
Frame 08: () [0x000000000040188a]
functor2::func2(int) 于 D:\workspace\test/test_backtrace.cpp:360
Frame 09: () [0x000000000040183e]
functor3::func3(int) 于 D:\workspace\test/test_backtrace.cpp:375
Frame 10: () [0x0000000000401826]
functor3::func3(int) 于 D:\workspace\test/test_backtrace.cpp:371
Frame 11: () [0x00000000004017ed]
functor4::operator()(int) 于 D:\workspace\test/test_backtrace.cpp:385
Frame 12: () [0x00000000004017da]
functor4::operator()(int) 于 D:\workspace\test/test_backtrace.cpp:382
Frame 13: () [0x00000000004016ce]
func5(int) 于 D:\workspace\test/test_backtrace.cpp:395
Frame 14: () [0x00000000004016b6]
func5(int) 于 D:\workspace\test/test_backtrace.cpp:391
Frame 15: () [0x0000000000401689]
func6(int) 于 D:\workspace\test/test_backtrace.cpp:403
Frame 16: () [0x0000000000401676]
func6(int) 于 D:\workspace\test/test_backtrace.cpp:400
Frame 17: () [0x0000000000401734]
main 于 D:\workspace\test/test_backtrace.cpp:410
Frame 18: () [0x00000000004013f7]
__tmainCRTStartup 于 C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:343
Frame 19: () [0x000000000040152b]
mainCRTStartup 于 C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:221
Frame 20: () [0x00007ffcaa081fe4]
?? ??:0
Frame 21: () [0x00007ffcac64efb1]
?? ??:0
g++ test_backtrace.cpp -O0 -g -ggdb -o test_backtrace.exe -Wall -DUSING_GNU_EXECINFO=0
clang++ test_backtrace.cpp -O0 -g -ggdb -o test_backtrace.exe -Wall -DUSING_GNU_EXECINFO=0
命令和输出:
./test_backtrace.exe | eval 'while read -r line || [[ -n "$line" ]]; do ADDR=${line/*[}; ADDR=${ADDR%]*}; echo "${line}"; echo " $(addr2line -Cfpe ./test_backtrace.exe $ADDR)"; done'
Frame 00: () [0x00000000004015b4]
print_trace() 于 D:\workspace\test/test_backtrace.cpp:176
Frame 01: () [0x000000000040163b]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:353
Frame 02: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 03: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 04: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 05: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 06: () [0x0000000000401631]
func1(int) 于 D:\workspace\test/test_backtrace.cpp:349
Frame 07: () [0x000000000040189d]
functor2::func2(int) 于 D:\workspace\test/test_backtrace.cpp:363
Frame 08: () [0x000000000040188a]
functor2::func2(int) 于 D:\workspace\test/test_backtrace.cpp:360
Frame 09: () [0x000000000040183e]
functor3::func3(int) 于 D:\workspace\test/test_backtrace.cpp:375
Frame 10: () [0x0000000000401826]
functor3::func3(int) 于 D:\workspace\test/test_backtrace.cpp:371
Frame 11: () [0x00000000004017ed]
functor4::operator()(int) 于 D:\workspace\test/test_backtrace.cpp:385
Frame 12: () [0x00000000004017da]
functor4::operator()(int) 于 D:\workspace\test/test_backtrace.cpp:382
Frame 13: () [0x00000000004016ce]
func5(int) 于 D:\workspace\test/test_backtrace.cpp:395
Frame 14: () [0x00000000004016b6]
func5(int) 于 D:\workspace\test/test_backtrace.cpp:391
Frame 15: () [0x0000000000401689]
func6(int) 于 D:\workspace\test/test_backtrace.cpp:403
Frame 16: () [0x0000000000401676]
func6(int) 于 D:\workspace\test/test_backtrace.cpp:400
Frame 17: () [0x0000000000401734]
main 于 D:\workspace\test/test_backtrace.cpp:410
Frame 18: () [0x00000000004013f7]
__tmainCRTStartup 于 C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:343
Frame 19: () [0x000000000040152b]
mainCRTStartup 于 C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:221
Frame 20: () [0x00007ffcaa081fe4]
?? ??:0
Frame 21: () [0x00007ffcac64efb1]
?? ??:0