Every time the process stops, I use SBFrame::GetVariables to get to variable 
list and display them in the "variable" window. Since variable within different 
scope may have same name, I want to use the address of the variable to check if 
they are same. For example, when the process first stop, I got a variable "a" 
at address 0x123. While on the next stop, I got a variable "a" at address 
0x456, so I know these two "a" are different variables.
If variable can also be in register, how can I know if two variables got from 
two stop are the same. Is there a way to get the identity of variables?
PS: I know there's a function SBValue::GetID, but that seems to return 
different result on different stop.> Subject: Re: [lldb-dev] What's the 
difference between GetLocation, AddressOf and GetLoadAddress
> From: gclay...@apple.com
> Date: Mon, 30 Mar 2015 13:03:14 -0700
> CC: lldb-dev@cs.uiuc.edu
> To: s.zim...@hotmail.com
> 
> If your variables are both pointers, then you just get the value as unsigned:
> 
> SBValue value1 = ...;
> SBValue value2 = ...;
> if (value1.GetType().IsPointerType() && value2.GetType().IsPointerType())
> {
>     if (value1.GetValueAsUnsigned() == value2.GetValueAsUnsigned())
>     {
>         // Pointers are the same
>     }
> }
> 
> 
> 
> > On Mar 30, 2015, at 11:50 AM, Ziming Song <s.zim...@hotmail.com> wrote:
> > 
> > I want to know if two pointer point to the same variable, so I want to get 
> > the location of each variable and the value of the pointer.
> > In the API doc, I found three functions that seem to do the work, they are:
> > 
> > - SBValue::GetLocation -> const char*
> > - SBValue::AddressOf -> SBValue
> > - SBValue::GetLoadLocation -> addr_t (uint64_t)
> > 
> Why do you want the location? A pointer will often be in a register like 
> "rax". And if a pointer is on the stack, why do you want the address of the 
> pointer (which is what SBValue::GetLocation() would tell you)?
> 
> So: SBValue::GetLocation() will tell you where a variable is stored. It might 
> be something like "rax" when it is in a register. Or some address when it is 
> on the stack, heap or .data section. But this is the location of the value 
> itself (address of the pointer). 
> 
> SBValue::AddressOf() will return a new SBValue that represents the address of 
> the value itself. If your variable is in a register, this will be invalid. If 
> you already have a pointer like a "Foo *", then calling AddressOf will return 
> you a value that is a "Foo **".
> 
> If you want to know if something is loaded in memory and not in a register, 
> you can call SBValue::GetLoadLocation() which will only return a valid 
> address _if_ the value is actually in memory. If you have a pointer that is 
> in "rax" you will get back LLDB_INVALID_ADDRESS.
> 
> So to sum up: if you have a SBValue that represents a pointer, you can ask 
> the value for its value as unsigned using SBValue::GetValueAsUnsigned() since 
> that will be the pointer value itself. You don't want the location (the 
> address of) the value. The SBValue::AddressOf() can be used on a variable 
> that is actually an instance of "Foo". So if you have a variable whose type 
> is "Foo", and a pointer to a "Foo":
> 
> SBValue foo1 = get_instance_of_foo();
> SBValue foo2 = get_pointer_to_foo();
> 
> You can still check if these point to the same instance if you wanted to:
> 
> lldb::addr_t foo1_load_location = LLDB_INVALID_ADDRESS;
> lldb::addr_t foo2_load_location = LLDB_INVALID_ADDRESS;
> if (foo1.GetType().IsPointerType())
>     foo1_load_location = foo1.GetValueAsUnsigned();
> else
>     foo1_load_location = foo1.GetLoadLocation();
> 
> if (foo2.GetType().IsPointerType())
>     foo2_load_location = foo2.GetValueAsUnsigned();
> else
>     foo2_load_location = foo2.GetLoadLocation();
> 
> if (foo1_load_location == foo2_load_location && foo2_load_location != 
> LLDB_INVALID_ADDRESS)
> {
>     // Two SBValue represent the same value in memory
> }
> 
> Again you really need to understand what you are asking of the value.
> 
> 
> Greg Clayton
> 
                                          
_______________________________________________
lldb-dev mailing list
lldb-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev

Reply via email to