سؤال

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

نصائح أخرى

you cannot using std::cout in commandline as you cannot WATCH it in ANY Debuger, but you can declare a reference to it like this:

std::ostream& os = std::cout;

so that you can execuate command expr os << "ok" in lldb.

here is the running result in my mac:

http://i.stack.imgur.com/lHvfa.jpg

hope it helpful

I'm not positive this is a dup but I believe the answer from Jim Ingham over in

Evaluating an expression with overloaded operators in c++ lldb

is likely highly relevant to the problem you're seeing here.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top