Skip to content

[lldb] Store the command in the CommandReturnObject #125132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lldb/include/lldb/API/SBCommandReturnObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class LLDB_API SBCommandReturnObject {

bool IsValid() const;

/// Get the command as the user typed it. Empty string if commands were run on
/// behalf of lldb.
const char *GetCommand();

const char *GetOutput();

const char *GetError();
Expand Down
8 changes: 8 additions & 0 deletions lldb/include/lldb/Interpreter/CommandReturnObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class CommandReturnObject {

~CommandReturnObject() = default;

/// Get the command as the user typed it. Empty string if commands were run on
/// behalf of lldb.
const std::string &GetCommand() const { return m_command; }

void SetCommand(std::string command) { m_command = std::move(command); }

/// Format any inline diagnostics with an indentation of \c indent.
std::string GetInlineDiagnosticString(unsigned indent) const;

Expand Down Expand Up @@ -182,6 +188,8 @@ class CommandReturnObject {
private:
enum { eStreamStringIndex = 0, eImmediateStreamIndex = 1 };

std::string m_command;

StreamTee m_out_stream;
StreamTee m_err_stream;
std::vector<DiagnosticDetail> m_diagnostics;
Expand Down
7 changes: 7 additions & 0 deletions lldb/source/API/SBCommandReturnObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ SBCommandReturnObject::operator bool() const {
return true;
}

const char *SBCommandReturnObject::GetCommand() {
LLDB_INSTRUMENT_VA(this);

ConstString output(ref().GetCommand());
return output.AsCString(/*value_if_empty*/ "");
}

const char *SBCommandReturnObject::GetOutput() {
LLDB_INSTRUMENT_VA(this);

Expand Down
10 changes: 6 additions & 4 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1887,12 +1887,13 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
std::string real_original_command_string(command_string);

Log *log = GetLog(LLDBLog::Commands);
llvm::PrettyStackTraceFormat stack_trace("HandleCommand(command = \"%s\")",
command_line);

LLDB_LOGF(log, "Processing command: %s", command_line);
LLDB_SCOPED_TIMERF("Processing command: %s.", command_line);

// Set the command in the CommandReturnObject here so that it's there even if
// the command is interrupted.
result.SetCommand(command_line);

if (INTERRUPT_REQUESTED(GetDebugger(), "Interrupted initiating command")) {
result.AppendError("... Interrupted");
return false;
Expand Down Expand Up @@ -2644,7 +2645,8 @@ void CommandInterpreter::HandleCommands(
(uint64_t)idx, cmd, error_msg);
m_debugger.SetAsyncExecution(old_async_execution);
return;
} else if (options.GetPrintResults()) {
}
if (options.GetPrintResults()) {
result.AppendMessageWithFormatv("Command #{0} '{1}' failed with {2}",
(uint64_t)idx + 1, cmd, error_msg);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class SBCommandReturnObjectTest(TestBase):
NO_DEBUG_INFO_TESTCASE = True

def test(self):
res = lldb.SBCommandReturnObject()
self.assertEqual(res.GetCommand(), "")

ci = self.dbg.GetCommandInterpreter()
ci.HandleCommand("help help", res)
self.assertTrue(res.Succeeded())
self.assertEqual(res.GetCommand(), "help help")