Skip to content

Commit d1bc75c

Browse files
committed
Convert ValueObject::Dump() to return llvm::Error() (NFCish)
This change by itself has no measurable effect on the LLDB testsuite. I'm making it in preparation for threading through more errors in the Swift language plugin.
1 parent 6bc71cd commit d1bc75c

File tree

20 files changed

+108
-44
lines changed

20 files changed

+108
-44
lines changed

lldb/include/lldb/Core/ValueObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,9 @@ class ValueObject {
694694

695695
virtual SymbolContextScope *GetSymbolContextScope();
696696

697-
void Dump(Stream &s);
697+
llvm::Error Dump(Stream &s);
698698

699-
void Dump(Stream &s, const DumpValueObjectOptions &options);
699+
llvm::Error Dump(Stream &s, const DumpValueObjectOptions &options);
700700

701701
static lldb::ValueObjectSP
702702
CreateValueObjectFromExpression(llvm::StringRef name,

lldb/include/lldb/DataFormatters/ValueObjectPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ValueObjectPrinter {
3333

3434
~ValueObjectPrinter() = default;
3535

36-
bool PrintValueObject();
36+
llvm::Error PrintValueObject();
3737

3838
protected:
3939
typedef std::set<uint64_t> InstancePointersSet;

lldb/source/API/SBValue.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
12331233
DumpValueObjectOptions options;
12341234
options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
12351235
options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
1236-
value_sp->Dump(strm, options);
1236+
if (llvm::Error error = value_sp->Dump(strm, options)) {
1237+
strm << "error: " << toString(std::move(error));
1238+
return false;
1239+
}
12371240
} else {
12381241
strm.PutCString("No value");
12391242
}

lldb/source/Breakpoint/Watchpoint.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char *prefix) const {
299299
.SetHideRootType(true)
300300
.SetHideRootName(true)
301301
.SetHideName(true);
302-
m_old_value_sp->Dump(strm, options);
302+
if (llvm::Error error = m_old_value_sp->Dump(strm, options))
303+
strm << "error: " << toString(std::move(error));
304+
303305
if (strm.GetData())
304306
values_ss.Printf("old value: %s", strm.GetData());
305307
}
@@ -322,7 +324,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char *prefix) const {
322324
.SetHideRootType(true)
323325
.SetHideRootName(true)
324326
.SetHideName(true);
325-
m_new_value_sp->Dump(strm, options);
327+
if (llvm::Error error = m_new_value_sp->Dump(strm, options))
328+
strm << "error: " << toString(std::move(error));
329+
326330
if (strm.GetData())
327331
values_ss.Printf("new value: %s", strm.GetData());
328332
}

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,17 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
133133
auto dump_val_object = [&](ValueObject &valobj) {
134134
if (is_po) {
135135
StreamString temp_result_stream;
136-
valobj.Dump(temp_result_stream, dump_options);
136+
if (llvm::Error error = valobj.Dump(temp_result_stream, dump_options)) {
137+
result.AppendError(toString(std::move(error)));
138+
return;
139+
}
137140
llvm::StringRef output = temp_result_stream.GetString();
138141
maybe_add_hint(output);
139142
result.GetOutputStream() << output;
140143
} else {
141-
valobj.Dump(result.GetOutputStream(), dump_options);
144+
if (llvm::Error error =
145+
valobj.Dump(result.GetOutputStream(), dump_options))
146+
result.AppendError(toString(std::move(error)));
142147
}
143148
};
144149

lldb/source/Commands/CommandObjectExpression.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,11 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
461461
options.SetVariableFormatDisplayLanguage(
462462
result_valobj_sp->GetPreferredDisplayLanguage());
463463

464-
result_valobj_sp->Dump(output_stream, options);
464+
if (llvm::Error error =
465+
result_valobj_sp->Dump(output_stream, options)) {
466+
result.AppendError(toString(std::move(error)));
467+
return false;
468+
}
465469

466470
if (suppress_result)
467471
if (auto result_var_sp =

lldb/source/Commands/CommandObjectFrame.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ class CommandObjectFrameDiagnose : public CommandObjectParsed {
170170
assert(valobj_sp.get() && "Must have a valid ValueObject to print");
171171
ValueObjectPrinter printer(*valobj_sp, &result.GetOutputStream(),
172172
options);
173-
printer.PrintValueObject();
173+
if (llvm::Error error = printer.PrintValueObject())
174+
result.AppendError(toString(std::move(error)));
174175
}
175176

176177
CommandOptions m_options;
@@ -555,7 +556,9 @@ may even involve JITing and running code in the target program.)");
555556
show_module))
556557
s.PutCString(": ");
557558
}
558-
valobj_sp->Dump(result.GetOutputStream(), options);
559+
auto &strm = result.GetOutputStream();
560+
if (llvm::Error error = valobj_sp->Dump(strm, options))
561+
result.AppendError(toString(std::move(error)));
559562
}
560563
}
561564
} else {
@@ -597,7 +600,8 @@ may even involve JITing and running code in the target program.)");
597600
Stream &output_stream = result.GetOutputStream();
598601
options.SetRootValueObjectName(
599602
valobj_sp->GetParent() ? entry.c_str() : nullptr);
600-
valobj_sp->Dump(output_stream, options);
603+
if (llvm::Error error = valobj_sp->Dump(output_stream, options))
604+
result.AppendError(toString(std::move(error)));
601605
} else {
602606
if (auto error_cstr = error.AsCString(nullptr))
603607
result.AppendError(error_cstr);
@@ -648,7 +652,9 @@ may even involve JITing and running code in the target program.)");
648652
valobj_sp->GetPreferredDisplayLanguage());
649653
options.SetRootValueObjectName(
650654
var_sp ? var_sp->GetName().AsCString() : nullptr);
651-
valobj_sp->Dump(result.GetOutputStream(), options);
655+
if (llvm::Error error =
656+
valobj_sp->Dump(result.GetOutputStream(), options))
657+
result.AppendError(toString(std::move(error)));
652658
}
653659
}
654660
}
@@ -669,7 +675,9 @@ may even involve JITing and running code in the target program.)");
669675
options.SetVariableFormatDisplayLanguage(
670676
rec_value_sp->GetPreferredDisplayLanguage());
671677
options.SetRootValueObjectName(rec_value_sp->GetName().AsCString());
672-
rec_value_sp->Dump(result.GetOutputStream(), options);
678+
if (llvm::Error error =
679+
rec_value_sp->Dump(result.GetOutputStream(), options))
680+
result.AppendError(toString(std::move(error)));
673681
}
674682
}
675683
}

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,10 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
815815
DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(
816816
eLanguageRuntimeDescriptionDisplayVerbosityFull, format));
817817

818-
valobj_sp->Dump(*output_stream_p, options);
818+
if (llvm::Error error = valobj_sp->Dump(*output_stream_p, options)) {
819+
result.AppendError(toString(std::move(error)));
820+
return;
821+
}
819822
} else {
820823
result.AppendErrorWithFormat(
821824
"failed to create a value object for: (%s) %s\n",

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@ class CommandObjectTargetVariable : public CommandObjectParsed {
784784

785785
options.SetRootValueObjectName(root_name);
786786

787-
valobj_sp->Dump(s, options);
787+
if (llvm::Error error = valobj_sp->Dump(s, options))
788+
s << "error: " << toString(std::move(error));
788789
}
789790

790791
static size_t GetVariableCallback(void *baton, const char *name,

lldb/source/Commands/CommandObjectThread.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,10 @@ class CommandObjectThreadException : public CommandObjectIterateOverThreads {
13861386
Stream &strm = result.GetOutputStream();
13871387
ValueObjectSP exception_object_sp = thread_sp->GetCurrentException();
13881388
if (exception_object_sp) {
1389-
exception_object_sp->Dump(strm);
1389+
if (llvm::Error error = exception_object_sp->Dump(strm)) {
1390+
result.AppendError(toString(std::move(error)));
1391+
return false;
1392+
}
13901393
}
13911394

13921395
ThreadSP exception_thread_sp = thread_sp->GetCurrentExceptionBacktrace();
@@ -1438,9 +1441,12 @@ class CommandObjectThreadSiginfo : public CommandObjectIterateOverThreads {
14381441
return false;
14391442
}
14401443
ValueObjectSP exception_object_sp = thread_sp->GetSiginfoValue();
1441-
if (exception_object_sp)
1442-
exception_object_sp->Dump(strm);
1443-
else
1444+
if (exception_object_sp) {
1445+
if (llvm::Error error = exception_object_sp->Dump(strm)) {
1446+
result.AppendError(toString(std::move(error)));
1447+
return false;
1448+
}
1449+
} else
14441450
strm.Printf("(no siginfo)\n");
14451451
strm.PutChar('\n');
14461452

lldb/source/Core/DumpRegisterValue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ static void dump_type_value(lldb_private::CompilerType &fields_type, T value,
5454
};
5555
dump_options.SetChildPrintingDecider(decider).SetHideRootType(true);
5656

57-
vobj_sp->Dump(strm, dump_options);
57+
if (llvm::Error error = vobj_sp->Dump(strm, dump_options))
58+
strm << "error: " << toString(std::move(error));
5859
}
5960

6061
void lldb_private::DumpRegisterValue(const RegisterValue &reg_val, Stream &s,

lldb/source/Core/FormatEntity.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,10 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
14011401
ValueObjectSP return_valobj_sp =
14021402
StopInfo::GetReturnValueObject(stop_info_sp);
14031403
if (return_valobj_sp) {
1404-
return_valobj_sp->Dump(s);
1404+
if (llvm::Error error = return_valobj_sp->Dump(s)) {
1405+
s << "error: " << toString(std::move(error));
1406+
return false;
1407+
}
14051408
return true;
14061409
}
14071410
}
@@ -1418,7 +1421,11 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
14181421
ExpressionVariableSP expression_var_sp =
14191422
StopInfo::GetExpressionVariable(stop_info_sp);
14201423
if (expression_var_sp && expression_var_sp->GetValueObject()) {
1421-
expression_var_sp->GetValueObject()->Dump(s);
1424+
if (llvm::Error error =
1425+
expression_var_sp->GetValueObject()->Dump(s)) {
1426+
s << "error: " << toString(std::move(error));
1427+
return false;
1428+
}
14221429
return true;
14231430
}
14241431
}

lldb/source/Core/ValueObject.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,11 +2713,14 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(
27132713
}
27142714
}
27152715

2716-
void ValueObject::Dump(Stream &s) { Dump(s, DumpValueObjectOptions(*this)); }
2716+
llvm::Error ValueObject::Dump(Stream &s) {
2717+
return Dump(s, DumpValueObjectOptions(*this));
2718+
}
27172719

2718-
void ValueObject::Dump(Stream &s, const DumpValueObjectOptions &options) {
2720+
llvm::Error ValueObject::Dump(Stream &s,
2721+
const DumpValueObjectOptions &options) {
27192722
ValueObjectPrinter printer(*this, &s, options);
2720-
printer.PrintValueObject();
2723+
return printer.PrintValueObject();
27212724
}
27222725

27232726
ValueObjectSP ValueObject::CreateConstantValue(ConstString name) {

lldb/source/DataFormatters/ValueObjectPrinter.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@ void ValueObjectPrinter::Init(
6969
SetupMostSpecializedValue();
7070
}
7171

72-
bool ValueObjectPrinter::PrintValueObject() {
72+
llvm::Error ValueObjectPrinter::PrintValueObject() {
7373
// If the incoming ValueObject is in an error state, the best we're going to
7474
// get out of it is its type. But if we don't even have that, just print
7575
// the error and exit early.
7676
if (m_orig_valobj.GetError().Fail() &&
77-
!m_orig_valobj.GetCompilerType().IsValid()) {
78-
m_stream->Printf("Error: '%s'", m_orig_valobj.GetError().AsCString());
79-
return true;
80-
}
77+
!m_orig_valobj.GetCompilerType().IsValid())
78+
return m_orig_valobj.GetError().ToError();
8179

8280
if (ShouldPrintValueObject()) {
8381
PrintLocationIfNeeded();
@@ -97,7 +95,7 @@ bool ValueObjectPrinter::PrintValueObject() {
9795
else
9896
m_stream->EOL();
9997

100-
return true;
98+
return llvm::Error::success();
10199
}
102100

103101
ValueObject &ValueObjectPrinter::GetMostSpecializedValue() {
@@ -619,7 +617,13 @@ void ValueObjectPrinter::PrintChild(
619617
ValueObjectPrinter child_printer(*(child_sp.get()), m_stream, child_options,
620618
ptr_depth, m_curr_depth + 1,
621619
m_printed_instance_pointers);
622-
child_printer.PrintValueObject();
620+
llvm::Error error = child_printer.PrintValueObject();
621+
if (error) {
622+
if (m_stream)
623+
*m_stream << "error: " << toString(std::move(error));
624+
else
625+
llvm::consumeError(std::move(error));
626+
}
623627
}
624628
}
625629

lldb/source/Plugins/REPL/Clang/ClangREPL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ bool ClangREPL::PrintOneVariable(Debugger &debugger,
9595
if (m_implicit_expr_result_regex.Execute(var->GetName().GetStringRef()))
9696
return true;
9797
}
98-
valobj_sp->Dump(*output_sp);
98+
if (llvm::Error error = valobj_sp->Dump(*output_sp))
99+
*output_sp << "error: " << toString(std::move(error));
100+
99101
return true;
100102
}
101103

lldb/test/API/commands/dwim-print/TestDWIMPrint.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_nested_values(self):
122122
"""Test dwim-print with nested values (structs, etc)."""
123123
self.build()
124124
lldbutil.run_to_source_breakpoint(
125-
self, "// break here", lldb.SBFileSpec("main.c")
125+
self, "break here", lldb.SBFileSpec("main.c")
126126
)
127127
self.runCmd("settings set auto-one-line-summaries false")
128128
self._expect_cmd(f"dwim-print s", "frame variable")
@@ -132,7 +132,7 @@ def test_summary_strings(self):
132132
"""Test dwim-print with nested values (structs, etc)."""
133133
self.build()
134134
lldbutil.run_to_source_breakpoint(
135-
self, "// break here", lldb.SBFileSpec("main.c")
135+
self, "break here", lldb.SBFileSpec("main.c")
136136
)
137137
self.runCmd("settings set auto-one-line-summaries false")
138138
self.runCmd("type summary add -e -s 'stub summary' Structure")
@@ -143,18 +143,26 @@ def test_void_result(self):
143143
"""Test dwim-print does not surface an error message for void expressions."""
144144
self.build()
145145
lldbutil.run_to_source_breakpoint(
146-
self, "// break here", lldb.SBFileSpec("main.c")
146+
self, "break here", lldb.SBFileSpec("main.c")
147147
)
148148
self.expect("dwim-print (void)15", matching=False, patterns=["(?i)error"])
149149

150150
def test_preserves_persistent_variables(self):
151151
"""Test dwim-print does not delete persistent variables."""
152152
self.build()
153153
lldbutil.run_to_source_breakpoint(
154-
self, "// break here", lldb.SBFileSpec("main.c")
154+
self, "break here", lldb.SBFileSpec("main.c")
155155
)
156156
self.expect("dwim-print int $i = 15")
157157
# Run the same expression twice and verify success. This ensures the
158158
# first command does not delete the persistent variable.
159159
for _ in range(2):
160160
self.expect("dwim-print $i", startstr="(int) 15")
161+
162+
def test_missing_type(self):
163+
"""The expected output of po opaque is its address (no error)"""
164+
self.build()
165+
lldbutil.run_to_source_breakpoint(
166+
self, "break here", lldb.SBFileSpec("main.c")
167+
)
168+
self.expect("dwim-print -O -- opaque", substrs=['0x'])

lldb/test/API/commands/dwim-print/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ struct Structure {
22
int number;
33
};
44

5+
struct Opaque;
6+
int puts(const char *s);
7+
58
int main(int argc, char **argv) {
69
struct Structure s;
710
s.number = 30;
8-
// break here
11+
struct Opaque *opaque = &s;
12+
puts("break here");
913
return 0;
1014
}

lldb/test/Shell/SymbolFile/DWARF/x86/class-type-nullptr-deref.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# RUN: llvm-mc --triple x86_64-pc-linux %s --filetype=obj -o %t
55
# RUN: %lldb %t -o "target variable x" -o exit 2>&1 | FileCheck %s
66

7-
# CHECK: 'Unable to determine byte size.'
7+
# CHECK: Unable to determine byte size.
88

99
# This tests a fix for a crash. If things are working we don't get a segfault.
1010

lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-signature-loop.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# RUN: ld.lld %t.o -o %t
55
# RUN: %lldb %t -o "target variable e" -b | FileCheck %s
66

7-
# CHECK: Error: 'Unable to determine byte size.'
7+
# CHECK: error: Unable to determine byte size.
88

99
.type e,@object # @e
1010
.section .rodata,"a",@progbits

lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ class ValueObjectMockProcessTest : public ::testing::Test {
9898
ExecutionContextScope *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
9999
for (auto [value, options, expected] : tests) {
100100
DataExtractor data_extractor{&value, sizeof(value), endian, 4};
101-
ValueObjectConstResult::Create(exe_scope, enum_type, var_name,
102-
data_extractor)
103-
->Dump(strm, options);
101+
auto valobj_sp = ValueObjectConstResult::Create(exe_scope, enum_type,
102+
var_name, data_extractor);
103+
if (llvm::Error error = valobj_sp->Dump(strm, options))
104+
llvm::consumeError(std::move(error));
104105
ASSERT_STREQ(strm.GetString().str().c_str(), expected);
105106
strm.Clear();
106107
}

0 commit comments

Comments
 (0)