Search code examples
c++lldb

lldb: Couldn't lookup a std::string symbols


I'm a beginner in using lldb, I wonder whether lldb can call a member function that requires a std::string parameter, so I code the following demo.

#include <string>
#include <unordered_map>

struct A {
    std::unordered_map<std::string, std::string> m;
    std::string at(const std::string &s) { return m.at(s); }
};

// help function to generate a std::string in lldb
std::string SSS(const char *s) { return std::string(s); }

int main() {
    A a = {{}};
    a.m.insert({"good", "bad"});
    a.m.insert({"foo", "bar"});
    a.m.insert({"foofoo", "barbar"}); // <- set a breakpoint here
    return 0;
}

I compile this code via clang++, the compile command is clang++ foofoobar.cpp -std=c++2b -g.

in lldb I set a breakpoint at a.m.insert({"foofoo", "barbar"}); and launch the binary, the program stop at the breakpoint and I try to call at function defined in struct A, I use (lldb) p a.at(SSS("foo")) to call the function, but lldb throw an error error: expression failed to parse: error: Couldn't lookup symbols: __ZN1A2atERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE.

what does the error mean? Do I use the wrong way to call a member function? how do I solve this problem. I need help.


Solution

  • As at isn't used in your program the linker won't add it to your executable. The debugger is therefore unable to find it to call. You could try using the function directly (though if using optimised code it could still be inlined and therefore not included in your executable) or something like &A::at might force the linker to not discard the method.