[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);
|
2016-11-13 02:47:11 +08:00
|
|
|
if (in_string.empty())
|
2010-06-09 00:52:24 +08:00
|
|
|
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) {
|
|
|
|
const char *error_cstr = error.AsCString();
|
2014-04-20 08:31:37 +08:00
|
|
|
if (error_cstr == nullptr)
|
2011-11-15 11:53:30 +08:00
|
|
|
error_cstr = fallback_error_cstr;
|
2013-07-10 04:14:26 +08:00
|
|
|
SetError(error_cstr);
|
2011-11-15 11:53:30 +08:00
|
|
|
}
|
2013-07-10 04:14:26 +08:00
|
|
|
|
2016-11-13 02:47:11 +08:00
|
|
|
void CommandReturnObject::SetError(llvm::StringRef error_str) {
|
2021-06-16 21:39:50 +08:00
|
|
|
SetStatus(eReturnStatusFailed);
|
2016-11-13 02:47:11 +08:00
|
|
|
if (error_str.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
AppendError(error_str);
|
2013-07-10 04:14:26 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2016-11-13 02:47:11 +08:00
|
|
|
if (in_string.empty())
|
|
|
|
return;
|
|
|
|
GetErrorStream() << in_string;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandReturnObject::SetStatus(ReturnStatus status) { m_status = status; }
|
|
|
|
|
|
|
|
ReturnStatus CommandReturnObject::GetStatus() { return m_status; }
|
|
|
|
|
|
|
|
bool CommandReturnObject::Succeeded() {
|
|
|
|
return m_status <= eReturnStatusSuccessContinuingResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommandReturnObject::HasResult() {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool CommandReturnObject::GetDidChangeProcessState() {
|
|
|
|
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;
|
|
|
|
}
|