我正在使用lldb在Xcode 5中调试C++程序,我想在调试器中评估任意表达式,特别是那些使用重载运算符的表达式.
例如,我创建了一个非常简单的Xcode 5 C++项目,其中包含以下main.cpp和所有编译器/链接器/ etc选项设置为默认值:
#include <iostream>
#include <vector>
int main(int argc, const char * argv[])
{
std::vector<int> vec;
vec.push_back(42);
std::cout << "vec[0] = " << vec[0] << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在线上设置断点return 0;并运行程序.
然后,在lldb提示符下,整个打印矢量工作正常:
(lldb) expr vec
(std::__1::vector<int, std::__1::allocator<int> >) $0 = size=1 {
[0] = 42
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法使用重载访问其成员operator[]:
(lldb) expr vec[0]
error: call to a function 'std::__1::vector<int, std::__1::allocator<int> >::operator[](unsigned long)' ('_ZNSt3__16vectorIiNS_9allocatorIiEEEixEm') that is not present in the target
error: The expression could not …Run Code Online (Sandbox Code Playgroud)