【发布时间】:2014-07-29 01:55:59
【问题描述】:
我无法使用 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”的预期输出。
但是,如果在 main 中的 return 语句之前设置了一个断点,并且尝试调用构造函数失败并显示一个神秘的错误消息:
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 上。
【问题讨论】: