Skip to content

Commit 7a38023

Browse files
committed
[lldb][NFC] Replace GetLocalBufferSize() with GetLocalBuffer()
GetLocalBuffer() makes more sense as an API.
1 parent 829f2bc commit 7a38023

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
@@ -869,17 +869,18 @@ class ValueObject {
869869

870870
virtual void SetLanguageFlags(uint64_t flags) { m_language_flags = flags; }
871871

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

884885
protected:
885886
typedef ClusterManager<ValueObject> ValueObjectManager;

lldb/source/ValueObject/ValueObject.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -917,20 +917,20 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) {
917917
return true;
918918
}
919919

920-
uint64_t ValueObject::GetLocalBufferSize() {
920+
llvm::ArrayRef<uint8_t> ValueObject::GetLocalBuffer() const {
921921
if (m_value.GetValueType() != Value::ValueType::HostAddress)
922-
return LLDB_INVALID_ADDRESS;
922+
return {};
923923
auto start = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
924924
if (start == LLDB_INVALID_ADDRESS)
925-
return LLDB_INVALID_ADDRESS;
925+
return {};
926926
// Does our pointer point to this value object's m_data buffer?
927927
if ((uint64_t)m_data.GetDataStart() == start)
928-
return m_data.GetByteSize();
928+
return m_data.GetData();
929929
// Does our pointer point to the value's buffer?
930930
if ((uint64_t)m_value.GetBuffer().GetBytes() == start)
931-
return m_value.GetBuffer().GetByteSize();
931+
return m_value.GetBuffer().GetData();
932932
// Our pointer points to something else. We can't know what the size is.
933-
return LLDB_INVALID_ADDRESS;
933+
return {};
934934
}
935935

936936
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
@@ -279,7 +279,7 @@ bool ValueObjectDynamicValue::UpdateValue() {
279279
SetValueDidChange(true);
280280

281281
// If we found a host address, and the dynamic type fits in the local buffer
282-
// that was found, point to thar buffer. Later on this function will copy
282+
// that was found, point to that buffer. Later on this function will copy
283283
// the buffer over.
284284
if (value_type == Value::ValueType::HostAddress && !local_buffer.empty()) {
285285
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)