Skip to content

Commit 014ba7b

Browse files
committed
[lldb] Store the command in the CommandReturnObject
1 parent 5ede432 commit 014ba7b

File tree

14 files changed

+56
-17
lines changed

14 files changed

+56
-17
lines changed

lldb/include/lldb/API/SBCommandReturnObject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class LLDB_API SBCommandReturnObject {
4242

4343
bool IsValid() const;
4444

45+
const char *GetCommand();
46+
4547
const char *GetOutput();
4648

4749
const char *GetError();

lldb/include/lldb/Interpreter/CommandReturnObject.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ namespace lldb_private {
2727

2828
class CommandReturnObject {
2929
public:
30-
CommandReturnObject(bool colors);
30+
CommandReturnObject(std::string command, bool colors);
3131

3232
~CommandReturnObject() = default;
3333

34+
const std::string &GetCommand() const { return m_command; }
35+
36+
void SetCommand(std::string command) { m_command = std::move(command); }
37+
3438
/// Format any inline diagnostics with an indentation of \c indent.
3539
std::string GetInlineDiagnosticString(unsigned indent) const;
3640

@@ -182,6 +186,8 @@ class CommandReturnObject {
182186
private:
183187
enum { eStreamStringIndex = 0, eImmediateStreamIndex = 1 };
184188

189+
std::string m_command;
190+
185191
StreamTee m_out_stream;
186192
StreamTee m_err_stream;
187193
std::vector<DiagnosticDetail> m_diagnostics;

lldb/source/API/SBCommandReturnObject.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace lldb_private;
2323

2424
class lldb_private::SBCommandReturnObjectImpl {
2525
public:
26-
SBCommandReturnObjectImpl() : m_ptr(new CommandReturnObject(false)) {}
26+
SBCommandReturnObjectImpl() : m_ptr(new CommandReturnObject("", false)) {}
2727
SBCommandReturnObjectImpl(CommandReturnObject &ref)
2828
: m_ptr(&ref), m_owned(false) {}
2929
SBCommandReturnObjectImpl(const SBCommandReturnObjectImpl &rhs)
@@ -84,6 +84,13 @@ SBCommandReturnObject::operator bool() const {
8484
return true;
8585
}
8686

87+
const char *SBCommandReturnObject::GetCommand() {
88+
LLDB_INSTRUMENT_VA(this);
89+
90+
ConstString output(ref().GetCommand());
91+
return output.AsCString(/*value_if_empty*/ "");
92+
}
93+
8794
const char *SBCommandReturnObject::GetOutput() {
8895
LLDB_INSTRUMENT_VA(this);
8996

lldb/source/Breakpoint/BreakpointOptions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ bool BreakpointOptions::BreakpointOptionsCallbackFunction(
616616
Target *target = exe_ctx.GetTargetPtr();
617617
if (target) {
618618
Debugger &debugger = target->GetDebugger();
619-
CommandReturnObject result(debugger.GetUseColor());
619+
CommandReturnObject result("<breakpoint callback>",
620+
debugger.GetUseColor());
620621

621622
// Rig up the results secondary output stream to the debugger's, so the
622623
// output will come out synchronously if the debugger is set up that way.

lldb/source/Commands/CommandObjectExpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ void CommandObjectExpression::IOHandlerInputComplete(IOHandler &io_handler,
504504
StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
505505

506506
CommandReturnObject return_obj(
507-
GetCommandInterpreter().GetDebugger().GetUseColor());
507+
line, GetCommandInterpreter().GetDebugger().GetUseColor());
508508
EvaluateExpression(line.c_str(), *output_sp, *error_sp, return_obj);
509509

510510
if (output_sp)

lldb/source/Commands/CommandObjectWatchpointCommand.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ are no syntax errors may indicate that a function was declared but never called.
243243
Target *target = exe_ctx.GetTargetPtr();
244244
if (target) {
245245
Debugger &debugger = target->GetDebugger();
246-
CommandReturnObject result(debugger.GetUseColor());
246+
CommandReturnObject result("<watchpoint callback>",
247+
debugger.GetUseColor());
247248

248249
// Rig up the results secondary output stream to the debugger's, so the
249250
// output will come out synchronously if the debugger is set up that

lldb/source/Core/Debugger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ void Debugger::Destroy(DebuggerSP &debugger_sp) {
799799
CommandInterpreter &cmd_interpreter = debugger_sp->GetCommandInterpreter();
800800

801801
if (cmd_interpreter.GetSaveSessionOnQuit()) {
802-
CommandReturnObject result(debugger_sp->GetUseColor());
802+
CommandReturnObject result("<save transcript>", debugger_sp->GetUseColor());
803803
cmd_interpreter.SaveTranscript(result);
804804
if (result.Succeeded())
805805
(*debugger_sp->GetAsyncOutputStream())

lldb/source/Expression/REPL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
255255
ci.SetPromptOnQuit(false);
256256

257257
// Execute the command
258-
CommandReturnObject result(debugger.GetUseColor());
258+
CommandReturnObject result(code, debugger.GetUseColor());
259259
result.SetImmediateOutputStream(output_sp);
260260
result.SetImmediateErrorStream(error_sp);
261261
ci.HandleCommand(code.c_str(), eLazyBoolNo, result);

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,8 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
18931893
LLDB_LOGF(log, "Processing command: %s", command_line);
18941894
LLDB_SCOPED_TIMERF("Processing command: %s.", command_line);
18951895

1896+
result.SetCommand(command_line);
1897+
18961898
if (INTERRUPT_REQUESTED(GetDebugger(), "Interrupted initiating command")) {
18971899
result.AppendError("... Interrupted");
18981900
return false;
@@ -2616,7 +2618,7 @@ void CommandInterpreter::HandleCommands(
26162618
m_debugger.GetPrompt().str().c_str(), cmd);
26172619
}
26182620

2619-
CommandReturnObject tmp_result(m_debugger.GetUseColor());
2621+
CommandReturnObject tmp_result(cmd, m_debugger.GetUseColor());
26202622
tmp_result.SetInteractive(result.GetInteractive());
26212623
tmp_result.SetSuppressImmediateOutput(true);
26222624

@@ -2644,7 +2646,8 @@ void CommandInterpreter::HandleCommands(
26442646
(uint64_t)idx, cmd, error_msg);
26452647
m_debugger.SetAsyncExecution(old_async_execution);
26462648
return;
2647-
} else if (options.GetPrintResults()) {
2649+
}
2650+
if (options.GetPrintResults()) {
26482651
result.AppendMessageWithFormatv("Command #{0} '{1}' failed with {2}",
26492652
(uint64_t)idx + 1, cmd, error_msg);
26502653
}
@@ -3177,7 +3180,7 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler,
31773180
RestoreExecutionContext();
31783181
});
31793182

3180-
lldb_private::CommandReturnObject result(m_debugger.GetUseColor());
3183+
lldb_private::CommandReturnObject result(line, m_debugger.GetUseColor());
31813184
HandleCommand(line.c_str(), eLazyBoolCalculate, result);
31823185

31833186
// Now emit the command output text from the command we just executed

lldb/source/Interpreter/CommandReturnObject.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ static void DumpStringToStreamWithNewline(Stream &strm, const std::string &s) {
4747
strm.EOL();
4848
}
4949

50-
CommandReturnObject::CommandReturnObject(bool colors)
51-
: m_out_stream(colors), m_err_stream(colors), m_colors(colors) {}
50+
CommandReturnObject::CommandReturnObject(std::string command, bool colors)
51+
: m_command(std::move(command)), m_out_stream(colors), m_err_stream(colors),
52+
m_colors(colors) {}
5253

5354
void CommandReturnObject::AppendErrorWithFormat(const char *format, ...) {
5455
SetStatus(eReturnStatusFailed);

lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,8 @@ bool RunEnableCommand(CommandInterpreter &interpreter) {
10341034
}
10351035

10361036
// Run the command.
1037-
CommandReturnObject return_object(interpreter.GetDebugger().GetUseColor());
1037+
CommandReturnObject return_object("<enable command>",
1038+
interpreter.GetDebugger().GetUseColor());
10381039
interpreter.HandleCommand(command_stream.GetData(), eLazyBoolNo,
10391040
return_object);
10401041
return return_object.Succeeded();

lldb/source/Target/Target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3933,7 +3933,7 @@ Target::StopHookCommandLine::HandleStop(ExecutionContext &exc_ctx,
39333933
if (!m_commands.GetSize())
39343934
return StopHookResult::KeepStopped;
39353935

3936-
CommandReturnObject result(false);
3936+
CommandReturnObject result("<stop hook>", false);
39373937
result.SetImmediateOutputStream(output_sp);
39383938
result.SetInteractive(false);
39393939
Debugger &debugger = exc_ctx.GetTargetPtr()->GetDebugger();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
7+
class SBCommandReturnObjectTest(TestBase):
8+
NO_DEBUG_INFO_TESTCASE = True
9+
10+
def test(self):
11+
res = lldb.SBCommandReturnObject()
12+
self.assertEqual(res.GetCommand(), "")
13+
14+
ci = self.dbg.GetCommandInterpreter()
15+
ci.HandleCommand("help help", res)
16+
self.assertTrue(res.Succeeded())
17+
self.assertEqual(res.GetCommand(), "help help")

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ int opts::breakpoint::evaluateBreakpoints(Debugger &Dbg) {
442442

443443
std::string Command = substitute(Line);
444444
P.formatLine("Command: {0}", Command);
445-
CommandReturnObject Result(/*colors*/ false);
445+
CommandReturnObject Result("", /*colors*/ false);
446446
if (!Dbg.GetCommandInterpreter().HandleCommand(
447447
Command.c_str(), /*add_to_history*/ eLazyBoolNo, Result)) {
448448
P.formatLine("Failed: {0}", Result.GetErrorString());
@@ -1189,7 +1189,7 @@ int opts::irmemorymap::evaluateMemoryMapCommands(Debugger &Dbg) {
11891189

11901190
// Set up a Process. In order to allocate memory within a target, this
11911191
// process must be alive and must support JIT'ing.
1192-
CommandReturnObject Result(/*colors*/ false);
1192+
CommandReturnObject Result("", /*colors*/ false);
11931193
Dbg.SetAsyncExecution(false);
11941194
CommandInterpreter &CI = Dbg.GetCommandInterpreter();
11951195
auto IssueCmd = [&](const char *Cmd) -> bool {
@@ -1258,7 +1258,7 @@ int main(int argc, const char *argv[]) {
12581258

12591259
auto Dbg = lldb_private::Debugger::CreateInstance();
12601260
ModuleList::GetGlobalModuleListProperties().SetEnableExternalLookup(false);
1261-
CommandReturnObject Result(/*colors*/ false);
1261+
CommandReturnObject Result("", /*colors*/ false);
12621262
Dbg->GetCommandInterpreter().HandleCommand(
12631263
"settings set plugin.process.gdb-remote.packet-timeout 60",
12641264
/*add_to_history*/ eLazyBoolNo, Result);

0 commit comments

Comments
 (0)