我想使用backtrace和backtrace_symbols結果打印出我捕獲SIGSEGV信號後代碼崩潰的位置。我明確地從一個工作者線程觸發。我用選項-rdynamic編譯了我的靜態鏈接多線程C++程序,並且我期待backtrace_symbols會返回一個堆棧跟蹤來告訴我發生崩潰的位置,但下面的結果並不是我所期望的,MyApplicationService不是一種方法,但只是可執行文件的名稱,我不明白爲什麼。回溯結果沒有顯示崩潰位置
2013-03-07 15:13:18.119986598 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZNK5boost4_mfi3mf2IvN18my_app__service_lib14service_runnerERKNS_6system10error_codeEiEclEPS3_S7_i+0x74) [0xcd69fa]
2013-03-07 15:13:18.119988126 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN5boost3_bi5list3INS0_5valueIPN18my_app__service_lib14service_runnerEEENS_3argILi1EEENS7_ILi2EEEEclINS_4_mfi3mf2IvS4_RKNS_6system10error_codeEiEENS0_5list2ISH_RKiEEEEvNS0_4typeIvEERT_RT0_i+0x7c) [0xcd6848]
2013-03-07 15:13:18.119989192 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN5boost3_bi6bind_tIvNS_4_mfi3mf2IvN18my_app__service_lib14service_runnerERKNS_6system10error_codeEiEENS0_5list3INS0_5valueIPS5_EENS_3argILi1EEENSF_ILi2EEEEEEclIS7_iEEvRKT_RKT0_+0x4c) [0xcd6690]
2013-03-07 15:13:18.119990120 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN5boost4asio6detail7binder2INS_3_bi6bind_tIvNS_4_mfi3mf2IvN18my_app__service_lib14service_runnerERKNS_6system10error_codeEiEENS3_5list3INS3_5valueIPS8_EENS_3argILi1EEENSI_ILi2EEEEEEESA_iEclEv+0x2b) [0xcd6597]
2013-03-07 15:13:18.119991031 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN5boost4asio19asio_handler_invokeINS0_6detail7binder2INS_3_bi6bind_tIvNS_4_mfi3mf2IvN18my_app__service_lib14service_runnerERKNS_6system10error_codeEiEENS4_5list3INS4_5valueIPS9_EENS_3argILi1EEENSJ_ILi2EEEEEEESB_iEEEEvT_z+0x62) [0xcd64b0]
2013-03-07 15:13:18.119992105 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN33boost_asio_handler_invoke_helpers6invokeIN5boost4asio6detail7binder2INS1_3_bi6bind_tIvNS1_4_mfi3mf2IvN18my_app__service_lib14service_runnerERKNS1_6system10error_codeEiEENS5_5list3INS5_5valueIPSA_EENS1_3argILi1EEENSK_ILi2EEEEEEESC_iEESO_EEvRT_RT0_+0x64) [0xcd636c]
2013-03-07 15:13:18.119993000 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN5boost4asio6detail14signal_handlerINS_3_bi6bind_tIvNS_4_mfi3mf2IvN18my_app__service_lib14service_runnerERKNS_6system10error_codeEiEENS3_5list3INS3_5valueIPS8_EENS_3argILi1EEENSI_ILi2EEEEEEEE11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationESC_m+0xb9) [0xcd605d]
2013-03-07 15:13:18.119993884 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN5boost4asio6detail25task_io_service_operation8completeERNS1_15task_io_serviceERKNS_6system10error_codeEm+0x32) [0xccceac]
2013-03-07 15:13:18.119994819 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN5boost4asio6detail15task_io_service10do_run_oneERNS1_11scoped_lockINS1_11posix_mutexEEERNS2_11thread_infoERKNS_6system10error_codeE+0x1a1) [0xccf4a5]
2013-03-07 15:13:18.119995795 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN5boost4asio6detail15task_io_service3runERNS_6system10error_codeE+0x137) [0xcceffd]
2013-03-07 15:13:18.119996845 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN5boost4asio10io_service3runEv+0x2f) [0xccf823]
2013-03-07 15:13:18.119997845 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(_ZN18my_app__service_lib14service_runner3runEv+0x97) [0xccbb65]
2013-03-07 15:13:18.119998914 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService(main+0x4cc) [0xcc4608]
2013-03-07 15:13:18.119999767 [7f2279bbe720] INFO service_runner - /lib64/libc.so.6(__libc_start_main+0xfd) [0x3f0f01ecdd]
2013-03-07 15:13:18.120000694 [7f2279bbe720] INFO service_runner - ../Debug/MyApplicationService() [0xcc4059]
這是我用來打印上述結果的代碼:
void *trace[16];
char **messages = (char **)NULL;
int i, trace_size = 0;
SERVICE_LOG_INFO << "Receive signal " << sig ;
trace_size = backtrace(trace, 16);
messages = backtrace_symbols(trace, trace_size);
LOG << "[bt] Execution path:" ;
for (i=1; i<trace_size; ++i)
LOG << messages[i];
其它信息:
OS: RHEL 6.3
compiler: gcc 4.4.6
compile option: -I/opt/rh/devtoolset-1.0/root/usr/include -I/opt/rh/devtoolset-1.0/root/usr/include/c++/4.7.0 -I/opt/rh/devtoolset-1.0/root/usr/include/c++/4.7.0/backward -I/opt/rh/devtoolset-1.0/root/usr/include/c++/4.7.0/x86_64-redhat-linux -I/opt/rh/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/include -I/opt/boost_1_52_0 -I/opt/tbb41_20121003oss/include -I/opt/libev-4.11/include -I"Myapp/include" -O0 -g3 -rdynamic -Wall -c -fmessage-length=0 -std=c++11 -fno-strict-aliasing -MMD -MP -MF"src/service_runner.d" -MT"src/service_runner.d" -o "src/service_runner.o" "../src/service_runner.cpp"
你建立與調試信息?爲什麼不嘗試在調試器中運行它? – 2013-03-07 06:31:35
是與-g3。我正在使用eclipse CDT – 2013-03-07 06:32:21
我們需要更多信息,例如當你編譯和鏈接你的應用程序時,命令行看起來如何?您使用的編譯器和版本等。 – 2013-03-07 06:33:54