[lldb-dev] SBValues referencing deallocated memory

Pavel Labath via lldb-dev lldb-dev at lists.llvm.org
Wed Nov 27 00:03:13 PST 2019

On 27/11/2019 08:47, Raphael “Teemperor” Isemann via lldb-dev wrote:
> This can also be reproduced in the command line like this:
> (lldb) expr "foo"
> (const char [4]) $0 = "foo"
> (lldb) expr "bar"
> (const char [4]) $1 = "bar"
> (lldb) expr $0
> (const char [4]) $0 = “bar”
> This however works just fine:
> (lldb) expr char c[] = "foo"; c
> (char [4]) $0 = "foo"
> (lldb) expr char c[] = "bar"; c
> (char [4]) $1 = "bar"
> (lldb) expr $0
> (char [4]) $0 = “foo”
> I don’t know the related code so well, but from what I remember we have 
> a storage mechanism for persistent variables that we fill up (in 
> the ‘Materializer’ IIRC). We probably just copy the pointer itself to 
> this storage but not the memory it points to. I guess we could tweak 
> that logic to detect pointers that point into memory LLDB allocated and 
> then either extract the necessary memory into our storage or keep the 
> related sections around.
> Anyway, I filed https://bugs.llvm.org/show_bug.cgi?id=44155 and I will 
> ask around what solution people would prefer once thanksgiving is over.

You can find a kind of a description of how this is meant to work in 

Persisting string literals that were typed into the expression seems 
reasonable and hopefully not too difficult, and it would kind of match 
what happens during "normal" compilation. Doing that for random "const 
char *"s that you happen to stumble upon in the result variable seems 
more problematic, and I'm not sure we should even try...


More information about the lldb-dev mailing list