boost :: stacktrace打印地址

时间:2017-10-15 09:41:41

标签: c++ bash boost stack-trace

我可以编译boost:stacktrace的所有示例。这是我的bash脚本:

#!/bin/bash

export CXX=~/x-tools/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-g++
export BOOST_INCLUDE=$HOME/x-libs/$($CXX -dumpmachine)/include
export BOOST_LIB=$HOME/x-libs/$($CXX -dumpmachine)/lib
export BOOST_SUFFIX="mt-d"
(ls $BOOST_LIB/*$BOOST_SUFFIX.a | tr "\n" "\0" | xargs -0 -n 1 basename | while read A; do B=-l$(echo $A | sed -e 's/^lib//' | sed -e 's/\.a//'); echo $B; done;) | tr "\n" " " > $BOOST_LIB/list_boost.txt
export BOOST_LIBS="cat $BOOST_LIB/list_boost.txt"
export EXECUTABLE_SUFFIX=""

$CXX -w -g3 -o assert_handler-$($CXX -dumpmachine)$EXECUTABLE_SUFFIX assert_handler.cpp -std=c++11 -static -I$BOOST_INCLUDE -L$BOOST_LIB $(eval $BOOST_LIBS) -ldl
$CXX -w -g3 -o debug_function-$($CXX -dumpmachine)$EXECUTABLE_SUFFIX debug_function.cpp -std=c++11 -static -I$BOOST_INCLUDE -L$BOOST_LIB $(eval $BOOST_LIBS) -ldl
$CXX -w -g3 -o terminate_handler-$($CXX -dumpmachine)$EXECUTABLE_SUFFIX terminate_handler.cpp -std=c++11 -static -I$BOOST_INCLUDE -L$BOOST_LIB $(eval $BOOST_LIBS) -ldl -lrt -lpthread
$CXX -w -g3 -o throwing_st-$($CXX -dumpmachine)$EXECUTABLE_SUFFIX throwing_st.cpp -std=c++11 -static -I$BOOST_INCLUDE -L$BOOST_LIB $(eval $BOOST_LIBS) -ldl
$CXX -w -g3 -o trace_addresses-$($CXX -dumpmachine)$EXECUTABLE_SUFFIX trace_addresses.cpp -std=c++11 -static -I$BOOST_INCLUDE -L$BOOST_LIB $(eval $BOOST_LIBS)
$CXX -w -g3 -o user_config-$($CXX -dumpmachine)$EXECUTABLE_SUFFIX user_config.cpp -std=c++11 -static -I$BOOST_INCLUDE -L$BOOST_LIB $(eval $BOOST_LIBS) -ldl

生成的提升列表如下所示:

-lboost_atomic-mt-d -lboost_chrono-mt-d -lboost_container-mt-d -lboost_context-mt-d -lboost_coroutine-mt-d -lboost_date_time-mt-d -lboost_exception-mt-d -lboost_fiber-mt-d -lboost_filesystem-mt-d -lboost_graph-mt-d -lboost_iostreams-mt-d -lboost_locale-mt-d -lboost_log-mt-d -lboost_log_setup-mt-d -lboost_math_c99f-mt-d -lboost_math_c99l-mt-d -lboost_math_c99-mt-d -lboost_math_tr1f-mt-d -lboost_math_tr1l-mt-d -lboost_math_tr1-mt-d -lboost_prg_exec_monitor-mt-d -lboost_program_options-mt-d -lboost_random-mt-d -lboost_regex-mt-d -lboost_serialization-mt-d -lboost_signals-mt-d -lboost_stacktrace_addr2line-mt-d -lboost_stacktrace_basic-mt-d -lboost_stacktrace_noop-mt-d -lboost_system-mt-d -lboost_test_exec_monitor-mt-d -lboost_thread-mt-d -lboost_timer-mt-d -lboost_type_erasure-mt-d -lboost_unit_test_framework-mt-d -lboost_wave-mt-d -lboost_wserialization-mt-d 

如果我运行一个例子,它会输出指针:

./assert_handler-x86_64-unknown-linux-gnu 
Expression 'i < N' is false in function 'T& boost::array<T, N>::operator[](boost::array<T, N>::size_type) [with T = int; long unsigned int N = 5ul; boost::array<T, N>::reference = int&; boost::array<T, N>::size_type = long unsigned int]': out of range.
Backtrace:
 0# 0x00000000004019B2
 1# 0x0000000000401B39
 2# 0x0000000000400E3B
 3# 0x0000000000400E6B
 4# 0x0000000000400E44
 5# 0x0000000000400E6B
 6# 0x0000000000400E7C
 7# 0x000000000045BF2B
 8# 0x000000000045C1D1
 9# 0x0000000000400CEA

我错过了什么吗?

1 个答案:

答案 0 :(得分:3)

现在适合我。

  1. boost :: stacktrace需要libbacktrace才能打印多个指针
  2. 编译器需要-lbacktrace -DBOOST_STACKTRACE_USE_BACKTRACE
  3. 然后在上部bash脚本示例中进行编译的完整行:

    $CXX -w -g3 -o assert_handler-$($CXX -dumpmachine)$EXECUTABLE_SUFFIX assert_handler.cpp -std=c++11 -static -I$BOOST_INCLUDE -L$BOOST_LIB $(eval $BOOST_LIBS) -ldl -lbacktrace -DBOOST_STACKTRACE_USE_BACKTRACE
    

    boost :: stacktrace在当前的Boost v1.65.1和Debian Stretch中是新的,我使用的只有v1.62.0并且不提供libbacktrace。所以我必须自己下载/编译这两个。

    我为x86_64-unknown-linux-gnu和i686-w64-mingw32交叉编译。它适用于Linux,但mingw可执行文件几乎不打印。我会对此进行调查,也许会在稍后发布我的结果。