<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>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.<div><br></div><div>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?</div><div><br></div><div>PS: I know there's a function SBValue::GetID, but that seems to return different result on different stop.</div><br /><br /><div>> Subject: Re: [lldb-dev] What's the difference between GetLocation, AddressOf and GetLoadAddress<br>> From: gclayton@apple.com<br>> Date: Mon, 30 Mar 2015 13:03:14 -0700<br>> CC: lldb-dev@cs.uiuc.edu<br>> To: s.ziming@hotmail.com<br>> <br>> If your variables are both pointers, then you just get the value as unsigned:<br>> <br>> SBValue value1 = ...;<br>> SBValue value2 = ...;<br>> if (value1.GetType().IsPointerType() && value2.GetType().IsPointerType())<br>> {<br>>     if (value1.GetValueAsUnsigned() == value2.GetValueAsUnsigned())<br>>     {<br>>         // Pointers are the same<br>>     }<br>> }<br>> <br>> <br>> <br>> > On Mar 30, 2015, at 11:50 AM, Ziming Song <s.ziming@hotmail.com> wrote:<br>> > <br>> > 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.<br>> > In the API doc, I found three functions that seem to do the work, they are:<br>> > <br>> > - SBValue::GetLocation -> const char*<br>> > - SBValue::AddressOf -> SBValue<br>> > - SBValue::GetLoadLocation -> addr_t (uint64_t)<br>> > <br>> 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)?<br>> <br>> 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). <br>> <br>> 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 **".<br>> <br>> 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.<br>> <br>> 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":<br>> <br>> SBValue foo1 = get_instance_of_foo();<br>> SBValue foo2 = get_pointer_to_foo();<br>> <br>> You can still check if these point to the same instance if you wanted to:<br>> <br>> lldb::addr_t foo1_load_location = LLDB_INVALID_ADDRESS;<br>> lldb::addr_t foo2_load_location = LLDB_INVALID_ADDRESS;<br>> if (foo1.GetType().IsPointerType())<br>>     foo1_load_location = foo1.GetValueAsUnsigned();<br>> else<br>>     foo1_load_location = foo1.GetLoadLocation();<br>> <br>> if (foo2.GetType().IsPointerType())<br>>     foo2_load_location = foo2.GetValueAsUnsigned();<br>> else<br>>     foo2_load_location = foo2.GetLoadLocation();<br>> <br>> if (foo1_load_location == foo2_load_location && foo2_load_location != LLDB_INVALID_ADDRESS)<br>> {<br>>     // Two SBValue represent the same value in memory<br>> }<br>> <br>> Again you really need to understand what you are asking of the value.<br>> <br>> <br>> Greg Clayton<br>> <br></div>                                      </div></body>
</html>