Skip to content

Commit de0e550

Browse files
committed
[lldb] Rename CommandReturnObject::Get.*Data -> Get.*String (llvm#112062)
In a later commit, I want to add a method to access diagnostics as actual structured data, which will make these function names rather confusing. (cherry picked from commit c275080)
1 parent 0836f9c commit de0e550

File tree

7 files changed

+28
-25
lines changed

7 files changed

+28
-25
lines changed

lldb/include/lldb/Interpreter/CommandReturnObject.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ class CommandReturnObject {
3030

3131
~CommandReturnObject() = default;
3232

33-
llvm::StringRef GetInlineDiagnosticsData(unsigned indent);
33+
/// Format any inline diagnostics with an indentation of \c indent.
34+
llvm::StringRef GetInlineDiagnosticString(unsigned indent);
3435

35-
llvm::StringRef GetOutputData() {
36+
llvm::StringRef GetOutputString() {
3637
lldb::StreamSP stream_sp(m_out_stream.GetStreamAtIndex(eStreamStringIndex));
3738
if (stream_sp)
3839
return std::static_pointer_cast<StreamString>(stream_sp)->GetString();
3940
return llvm::StringRef();
4041
}
4142

42-
llvm::StringRef GetErrorData();
43+
llvm::StringRef GetErrorString();
4344

4445
Stream &GetOutputStream() {
4546
// Make sure we at least have our normal string stream output stream

lldb/source/API/SBCommandReturnObject.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,27 @@ SBCommandReturnObject::operator bool() const {
8585
const char *SBCommandReturnObject::GetOutput() {
8686
LLDB_INSTRUMENT_VA(this);
8787

88-
ConstString output(ref().GetOutputData());
88+
ConstString output(ref().GetOutputString());
8989
return output.AsCString(/*value_if_empty*/ "");
9090
}
9191

9292
const char *SBCommandReturnObject::GetError() {
9393
LLDB_INSTRUMENT_VA(this);
9494

95-
ConstString output(ref().GetErrorData());
95+
ConstString output(ref().GetErrorString());
9696
return output.AsCString(/*value_if_empty*/ "");
9797
}
9898

9999
size_t SBCommandReturnObject::GetOutputSize() {
100100
LLDB_INSTRUMENT_VA(this);
101101

102-
return ref().GetOutputData().size();
102+
return ref().GetOutputString().size();
103103
}
104104

105105
size_t SBCommandReturnObject::GetErrorSize() {
106106
LLDB_INSTRUMENT_VA(this);
107107

108-
return ref().GetErrorData().size();
108+
return ref().GetErrorString().size();
109109
}
110110

111111
size_t SBCommandReturnObject::PutOutput(FILE *fh) {

lldb/source/Commands/CommandObjectCommands.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ class CommandObjectPythonFunction : public CommandObjectRaw {
10991099
} else {
11001100
// Don't change the status if the command already set it...
11011101
if (result.GetStatus() == eReturnStatusInvalid) {
1102-
if (result.GetOutputData().empty())
1102+
if (result.GetOutputString().empty())
11031103
result.SetStatus(eReturnStatusSuccessFinishNoResult);
11041104
else
11051105
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -1205,7 +1205,7 @@ class CommandObjectScriptingObjectRaw : public CommandObjectRaw {
12051205
} else {
12061206
// Don't change the status if the command already set it...
12071207
if (result.GetStatus() == eReturnStatusInvalid) {
1208-
if (result.GetOutputData().empty())
1208+
if (result.GetOutputString().empty())
12091209
result.SetStatus(eReturnStatusSuccessFinishNoResult);
12101210
else
12111211
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -1946,7 +1946,7 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
19461946
} else {
19471947
// Don't change the status if the command already set it...
19481948
if (result.GetStatus() == eReturnStatusInvalid) {
1949-
if (result.GetOutputData().empty())
1949+
if (result.GetOutputString().empty())
19501950
result.SetStatus(eReturnStatusSuccessFinishNoResult);
19511951
else
19521952
result.SetStatus(eReturnStatusSuccessFinishResult);

lldb/source/Core/Debugger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,10 @@ void Debugger::Destroy(DebuggerSP &debugger_sp) {
784784
CommandReturnObject result(debugger_sp->GetUseColor());
785785
cmd_interpreter.SaveTranscript(result);
786786
if (result.Succeeded())
787-
(*debugger_sp->GetAsyncOutputStream()) << result.GetOutputData() << '\n';
787+
(*debugger_sp->GetAsyncOutputStream())
788+
<< result.GetOutputString() << '\n';
788789
else
789-
(*debugger_sp->GetAsyncErrorStream()) << result.GetErrorData() << '\n';
790+
(*debugger_sp->GetAsyncErrorStream()) << result.GetErrorString() << '\n';
790791
}
791792

792793
debugger_sp->Clear();

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,11 +2106,11 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
21062106
// used instead of `GetSaveTrasncript()`. This is because the latter will
21072107
// fail when the command is "settings set interpreter.save-transcript true".
21082108
if (transcript_item) {
2109-
m_transcript_stream << result.GetOutputData();
2110-
m_transcript_stream << result.GetErrorData();
2109+
m_transcript_stream << result.GetOutputString();
2110+
m_transcript_stream << result.GetErrorString();
21112111

2112-
transcript_item->AddStringItem("output", result.GetOutputData());
2113-
transcript_item->AddStringItem("error", result.GetErrorData());
2112+
transcript_item->AddStringItem("output", result.GetOutputString());
2113+
transcript_item->AddStringItem("error", result.GetErrorString());
21142114
transcript_item->AddFloatItem("durationInSeconds",
21152115
execute_time.get().count());
21162116
}
@@ -2644,11 +2644,11 @@ void CommandInterpreter::HandleCommands(const StringList &commands,
26442644

26452645
if (options.GetPrintResults()) {
26462646
if (tmp_result.Succeeded())
2647-
result.AppendMessage(tmp_result.GetOutputData());
2647+
result.AppendMessage(tmp_result.GetOutputString());
26482648
}
26492649

26502650
if (!success || !tmp_result.Succeeded()) {
2651-
llvm::StringRef error_msg = tmp_result.GetErrorData();
2651+
llvm::StringRef error_msg = tmp_result.GetErrorString();
26522652
if (error_msg.empty())
26532653
error_msg = "<unknown error>.\n";
26542654
if (options.GetStopOnError()) {
@@ -3204,7 +3204,7 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler,
32043204
unsigned prompt_len = m_debugger.GetPrompt().size();
32053205
if (auto indent = result.GetDiagnosticIndent()) {
32063206
llvm::StringRef diags =
3207-
result.GetInlineDiagnosticsData(prompt_len + *indent);
3207+
result.GetInlineDiagnosticString(prompt_len + *indent);
32083208
PrintCommandOutput(io_handler, diags, true);
32093209
}
32103210
}
@@ -3213,13 +3213,13 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler,
32133213
GetProcessOutput();
32143214

32153215
if (!result.GetImmediateOutputStream()) {
3216-
llvm::StringRef output = result.GetOutputData();
3216+
llvm::StringRef output = result.GetOutputString();
32173217
PrintCommandOutput(io_handler, output, true);
32183218
}
32193219

32203220
// Now emit the command error text from the command we just executed.
32213221
if (!result.GetImmediateErrorStream()) {
3222-
llvm::StringRef error = result.GetErrorData();
3222+
llvm::StringRef error = result.GetErrorString();
32233223
PrintCommandOutput(io_handler, error, false);
32243224
}
32253225
}

lldb/source/Interpreter/CommandReturnObject.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ void CommandReturnObject::SetError(llvm::Error error) {
123123
}
124124
}
125125

126-
llvm::StringRef CommandReturnObject::GetInlineDiagnosticsData(unsigned indent) {
126+
llvm::StringRef
127+
CommandReturnObject::GetInlineDiagnosticString(unsigned indent) {
127128
RenderDiagnosticDetails(m_diag_stream, indent, true, m_diagnostics);
128129
// Duplex the diagnostics to the secondary stream (but not inlined).
129130
if (auto stream_sp = m_err_stream.GetStreamAtIndex(eStreamStringIndex))
@@ -134,7 +135,7 @@ llvm::StringRef CommandReturnObject::GetInlineDiagnosticsData(unsigned indent) {
134135
return m_diag_stream.GetString();
135136
}
136137

137-
llvm::StringRef CommandReturnObject::GetErrorData() {
138+
llvm::StringRef CommandReturnObject::GetErrorString() {
138139
// Diagnostics haven't been fetched; render them now (not inlined).
139140
if (!m_diagnostics.empty()) {
140141
RenderDiagnosticDetails(GetErrorStream(), std::nullopt, false,

lldb/tools/lldb-test/lldb-test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ int opts::breakpoint::evaluateBreakpoints(Debugger &Dbg) {
434434
CommandReturnObject Result(/*colors*/ false);
435435
if (!Dbg.GetCommandInterpreter().HandleCommand(
436436
Command.c_str(), /*add_to_history*/ eLazyBoolNo, Result)) {
437-
P.formatLine("Failed: {0}", Result.GetErrorData());
437+
P.formatLine("Failed: {0}", Result.GetErrorString());
438438
HadErrors = 1;
439439
continue;
440440
}
@@ -1151,7 +1151,7 @@ int opts::irmemorymap::evaluateMemoryMapCommands(Debugger &Dbg) {
11511151
return CI.HandleCommand(Cmd, eLazyBoolNo, Result);
11521152
};
11531153
if (!IssueCmd("b main") || !IssueCmd("run")) {
1154-
outs() << formatv("Failed: {0}\n", Result.GetErrorData());
1154+
outs() << formatv("Failed: {0}\n", Result.GetErrorString());
11551155
exit(1);
11561156
}
11571157

0 commit comments

Comments
 (0)