[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
|
|
|
//===-- SBStructuredData.cpp ----------------------------------------------===//
|
2016-08-19 12:21: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
|
2016-08-19 12:21:48 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBStructuredData.h"
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
#include "lldb/API/SBStream.h"
|
2018-09-14 05:35:32 +08:00
|
|
|
#include "lldb/API/SBStringList.h"
|
2017-04-26 16:48:50 +08:00
|
|
|
#include "lldb/Core/StructuredDataImpl.h"
|
2016-08-19 12:21:48 +08:00
|
|
|
#include "lldb/Target/StructuredDataPlugin.h"
|
2018-12-14 23:59:49 +08:00
|
|
|
#include "lldb/Utility/Event.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-06-27 18:45:31 +08:00
|
|
|
#include "lldb/Utility/StructuredData.h"
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
#pragma mark--
|
|
|
|
#pragma mark SBStructuredData
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBStructuredData);
|
|
|
|
}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs)
|
2019-03-06 08:06:00 +08:00
|
|
|
: m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBStructuredData, (const lldb::SBStructuredData &),
|
|
|
|
rhs);
|
|
|
|
}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp)
|
2019-03-06 08:06:00 +08:00
|
|
|
: m_impl_up(new StructuredDataImpl(event_sp)) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBStructuredData, (const lldb::EventSP &), event_sp);
|
|
|
|
}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2018-09-14 05:35:32 +08:00
|
|
|
SBStructuredData::SBStructuredData(lldb_private::StructuredDataImpl *impl)
|
2019-03-06 08:06:00 +08:00
|
|
|
: m_impl_up(impl) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBStructuredData,
|
|
|
|
(lldb_private::StructuredDataImpl *), impl);
|
|
|
|
}
|
2018-09-14 05:35:32 +08:00
|
|
|
|
2020-02-18 14:57:06 +08:00
|
|
|
SBStructuredData::~SBStructuredData() = default;
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
SBStructuredData &SBStructuredData::
|
|
|
|
operator=(const lldb::SBStructuredData &rhs) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(
|
|
|
|
lldb::SBStructuredData &,
|
|
|
|
SBStructuredData, operator=,(const lldb::SBStructuredData &), rhs);
|
|
|
|
|
2016-08-19 12:21:48 +08:00
|
|
|
*m_impl_up = *rhs.m_impl_up;
|
2019-04-04 05:31:22 +08:00
|
|
|
return LLDB_RECORD_RESULT(*this);
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
|
|
|
|
2017-04-26 16:48:50 +08:00
|
|
|
lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(lldb::SBError, SBStructuredData, SetFromJSON,
|
|
|
|
(lldb::SBStream &), stream);
|
|
|
|
|
2017-04-26 16:48:50 +08: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 16:25:46 +08:00
|
|
|
if (!json_obj || json_obj->GetType() != eStructuredDataTypeDictionary)
|
2017-04-26 16:48:50 +08:00
|
|
|
error.SetErrorString("Invalid Syntax");
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(error);
|
2017-04-26 16:48:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08: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 21:58:46 +08:00
|
|
|
return this->operator bool();
|
|
|
|
}
|
|
|
|
SBStructuredData::operator bool() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBStructuredData, operator bool);
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
return m_impl_up->IsValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBStructuredData::Clear() {
|
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBStructuredData, Clear);
|
|
|
|
|
|
|
|
m_impl_up->Clear();
|
|
|
|
}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(lldb::SBError, SBStructuredData, GetAsJSON,
|
|
|
|
(lldb::SBStream &), stream);
|
|
|
|
|
2017-04-26 16:48:50 +08:00
|
|
|
SBError error;
|
|
|
|
error.SetError(m_impl_up->GetAsJSON(stream.ref()));
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(error);
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(lldb::SBError, SBStructuredData, GetDescription,
|
|
|
|
(lldb::SBStream &), stream);
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error = m_impl_up->GetDescription(stream.ref());
|
2016-11-10 07:21:04 +08:00
|
|
|
SBError sb_error;
|
|
|
|
sb_error.SetError(error);
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_error);
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
2017-05-29 16:25:46 +08:00
|
|
|
|
|
|
|
StructuredDataType SBStructuredData::GetType() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::StructuredDataType, SBStructuredData,
|
|
|
|
GetType);
|
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
return (m_impl_up ? m_impl_up->GetType() : eStructuredDataTypeInvalid);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SBStructuredData::GetSize() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(size_t, SBStructuredData, GetSize);
|
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
return (m_impl_up ? m_impl_up->GetSize() : 0);
|
|
|
|
}
|
|
|
|
|
2018-09-14 05:35:32 +08:00
|
|
|
bool SBStructuredData::GetKeys(lldb::SBStringList &keys) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(bool, SBStructuredData, GetKeys,
|
|
|
|
(lldb::SBStringList &), keys);
|
|
|
|
|
2018-09-14 05:35:32 +08:00
|
|
|
if (!m_impl_up)
|
|
|
|
return false;
|
2020-02-06 13:20:12 +08:00
|
|
|
|
2018-09-14 05:35:32 +08:00
|
|
|
if (GetType() != eStructuredDataTypeDictionary)
|
|
|
|
return false;
|
2020-02-06 13:20:12 +08:00
|
|
|
|
2018-09-14 05:35:32 +08: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-06 13:20:12 +08:00
|
|
|
|
2018-09-14 05:35:32 +08: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 16:25:46 +08:00
|
|
|
lldb::SBStructuredData SBStructuredData::GetValueForKey(const char *key) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(lldb::SBStructuredData, SBStructuredData,
|
|
|
|
GetValueForKey, (const char *), key);
|
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
if (!m_impl_up)
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(SBStructuredData());
|
2017-05-29 16:25:46 +08:00
|
|
|
|
|
|
|
SBStructuredData result;
|
|
|
|
result.m_impl_up->SetObjectSP(m_impl_up->GetValueForKey(key));
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(result);
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::SBStructuredData SBStructuredData::GetItemAtIndex(size_t idx) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(lldb::SBStructuredData, SBStructuredData,
|
|
|
|
GetItemAtIndex, (size_t), idx);
|
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
if (!m_impl_up)
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(SBStructuredData());
|
2017-05-29 16:25:46 +08:00
|
|
|
|
|
|
|
SBStructuredData result;
|
|
|
|
result.m_impl_up->SetObjectSP(m_impl_up->GetItemAtIndex(idx));
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(result);
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t SBStructuredData::GetIntegerValue(uint64_t fail_value) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(uint64_t, SBStructuredData, GetIntegerValue,
|
|
|
|
(uint64_t), fail_value);
|
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
return (m_impl_up ? m_impl_up->GetIntegerValue(fail_value) : fail_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
double SBStructuredData::GetFloatValue(double fail_value) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(double, SBStructuredData, GetFloatValue, (double),
|
|
|
|
fail_value);
|
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
return (m_impl_up ? m_impl_up->GetFloatValue(fail_value) : fail_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBStructuredData::GetBooleanValue(bool fail_value) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(bool, SBStructuredData, GetBooleanValue, (bool),
|
|
|
|
fail_value);
|
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
return (m_impl_up ? m_impl_up->GetBooleanValue(fail_value) : fail_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SBStructuredData::GetStringValue(char *dst, size_t dst_len) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(size_t, SBStructuredData, GetStringValue,
|
2020-02-06 13:20:12 +08:00
|
|
|
(char *, size_t), "", dst_len);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
return (m_impl_up ? m_impl_up->GetStringValue(dst, dst_len) : 0);
|
|
|
|
}
|
2019-03-20 01:13:13 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
namespace repro {
|
|
|
|
|
2020-02-06 11:41:09 +08:00
|
|
|
template <> void RegisterMethods<SBStructuredData>(Registry &R) {
|
2019-03-20 01:13:13 +08:00
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBStructuredData, ());
|
2020-02-06 11:41:09 +08:00
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBStructuredData, (const lldb::SBStructuredData &));
|
2019-03-20 01:13:13 +08: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-06 11:41:09 +08:00
|
|
|
LLDB_REGISTER_METHOD_CONST(double, SBStructuredData, GetFloatValue, (double));
|
2019-03-20 01:13:13 +08:00
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBStructuredData, GetBooleanValue, (bool));
|
2020-02-06 11:41:09 +08:00
|
|
|
LLDB_REGISTER_CHAR_PTR_REDIRECT_CONST(size_t, SBStructuredData,
|
|
|
|
GetStringValue);
|
2019-03-20 01:13:13 +08:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:41:09 +08:00
|
|
|
} // namespace repro
|
|
|
|
} // namespace lldb_private
|