I'm trying to call std::cout
within lldb in an Xcode 5 C++ project. My project has an #include <iostream>
line (and I verified that compiled std::cout
commands work fine), but it does not have a using namespace std;
line.
When I stop at a breakpoint in lldb, I can't call std::cout
:
(lldb) expr std::cout << "test"
error: no member named 'cout' in namespace 'std'
error: 1 errors parsing expression
(lldb) expr cout << "test"
error: use of undeclared identifier 'cout'
error: 1 errors parsing expression
For those interested, I'm trying to use std::cout
to print an OpenCV Mat
object. But that detail is probably not important.
My lldb version is lldb-300.2.53
.
By request, here's the (trivial) code:
#include <iostream>
int main(int argc, const char * argv[])
{
std::cout << "Hello World" << std::endl;
return 0;
}
The breakpoint is at the return 0;
line.
maybe you can do it by another way:
1, create a dylib, import all headers needed, write a function like this:
void mylog(const MyObject& obj)
{
//assume MyObject is the type you want to view in Debuger
std::cout << obj << std::endl;
}
build as libdbghelper.dylib in your desktop(or another path which is short).
2,load it in to your debugging project:
(lldb) target modules add /Users/yourName/Desktop/libdbghelper.dylib
3,then you can log it with command
(lldb)expr mylog((const MyObject&)myobj);
here is the running result in my mac: http://i.stack.imgur.com/LBBLJ.jpg
the code of dylib like that: http://i.stack.imgur.com/H1Q9v.jpg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With