Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBCommandReturnObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class LLDB_API SBCommandReturnObject {

void SetError(const char *error_cstr);

lldb::SBValue GetReturnValue(lldb::DynamicValueType use_dynamic);

protected:
friend class SBCommandInterpreter;
friend class SBOptions;
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/API/SBValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ class LLDB_API SBValue {

protected:
friend class SBBlock;
friend class SBCommandReturnObject;
friend class SBFrame;
friend class SBModule;
friend class SBTarget;
Expand Down
9 changes: 9 additions & 0 deletions lldb/include/lldb/Interpreter/CommandReturnObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ class CommandReturnObject {
return m_diagnostic_indent;
}

lldb::ValueObjectSP GetValueObjectSP() const { return m_value_object_sp; }

void SetValueObjectSP(lldb::ValueObjectSP value_object_sp) {
m_value_object_sp = value_object_sp;
}

lldb::ReturnStatus GetStatus() const;

void SetStatus(lldb::ReturnStatus status);
Expand Down Expand Up @@ -197,6 +203,9 @@ class CommandReturnObject {

lldb::ReturnStatus m_status = lldb::eReturnStatusStarted;

/// An optional return ValueObjectSP.
lldb::ValueObjectSP m_value_object_sp;

bool m_did_change_process_state = false;
bool m_suppress_immediate_output = false;

Expand Down
10 changes: 10 additions & 0 deletions lldb/source/API/SBCommandReturnObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "lldb/API/SBFile.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStructuredData.h"
#include "lldb/API/SBValue.h"
#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Utility/ConstString.h"
Expand Down Expand Up @@ -356,3 +357,12 @@ void SBCommandReturnObject::SetError(const char *error_cstr) {
if (error_cstr)
ref().AppendError(error_cstr);
}

SBValue
SBCommandReturnObject::GetReturnValue(lldb::DynamicValueType use_dynamic) {
LLDB_INSTRUMENT_VA(this, use_dynamic);

SBValue sb_value;
sb_value.SetSP(ref().GetValueObjectSP(), use_dynamic);
return sb_value;
}
3 changes: 3 additions & 0 deletions lldb/source/Commands/CommandObjectDWIMPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
ExpressionResults expr_result = target.EvaluateExpression(
expr, exe_scope, valobj_sp, eval_options, &fixed_expression);

if (valobj_sp)
result.SetValueObjectSP(valobj_sp);

// Record the position of the expression in the command.
std::optional<uint16_t> indent;
if (fixed_expression.empty()) {
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Commands/CommandObjectExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
}

if (result_valobj_sp) {
result.SetValueObjectSP(result_valobj_sp);

Format format = m_format_options.GetFormat();

if (result_valobj_sp->GetError().Success()) {
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Commands/CommandObjectFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class CommandObjectFrameDiagnose : public CommandObjectParsed {
return;
}

result.SetValueObjectSP(valobj_sp);
DumpValueObjectOptions::DeclPrintingHelper helper =
[&valobj_sp](ConstString type, ConstString var,
const DumpValueObjectOptions &opts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ def test_get_command(self):
ci.HandleCommand("help help", res)
self.assertTrue(res.Succeeded())
self.assertEqual(res.GetCommand(), "help help")

value = res.GetReturnValue(lldb.eNoDynamicValues)
self.assertFalse(value)

def test_get_value(self):
res = lldb.SBCommandReturnObject()
ci = self.dbg.GetCommandInterpreter()
ci.HandleCommand("p 1 + 1", res)
self.assertTrue(res.Succeeded())

value = res.GetReturnValue(lldb.eNoDynamicValues)
self.assertTrue(value)
self.assertEqual(value.GetValue(), "2")