Menu

How to use boost.stacktrace to get full stack trace with source file names and line numbers

Help
2019-01-31
2025-06-04
  • Gimhani Uthpala

    Gimhani Uthpala - 2019-01-31

    I am trying to use boost.stacktrace library to get a full-descriptive stack-trace in c++ program with file locations and line numbers.
    Without using any macros or without linking libdl /libbacktrace libraries, it is only printing a simple stacktrace.
    eg:

    0# StackTrace_CaptureAndStream_Test::TestBody() in ./test-common-exception
    1# void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) in ./test-common-exception
    2# void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) in ./test-common-exception
    3# testing::Test::Run() in ./test-common-exception
    4# testing::TestInfo::Run() in ./test-common-exception
    5# testing::TestCase::Run() in ./test-common-exception
    6# testing::internal::UnitTestImpl::RunAllTests() in ./test-common-exception
    

    As for the getting started page, it describes "Configuration and build settings" to get the full stack trace. But, the description given is ambiguous for me.
    I am confused with the sentence
    'In header only mode library could be tuned by macro. If one of the link macro from above is defined, you have to manually link with one of the libraries:'
    for what it refers to macros and libraries.

    I am pleased if someone can help me in understading how this can be achieved if you are working with a gcc compiler.
    I want output to be as in the example in boost getting started page:

    0# bar(int) at /path/to/source/file.cpp:70
    1# bar(int) at /path/to/source/file.cpp:70
    2# bar(int) at /path/to/source/file.cpp:70
    3# bar(int) at /path/to/source/file.cpp:70
    4# main at /path/to/main.cpp:93
    5# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
    6# _start
    
     
  • Caldora cruz

    Caldora cruz - 2025-06-04

    Hello, I am having the issue at my website, can someone else please help with this please?

    Steps I've already tried:

    • Compiling with -g -O0
    • Linking with -lboost_stacktrace_backtrace
    • Verified addr2line works on the executable manually
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.