[Lldb-commits] [lldb] 1d9b860 - Unify the return value of GetByteSize to an llvm::Optional<uint64_t> (NFC-ish)

Eric Christopher via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 27 09:54:39 PDT 2020


No problem, thanks! :)

On Mon, Jul 27, 2020, 9:26 AM Adrian Prantl <aprantl at apple.com> wrote:

> Thanks, Eric! Sorry for not paying attention after landing this.
>
> -- adrian
>
> On Jul 25, 2020, at 6:43 PM, Eric Christopher <echristo at gmail.com> wrote:
>
> Hi Adrian,
>
> I'm really sorry, but I've just reverted this. I'm not sure what's up, but
> it's causing massive test failures in lldb on linux. Happy to help sync up
> with you.
>
> echristo at athyra ~/s/llvm-project> git push
> To github.com:llvm/llvm-project.git
>    18975762c19..4b14ef33e81  master -> master
>
> Thanks!
>
> -eric
>
> On Sat, Jul 25, 2020 at 8:28 AM Adrian Prantl via lldb-commits <
> lldb-commits at lists.llvm.org> wrote:
>
>>
>> Author: Adrian Prantl
>> Date: 2020-07-25T08:27:21-07:00
>> New Revision: 1d9b860fb6a85df33fd52fcacc6a5efb421621bd
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/1d9b860fb6a85df33fd52fcacc6a5efb421621bd
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/1d9b860fb6a85df33fd52fcacc6a5efb421621bd.diff
>>
>> LOG: Unify the return value of GetByteSize to an llvm::Optional<uint64_t>
>> (NFC-ish)
>>
>> This cleanup patch unifies all methods called GetByteSize() in the
>> ValueObject hierarchy to return an optional, like the methods in
>> CompilerType do. This means fewer magic 0 values, which could fix bugs
>> down the road in languages where types can have a size of zero, such
>> as Swift and C (but not C++).
>>
>> Differential Revision: https://reviews.llvm.org/D84285
>>
>> Added:
>>
>>
>> Modified:
>>     lldb/include/lldb/Core/ValueObject.h
>>     lldb/include/lldb/Core/ValueObjectCast.h
>>     lldb/include/lldb/Core/ValueObjectChild.h
>>     lldb/include/lldb/Core/ValueObjectConstResult.h
>>     lldb/include/lldb/Core/ValueObjectDynamicValue.h
>>     lldb/include/lldb/Core/ValueObjectMemory.h
>>     lldb/include/lldb/Core/ValueObjectRegister.h
>>     lldb/include/lldb/Core/ValueObjectSyntheticFilter.h
>>     lldb/include/lldb/Core/ValueObjectVariable.h
>>     lldb/include/lldb/Expression/ExpressionVariable.h
>>     lldb/include/lldb/Target/StackFrameRecognizer.h
>>     lldb/source/API/SBValue.cpp
>>     lldb/source/Commands/CommandObjectWatchpoint.cpp
>>     lldb/source/Core/ValueObject.cpp
>>     lldb/source/Core/ValueObjectCast.cpp
>>     lldb/source/Core/ValueObjectConstResult.cpp
>>     lldb/source/Core/ValueObjectDynamicValue.cpp
>>     lldb/source/Core/ValueObjectMemory.cpp
>>     lldb/source/Core/ValueObjectRegister.cpp
>>     lldb/source/Core/ValueObjectSyntheticFilter.cpp
>>     lldb/source/Core/ValueObjectVariable.cpp
>>     lldb/source/Expression/ExpressionVariable.cpp
>>     lldb/source/Expression/Materializer.cpp
>>     lldb/source/Target/StackFrame.cpp
>>
>> Removed:
>>
>>
>>
>>
>> ################################################################################
>> diff  --git a/lldb/include/lldb/Core/ValueObject.h
>> b/lldb/include/lldb/Core/ValueObject.h
>> index 0080368fd996..a557d69f3ae3 100644
>> --- a/lldb/include/lldb/Core/ValueObject.h
>> +++ b/lldb/include/lldb/Core/ValueObject.h
>> @@ -358,7 +358,7 @@ class ValueObject : public UserID {
>>    virtual bool CanProvideValue();
>>
>>    // Subclasses must implement the functions below.
>> -  virtual uint64_t GetByteSize() = 0;
>> +  virtual llvm::Optional<uint64_t> GetByteSize() = 0;
>>
>>    virtual lldb::ValueType GetValueType() const = 0;
>>
>>
>> diff  --git a/lldb/include/lldb/Core/ValueObjectCast.h
>> b/lldb/include/lldb/Core/ValueObjectCast.h
>> index d91ca6a92be8..342803f8ca63 100644
>> --- a/lldb/include/lldb/Core/ValueObjectCast.h
>> +++ b/lldb/include/lldb/Core/ValueObjectCast.h
>> @@ -30,7 +30,7 @@ class ValueObjectCast : public ValueObject {
>>                                      ConstString name,
>>                                      const CompilerType &cast_type);
>>
>> -  uint64_t GetByteSize() override;
>> +  llvm::Optional<uint64_t> GetByteSize() override;
>>
>>    size_t CalculateNumChildren(uint32_t max) override;
>>
>>
>> diff  --git a/lldb/include/lldb/Core/ValueObjectChild.h
>> b/lldb/include/lldb/Core/ValueObjectChild.h
>> index c6f44a29b059..9a9fd9294261 100644
>> --- a/lldb/include/lldb/Core/ValueObjectChild.h
>> +++ b/lldb/include/lldb/Core/ValueObjectChild.h
>> @@ -30,7 +30,7 @@ class ValueObjectChild : public ValueObject {
>>  public:
>>    ~ValueObjectChild() override;
>>
>> -  uint64_t GetByteSize() override { return m_byte_size; }
>> +  llvm::Optional<uint64_t> GetByteSize() override { return m_byte_size; }
>>
>>    lldb::offset_t GetByteOffset() override { return m_byte_offset; }
>>
>>
>> diff  --git a/lldb/include/lldb/Core/ValueObjectConstResult.h
>> b/lldb/include/lldb/Core/ValueObjectConstResult.h
>> index 0e868c687e93..8d823baa0b7b 100644
>> --- a/lldb/include/lldb/Core/ValueObjectConstResult.h
>> +++ b/lldb/include/lldb/Core/ValueObjectConstResult.h
>> @@ -62,7 +62,7 @@ class ValueObjectConstResult : public ValueObject {
>>    static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope,
>>                                      const Status &error);
>>
>> -  uint64_t GetByteSize() override;
>> +  llvm::Optional<uint64_t> GetByteSize() override;
>>
>>    lldb::ValueType GetValueType() const override;
>>
>> @@ -113,7 +113,7 @@ class ValueObjectConstResult : public ValueObject {
>>    CompilerType GetCompilerTypeImpl() override;
>>
>>    ConstString m_type_name;
>> -  uint64_t m_byte_size;
>> +  llvm::Optional<uint64_t> m_byte_size;
>>
>>    ValueObjectConstResultImpl m_impl;
>>
>>
>> diff  --git a/lldb/include/lldb/Core/ValueObjectDynamicValue.h
>> b/lldb/include/lldb/Core/ValueObjectDynamicValue.h
>> index 9f5304b55e93..2806857339ef 100644
>> --- a/lldb/include/lldb/Core/ValueObjectDynamicValue.h
>> +++ b/lldb/include/lldb/Core/ValueObjectDynamicValue.h
>> @@ -34,7 +34,7 @@ class ValueObjectDynamicValue : public ValueObject {
>>  public:
>>    ~ValueObjectDynamicValue() override;
>>
>> -  uint64_t GetByteSize() override;
>> +  llvm::Optional<uint64_t> GetByteSize() override;
>>
>>    ConstString GetTypeName() override;
>>
>>
>> diff  --git a/lldb/include/lldb/Core/ValueObjectMemory.h
>> b/lldb/include/lldb/Core/ValueObjectMemory.h
>> index d1cd6ae41445..b5d5e6ecf4c0 100644
>> --- a/lldb/include/lldb/Core/ValueObjectMemory.h
>> +++ b/lldb/include/lldb/Core/ValueObjectMemory.h
>> @@ -40,7 +40,7 @@ class ValueObjectMemory : public ValueObject {
>>                                      const Address &address,
>>                                      const CompilerType &ast_type);
>>
>> -  uint64_t GetByteSize() override;
>> +  llvm::Optional<uint64_t> GetByteSize() override;
>>
>>    ConstString GetTypeName() override;
>>
>>
>> diff  --git a/lldb/include/lldb/Core/ValueObjectRegister.h
>> b/lldb/include/lldb/Core/ValueObjectRegister.h
>> index 41051d93b707..3968584ad518 100644
>> --- a/lldb/include/lldb/Core/ValueObjectRegister.h
>> +++ b/lldb/include/lldb/Core/ValueObjectRegister.h
>> @@ -36,7 +36,7 @@ class ValueObjectRegisterSet : public ValueObject {
>>                                      lldb::RegisterContextSP &reg_ctx_sp,
>>                                      uint32_t set_idx);
>>
>> -  uint64_t GetByteSize() override;
>> +  llvm::Optional<uint64_t> GetByteSize() override;
>>
>>    lldb::ValueType GetValueType() const override {
>>      return lldb::eValueTypeRegisterSet;
>> @@ -86,7 +86,7 @@ class ValueObjectRegister : public ValueObject {
>>                                      lldb::RegisterContextSP &reg_ctx_sp,
>>                                      uint32_t reg_num);
>>
>> -  uint64_t GetByteSize() override;
>> +  llvm::Optional<uint64_t> GetByteSize() override;
>>
>>    lldb::ValueType GetValueType() const override {
>>      return lldb::eValueTypeRegister;
>>
>> diff  --git a/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h
>> b/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h
>> index cb471657aec9..41c461ce13f0 100644
>> --- a/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h
>> +++ b/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h
>> @@ -36,7 +36,7 @@ class ValueObjectSynthetic : public ValueObject {
>>  public:
>>    ~ValueObjectSynthetic() override;
>>
>> -  uint64_t GetByteSize() override;
>> +  llvm::Optional<uint64_t> GetByteSize() override;
>>
>>    ConstString GetTypeName() override;
>>
>>
>> diff  --git a/lldb/include/lldb/Core/ValueObjectVariable.h
>> b/lldb/include/lldb/Core/ValueObjectVariable.h
>> index b7e262574a14..23fdedbf5a4a 100644
>> --- a/lldb/include/lldb/Core/ValueObjectVariable.h
>> +++ b/lldb/include/lldb/Core/ValueObjectVariable.h
>> @@ -37,7 +37,7 @@ class ValueObjectVariable : public ValueObject {
>>    static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope,
>>                                      const lldb::VariableSP &var_sp);
>>
>> -  uint64_t GetByteSize() override;
>> +  llvm::Optional<uint64_t> GetByteSize() override;
>>
>>    ConstString GetTypeName() override;
>>
>>
>> diff  --git a/lldb/include/lldb/Expression/ExpressionVariable.h
>> b/lldb/include/lldb/Expression/ExpressionVariable.h
>> index 60062d212bad..4259e6395da4 100644
>> --- a/lldb/include/lldb/Expression/ExpressionVariable.h
>> +++ b/lldb/include/lldb/Expression/ExpressionVariable.h
>> @@ -32,7 +32,7 @@ class ExpressionVariable
>>
>>    virtual ~ExpressionVariable();
>>
>> -  size_t GetByteSize() { return m_frozen_sp->GetByteSize(); }
>> +  llvm::Optional<uint64_t> GetByteSize() { return
>> m_frozen_sp->GetByteSize(); }
>>
>>    ConstString GetName() { return m_frozen_sp->GetName(); }
>>
>>
>> diff  --git a/lldb/include/lldb/Target/StackFrameRecognizer.h
>> b/lldb/include/lldb/Target/StackFrameRecognizer.h
>> index 302b56bec907..baffc890bb06 100644
>> --- a/lldb/include/lldb/Target/StackFrameRecognizer.h
>> +++ b/lldb/include/lldb/Target/StackFrameRecognizer.h
>> @@ -154,7 +154,9 @@ class ValueObjectRecognizerSynthesizedValue : public
>> ValueObject {
>>      SetName(parent.GetName());
>>    }
>>
>> -  uint64_t GetByteSize() override { return m_parent->GetByteSize(); }
>> +  llvm::Optional<uint64_t> GetByteSize() override {
>> +    return m_parent->GetByteSize();
>> +  }
>>    lldb::ValueType GetValueType() const override { return m_type; }
>>    bool UpdateValue() override {
>>      if (!m_parent->UpdateValueIfNeeded()) return false;
>>
>> diff  --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
>> index 7485b0ee1838..686d1f23a75a 100644
>> --- a/lldb/source/API/SBValue.cpp
>> +++ b/lldb/source/API/SBValue.cpp
>> @@ -333,7 +333,7 @@ size_t SBValue::GetByteSize() {
>>    ValueLocker locker;
>>    lldb::ValueObjectSP value_sp(GetSP(locker));
>>    if (value_sp) {
>> -    result = value_sp->GetByteSize();
>> +    result = value_sp->GetByteSize().getValueOr(0);
>>    }
>>
>>    return result;
>>
>> diff  --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp
>> b/lldb/source/Commands/CommandObjectWatchpoint.cpp
>> index ce4662930a7c..c2a008af79d6 100644
>> --- a/lldb/source/Commands/CommandObjectWatchpoint.cpp
>> +++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp
>> @@ -905,7 +905,7 @@ corresponding to the byte size of the data type.");
>>          // We're in business.
>>          // Find out the size of this variable.
>>          size = m_option_watchpoint.watch_size == 0
>> -                   ? valobj_sp->GetByteSize()
>> +                   ? valobj_sp->GetByteSize().getValueOr(0)
>>                     : m_option_watchpoint.watch_size;
>>        }
>>        compiler_type = valobj_sp->GetCompilerType();
>>
>> diff  --git a/lldb/source/Core/ValueObject.cpp
>> b/lldb/source/Core/ValueObject.cpp
>> index 3a775b07e5e1..aedefd0cf0fd 100644
>> --- a/lldb/source/Core/ValueObject.cpp
>> +++ b/lldb/source/Core/ValueObject.cpp
>> @@ -849,7 +849,7 @@ bool ValueObject::SetData(DataExtractor &data, Status
>> &error) {
>>    uint64_t count = 0;
>>    const Encoding encoding = GetCompilerType().GetEncoding(count);
>>
>> -  const size_t byte_size = GetByteSize();
>> +  const size_t byte_size = GetByteSize().getValueOr(0);
>>
>>    Value::ValueType value_type = m_value.GetValueType();
>>
>> @@ -1524,7 +1524,7 @@ bool ValueObject::SetValueFromCString(const char
>> *value_str, Status &error) {
>>    uint64_t count = 0;
>>    const Encoding encoding = GetCompilerType().GetEncoding(count);
>>
>> -  const size_t byte_size = GetByteSize();
>> +  const size_t byte_size = GetByteSize().getValueOr(0);
>>
>>    Value::ValueType value_type = m_value.GetValueType();
>>
>> @@ -1741,13 +1741,13 @@ ValueObjectSP
>> ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to,
>>        uint32_t bit_field_offset = from;
>>        if (GetDataExtractor().GetByteOrder() == eByteOrderBig)
>>          bit_field_offset =
>> -            GetByteSize() * 8 - bit_field_size - bit_field_offset;
>> +            GetByteSize().getValueOr(0) * 8 - bit_field_size -
>> bit_field_offset;
>>        // We haven't made a synthetic array member for INDEX yet, so lets
>> make
>>        // one and cache it for any future reference.
>>        ValueObjectChild *synthetic_child = new ValueObjectChild(
>> -          *this, GetCompilerType(), index_const_str, GetByteSize(), 0,
>> -          bit_field_size, bit_field_offset, false, false,
>> eAddressTypeInvalid,
>> -          0);
>> +          *this, GetCompilerType(), index_const_str,
>> +          GetByteSize().getValueOr(0), 0, bit_field_size,
>> bit_field_offset,
>> +          false, false, eAddressTypeInvalid, 0);
>>
>>        // Cache the value if we got one back...
>>        if (synthetic_child) {
>>
>> diff  --git a/lldb/source/Core/ValueObjectCast.cpp
>> b/lldb/source/Core/ValueObjectCast.cpp
>> index 22e856be539b..7b6d3591faf4 100644
>> --- a/lldb/source/Core/ValueObjectCast.cpp
>> +++ b/lldb/source/Core/ValueObjectCast.cpp
>> @@ -47,7 +47,7 @@ size_t ValueObjectCast::CalculateNumChildren(uint32_t
>> max) {
>>    return children_count <= max ? children_count : max;
>>  }
>>
>> -uint64_t ValueObjectCast::GetByteSize() {
>> +llvm::Optional<uint64_t> ValueObjectCast::GetByteSize() {
>>    ExecutionContext exe_ctx(GetExecutionContextRef());
>>    return m_value.GetValueByteSize(nullptr, &exe_ctx);
>>  }
>>
>> diff  --git a/lldb/source/Core/ValueObjectConstResult.cpp
>> b/lldb/source/Core/ValueObjectConstResult.cpp
>> index 8d84f8e62ccc..fd31ddc676b4 100644
>> --- a/lldb/source/Core/ValueObjectConstResult.cpp
>> +++ b/lldb/source/Core/ValueObjectConstResult.cpp
>> @@ -179,8 +179,7 @@ ValueObjectSP
>> ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
>>  ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope
>> *exe_scope,
>>                                                 ValueObjectManager
>> &manager,
>>                                                 const Status &error)
>> -    : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0),
>> -      m_impl(this) {
>> +    : ValueObject(exe_scope, manager), m_impl(this) {
>>    m_error = error;
>>    SetIsConstant();
>>  }
>> @@ -189,8 +188,7 @@
>> ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope
>> *exe_scope,
>>                                                 ValueObjectManager
>> &manager,
>>                                                 const Value &value,
>>                                                 ConstString name, Module
>> *module)
>> -    : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0),
>> -      m_impl(this) {
>> +    : ValueObject(exe_scope, manager), m_impl(this) {
>>    m_value = value;
>>    m_name = name;
>>    ExecutionContext exe_ctx;
>> @@ -208,9 +206,9 @@ lldb::ValueType
>> ValueObjectConstResult::GetValueType() const {
>>    return eValueTypeConstResult;
>>  }
>>
>> -uint64_t ValueObjectConstResult::GetByteSize() {
>> +llvm::Optional<uint64_t> ValueObjectConstResult::GetByteSize() {
>>    ExecutionContext exe_ctx(GetExecutionContextRef());
>> -  if (m_byte_size == 0) {
>> +  if (!m_byte_size) {
>>      if (auto size =
>>
>>  GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()))
>>        SetByteSize(*size);
>>
>> diff  --git a/lldb/source/Core/ValueObjectDynamicValue.cpp
>> b/lldb/source/Core/ValueObjectDynamicValue.cpp
>> index ca66740cb55d..1c25b8c85a05 100644
>> --- a/lldb/source/Core/ValueObjectDynamicValue.cpp
>> +++ b/lldb/source/Core/ValueObjectDynamicValue.cpp
>> @@ -98,7 +98,7 @@ size_t
>> ValueObjectDynamicValue::CalculateNumChildren(uint32_t max) {
>>      return m_parent->GetNumChildren(max);
>>  }
>>
>> -uint64_t ValueObjectDynamicValue::GetByteSize() {
>> +llvm::Optional<uint64_t> ValueObjectDynamicValue::GetByteSize() {
>>    const bool success = UpdateValueIfNeeded(false);
>>    if (success && m_dynamic_type_info.HasType()) {
>>      ExecutionContext exe_ctx(GetExecutionContextRef());
>>
>> diff  --git a/lldb/source/Core/ValueObjectMemory.cpp
>> b/lldb/source/Core/ValueObjectMemory.cpp
>> index 8e7d3ebc93f6..17fade9e5fdc 100644
>> --- a/lldb/source/Core/ValueObjectMemory.cpp
>> +++ b/lldb/source/Core/ValueObjectMemory.cpp
>> @@ -139,13 +139,11 @@ size_t
>> ValueObjectMemory::CalculateNumChildren(uint32_t max) {
>>    return child_count <= max ? child_count : max;
>>  }
>>
>> -uint64_t ValueObjectMemory::GetByteSize() {
>> +llvm::Optional<uint64_t> ValueObjectMemory::GetByteSize() {
>>    ExecutionContext exe_ctx(GetExecutionContextRef());
>>    if (m_type_sp)
>> -    return m_type_sp->GetByteSize(exe_ctx.GetBestExecutionContextScope())
>> -        .getValueOr(0);
>> -  return
>> m_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope())
>> -      .getValueOr(0);
>> +    return
>> m_type_sp->GetByteSize(exe_ctx.GetBestExecutionContextScope());
>> +  return
>> m_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
>>  }
>>
>>  lldb::ValueType ValueObjectMemory::GetValueType() const {
>>
>> diff  --git a/lldb/source/Core/ValueObjectRegister.cpp
>> b/lldb/source/Core/ValueObjectRegister.cpp
>> index ec87c38fb367..27461e9cebc4 100644
>> --- a/lldb/source/Core/ValueObjectRegister.cpp
>> +++ b/lldb/source/Core/ValueObjectRegister.cpp
>> @@ -81,7 +81,7 @@ size_t
>> ValueObjectRegisterSet::CalculateNumChildren(uint32_t max) {
>>    return 0;
>>  }
>>
>> -uint64_t ValueObjectRegisterSet::GetByteSize() { return 0; }
>> +llvm::Optional<uint64_t> ValueObjectRegisterSet::GetByteSize() { return
>> 0; }
>>
>>  bool ValueObjectRegisterSet::UpdateValue() {
>>    m_error.Clear();
>> @@ -229,7 +229,9 @@ size_t
>> ValueObjectRegister::CalculateNumChildren(uint32_t max) {
>>    return children_count <= max ? children_count : max;
>>  }
>>
>> -uint64_t ValueObjectRegister::GetByteSize() { return
>> m_reg_info.byte_size; }
>> +llvm::Optional<uint64_t> ValueObjectRegister::GetByteSize() {
>> +  return m_reg_info.byte_size;
>> +}
>>
>>  bool ValueObjectRegister::UpdateValue() {
>>    m_error.Clear();
>>
>> diff  --git a/lldb/source/Core/ValueObjectSyntheticFilter.cpp
>> b/lldb/source/Core/ValueObjectSyntheticFilter.cpp
>> index 32d1e6ab8368..fb2d32e602ce 100644
>> --- a/lldb/source/Core/ValueObjectSyntheticFilter.cpp
>> +++ b/lldb/source/Core/ValueObjectSyntheticFilter.cpp
>> @@ -121,7 +121,9 @@ bool ValueObjectSynthetic::MightHaveChildren() {
>>    return (m_might_have_children != eLazyBoolNo);
>>  }
>>
>> -uint64_t ValueObjectSynthetic::GetByteSize() { return
>> m_parent->GetByteSize(); }
>> +llvm::Optional<uint64_t> ValueObjectSynthetic::GetByteSize() {
>> +  return m_parent->GetByteSize();
>> +}
>>
>>  lldb::ValueType ValueObjectSynthetic::GetValueType() const {
>>    return m_parent->GetValueType();
>>
>> diff  --git a/lldb/source/Core/ValueObjectVariable.cpp
>> b/lldb/source/Core/ValueObjectVariable.cpp
>> index 0d1e7b047a0a..ab67e3038cf0 100644
>> --- a/lldb/source/Core/ValueObjectVariable.cpp
>> +++ b/lldb/source/Core/ValueObjectVariable.cpp
>> @@ -105,15 +105,15 @@ size_t
>> ValueObjectVariable::CalculateNumChildren(uint32_t max) {
>>    return child_count <= max ? child_count : max;
>>  }
>>
>> -uint64_t ValueObjectVariable::GetByteSize() {
>> +llvm::Optional<uint64_t> ValueObjectVariable::GetByteSize() {
>>    ExecutionContext exe_ctx(GetExecutionContextRef());
>>
>>    CompilerType type(GetCompilerType());
>>
>>    if (!type.IsValid())
>> -    return 0;
>> +    return {};
>>
>> -  return
>> type.GetByteSize(exe_ctx.GetBestExecutionContextScope()).getValueOr(0);
>> +  return type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
>>  }
>>
>>  lldb::ValueType ValueObjectVariable::GetValueType() const {
>>
>> diff  --git a/lldb/source/Expression/ExpressionVariable.cpp
>> b/lldb/source/Expression/ExpressionVariable.cpp
>> index d95f0745cf4b..8b3dda7b2fe1 100644
>> --- a/lldb/source/Expression/ExpressionVariable.cpp
>> +++ b/lldb/source/Expression/ExpressionVariable.cpp
>> @@ -16,10 +16,10 @@ using namespace lldb_private;
>>  ExpressionVariable::~ExpressionVariable() {}
>>
>>  uint8_t *ExpressionVariable::GetValueBytes() {
>> -  const size_t byte_size = m_frozen_sp->GetByteSize();
>> -  if (byte_size > 0) {
>> -    if (m_frozen_sp->GetDataExtractor().GetByteSize() < byte_size) {
>> -      m_frozen_sp->GetValue().ResizeData(byte_size);
>> +  llvm::Optional<uint64_t> byte_size = m_frozen_sp->GetByteSize();
>> +  if (byte_size && *byte_size) {
>> +    if (m_frozen_sp->GetDataExtractor().GetByteSize() < *byte_size) {
>> +      m_frozen_sp->GetValue().ResizeData(*byte_size);
>>        m_frozen_sp->GetValue().GetData(m_frozen_sp->GetDataExtractor());
>>      }
>>      return const_cast<uint8_t *>(
>>
>> diff  --git a/lldb/source/Expression/Materializer.cpp
>> b/lldb/source/Expression/Materializer.cpp
>> index 6f8d9b154570..327e15a26266 100644
>> --- a/lldb/source/Expression/Materializer.cpp
>> +++ b/lldb/source/Expression/Materializer.cpp
>> @@ -67,7 +67,7 @@ class EntityPersistentVariable : public
>> Materializer::Entity {
>>      const bool zero_memory = false;
>>
>>      lldb::addr_t mem = map.Malloc(
>> -        m_persistent_variable_sp->GetByteSize(), 8,
>> +        m_persistent_variable_sp->GetByteSize().getValueOr(0), 8,
>>          lldb::ePermissionsReadable | lldb::ePermissionsWritable,
>>          IRMemoryMap::eAllocationPolicyMirror, zero_memory,
>> allocate_error);
>>
>> @@ -106,7 +106,8 @@ class EntityPersistentVariable : public
>> Materializer::Entity {
>>      Status write_error;
>>
>>      map.WriteMemory(mem, m_persistent_variable_sp->GetValueBytes(),
>> -                    m_persistent_variable_sp->GetByteSize(),
>> write_error);
>> +
>> m_persistent_variable_sp->GetByteSize().getValueOr(0),
>> +                    write_error);
>>
>>      if (!write_error.Success()) {
>>        err.SetErrorStringWithFormat(
>> @@ -234,7 +235,7 @@ class EntityPersistentVariable : public
>> Materializer::Entity {
>>              map.GetBestExecutionContextScope(),
>>              m_persistent_variable_sp.get()->GetCompilerType(),
>>              m_persistent_variable_sp->GetName(), location,
>> eAddressTypeLoad,
>> -            m_persistent_variable_sp->GetByteSize());
>> +            m_persistent_variable_sp->GetByteSize().getValueOr(0));
>>
>>          if (frame_top != LLDB_INVALID_ADDRESS &&
>>              frame_bottom != LLDB_INVALID_ADDRESS && location >=
>> frame_bottom &&
>> @@ -279,7 +280,8 @@ class EntityPersistentVariable : public
>> Materializer::Entity {
>>          LLDB_LOGF(log, "Dematerializing %s from 0x%" PRIx64 " (size =
>> %llu)",
>>                    m_persistent_variable_sp->GetName().GetCString(),
>>                    (uint64_t)mem,
>> -                  (unsigned long
>> long)m_persistent_variable_sp->GetByteSize());
>> +                  (unsigned long
>> long)m_persistent_variable_sp->GetByteSize()
>> +                      .getValueOr(0));
>>
>>          // Read the contents of the spare memory area
>>
>> @@ -288,7 +290,7 @@ class EntityPersistentVariable : public
>> Materializer::Entity {
>>          Status read_error;
>>
>>          map.ReadMemory(m_persistent_variable_sp->GetValueBytes(), mem,
>> -                       m_persistent_variable_sp->GetByteSize(),
>> read_error);
>> +
>>  m_persistent_variable_sp->GetByteSize().getValueOr(0), read_error);
>>
>>          if (!read_error.Success()) {
>>            err.SetErrorStringWithFormat(
>> @@ -369,10 +371,11 @@ class EntityPersistentVariable : public
>> Materializer::Entity {
>>        if (!err.Success()) {
>>          dump_stream.Printf("  <could not be read>\n");
>>        } else {
>> -        DataBufferHeap data(m_persistent_variable_sp->GetByteSize(), 0);
>> +        DataBufferHeap data(
>> +            m_persistent_variable_sp->GetByteSize().getValueOr(0), 0);
>>
>>          map.ReadMemory(data.GetBytes(), target_address,
>> -                       m_persistent_variable_sp->GetByteSize(), err);
>> +
>>  m_persistent_variable_sp->GetByteSize().getValueOr(0), err);
>>
>>          if (!err.Success()) {
>>            dump_stream.Printf("  <could not be read>\n");
>> @@ -621,8 +624,8 @@ class EntityVariable : public Materializer::Entity {
>>
>>        Status extract_error;
>>
>> -      map.GetMemoryData(data, m_temporary_allocation,
>> valobj_sp->GetByteSize(),
>> -                        extract_error);
>> +      map.GetMemoryData(data, m_temporary_allocation,
>> +                        valobj_sp->GetByteSize().getValueOr(0),
>> extract_error);
>>
>>        if (!extract_error.Success()) {
>>          err.SetErrorStringWithFormat("couldn't get the data for variable
>> %s",
>> @@ -919,7 +922,7 @@ class EntityResultVariable : public
>> Materializer::Entity {
>>
>>      ret->ValueUpdated();
>>
>> -    const size_t pvar_byte_size = ret->GetByteSize();
>> +    const size_t pvar_byte_size = ret->GetByteSize().getValueOr(0);
>>      uint8_t *pvar_data = ret->GetValueBytes();
>>
>>      map.ReadMemory(pvar_data, address, pvar_byte_size, read_error);
>>
>> diff  --git a/lldb/source/Target/StackFrame.cpp
>> b/lldb/source/Target/StackFrame.cpp
>> index 098aed9cd812..22bca52d7f98 100644
>> --- a/lldb/source/Target/StackFrame.cpp
>> +++ b/lldb/source/Target/StackFrame.cpp
>> @@ -1408,7 +1408,7 @@ ValueObjectSP GetValueForOffset(StackFrame &frame,
>> ValueObjectSP &parent,
>>      }
>>
>>      int64_t child_offset = child_sp->GetByteOffset();
>> -    int64_t child_size = child_sp->GetByteSize();
>> +    int64_t child_size = child_sp->GetByteSize().getValueOr(0);
>>
>>      if (offset >= child_offset && offset < (child_offset + child_size)) {
>>        return GetValueForOffset(frame, child_sp, offset - child_offset);
>> @@ -1441,8 +1441,8 @@ ValueObjectSP
>> GetValueForDereferincingOffset(StackFrame &frame,
>>    }
>>
>>    if (offset >= 0 && uint64_t(offset) >= pointee->GetByteSize()) {
>> -    int64_t index = offset / pointee->GetByteSize();
>> -    offset = offset % pointee->GetByteSize();
>> +    int64_t index = offset / pointee->GetByteSize().getValueOr(1);
>> +    offset = offset % pointee->GetByteSize().getValueOr(1);
>>      const bool can_create = true;
>>      pointee = base->GetSyntheticArrayMember(index, can_create);
>>    }
>>
>>
>>
>> _______________________________________________
>> lldb-commits mailing list
>> lldb-commits at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200727/94a99b95/attachment-0001.html>


More information about the lldb-commits mailing list