Skip to content

Commit 9d5edc9

Browse files
authored
[lldb][NFC] Replace GetLocalBufferSize() with GetLocalBuffer() (#126333)
1 parent b850ce4 commit 9d5edc9

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

lldb/include/lldb/ValueObject/ValueObject.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -865,17 +865,18 @@ class ValueObject {
865865

866866
virtual void SetLanguageFlags(uint64_t flags) { m_language_flags = flags; }
867867

868-
/// Returns the size of the local buffer if it's available.
868+
/// Returns the local buffer that this ValueObject points to if it's
869+
/// available.
869870
/// \return
870-
/// The size of the local buffer if this value object's value points to a
871-
/// host address, and if that size can be determined. Otherwise, returns
872-
/// LLDB_INVALID_ADDRESS.
871+
/// The local buffer if this value object's value points to a
872+
/// host address, and if that buffer can be determined. Otherwise, returns
873+
/// an empty ArrayRef.
873874
///
874875
/// TODO: Because a ValueObject's Value can point to any arbitrary memory
875-
/// location, it is possible that the size of the local buffer can't be
876-
/// determined at all. See the comment in Value::m_value for a more thorough
877-
/// explanation of why that is.
878-
uint64_t GetLocalBufferSize();
876+
/// location, it is possible that we can't find what what buffer we're
877+
/// pointing to, and thus also can't know its size. See the comment in
878+
/// Value::m_value for a more thorough explanation of why that is.
879+
llvm::ArrayRef<uint8_t> GetLocalBuffer() const;
879880

880881
protected:
881882
typedef ClusterManager<ValueObject> ValueObjectManager;

lldb/source/ValueObject/ValueObject.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -849,20 +849,20 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) {
849849
return true;
850850
}
851851

852-
uint64_t ValueObject::GetLocalBufferSize() {
852+
llvm::ArrayRef<uint8_t> ValueObject::GetLocalBuffer() const {
853853
if (m_value.GetValueType() != Value::ValueType::HostAddress)
854-
return LLDB_INVALID_ADDRESS;
854+
return {};
855855
auto start = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
856856
if (start == LLDB_INVALID_ADDRESS)
857-
return LLDB_INVALID_ADDRESS;
857+
return {};
858858
// Does our pointer point to this value object's m_data buffer?
859859
if ((uint64_t)m_data.GetDataStart() == start)
860-
return m_data.GetByteSize();
860+
return m_data.GetData();
861861
// Does our pointer point to the value's buffer?
862862
if ((uint64_t)m_value.GetBuffer().GetBytes() == start)
863-
return m_value.GetBuffer().GetByteSize();
863+
return m_value.GetBuffer().GetData();
864864
// Our pointer points to something else. We can't know what the size is.
865-
return LLDB_INVALID_ADDRESS;
865+
return {};
866866
}
867867

868868
static bool CopyStringDataToBufferSP(const StreamString &source,

lldb/source/ValueObject/ValueObjectDynamicValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ bool ValueObjectDynamicValue::UpdateValue() {
241241
SetValueDidChange(true);
242242

243243
// If we found a host address, and the dynamic type fits in the local buffer
244-
// that was found, point to thar buffer. Later on this function will copy
244+
// that was found, point to that buffer. Later on this function will copy
245245
// the buffer over.
246246
if (value_type == Value::ValueType::HostAddress && !local_buffer.empty()) {
247247
auto *exe_scope = exe_ctx.GetBestExecutionContextScope();

lldb/unittests/ValueObject/DynamicValueObjectLocalBuffer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ struct MockLanguageRuntime : public LanguageRuntime {
6666
*ast, "TypeWitInt", ast->GetBasicType(lldb::BasicType::eBasicTypeInt),
6767
"theIntField", LanguageType::eLanguageTypeC_plus_plus);
6868
class_type_or_name.SetCompilerType(int_type);
69-
local_buffer = {(uint8_t *)in_value.GetValue().GetScalar().ULongLong(
70-
LLDB_INVALID_ADDRESS),
71-
static_cast<size_t>(in_value.GetLocalBufferSize())};
69+
local_buffer = in_value.GetLocalBuffer();
7270
value_type = Value::ValueType::HostAddress;
73-
7471
return true;
7572
}
7673

0 commit comments

Comments
 (0)