[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"
|
2022-01-20 03:38:26 +08:00
|
|
|
#include "lldb/Utility/Instrumentation.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()) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs)
|
2021-04-30 07:03:46 +08:00
|
|
|
: m_impl_up(new StructuredDataImpl(*rhs.m_impl_up)) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
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)) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, event_sp);
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2021-11-25 21:01:41 +08:00
|
|
|
SBStructuredData::SBStructuredData(const lldb_private::StructuredDataImpl &impl)
|
|
|
|
: m_impl_up(new StructuredDataImpl(impl)) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, impl);
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
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) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2016-08-19 12:21:48 +08:00
|
|
|
*m_impl_up = *rhs.m_impl_up;
|
2022-01-10 14:54:08 +08:00
|
|
|
return *this;
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
|
|
|
|
2017-04-26 16:48:50 +08:00
|
|
|
lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, stream);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
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");
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2017-04-26 16:48:50 +08:00
|
|
|
}
|
|
|
|
|
2021-06-02 06:34:06 +08:00
|
|
|
lldb::SBError SBStructuredData::SetFromJSON(const char *json) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, json);
|
2021-06-02 06:34:06 +08:00
|
|
|
lldb::SBStream s;
|
|
|
|
s.Print(json);
|
2022-01-10 14:54:08 +08:00
|
|
|
return SetFromJSON(s);
|
2021-06-02 06:34:06 +08:00
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
bool SBStructuredData::IsValid() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
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();
|
|
|
|
}
|
2021-06-02 06:34:06 +08:00
|
|
|
|
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
|
|
|
SBStructuredData::operator bool() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
return m_impl_up->IsValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBStructuredData::Clear() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
|
|
|
m_impl_up->Clear();
|
|
|
|
}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, stream);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2017-04-26 16:48:50 +08:00
|
|
|
SBError error;
|
|
|
|
error.SetError(m_impl_up->GetAsJSON(stream.ref()));
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, stream);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
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);
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_error;
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
2017-05-29 16:25:46 +08:00
|
|
|
|
|
|
|
StructuredDataType SBStructuredData::GetType() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2021-04-30 07:03:46 +08:00
|
|
|
return m_impl_up->GetType();
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t SBStructuredData::GetSize() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2021-04-30 07:03:46 +08:00
|
|
|
return m_impl_up->GetSize();
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|
|
|
|
|
2018-09-14 05:35:32 +08:00
|
|
|
bool SBStructuredData::GetKeys(lldb::SBStringList &keys) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, keys);
|
2019-03-06 08:06:00 +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 {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, key);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
SBStructuredData result;
|
|
|
|
result.m_impl_up->SetObjectSP(m_impl_up->GetValueForKey(key));
|
2022-01-10 14:54:08 +08:00
|
|
|
return result;
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::SBStructuredData SBStructuredData::GetItemAtIndex(size_t idx) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, idx);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
SBStructuredData result;
|
|
|
|
result.m_impl_up->SetObjectSP(m_impl_up->GetItemAtIndex(idx));
|
2022-01-10 14:54:08 +08:00
|
|
|
return result;
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t SBStructuredData::GetIntegerValue(uint64_t fail_value) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, fail_value);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2021-04-30 07:03:46 +08:00
|
|
|
return m_impl_up->GetIntegerValue(fail_value);
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
double SBStructuredData::GetFloatValue(double fail_value) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, fail_value);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2021-04-30 07:03:46 +08:00
|
|
|
return m_impl_up->GetFloatValue(fail_value);
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SBStructuredData::GetBooleanValue(bool fail_value) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, fail_value);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2021-04-30 07:03:46 +08:00
|
|
|
return m_impl_up->GetBooleanValue(fail_value);
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t SBStructuredData::GetStringValue(char *dst, size_t dst_len) const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, dst, dst_len);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2021-04-30 07:03:46 +08:00
|
|
|
return m_impl_up->GetStringValue(dst, dst_len);
|
2017-05-29 16:25:46 +08:00
|
|
|
}
|