aboutsummaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/API/SBCommandReturnObject.h2
-rw-r--r--lldb/include/lldb/API/SBValue.h1
-rw-r--r--lldb/include/lldb/Interpreter/CommandReturnObject.h14
-rw-r--r--lldb/include/lldb/ValueObject/ValueObjectList.h2
-rw-r--r--lldb/source/API/SBCommandReturnObject.cpp18
-rw-r--r--lldb/source/Commands/CommandObjectDWIMPrint.cpp3
-rw-r--r--lldb/source/Commands/CommandObjectExpression.cpp2
-rw-r--r--lldb/source/Commands/CommandObjectFrame.cpp16
-rw-r--r--lldb/source/Commands/CommandObjectTarget.cpp19
-rw-r--r--lldb/source/ValueObject/ValueObjectList.cpp6
-rw-r--r--lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py13
-rw-r--r--lldb/test/API/commands/frame/var/TestFrameVar.py9
-rw-r--r--lldb/test/API/functionalities/target_var/TestTargetVar.py9
13 files changed, 91 insertions, 23 deletions
diff --git a/lldb/include/lldb/API/SBCommandReturnObject.h b/lldb/include/lldb/API/SBCommandReturnObject.h
index 9a63c1f..6386bd2 100644
--- a/lldb/include/lldb/API/SBCommandReturnObject.h
+++ b/lldb/include/lldb/API/SBCommandReturnObject.h
@@ -136,6 +136,8 @@ public:
void SetError(const char *error_cstr);
+ lldb::SBValueList GetValues(lldb::DynamicValueType use_dynamic);
+
protected:
friend class SBCommandInterpreter;
friend class SBOptions;
diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h
index 46ef6da..75d20a43 100644
--- a/lldb/include/lldb/API/SBValue.h
+++ b/lldb/include/lldb/API/SBValue.h
@@ -442,6 +442,7 @@ public:
protected:
friend class SBBlock;
+ friend class SBCommandReturnObject;
friend class SBFrame;
friend class SBModule;
friend class SBTarget;
diff --git a/lldb/include/lldb/Interpreter/CommandReturnObject.h b/lldb/include/lldb/Interpreter/CommandReturnObject.h
index 803bcd7..d53aeb8 100644
--- a/lldb/include/lldb/Interpreter/CommandReturnObject.h
+++ b/lldb/include/lldb/Interpreter/CommandReturnObject.h
@@ -14,6 +14,7 @@
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StreamTee.h"
#include "lldb/Utility/StructuredData.h"
+#include "lldb/ValueObject/ValueObjectList.h"
#include "lldb/lldb-private.h"
#include "llvm/ADT/StringRef.h"
@@ -134,7 +135,7 @@ public:
__attribute__((format(printf, 2, 3)));
template <typename... Args>
- void AppendMessageWithFormatv(const char *format, Args &&... args) {
+ void AppendMessageWithFormatv(const char *format, Args &&...args) {
AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
}
@@ -144,12 +145,12 @@ public:
}
template <typename... Args>
- void AppendWarningWithFormatv(const char *format, Args &&... args) {
+ void AppendWarningWithFormatv(const char *format, Args &&...args) {
AppendWarning(llvm::formatv(format, std::forward<Args>(args)...).str());
}
template <typename... Args>
- void AppendErrorWithFormatv(const char *format, Args &&... args) {
+ void AppendErrorWithFormatv(const char *format, Args &&...args) {
AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
}
@@ -165,6 +166,10 @@ public:
return m_diagnostic_indent;
}
+ const ValueObjectList &GetValueObjectList() const { return m_value_objects; }
+
+ ValueObjectList &GetValueObjectList() { return m_value_objects; }
+
lldb::ReturnStatus GetStatus() const;
void SetStatus(lldb::ReturnStatus status);
@@ -197,6 +202,9 @@ private:
lldb::ReturnStatus m_status = lldb::eReturnStatusStarted;
+ /// An optionally empty list of values produced by this command.
+ ValueObjectList m_value_objects;
+
bool m_did_change_process_state = false;
bool m_suppress_immediate_output = false;
diff --git a/lldb/include/lldb/ValueObject/ValueObjectList.h b/lldb/include/lldb/ValueObject/ValueObjectList.h
index 5d63c65..524b66b 100644
--- a/lldb/include/lldb/ValueObject/ValueObjectList.h
+++ b/lldb/include/lldb/ValueObject/ValueObjectList.h
@@ -22,8 +22,6 @@ class ValueObject;
/// A collection of ValueObject values that.
class ValueObjectList {
public:
- const ValueObjectList &operator=(const ValueObjectList &rhs);
-
void Append(const lldb::ValueObjectSP &val_obj_sp);
void Append(const ValueObjectList &valobj_list);
diff --git a/lldb/source/API/SBCommandReturnObject.cpp b/lldb/source/API/SBCommandReturnObject.cpp
index 6f54581..e78e213a 100644
--- a/lldb/source/API/SBCommandReturnObject.cpp
+++ b/lldb/source/API/SBCommandReturnObject.cpp
@@ -12,11 +12,14 @@
#include "lldb/API/SBFile.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStructuredData.h"
+#include "lldb/API/SBValue.h"
+#include "lldb/API/SBValueList.h"
#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Instrumentation.h"
#include "lldb/Utility/Status.h"
+#include "lldb/lldb-forward.h"
using namespace lldb;
using namespace lldb_private;
@@ -356,3 +359,18 @@ void SBCommandReturnObject::SetError(const char *error_cstr) {
if (error_cstr)
ref().AppendError(error_cstr);
}
+
+SBValueList
+SBCommandReturnObject::GetValues(lldb::DynamicValueType use_dynamic) {
+ LLDB_INSTRUMENT_VA(this, use_dynamic);
+
+ SBValueList value_list;
+ for (ValueObjectSP value_object_sp :
+ ref().GetValueObjectList().GetObjects()) {
+ SBValue value_sb;
+ value_sb.SetSP(value_object_sp, use_dynamic);
+ value_list.Append(value_sb);
+ }
+
+ return value_list;
+}
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index d4d038d..0414242 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -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.GetValueObjectList().Append(valobj_sp);
+
// Record the position of the expression in the command.
std::optional<uint16_t> indent;
if (fixed_expression.empty()) {
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index 7e26381..18526c4 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -434,6 +434,8 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
}
if (result_valobj_sp) {
+ result.GetValueObjectList().Append(result_valobj_sp);
+
Format format = m_format_options.GetFormat();
if (result_valobj_sp->GetError().Success()) {
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index a5709b3..7e42ef2 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -152,6 +152,7 @@ protected:
return;
}
+ result.GetValueObjectList().Append(valobj_sp);
DumpValueObjectOptions::DeclPrintingHelper helper =
[&valobj_sp](ConstString type, ConstString var,
const DumpValueObjectOptions &opts,
@@ -317,10 +318,10 @@ protected:
} else if (*m_options.relative_frame_offset > 0) {
// I don't want "up 20" where "20" takes you past the top of the stack
// to produce an error, but rather to just go to the top. OTOH, start
- // by seeing if the requested frame exists, in which case we can avoid
+ // by seeing if the requested frame exists, in which case we can avoid
// counting the stack here...
- const uint32_t frame_requested = frame_idx
- + *m_options.relative_frame_offset;
+ const uint32_t frame_requested =
+ frame_idx + *m_options.relative_frame_offset;
StackFrameSP frame_sp = thread->GetStackFrameAtIndex(frame_requested);
if (frame_sp)
frame_idx = frame_requested;
@@ -515,8 +516,8 @@ protected:
if (error.Fail() && (!variable_list || variable_list->GetSize() == 0)) {
result.AppendError(error.AsCString());
-
}
+
ValueObjectSP valobj_sp;
TypeSummaryImplSP summary_format_sp;
@@ -564,6 +565,8 @@ protected:
valobj_sp = frame->GetValueObjectForFrameVariable(
var_sp, m_varobj_options.use_dynamic);
if (valobj_sp) {
+ result.GetValueObjectList().Append(valobj_sp);
+
std::string scope_string;
if (m_option_variable.show_scope)
scope_string = GetScopeString(var_sp).str();
@@ -604,6 +607,8 @@ protected:
entry.ref(), m_varobj_options.use_dynamic, expr_path_options,
var_sp, error);
if (valobj_sp) {
+ result.GetValueObjectList().Append(valobj_sp);
+
std::string scope_string;
if (m_option_variable.show_scope)
scope_string = GetScopeString(var_sp).str();
@@ -653,6 +658,8 @@ protected:
valobj_sp = frame->GetValueObjectForFrameVariable(
var_sp, m_varobj_options.use_dynamic);
if (valobj_sp) {
+ result.GetValueObjectList().Append(valobj_sp);
+
// When dumping all variables, don't print any variables that are
// not in scope to avoid extra unneeded output
if (valobj_sp->IsInScope()) {
@@ -694,6 +701,7 @@ protected:
recognized_frame->GetRecognizedArguments();
if (recognized_arg_list) {
for (auto &rec_value_sp : recognized_arg_list->GetObjects()) {
+ result.GetValueObjectList().Append(rec_value_sp);
options.SetFormat(m_option_format.GetFormat());
options.SetVariableFormatDisplayLanguage(
rec_value_sp->GetPreferredDisplayLanguage());
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index da50fe0..71ddc8d 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -803,7 +803,9 @@ public:
protected:
void DumpGlobalVariableList(const ExecutionContext &exe_ctx,
const SymbolContext &sc,
- const VariableList &variable_list, Stream &s) {
+ const VariableList &variable_list,
+ CommandReturnObject &result) {
+ Stream &s = result.GetOutputStream();
if (variable_list.Empty())
return;
if (sc.module_sp) {
@@ -824,15 +826,16 @@ protected:
ValueObjectSP valobj_sp(ValueObjectVariable::Create(
exe_ctx.GetBestExecutionContextScope(), var_sp));
- if (valobj_sp)
+ if (valobj_sp) {
+ result.GetValueObjectList().Append(valobj_sp);
DumpValueObject(s, var_sp, valobj_sp, var_sp->GetName().GetCString());
+ }
}
}
void DoExecute(Args &args, CommandReturnObject &result) override {
Target *target = m_exe_ctx.GetTargetPtr();
const size_t argc = args.GetArgumentCount();
- Stream &s = result.GetOutputStream();
if (argc > 0) {
for (const Args::ArgEntry &arg : args) {
@@ -874,7 +877,7 @@ protected:
m_exe_ctx.GetBestExecutionContextScope(), var_sp);
if (valobj_sp)
- DumpValueObject(s, var_sp, valobj_sp,
+ DumpValueObject(result.GetOutputStream(), var_sp, valobj_sp,
use_var_name ? var_sp->GetName().GetCString()
: arg.c_str());
}
@@ -903,7 +906,8 @@ protected:
if (comp_unit_varlist_sp) {
size_t count = comp_unit_varlist_sp->GetSize();
if (count > 0) {
- DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
+ DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp,
+ result);
success = true;
}
}
@@ -964,7 +968,8 @@ protected:
VariableListSP comp_unit_varlist_sp(
sc.comp_unit->GetVariableList(can_create));
if (comp_unit_varlist_sp)
- DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
+ DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp,
+ result);
} else if (sc.module_sp) {
// Get all global variables for this module
lldb_private::RegularExpression all_globals_regex(
@@ -972,7 +977,7 @@ protected:
VariableList variable_list;
sc.module_sp->FindGlobalVariables(all_globals_regex, UINT32_MAX,
variable_list);
- DumpGlobalVariableList(m_exe_ctx, sc, variable_list, s);
+ DumpGlobalVariableList(m_exe_ctx, sc, variable_list, result);
}
}
}
diff --git a/lldb/source/ValueObject/ValueObjectList.cpp b/lldb/source/ValueObject/ValueObjectList.cpp
index a79a040..fdee957 100644
--- a/lldb/source/ValueObject/ValueObjectList.cpp
+++ b/lldb/source/ValueObject/ValueObjectList.cpp
@@ -16,12 +16,6 @@
using namespace lldb;
using namespace lldb_private;
-const ValueObjectList &ValueObjectList::operator=(const ValueObjectList &rhs) {
- if (this != &rhs)
- m_value_objects = rhs.m_value_objects;
- return *this;
-}
-
void ValueObjectList::Append(const ValueObjectSP &val_obj_sp) {
m_value_objects.push_back(val_obj_sp);
}
diff --git a/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py b/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py
index 2193b72..f8632fd 100644
--- a/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py
+++ b/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py
@@ -33,3 +33,16 @@ class TestSBCommandReturnObject(TestBase):
ci.HandleCommand("help help", res)
self.assertTrue(res.Succeeded())
self.assertEqual(res.GetCommand(), "help help")
+
+ value_list = res.GetValues(lldb.eNoDynamicValues)
+ self.assertEqual(value_list.GetSize(), 0)
+
+ def test_get_value(self):
+ res = lldb.SBCommandReturnObject()
+ ci = self.dbg.GetCommandInterpreter()
+ ci.HandleCommand("p 1 + 1", res)
+ self.assertTrue(res.Succeeded())
+
+ value_list = res.GetValues(lldb.eNoDynamicValues)
+ self.assertEqual(value_list.GetSize(), 1)
+ self.assertEqual(value_list.GetValueAtIndex(0).GetValue(), "2")
diff --git a/lldb/test/API/commands/frame/var/TestFrameVar.py b/lldb/test/API/commands/frame/var/TestFrameVar.py
index 7211cad..d8260a5 100644
--- a/lldb/test/API/commands/frame/var/TestFrameVar.py
+++ b/lldb/test/API/commands/frame/var/TestFrameVar.py
@@ -2,7 +2,6 @@
Make sure the frame variable -g, -a, and -l flags work.
"""
-
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.decorators import *
@@ -79,6 +78,14 @@ class TestFrameVar(TestBase):
self.assertNotIn("test_var", output, "Args found a local")
self.assertNotIn("g_var", output, "Args found a global")
+ value_list = command_result.GetValues(lldb.eNoDynamicValues)
+ self.assertGreaterEqual(value_list.GetSize(), 2)
+ value_names = []
+ for value in value_list:
+ value_names.append(value.GetName())
+ self.assertIn("argc", value_names)
+ self.assertIn("argv", value_names)
+
# Just get locals:
result = interp.HandleCommand("frame var -a", command_result)
self.assertEqual(
diff --git a/lldb/test/API/functionalities/target_var/TestTargetVar.py b/lldb/test/API/functionalities/target_var/TestTargetVar.py
index 54b7b77..0ef3d00 100644
--- a/lldb/test/API/functionalities/target_var/TestTargetVar.py
+++ b/lldb/test/API/functionalities/target_var/TestTargetVar.py
@@ -34,3 +34,12 @@ class targetCommandTestCase(TestBase):
error=True,
substrs=["can't find global variable 'var[0]'"],
)
+
+ command_result = lldb.SBCommandReturnObject()
+ result = self.ci.HandleCommand("target var", command_result)
+ value_list = command_result.GetValues(lldb.eNoDynamicValues)
+ self.assertGreaterEqual(value_list.GetSize(), 2)
+ value_names = []
+ for value in value_list:
+ value_names.append(value.GetName())
+ self.assertIn("i", value_names)