4

We've a backtrace for a segfault that quotes a compiler-generated name for a lambda:

(gdb) bt
#0  std::_Function_handler<std::function<bool()>(), bold::AdHocOptionTreeBuilder::buildTree(bold::Agent*)::__lambda59>::_M_invoke(const std::_Any_data &) (__functor=...) at /usr/include/c++/4.8/functional:2057
#1  0x08146d2c in operator() (this=<optimized out>) at /usr/include/c++/4.8/functional:2464
...

The assigned name is bold::AdHocOptionTreeBuilder::buildTree(bold::Agent*)::__lambda59. However as you can tell that file has a lot of lambda in it! Is there a way to map that generated function's name to a line number in the source code? We have line numbers for other functions, however here it's only quoted as a type param for std::_Function_handler<>.

1
  • 1
    Compile the file, introducing errors in the lambda bodies, see if the compiler spits out a name? It may number them sequentially which coukd make searching fast. Commented Jan 30, 2014 at 12:48

1 Answer 1

1

The linker option -Map mapfile should give you the information showing where each function originated, including lambda's. nm --line-numbers might work too, if the program was compiled with debug info -g.

Also, I think you can use set print symbol-filename on in GDB, and then evaluate &bold::AdHocOptionTreeBuilder::buildTree(bold::Agent*)::__lambda59

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks very much for this. I'll be sure to try this when I next reproduce the error.
Testing this out today I find that nm doesn't list any lambdas. The set command works, though does not change the information in the backtrace. Is there a specific command to use for evaluating the full type name? print &bold::AdHocOptionTreeBuilder::buildTree(bold::Agent*) works, but print &bold::AdHocOptionTreeBuilder::buildTree(bold::Agent*)::__lambda59 gives A syntax error in expression, near `__lambda58'.
@DrewNoakes: Tricky. When we say "lambda", we usually mean an unnamed object of an unnamed type, which always has an operator() member. nm shows functions, not types, but I guess the std::_Function_handler template parameter in your example is a type, not a function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.