[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
|
|
|
//===-- SBStream.cpp ------------------------------------------------------===//
|
2010-09-18 01:42:16 +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
|
2010-09-18 01:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBStream.h"
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
2019-10-16 01:41:40 +08:00
|
|
|
#include "lldb/API/SBFile.h"
|
2010-09-18 01:42:16 +08:00
|
|
|
#include "lldb/Core/StreamFile.h"
|
2018-11-03 06:34:51 +08:00
|
|
|
#include "lldb/Host/FileSystem.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"
|
|
|
|
#include "lldb/Utility/StreamString.h"
|
2010-09-18 01:42:16 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBStream::SBStream() : m_opaque_up(new StreamString()), m_is_file(false) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBStream);
|
|
|
|
}
|
2010-09-18 01:42:16 +08:00
|
|
|
|
2015-12-16 07:03:22 +08:00
|
|
|
SBStream::SBStream(SBStream &&rhs)
|
2019-02-13 14:25:41 +08:00
|
|
|
: m_opaque_up(std::move(rhs.m_opaque_up)), m_is_file(rhs.m_is_file) {}
|
2015-12-16 07:03:22 +08:00
|
|
|
|
2020-02-18 14:57:06 +08:00
|
|
|
SBStream::~SBStream() = default;
|
2015-12-16 07:03:22 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
bool SBStream::IsValid() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBStream, 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();
|
|
|
|
}
|
|
|
|
SBStream::operator bool() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBStream, operator bool);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
return (m_opaque_up != nullptr);
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2010-09-18 01:42:16 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// If this stream is not redirected to a file, it will maintain a local cache
|
|
|
|
// for the stream data which can be accessed using this accessor.
|
2010-09-18 01:42:16 +08:00
|
|
|
const char *SBStream::GetData() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(const char *, SBStream, GetData);
|
|
|
|
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (m_is_file || m_opaque_up == nullptr)
|
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return static_cast<StreamString *>(m_opaque_up.get())->GetData();
|
2010-09-18 01:42:16 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// If this stream is not redirected to a file, it will maintain a local cache
|
|
|
|
// for the stream output whose length can be accessed using this accessor.
|
2010-09-18 01:42:16 +08:00
|
|
|
size_t SBStream::GetSize() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(size_t, SBStream, GetSize);
|
|
|
|
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (m_is_file || m_opaque_up == nullptr)
|
2012-04-03 12:14:31 +08:00
|
|
|
return 0;
|
2010-09-18 01:42:16 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return static_cast<StreamString *>(m_opaque_up.get())->GetSize();
|
2010-09-18 01:42:16 +08:00
|
|
|
}
|
|
|
|
|
2020-05-21 01:32:51 +08:00
|
|
|
void SBStream::Print(const char *str) {
|
|
|
|
LLDB_RECORD_METHOD(void, SBStream, Print, (const char *), str);
|
|
|
|
|
|
|
|
Printf("%s", str);
|
|
|
|
}
|
|
|
|
|
2010-09-18 01:42:16 +08:00
|
|
|
void SBStream::Printf(const char *format, ...) {
|
2015-01-15 02:34:35 +08:00
|
|
|
if (!format)
|
|
|
|
return;
|
2010-09-18 01:42:16 +08:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2013-11-21 05:07:01 +08:00
|
|
|
ref().PrintfVarArg(format, args);
|
2010-09-18 01:42:16 +08:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBStream::RedirectToFile(const char *path, bool append) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBStream, RedirectToFile, (const char *, bool), path,
|
|
|
|
append);
|
|
|
|
|
2015-01-15 02:34:35 +08:00
|
|
|
if (path == nullptr)
|
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-09-18 01:42:16 +08:00
|
|
|
std::string local_data;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
2010-09-18 01:42:16 +08:00
|
|
|
// See if we have any locally backed data. If so, copy it so we can then
|
|
|
|
// redirect it to the file so we don't lose the data
|
|
|
|
if (!m_is_file)
|
2020-01-29 03:23:46 +08:00
|
|
|
local_data = std::string(
|
|
|
|
static_cast<StreamString *>(m_opaque_up.get())->GetString());
|
2010-09-18 01:42:16 +08:00
|
|
|
}
|
2019-10-15 04:15:34 +08:00
|
|
|
auto open_options = File::eOpenOptionWrite | File::eOpenOptionCanCreate;
|
2010-09-18 01:42:16 +08:00
|
|
|
if (append)
|
2011-02-09 09:08:52 +08:00
|
|
|
open_options |= File::eOpenOptionAppend;
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2014-07-31 01:38:47 +08:00
|
|
|
open_options |= File::eOpenOptionTruncate;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
llvm::Expected<FileUP> file =
|
|
|
|
FileSystem::Instance().Open(FileSpec(path), open_options);
|
|
|
|
if (!file) {
|
|
|
|
LLDB_LOG_ERROR(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), file.takeError(),
|
|
|
|
"Cannot open {1}: {0}", path);
|
|
|
|
return;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
m_opaque_up = std::make_unique<StreamFile>(std::move(file.get()));
|
|
|
|
m_is_file = true;
|
|
|
|
|
|
|
|
// If we had any data locally in our StreamString, then pass that along to
|
|
|
|
// the to new file we are redirecting to.
|
|
|
|
if (!local_data.empty())
|
|
|
|
m_opaque_up->Write(&local_data[0], local_data.size());
|
2010-09-18 01:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBStream::RedirectToFileHandle(FILE *fh, bool transfer_fh_ownership) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBStream, RedirectToFileHandle, (FILE *, bool), fh,
|
|
|
|
transfer_fh_ownership);
|
2019-10-16 01:41:40 +08:00
|
|
|
FileSP file = std::make_unique<NativeFile>(fh, transfer_fh_ownership);
|
|
|
|
return RedirectToFile(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBStream::RedirectToFile(SBFile file) {
|
|
|
|
LLDB_RECORD_METHOD(void, SBStream, RedirectToFile, (SBFile), file)
|
|
|
|
RedirectToFile(file.GetFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBStream::RedirectToFile(FileSP file_sp) {
|
|
|
|
LLDB_RECORD_METHOD(void, SBStream, RedirectToFile, (FileSP), file_sp);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-10-16 01:41:40 +08:00
|
|
|
if (!file_sp || !file_sp->IsValid())
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
|
2010-09-18 01:42:16 +08:00
|
|
|
std::string local_data;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
2010-09-18 01:42:16 +08:00
|
|
|
// See if we have any locally backed data. If so, copy it so we can then
|
|
|
|
// redirect it to the file so we don't lose the data
|
|
|
|
if (!m_is_file)
|
2020-01-29 03:23:46 +08:00
|
|
|
local_data = std::string(
|
|
|
|
static_cast<StreamString *>(m_opaque_up.get())->GetString());
|
2010-09-18 01:42:16 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-10-16 01:41:40 +08:00
|
|
|
m_opaque_up = std::make_unique<StreamFile>(file_sp);
|
2019-09-27 01:54:59 +08:00
|
|
|
m_is_file = true;
|
|
|
|
|
|
|
|
// If we had any data locally in our StreamString, then pass that along to
|
|
|
|
// the to new file we are redirecting to.
|
|
|
|
if (!local_data.empty())
|
|
|
|
m_opaque_up->Write(&local_data[0], local_data.size());
|
2010-09-18 01:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBStream::RedirectToFileDescriptor(int fd, bool transfer_fh_ownership) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBStream, RedirectToFileDescriptor, (int, bool), fd,
|
|
|
|
transfer_fh_ownership);
|
|
|
|
|
2010-09-18 01:42:16 +08:00
|
|
|
std::string local_data;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
2010-09-18 01:42:16 +08:00
|
|
|
// See if we have any locally backed data. If so, copy it so we can then
|
|
|
|
// redirect it to the file so we don't lose the data
|
|
|
|
if (!m_is_file)
|
2020-01-29 03:23:46 +08:00
|
|
|
local_data = std::string(
|
|
|
|
static_cast<StreamString *>(m_opaque_up.get())->GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
m_opaque_up = std::make_unique<StreamFile>(fd, transfer_fh_ownership);
|
|
|
|
m_is_file = true;
|
|
|
|
|
|
|
|
// If we had any data locally in our StreamString, then pass that along to
|
|
|
|
// the to new file we are redirecting to.
|
|
|
|
if (!local_data.empty())
|
|
|
|
m_opaque_up->Write(&local_data[0], local_data.size());
|
2010-09-18 01:42:16 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
lldb_private::Stream *SBStream::operator->() { return m_opaque_up.get(); }
|
2010-09-18 01:42:16 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
lldb_private::Stream *SBStream::get() { return m_opaque_up.get(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-09-18 01:42:16 +08:00
|
|
|
lldb_private::Stream &SBStream::ref() {
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (m_opaque_up == nullptr)
|
2020-06-25 07:25:05 +08:00
|
|
|
m_opaque_up = std::make_unique<StreamString>();
|
2019-02-13 14:25:41 +08:00
|
|
|
return *m_opaque_up;
|
2010-09-18 01:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBStream::Clear() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBStream, Clear);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
2010-09-18 01:42:16 +08:00
|
|
|
// See if we have any locally backed data. If so, copy it so we can then
|
|
|
|
// redirect it to the file so we don't lose the data
|
|
|
|
if (m_is_file)
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up.reset();
|
2010-09-18 01:42:16 +08:00
|
|
|
else
|
2019-02-13 14:25:41 +08:00
|
|
|
static_cast<StreamString *>(m_opaque_up.get())->Clear();
|
2010-09-18 01:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
2019-03-20 01:13:13 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
namespace repro {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void RegisterMethods<SBStream>(Registry &R) {
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBStream, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBStream, IsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBStream, operator bool, ());
|
|
|
|
LLDB_REGISTER_METHOD(const char *, SBStream, GetData, ());
|
|
|
|
LLDB_REGISTER_METHOD(size_t, SBStream, GetSize, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBStream, RedirectToFile, (const char *, bool));
|
2019-10-16 01:41:40 +08:00
|
|
|
LLDB_REGISTER_METHOD(void, SBStream, RedirectToFile, (FileSP));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBStream, RedirectToFile, (SBFile));
|
2019-03-20 01:13:13 +08:00
|
|
|
LLDB_REGISTER_METHOD(void, SBStream, RedirectToFileHandle, (FILE *, bool));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBStream, RedirectToFileDescriptor, (int, bool));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBStream, Clear, ());
|
2020-05-21 01:32:51 +08:00
|
|
|
LLDB_REGISTER_METHOD(void, SBStream, Print, (const char *));
|
2019-03-20 01:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|