dimakovalenko
dimakovalenko

Reputation: 23

LLDB evaluations run out of memory on iOS. How can I free some memory?

In LLDB console on iOS, I repeated

(lldb) p/x $r1
(unsigned int) $1 = 0x07000006

(lldb) p/x $r1
(unsigned int) $2 = 0x07000006

(lldb) p/x $r1
(unsigned int) $3 = 0x07000006
 ...etc

about 1500 times, and finally got the following error message

error: Couldn't allocate space for the stack frame: Couldn't malloc: address space is full
Errored out in Execute, couldn't PrepareToExecuteJITExpression

As far as I understand it, each time I run p/x $r1, the debugger evaluates $r1 as an expression and allocates a buffer in a memory for a temporary variable $N (where N = 1, 2, 3, ...). After about 1500 evaluations, the debugger run out of memory and can't allocate buffers anymore.

My question is how can I free some memory? E.g. if I do not need the temporary variable $1 anymore, can I do something like free($1)? Are there any "secret" lldb commands for that?

Thanks in advance for your answers.

Upvotes: 2

Views: 978

Answers (1)

Jim Ingham
Jim Ingham

Reputation: 27203

Are you doing p/x $r1 because you need to preserve value of $r1 in a temporary, or do you just want to see its value? If the latter, you can use:

(lldb) register read/x r1

which can be shortened to:

(lldb) re r/x r1

That directly prints the register without constructing a temporary. Similarly, if you just want to see the value of a local variable:

(lldb) frame variable foo

will print the value of foo without going through the full expression parser.

Note, there is also a bug in the current lldb that causes expressions to allocate way more memory than they need to - 1500 expressions is too few for you to really be running out of memory, even on a 32 bit system... That's been fixed in the lldb.llvm.org sources, but I don't know when the fix will make its way into a release.

There isn't currently a way to tell lldb either not to make, or to discard, these convenience variables. There's no reason this couldn't be done, there just hasn't been a need for it.

Upvotes: 1

Related Questions