我无法使用 lldb 调用采用字符串参数的简单非模板化函数。有没有办法让 lldb 理解 C++ 数据类型“字符串”,这是 C++ 程序中常用的数据类型?
这里的示例源代码只是创建一个带有几个构造函数的简单类,然后调用它们(省略了“iostream”和“string”的包含):
using namespace std;
struct lldbtest{
int bar=5;
lldbtest(){bar=6;}
lldbtest(int foo){bar=foo;}
lldbtest(string fum){bar=7;}
};
int main(){
string name="fum";
lldbtest x,y(3);
cout<<x.bar<<y.bar<<endl;
return 0;
}
在 Mac Maverick 上编译时
g++ -g -std=c++11 -o testconstructor testconstructor.cpp
程序运行并打印预期输出“63”。
但是,当在 return 语句之前在 main 中设置断点时,尝试调用构造函数会失败并显示神秘的错误消息:
p lldbtest(string("hey there"))
error: call to a function 'lldbtest::lldbtest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)' ('_ZN8lldbtestC1ENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE') that is not present in the target
error: The expression could not be prepared to run in the target
可能也相关的是,命令:
p lldbtest(name)
根本不打印任何内容。
此外,使用字符串文字调用构造函数也失败了,标准方法是:
p lldbtest("foo")
给出类似的长错误:
error: call to a function
'lldbtest::lldbtest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)' ('_ZN8lldbtestC1ENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE') that is not present in the targeterror: The expression could not be prepared to run in the target
有没有办法让 lldb 理解和使用 C++“字符串”数据类型?我有许多采用字符串参数的函数,并且需要一种从调试器调用这些函数的方法。在 Mac 上。