Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lldb : Printing a variable's address

Tags:

I am trying to print a variable's address with lldb. However, calling print &(myVar) prints the variable's content instead of its address.

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

Same for expression &(myVar).

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

I also tried expression's -L option :

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

However the address outputted changes each time I invoke expression -L. Hence I am assuming that it does not correspond to the variable's address in memory.

How do I get the variable's address in memory ?

(I use lldb 3.4)

like image 641
Gael Lorieul Avatar asked Mar 19 '16 17:03

Gael Lorieul


People also ask

How do I display a variable in LLDB?

To do that, you can use %format inside an expression path, as in ${var. x->x%u}, which would display the value of x as an unsigned integer. Use this object's location (memory address, register name, …) Since lldb 3.7.

How do you set a breakpoint in LLDB?

In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )


1 Answers

Yes, the -L location is telling you about the variable that lldb makes to represent the expression result, so that isn't what you want. Even though the common command alias print makes it seem like this command just prints values, it does a lot more than that: e.g. creating new entities in the running program. So the location of the expression result is not trivially related to the expression you evaluated.

Anyway, there are two easy ways to get at this. The first is to turn off the string summary, so you can see the actual result of printing the address:

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

Another way to get at the same data is to use the "frame variable" command. This command gives you access to local variables, without the overhead of the full expression parser. Since frame variable prints the variables directly as reported by the debug info, in that case the -L option is exactly the variable's location:

(lldb) frame var -L my_string 0x00007fff5fbff618: (std::__1::string) my_string = "Some string here" 
like image 112
Jim Ingham Avatar answered Sep 23 '22 00:09

Jim Ingham