8

When print a value in lldb, I got the following error

error: no member named 'rec' in namespace '$__lldb_local_vars'

My code was compiled by -g. Why is lldb not able to print values?

1 Answer 1

10

$__lldb_local_vars was a bit of a hack to work around some problems in the name lookup affordances provided by clang for lldb's expression parser. The hack tries to promote local variables to the head of name lookup (ahead of locally visible class and namespace lookups) by injecting local variables into a namespace that is then imported into the expression. This has some performance issues, and it is also fragile since it requires realizing all visible locals. We did a bunch of work to remove locals that we can tell we won't be able to realize, but it still didn't work very reliably.

This hack is off by default in all the lldb's that Apple releases, and is controlled by setting:

(lldb) set list target.experimental.inject-local-vars
  target.experimental.inject-local-vars -- If true, inject local variables explicitly into the
                                           expression text.  This will fix symbol resolution
                                           when there are name collisions between ivars and
                                           local variables.  But it can make expressions run
                                           much more slowly.

You can use settings show to show the current value of this setting, and settings set to change it.

If you can make available an example showing this failure, it would be helpful to file a bug with the llvm bug reporter: https://bugs.llvm.org.

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

4 Comments

is this kind of bug fixed in the latest lldb?
No, we haven't figured out a better way to tell clang about locals yet. We had to do a bunch of ground work, cleaning up the interface between the lldb expression parser and clang first, but it hasn't born fruit yet.
in my case the binary was compiled by gcc not clang. Does lldb support debugging code built by gcc?
lldb primarily uses the DWARF debug format. gcc & clang both emit DWARF, so lldb should work with the output of either compiler. DWARF is now the default format for gcc, -g should get you that. Of course, all compilers have bugs (or "yes that's legal but why?" moments) in their debug info emission, and lldb has been used more frequently with clang than gcc output. So there are likely more bugs in our handling of gcc debug info than clang. But that should be on the margins.

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.