[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- ValueObjectCast.cpp -----------------------------------------------===//
|
2012-10-27 10:05:48 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-10-27 10:05:48 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/ValueObjectCast.h"
|
|
|
|
|
|
|
|
#include "lldb/Core/Value.h"
|
|
|
|
#include "lldb/Core/ValueObject.h"
|
2015-08-12 06:53:00 +08:00
|
|
|
#include "lldb/Symbol/CompilerType.h"
|
2012-10-27 10:05:48 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/Scalar.h"
|
|
|
|
#include "lldb/Utility/Status.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
class ConstString;
|
|
|
|
}
|
2012-10-27 10:05:48 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
|
2019-03-07 05:22:25 +08:00
|
|
|
ConstString name,
|
2015-08-12 06:53:00 +08:00
|
|
|
const CompilerType &cast_type) {
|
2012-10-27 10:05:48 +08:00
|
|
|
ValueObjectCast *cast_valobj_ptr =
|
|
|
|
new ValueObjectCast(parent, name, cast_type);
|
|
|
|
return cast_valobj_ptr->GetSP();
|
|
|
|
}
|
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
ValueObjectCast::ValueObjectCast(ValueObject &parent, ConstString name,
|
2015-08-12 06:53:00 +08:00
|
|
|
const CompilerType &cast_type)
|
2012-10-27 10:05:48 +08:00
|
|
|
: ValueObject(parent), m_cast_type(cast_type) {
|
|
|
|
SetName(name);
|
2015-08-25 07:46:31 +08:00
|
|
|
m_value.SetCompilerType(cast_type);
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
|
|
|
|
2021-07-03 02:27:37 +08:00
|
|
|
ValueObjectCast::~ValueObjectCast() = default;
|
2012-10-27 10:05:48 +08:00
|
|
|
|
2015-08-25 07:46:31 +08:00
|
|
|
CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
|
2012-10-27 10:05:48 +08:00
|
|
|
|
2015-10-22 03:28:08 +08:00
|
|
|
size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
|
2018-11-06 04:49:07 +08:00
|
|
|
ExecutionContext exe_ctx(GetExecutionContextRef());
|
|
|
|
auto children_count = GetCompilerType().GetNumChildren(
|
|
|
|
true, &exe_ctx);
|
2015-10-22 03:28:08 +08:00
|
|
|
return children_count <= max ? children_count : max;
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
|
|
|
|
2020-07-25 23:27:21 +08:00
|
|
|
llvm::Optional<uint64_t> ValueObjectCast::GetByteSize() {
|
2015-10-15 06:44:30 +08:00
|
|
|
ExecutionContext exe_ctx(GetExecutionContextRef());
|
|
|
|
return m_value.GetValueByteSize(nullptr, &exe_ctx);
|
2012-10-27 10:05:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::ValueType ValueObjectCast::GetValueType() const {
|
|
|
|
// Let our parent answer global, local, argument, etc...
|
|
|
|
return m_parent->GetValueType();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ValueObjectCast::UpdateValue() {
|
|
|
|
SetValueIsValid(false);
|
|
|
|
m_error.Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-10-27 10:05:48 +08:00
|
|
|
if (m_parent->UpdateValueIfNeeded(false)) {
|
|
|
|
Value old_value(m_value);
|
|
|
|
m_update_point.SetUpdated();
|
|
|
|
m_value = m_parent->GetValue();
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType compiler_type(GetCompilerType());
|
|
|
|
m_value.SetCompilerType(compiler_type);
|
2012-10-27 10:05:48 +08:00
|
|
|
SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
|
Extend synthetic children to produce synthetic values (as in, those that GetValueAsUnsigned(), GetValueAsCString() would return)
The way to do this is to write a synthetic child provider for your type, and have it vend the (optional) get_value function.
If get_value is defined, and it returns a valid SBValue, that SBValue's value (as in lldb_private::Value) will be used as the synthetic ValueObject's Value
The rationale for doing things this way is twofold:
- there are many possible ways to define a "value" (SBData, a Python number, ...) but SBValue seems general enough as a thing that stores a "value", so we just trade values that way and that keeps our currency trivial
- we could introduce a new level of layering (ValueObjectSyntheticValue), a new kind of formatter (synthetic value producer), but that would complicate the model (can I have a dynamic with no synthetic children but synthetic value? synthetic value with synthetic children but no dynamic?), and I really couldn't see much benefit to be reaped from this added complexity in the matrix
On the other hand, just defining a synthetic child provider with a get_value but returning no actual children is easy enough that it's not a significant road-block to adoption of this feature
Comes with a test case
llvm-svn: 219330
2014-10-09 02:27:36 +08:00
|
|
|
if (!CanProvideValue()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// this value object represents an aggregate type whose children have
|
|
|
|
// values, but this object does not. So we say we are changed if our
|
|
|
|
// location has changed.
|
2012-10-27 10:05:48 +08:00
|
|
|
SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
|
|
|
|
m_value.GetScalar() != old_value.GetScalar());
|
|
|
|
}
|
|
|
|
ExecutionContext exe_ctx(GetExecutionContextRef());
|
2019-08-09 03:22:32 +08:00
|
|
|
m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());
|
2012-10-27 10:05:48 +08:00
|
|
|
SetValueDidChange(m_parent->GetValueDidChange());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The dynamic value failed to get an error, pass the error along
|
|
|
|
if (m_error.Success() && m_parent->GetError().Fail())
|
|
|
|
m_error = m_parent->GetError();
|
|
|
|
SetValueIsValid(false);
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-10-27 10:05:48 +08:00
|
|
|
bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }
|