Lldb: print variable address

I am trying to print the address of a variable using lldb . However, calling print &(myVar) prints the contents of the variable instead of its address.

 (lldb) print &(myVar) (const string *) $18 = "hello" 

Same thing for expression &(myVar) .

 (lldb) expression &(myVar) (const string *) $19 = "hello" 

I also tried the expression -L option:

 (lldb) expression -L -- &(myVar) 0x00000000021aea80: (const string *) $20 = "hello" (lldb) expression -L -- myVar 0x0000000002a15430: (std::string) $23 = "hello" 

However, the address is output every time I call expression -L . Therefore, I assume that it does not match the address of the variable in memory.

How to get the address of a variable in memory?

(I am using lldb 3.4)

+6
source share
1 answer

Yes, the -L location tells you about the variable that lldb does to represent the result of the expression, so this is not what you want. Despite the fact that the common alias of the print command pretends that this command simply prints values, it does much more than that: for example. creating new objects in a running program. Thus, the location of the result of the expression is not trivially related to the expression that you evaluated.

In any case, there are two easy ways to achieve this. First off, turn off the summary of the lines so you can see the actual result of printing the address:

 (lldb) expr --raw -- &my_string (string *) $14 = 0x00007fff5fbff618 

Another way to get the same data is to use the "frame variable" command. This command gives you access to local variables without the overhead of a full expression parser. Since the frame variable prints the variables directly, as the debugging information reports, in this case the -L parameter is exactly the location of the variable:

 (lldb) frame var -L my_string 0x00007fff5fbff618: (std::__1::string) my_string = "Some string here" 
+8
source

All Articles