[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 08:23:27 +01:00
|
|
|
//===-- SBStructuredData.cpp ----------------------------------------------===//
|
2016-08-19 04:21:48 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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
|
2016-08-19 04:21:48 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/API/SBStructuredData.h"
|
2019-03-06 00:06:00 +00:00
|
|
|
#include "SBReproducerPrivate.h"
|
2016-08-19 04:21:48 +00:00
|
|
|
|
|
|
|
|
#include "lldb/API/SBStream.h"
|
2018-09-13 21:35:32 +00:00
|
|
|
#include "lldb/API/SBStringList.h"
|
2017-04-26 08:48:50 +00:00
|
|
|
#include "lldb/Core/StructuredDataImpl.h"
|
2016-08-19 04:21:48 +00:00
|
|
|
#include "lldb/Target/StructuredDataPlugin.h"
|
2018-12-14 15:59:49 +00:00
|
|
|
#include "lldb/Utility/Event.h"
|
2017-05-12 04:51:55 +00:00
|
|
|
#include "lldb/Utility/Status.h"
|
2017-02-02 21:39:50 +00:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-06-27 10:45:31 +00:00
|
|
|
#include "lldb/Utility/StructuredData.h"
|
2016-08-19 04:21:48 +00:00
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
#pragma mark--
|
|
|
|
|
#pragma mark SBStructuredData
|
|
|
|
|
|
2019-03-06 00:06:00 +00:00
|
|
|
SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {
|
|
|
|
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBStructuredData);
|
|
|
|
|
}
|
2016-08-19 04:21:48 +00:00
|
|
|
|
|
|
|
|
SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs)
|
2019-03-06 00:06:00 +00:00
|
|
|
: m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {
|
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBStructuredData, (const lldb::SBStructuredData &),
|
|
|
|
|
rhs);
|
|
|
|
|
}
|
2016-08-19 04:21:48 +00:00
|
|
|
|
|
|
|
|
SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp)
|
2019-03-06 00:06:00 +00:00
|
|
|
: m_impl_up(new StructuredDataImpl(event_sp)) {
|
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBStructuredData, (const lldb::EventSP &), event_sp);
|
|
|
|
|
}
|
2016-08-19 04:21:48 +00:00
|
|
|
|
2018-09-13 21:35:32 +00:00
|
|
|
SBStructuredData::SBStructuredData(lldb_private::StructuredDataImpl *impl)
|
2019-03-06 00:06:00 +00:00
|
|
|
: m_impl_up(impl) {
|
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBStructuredData,
|
|
|
|
|
(lldb_private::StructuredDataImpl *), impl);
|
|
|
|
|
}
|
2018-09-13 21:35:32 +00:00
|
|
|
|
2020-02-17 22:57:06 -08:00
|
|
|
SBStructuredData::~SBStructuredData() = default;
|
2016-08-19 04:21:48 +00:00
|
|
|
|
|
|
|
|
SBStructuredData &SBStructuredData::
|
|
|
|
|
operator=(const lldb::SBStructuredData &rhs) {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD(
|
|
|
|
|
lldb::SBStructuredData &,
|
|
|
|
|
SBStructuredData, operator=,(const lldb::SBStructuredData &), rhs);
|
|
|
|
|
|
2016-08-19 04:21:48 +00:00
|
|
|
*m_impl_up = *rhs.m_impl_up;
|
2019-04-03 21:31:22 +00:00
|
|
|
return LLDB_RECORD_RESULT(*this);
|
2016-08-19 04:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
2017-04-26 08:48:50 +00:00
|
|
|
lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD(lldb::SBError, SBStructuredData, SetFromJSON,
|
|
|
|
|
(lldb::SBStream &), stream);
|
|
|
|
|
|
2017-04-26 08:48:50 +00:00
|
|
|
lldb::SBError error;
|
|
|
|
|
std::string json_str(stream.GetData());
|
|
|
|
|
|
|
|
|
|
StructuredData::ObjectSP json_obj = StructuredData::ParseJSON(json_str);
|
|
|
|
|
m_impl_up->SetObjectSP(json_obj);
|
|
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
if (!json_obj || json_obj->GetType() != eStructuredDataTypeDictionary)
|
2017-04-26 08:48:50 +00:00
|
|
|
error.SetErrorString("Invalid Syntax");
|
2019-03-06 00:06:00 +00:00
|
|
|
return LLDB_RECORD_RESULT(error);
|
2017-04-26 08:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-06 00:06:00 +00:00
|
|
|
bool SBStructuredData::IsValid() const {
|
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBStructuredData, IsValid);
|
Add "operator bool" to SB APIs
Summary:
Our python version of the SB API has (the python equivalent of)
operator bool, but the C++ version doesn't.
This is because our python operators are added by modify-python-lldb.py,
which performs postprocessing on the swig-generated interface files.
In this patch, I add the "operator bool" to all SB classes which have an
IsValid method (which is the same logic used by modify-python-lldb.py).
This way, we make the two interfaces more constent, and it allows us to
rely on swig's automatic syntesis of python __nonzero__ methods instead
of doing manual fixups.
Reviewers: zturner, jingham, clayborg, jfb, serge-sans-paille
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D58792
llvm-svn: 355824
2019-03-11 13:58:46 +00:00
|
|
|
return this->operator bool();
|
|
|
|
|
}
|
|
|
|
|
SBStructuredData::operator bool() const {
|
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBStructuredData, operator bool);
|
2016-08-19 04:21:48 +00:00
|
|
|
|
2019-03-06 00:06:00 +00:00
|
|
|
return m_impl_up->IsValid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SBStructuredData::Clear() {
|
|
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBStructuredData, Clear);
|
|
|
|
|
|
|
|
|
|
m_impl_up->Clear();
|
|
|
|
|
}
|
2016-08-19 04:21:48 +00:00
|
|
|
|
|
|
|
|
SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST(lldb::SBError, SBStructuredData, GetAsJSON,
|
|
|
|
|
(lldb::SBStream &), stream);
|
|
|
|
|
|
2017-04-26 08:48:50 +00:00
|
|
|
SBError error;
|
|
|
|
|
error.SetError(m_impl_up->GetAsJSON(stream.ref()));
|
2019-03-06 00:06:00 +00:00
|
|
|
return LLDB_RECORD_RESULT(error);
|
2016-08-19 04:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST(lldb::SBError, SBStructuredData, GetDescription,
|
|
|
|
|
(lldb::SBStream &), stream);
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error = m_impl_up->GetDescription(stream.ref());
|
2016-11-09 23:21:04 +00:00
|
|
|
SBError sb_error;
|
|
|
|
|
sb_error.SetError(error);
|
2019-03-06 00:06:00 +00:00
|
|
|
return LLDB_RECORD_RESULT(sb_error);
|
2016-08-19 04:21:48 +00:00
|
|
|
}
|
2017-05-29 08:25:46 +00:00
|
|
|
|
|
|
|
|
StructuredDataType SBStructuredData::GetType() const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::StructuredDataType, SBStructuredData,
|
|
|
|
|
GetType);
|
|
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
return (m_impl_up ? m_impl_up->GetType() : eStructuredDataTypeInvalid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t SBStructuredData::GetSize() const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(size_t, SBStructuredData, GetSize);
|
|
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
return (m_impl_up ? m_impl_up->GetSize() : 0);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 21:35:32 +00:00
|
|
|
bool SBStructuredData::GetKeys(lldb::SBStringList &keys) const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST(bool, SBStructuredData, GetKeys,
|
|
|
|
|
(lldb::SBStringList &), keys);
|
|
|
|
|
|
2018-09-13 21:35:32 +00:00
|
|
|
if (!m_impl_up)
|
|
|
|
|
return false;
|
2020-02-05 21:20:12 -08:00
|
|
|
|
2018-09-13 21:35:32 +00:00
|
|
|
if (GetType() != eStructuredDataTypeDictionary)
|
|
|
|
|
return false;
|
2020-02-05 21:20:12 -08:00
|
|
|
|
2018-09-13 21:35:32 +00:00
|
|
|
StructuredData::ObjectSP obj_sp = m_impl_up->GetObjectSP();
|
|
|
|
|
if (!obj_sp)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
StructuredData::Dictionary *dict = obj_sp->GetAsDictionary();
|
|
|
|
|
// We claimed we were a dictionary, so this can't be null.
|
|
|
|
|
assert(dict);
|
|
|
|
|
// The return kind of GetKeys is an Array:
|
|
|
|
|
StructuredData::ObjectSP array_sp = dict->GetKeys();
|
|
|
|
|
StructuredData::Array *key_arr = array_sp->GetAsArray();
|
|
|
|
|
assert(key_arr);
|
2020-02-05 21:20:12 -08:00
|
|
|
|
2018-09-13 21:35:32 +00:00
|
|
|
key_arr->ForEach([&keys] (StructuredData::Object *object) -> bool {
|
|
|
|
|
llvm::StringRef key = object->GetStringValue("");
|
|
|
|
|
keys.AppendString(key.str().c_str());
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
lldb::SBStructuredData SBStructuredData::GetValueForKey(const char *key) const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST(lldb::SBStructuredData, SBStructuredData,
|
|
|
|
|
GetValueForKey, (const char *), key);
|
|
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
if (!m_impl_up)
|
2019-03-06 00:06:00 +00:00
|
|
|
return LLDB_RECORD_RESULT(SBStructuredData());
|
2017-05-29 08:25:46 +00:00
|
|
|
|
|
|
|
|
SBStructuredData result;
|
|
|
|
|
result.m_impl_up->SetObjectSP(m_impl_up->GetValueForKey(key));
|
2019-03-06 00:06:00 +00:00
|
|
|
return LLDB_RECORD_RESULT(result);
|
2017-05-29 08:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lldb::SBStructuredData SBStructuredData::GetItemAtIndex(size_t idx) const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST(lldb::SBStructuredData, SBStructuredData,
|
|
|
|
|
GetItemAtIndex, (size_t), idx);
|
|
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
if (!m_impl_up)
|
2019-03-06 00:06:00 +00:00
|
|
|
return LLDB_RECORD_RESULT(SBStructuredData());
|
2017-05-29 08:25:46 +00:00
|
|
|
|
|
|
|
|
SBStructuredData result;
|
|
|
|
|
result.m_impl_up->SetObjectSP(m_impl_up->GetItemAtIndex(idx));
|
2019-03-06 00:06:00 +00:00
|
|
|
return LLDB_RECORD_RESULT(result);
|
2017-05-29 08:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t SBStructuredData::GetIntegerValue(uint64_t fail_value) const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST(uint64_t, SBStructuredData, GetIntegerValue,
|
|
|
|
|
(uint64_t), fail_value);
|
|
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
return (m_impl_up ? m_impl_up->GetIntegerValue(fail_value) : fail_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double SBStructuredData::GetFloatValue(double fail_value) const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST(double, SBStructuredData, GetFloatValue, (double),
|
|
|
|
|
fail_value);
|
|
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
return (m_impl_up ? m_impl_up->GetFloatValue(fail_value) : fail_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SBStructuredData::GetBooleanValue(bool fail_value) const {
|
2019-03-06 00:06:00 +00:00
|
|
|
LLDB_RECORD_METHOD_CONST(bool, SBStructuredData, GetBooleanValue, (bool),
|
|
|
|
|
fail_value);
|
|
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
return (m_impl_up ? m_impl_up->GetBooleanValue(fail_value) : fail_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t SBStructuredData::GetStringValue(char *dst, size_t dst_len) const {
|
[lldb/Reproducers] Fix passive replay for (char*, size_t) functions.
Several SB API functions return strings using (char*, size_t) output
arguments. During capture, we serialize an empty string for the char*
because the memory can be uninitialized.
During active replay, we have custom replay redirects that ensure that
we don't override the buffer from which we're reading, but rather write
to a buffer on the heap with the given length. This is sufficient for
the active reproducer use case, where we only care about the side
effects of the API calls, not the values actually returned.
This approach does not not work for passive replay because here we
ignore all the incoming arguments, and re-execute the current function
with the arguments deserialized from the reproducer. This means that
these function will update the deserialized copy of the arguments,
rather than whatever was passed in by the SWIG wrapper.
To solve this problem, this patch extends the reproducer instrumentation
to handle this special case for passive replay. We nog ignore the
replayer in the registry and the incoming char pointer, and instead
reinvoke the current method on the deserialized class, and populate the
output argument.
Differential revision: https://reviews.llvm.org/D77759
2020-04-20 13:20:24 -07:00
|
|
|
LLDB_RECORD_CHAR_PTR_METHOD_CONST(size_t, SBStructuredData, GetStringValue,
|
|
|
|
|
(char *, size_t), dst, "", dst_len);
|
2019-03-06 00:06:00 +00:00
|
|
|
|
2017-05-29 08:25:46 +00:00
|
|
|
return (m_impl_up ? m_impl_up->GetStringValue(dst, dst_len) : 0);
|
|
|
|
|
}
|
2019-03-19 17:13:13 +00:00
|
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
|
namespace repro {
|
|
|
|
|
|
2020-02-05 19:41:09 -08:00
|
|
|
template <> void RegisterMethods<SBStructuredData>(Registry &R) {
|
2019-03-19 17:13:13 +00:00
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBStructuredData, ());
|
2020-02-05 19:41:09 -08:00
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBStructuredData, (const lldb::SBStructuredData &));
|
2019-03-19 17:13:13 +00:00
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBStructuredData, (const lldb::EventSP &));
|
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBStructuredData,
|
|
|
|
|
(lldb_private::StructuredDataImpl *));
|
|
|
|
|
LLDB_REGISTER_METHOD(
|
|
|
|
|
lldb::SBStructuredData &,
|
|
|
|
|
SBStructuredData, operator=,(const lldb::SBStructuredData &));
|
|
|
|
|
LLDB_REGISTER_METHOD(lldb::SBError, SBStructuredData, SetFromJSON,
|
|
|
|
|
(lldb::SBStream &));
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBStructuredData, IsValid, ());
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBStructuredData, operator bool, ());
|
|
|
|
|
LLDB_REGISTER_METHOD(void, SBStructuredData, Clear, ());
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(lldb::SBError, SBStructuredData, GetAsJSON,
|
|
|
|
|
(lldb::SBStream &));
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(lldb::SBError, SBStructuredData, GetDescription,
|
|
|
|
|
(lldb::SBStream &));
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(lldb::StructuredDataType, SBStructuredData,
|
|
|
|
|
GetType, ());
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(size_t, SBStructuredData, GetSize, ());
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBStructuredData, GetKeys,
|
|
|
|
|
(lldb::SBStringList &));
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(lldb::SBStructuredData, SBStructuredData,
|
|
|
|
|
GetValueForKey, (const char *));
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(lldb::SBStructuredData, SBStructuredData,
|
|
|
|
|
GetItemAtIndex, (size_t));
|
|
|
|
|
LLDB_REGISTER_METHOD_CONST(uint64_t, SBStructuredData, GetIntegerValue,
|
|
|
|
|
(uint64_t));
|
2020-02-05 19:41:09 -08:00
|
|
|
LLDB_REGISTER_METHOD_CONST(double, SBStructuredData, GetFloatValue, (double));
|
2019-03-19 17:13:13 +00:00
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBStructuredData, GetBooleanValue, (bool));
|
[lldb/Reproducers] Fix passive replay for (char*, size_t) functions.
Several SB API functions return strings using (char*, size_t) output
arguments. During capture, we serialize an empty string for the char*
because the memory can be uninitialized.
During active replay, we have custom replay redirects that ensure that
we don't override the buffer from which we're reading, but rather write
to a buffer on the heap with the given length. This is sufficient for
the active reproducer use case, where we only care about the side
effects of the API calls, not the values actually returned.
This approach does not not work for passive replay because here we
ignore all the incoming arguments, and re-execute the current function
with the arguments deserialized from the reproducer. This means that
these function will update the deserialized copy of the arguments,
rather than whatever was passed in by the SWIG wrapper.
To solve this problem, this patch extends the reproducer instrumentation
to handle this special case for passive replay. We nog ignore the
replayer in the registry and the incoming char pointer, and instead
reinvoke the current method on the deserialized class, and populate the
output argument.
Differential revision: https://reviews.llvm.org/D77759
2020-04-20 13:20:24 -07:00
|
|
|
LLDB_REGISTER_CHAR_PTR_METHOD_CONST(size_t, SBStructuredData, GetStringValue);
|
2019-03-19 17:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-05 19:41:09 -08:00
|
|
|
} // namespace repro
|
|
|
|
|
} // namespace lldb_private
|