BRabbit27
BRabbit27

Reputation: 6623

LLDB C++ debugging

I am new to LLDB and I am working with various std::vectors in my code, however when I try to print the values of a vector or to query the size of my vector with something like expr '(int)myVector[0]' or expr '(int)myVector.size()' the debugger prints values that have nothing to do with the values I know there are in the vector.

As I'm learning to debug with command line and LLDB, I'm sure I'm missing something here, can anyone spot my error or give some advise?

EDIT Forgot to say that I'm under OS X Mavericks with the latest command-line tools installed.

Upvotes: 13

Views: 9955

Answers (2)

BRabbit27
BRabbit27

Reputation: 6623

I found the answer myself. Apparently the overloaded operators like [] are not allowed since they are inlined, see this question for a better explanation on that.

Moreover, I don't know why did I put single quotes for the statement I wanted to evaluate (I'm pretty sure I saw it in other place ... what do they actually mean in LLDB?) like so expr 'printf("Hey")'

So, taking out the quotes and using the answer in the cited question it suffices with something like

expr (int) myVector.__begin_[0]

to get the single value of a position in the vector.

Upvotes: 20

James Bedford
James Bedford

Reputation: 28962

Use p myVector or po myVector. These will print out the contents of your vector (alongside the size) in a couple of different formats.

To print a single value from the vector, you can use something like p (int)myVector[0].

Upvotes: 3

Related Questions