[Lldb-commits] [PATCH] D98370: [lldb] Fix SBValue::Persist() for constant values

Jim Ingham via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 22 12:18:06 PDT 2021


jingham added a comment.

In D98370#2708672 <https://reviews.llvm.org/D98370#2708672>, @werat wrote:

> In D98370#2705741 <https://reviews.llvm.org/D98370#2705741>, @jingham wrote:
>
>> Sure.  But but when I was poking around at it a little bit, it seems like the other use cases already work, and the only one that was failing was the case where you call persist on a persistent variable.  If that is really true, then maybe we should fix the failing case directly.
>
> Right now `Persist()` doesn't really work for values created via `CreateValueFromData`. You can read them, but can't modify:
>
>   >>> data = lldb.SBData.CreateDataFromUInt64Array(lldb.process.GetByteOrder(), lldb.process.GetAddressByteSize(), [42])
>   >>> v = lldb.target.CreateValueFromData('v', data, lldb.target.GetBasicType(lldb.eBasicTypeUnsignedLong))
>   >>> v.value
>   '42'
>   >>> vp = v.Persist()
>   >>> vp.name
>   '$3'
>   >>> lldb.frame.EvaluateExpression('$3').value
>   '42'
>   >>> lldb.frame.EvaluateExpression('++$3 + 1').value
>   >>> lldb.frame.EvaluateExpression('++$3 + 1').error.GetCString()
>   "error: supposed to interpret, but failed: Interpreter couldn't read from memory\n"
>
> However I realized my patch doesn't completely fixes it either:
>
>   >>> data = lldb.SBData.CreateDataFromUInt64Array(lldb.process.GetByteOrder(), lldb.process.GetAddressByteSize(), [42])
>   >>> v = lldb.target.CreateValueFromData('v', data, lldb.target.GetBasicType(lldb.eBasicTypeUnsignedLong))
>   >>> vp = v.Persist()
>   >>> vp.name
>   '$0'
>   >>> lldb.frame.EvaluateExpression('$0').value
>   '42'
>   >>> lldb.frame.EvaluateExpression('++$0').value
>   '43'
>   >>> lldb.frame.EvaluateExpression('++$0').value
>   '44'
>   >>> vp.value
>   '42'
>
>
>
> In D98370#2705741 <https://reviews.llvm.org/D98370#2705741>, @jingham wrote:
>
>> Not sure why?  The API is a request:  "I made a variable somehow, and I would like you to make it persist so I can use its value later on even if the underlying data has changed."  Why do you care whether you get a copy of an already persistent or just a shared value?
>
> You're right, I got confused by something else. I don't care if I get a new name/copy, as long as I can use it by the returned name it's fine. However I want to point out that the current API does generate a new name every time (but the it points to the same data):
>
>   >>> x = lldb.frame.FindVariable('x')
>   >>> x.value
>   '1'
>   >>> xp1 = x.Persist()
>   >>> xp1.name
>   '$0'
>   >>> xp2 = x.Persist()
>   >>> xp2.name
>   '$1'
>   >>> lldb.frame.EvaluateExpression('++$0 + ++$1').value
>   '3'
>   >>> xp1.value
>   '3'
>   >>> xp2.value
>   '3'

Be careful here.  There are really two kinds of persistent variables: "expression results" and variables created in the expression parser.  The former are by design constant.  The idea is that you can use them to checkpoint the state of a value and refer to it later.  You can use their values in expressions, but they aren't supposed to be modifiable.  Those are the ones called $NUM.

The ones you make in an expression, like:

(lldb) expr int $myVar = 20

on the other hand are modifiable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98370/new/

https://reviews.llvm.org/D98370



More information about the lldb-commits mailing list