[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
|
|
|
//===-- CommandReturnObject.cpp -------------------------------------------===//
|
2010-06-09 00:52:24 +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-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.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/StreamString.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2020-06-10 01:21:09 +08:00
|
|
|
static llvm::raw_ostream &error(Stream &strm) {
|
|
|
|
return llvm::WithColor(strm.AsRawOstream(), llvm::HighlightColor::Error,
|
|
|
|
llvm::ColorMode::Enable)
|
|
|
|
<< "error: ";
|
|
|
|
}
|
|
|
|
|
|
|
|
static llvm::raw_ostream &warning(Stream &strm) {
|
|
|
|
return llvm::WithColor(strm.AsRawOstream(), llvm::HighlightColor::Warning,
|
|
|
|
llvm::ColorMode::Enable)
|
|
|
|
<< "warning: ";
|
|
|
|
}
|
|
|
|
|
2020-06-03 12:21:20 +08:00
|
|
|
static void DumpStringToStreamWithNewline(Stream &strm, const std::string &s) {
|
2011-07-03 05:07:54 +08:00
|
|
|
bool add_newline = false;
|
2020-06-03 12:21:20 +08:00
|
|
|
if (!s.empty()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We already checked for empty above, now make sure there is a newline in
|
|
|
|
// the error, and if there isn't one, add one.
|
2011-07-03 05:07:54 +08:00
|
|
|
strm.Write(s.c_str(), s.size());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-03 05:07:54 +08:00
|
|
|
const char last_char = *s.rbegin();
|
|
|
|
add_newline = last_char != '\n' && last_char != '\r';
|
|
|
|
}
|
|
|
|
if (add_newline)
|
|
|
|
strm.EOL();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-06-10 01:21:09 +08:00
|
|
|
CommandReturnObject::CommandReturnObject(bool colors)
|
2021-06-09 01:46:43 +08:00
|
|
|
: m_out_stream(colors), m_err_stream(colors) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void CommandReturnObject::AppendErrorWithFormat(const char *format, ...) {
|
2021-06-14 20:11:58 +08:00
|
|
|
SetStatus(eReturnStatusFailed);
|
|
|
|
|
2011-12-20 05:36:23 +08:00
|
|
|
if (!format)
|
|
|
|
return;
|
2010-06-09 00:52:24 +08:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
StreamString sstrm;
|
|
|
|
sstrm.PrintfVarArg(format, args);
|
|
|
|
va_end(args);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-01-29 03:23:46 +08:00
|
|
|
const std::string &s = std::string(sstrm.GetString());
|
2011-07-03 05:07:54 +08:00
|
|
|
if (!s.empty()) {
|
2020-06-10 01:21:09 +08:00
|
|
|
error(GetErrorStream());
|
|
|
|
DumpStringToStreamWithNewline(GetErrorStream(), s);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-03 05:07:54 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void CommandReturnObject::AppendMessageWithFormat(const char *format, ...) {
|
2011-12-20 05:36:23 +08:00
|
|
|
if (!format)
|
|
|
|
return;
|
2010-06-09 00:52:24 +08:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
StreamString sstrm;
|
|
|
|
sstrm.PrintfVarArg(format, args);
|
|
|
|
va_end(args);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-11-17 05:15:24 +08:00
|
|
|
GetOutputStream() << sstrm.GetString();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void CommandReturnObject::AppendWarningWithFormat(const char *format, ...) {
|
2011-12-20 05:36:23 +08:00
|
|
|
if (!format)
|
|
|
|
return;
|
2010-06-09 00:52:24 +08:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
StreamString sstrm;
|
|
|
|
sstrm.PrintfVarArg(format, args);
|
|
|
|
va_end(args);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-06-10 01:21:09 +08:00
|
|
|
warning(GetErrorStream()) << sstrm.GetString();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-11-13 02:47:11 +08:00
|
|
|
void CommandReturnObject::AppendMessage(llvm::StringRef in_string) {
|
|
|
|
if (in_string.empty())
|
2011-12-20 05:36:23 +08:00
|
|
|
return;
|
2021-02-24 21:08:49 +08:00
|
|
|
GetOutputStream() << in_string.rtrim() << '\n';
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-11-13 02:47:11 +08:00
|
|
|
void CommandReturnObject::AppendWarning(llvm::StringRef in_string) {
|
|
|
|
if (in_string.empty())
|
2011-12-20 05:36:23 +08:00
|
|
|
return;
|
2021-02-24 21:08:49 +08:00
|
|
|
warning(GetErrorStream()) << in_string.rtrim() << '\n';
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-11-13 02:47:11 +08:00
|
|
|
void CommandReturnObject::AppendError(llvm::StringRef in_string) {
|
2021-06-16 21:39:50 +08:00
|
|
|
SetStatus(eReturnStatusFailed);
|
2021-06-23 19:28:16 +08:00
|
|
|
if (in_string.empty())
|
|
|
|
return;
|
2021-02-24 21:08:49 +08:00
|
|
|
error(GetErrorStream()) << in_string.rtrim() << '\n';
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
void CommandReturnObject::SetError(const Status &error,
|
2011-11-15 11:53:30 +08:00
|
|
|
const char *fallback_error_cstr) {
|
2021-06-23 00:12:56 +08:00
|
|
|
AppendError(error.AsCString(fallback_error_cstr));
|
2013-07-10 04:14:26 +08:00
|
|
|
}
|
|
|
|
|
2022-02-24 03:52:20 +08:00
|
|
|
void CommandReturnObject::SetError(llvm::Error error) {
|
|
|
|
if (error)
|
|
|
|
AppendError(llvm::toString(std::move(error)));
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Similar to AppendError, but do not prepend 'Status: ' to message, and don't
|
|
|
|
// append "\n" to the end of it.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-11-13 02:47:11 +08:00
|
|
|
void CommandReturnObject::AppendRawError(llvm::StringRef in_string) {
|
2021-06-16 21:39:50 +08:00
|
|
|
SetStatus(eReturnStatusFailed);
|
2021-06-18 20:17:53 +08:00
|
|
|
assert(!in_string.empty() && "Expected a non-empty error message");
|
2016-11-13 02:47:11 +08:00
|
|
|
GetErrorStream() << in_string;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandReturnObject::SetStatus(ReturnStatus status) { m_status = status; }
|
|
|
|
|
2021-12-04 06:49:42 +08:00
|
|
|
ReturnStatus CommandReturnObject::GetStatus() const { return m_status; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2021-12-04 06:49:42 +08:00
|
|
|
bool CommandReturnObject::Succeeded() const {
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_status <= eReturnStatusSuccessContinuingResult;
|
|
|
|
}
|
|
|
|
|
2021-12-04 06:49:42 +08:00
|
|
|
bool CommandReturnObject::HasResult() const {
|
2011-02-20 10:15:07 +08:00
|
|
|
return (m_status == eReturnStatusSuccessFinishResult ||
|
2010-06-09 00:52:24 +08:00
|
|
|
m_status == eReturnStatusSuccessContinuingResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandReturnObject::Clear() {
|
2011-02-20 10:15:07 +08:00
|
|
|
lldb::StreamSP stream_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
stream_sp = m_out_stream.GetStreamAtIndex(eStreamStringIndex);
|
|
|
|
if (stream_sp)
|
|
|
|
static_cast<StreamString *>(stream_sp.get())->Clear();
|
2011-02-20 10:15:07 +08:00
|
|
|
stream_sp = m_err_stream.GetStreamAtIndex(eStreamStringIndex);
|
|
|
|
if (stream_sp)
|
|
|
|
static_cast<StreamString *>(stream_sp.get())->Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
m_status = eReturnStatusStarted;
|
|
|
|
m_did_change_process_state = false;
|
2021-06-09 01:46:43 +08:00
|
|
|
m_suppress_immediate_output = false;
|
2014-07-15 08:25:59 +08:00
|
|
|
m_interactive = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2021-12-04 06:49:42 +08:00
|
|
|
bool CommandReturnObject::GetDidChangeProcessState() const {
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_did_change_process_state;
|
2014-07-15 08:25:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandReturnObject::SetDidChangeProcessState(bool b) {
|
|
|
|
m_did_change_process_state = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommandReturnObject::GetInteractive() const { return m_interactive; }
|
|
|
|
|
|
|
|
void CommandReturnObject::SetInteractive(bool b) { m_interactive = b; }
|
2021-06-09 01:46:43 +08:00
|
|
|
|
|
|
|
bool CommandReturnObject::GetSuppressImmediateOutput() const {
|
|
|
|
return m_suppress_immediate_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandReturnObject::SetSuppressImmediateOutput(bool b) {
|
|
|
|
m_suppress_immediate_output = b;
|
|
|
|
}
|