taocp
taocp

Reputation: 23644

How to get members of class in LLDB through pointer to class instance

I am now using LLDB (pretty new user) in MAC. I have the following sample code:

 MessageCacheItem::pointer msg = getValue(objId);
 bool outdated = (NULL != msg.get()) && (msgSentTime > msg->m_msgSentTime);
 return outdated;

MessageCacheItem is a class that has a private member m_msgSentTime. Inside LLDB, I used the following command:

fr v msg->m_msgSentTime

It gave me the following error:

error: "msg" is not a pointer and -> was used to attempt to access "m_msgSentTime". Did you mean "badge.m_msgSentTime"?

While msg is a shared_pointer to the class instance.

My question is: How do I examine members of class with pointer to class instance in LLDB?

Upvotes: 0

Views: 1786

Answers (2)

Jason Molenda
Jason Molenda

Reputation: 15405

frame variable (fr v) has very simple C language syntax knowledge built in to it. It works on variables local to a stack frame (or global variables if you use target variable) - it knows how to dereference a pointer (*, ->) and it knows how to look at a sub element of a structure (.) and I think it can do array indexing ([1]). But that's about it. You definitely can't do a function call like fr v msg.get()->m_msgSentTime (or fr v msg->m_msgSentTime which is equivalent). You can't put any type casts in your variable expression with frame variable.

You might have been able to do this with something like fr v msg.__ptr_->m_msgSentTime or whatever, depending on the implementation of your shared pointer object.

Upvotes: 1

taocp
taocp

Reputation: 23644

Instead of using

fr v msg->m_msgSentTime

use the following instead:

p msg->msgSentTime

However, I have not found where is the difference between these two commands yet (Just in case someone might see the same issue, I answered my own question). If any LLDB guru knows the difference, you are welcomed to add more.

Upvotes: 1

Related Questions