Skip to content

Commit 2d53850

Browse files
author
git apple-llvm automerger
committed
Merge commit '5b37bd4c1c57' from swift/release/6.0 into stable/20230725
2 parents 897d03a + 5b37bd4 commit 2d53850

37 files changed

+420
-294
lines changed

lldb/include/lldb/Core/ValueObject.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class ValueObject {
522522
std::string &destination,
523523
const TypeSummaryOptions &options);
524524

525-
const char *GetObjectDescription();
525+
llvm::Expected<std::string> GetObjectDescription();
526526

527527
bool HasSpecialPrintableRepresentation(
528528
ValueObjectRepresentationStyle val_obj_display,
@@ -657,9 +657,9 @@ class ValueObject {
657657

658658
virtual SymbolContextScope *GetSymbolContextScope();
659659

660-
void Dump(Stream &s);
660+
llvm::Error Dump(Stream &s);
661661

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

664664
static lldb::ValueObjectSP
665665
CreateValueObjectFromExpression(llvm::StringRef name,

lldb/include/lldb/DataFormatters/ValueObjectPrinter.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ValueObjectPrinter {
3434

3535
~ValueObjectPrinter() = default;
3636

37-
bool PrintValueObject();
37+
llvm::Error PrintValueObject();
3838

3939
protected:
4040
typedef std::set<uint64_t> InstancePointersSet;
@@ -76,7 +76,7 @@ class ValueObjectPrinter {
7676

7777
void SetupMostSpecializedValue();
7878

79-
const char *GetDescriptionForDisplay();
79+
llvm::Expected<std::string> GetDescriptionForDisplay();
8080

8181
const char *GetRootNameForDisplay();
8282

@@ -109,7 +109,8 @@ class ValueObjectPrinter {
109109

110110
bool PrintValueAndSummaryIfNeeded(bool &value_printed, bool &summary_printed);
111111

112-
bool PrintObjectDescriptionIfNeeded(bool value_printed, bool summary_printed);
112+
llvm::Error PrintObjectDescriptionIfNeeded(bool value_printed,
113+
bool summary_printed);
113114

114115
bool
115116
ShouldPrintChildren(DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
@@ -133,7 +134,7 @@ class ValueObjectPrinter {
133134
PrintChildren(bool value_printed, bool summary_printed,
134135
const DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
135136

136-
void PrintChildrenIfNeeded(bool value_printed, bool summary_printed);
137+
llvm::Error PrintChildrenIfNeeded(bool value_printed, bool summary_printed);
137138

138139
bool PrintChildrenOneLiner(bool hide_names);
139140

lldb/include/lldb/Target/LanguageRuntime.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ class LanguageRuntime : public Runtime, public PluginInterface {
7474
return nullptr;
7575
}
7676

77-
virtual bool GetObjectDescription(Stream &str, ValueObject &object) = 0;
78-
79-
virtual bool GetObjectDescription(Stream &str, Value &value,
80-
ExecutionContextScope *exe_scope) = 0;
77+
virtual llvm::Error GetObjectDescription(Stream &str,
78+
ValueObject &object) = 0;
8179

80+
virtual llvm::Error
81+
GetObjectDescription(Stream &str, Value &value,
82+
ExecutionContextScope *exe_scope) = 0;
8283

8384
struct VTableInfo {
8485
Address addr; /// Address of the vtable's virtual function table
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- ErrorMessages.h -----------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_UTILITY_ERROR_MESSAGES_H
10+
#define LLDB_UTILITY_ERROR_MESSAGES_H
11+
12+
#include "lldb/lldb-defines.h"
13+
#include "lldb/lldb-enumerations.h"
14+
#include <string>
15+
16+
namespace lldb_private {
17+
18+
/// Produce a human-readable rendition of an ExpressionResults value.
19+
std::string toString(lldb::ExpressionResults e);
20+
21+
} // namespace lldb_private
22+
#endif

lldb/source/API/SBValue.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,10 @@ const char *SBValue::GetObjectDescription() {
379379
if (!value_sp)
380380
return nullptr;
381381

382-
return ConstString(value_sp->GetObjectDescription()).GetCString();
382+
llvm::Expected<std::string> str = value_sp->GetObjectDescription();
383+
if (!str)
384+
return ConstString("error: " + toString(str.takeError())).AsCString();
385+
return ConstString(*str).AsCString();
383386
}
384387

385388
SBType SBValue::GetType() {
@@ -1210,11 +1213,14 @@ bool SBValue::GetDescription(SBStream &description) {
12101213

12111214
ValueLocker locker;
12121215
lldb::ValueObjectSP value_sp(GetSP(locker));
1213-
if (value_sp)
1214-
value_sp->Dump(strm);
1215-
else
1216+
if (value_sp) {
1217+
if (llvm::Error error = value_sp->Dump(strm)) {
1218+
strm << "error: " << toString(std::move(error));
1219+
return false;
1220+
}
1221+
} else {
12161222
strm.PutCString("No value");
1217-
1223+
}
12181224
return true;
12191225
}
12201226

lldb/source/Breakpoint/Watchpoint.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char *prefix) const {
301301
.SetHideRootType(true)
302302
.SetHideRootName(true)
303303
.SetHideName(true);
304-
m_old_value_sp->Dump(strm, options);
304+
if (llvm::Error error = m_old_value_sp->Dump(strm, options))
305+
strm << "error: " << toString(std::move(error));
306+
305307
if (strm.GetData())
306308
values_ss.Printf("old value: %s", strm.GetData());
307309
}
@@ -324,7 +326,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char *prefix) const {
324326
.SetHideRootType(true)
325327
.SetHideRootName(true)
326328
.SetHideName(true);
327-
m_new_value_sp->Dump(strm, options);
329+
if (llvm::Error error = m_new_value_sp->Dump(strm, options))
330+
strm << "error: " << toString(std::move(error));
331+
328332
if (strm.GetData())
329333
values_ss.Printf("new value: %s", strm.GetData());
330334
}

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,28 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
138138
}
139139
};
140140

141+
// Dump `valobj` according to whether `po` was requested or not.
142+
auto dump_val_object = [&](ValueObject &valobj) {
143+
if (is_po) {
144+
StreamString temp_result_stream;
145+
if (llvm::Error error = valobj.Dump(temp_result_stream, dump_options)) {
146+
result.AppendError(toString(std::move(error)));
147+
return;
148+
}
149+
llvm::StringRef output = temp_result_stream.GetString();
150+
maybe_add_hint(output);
151+
result.GetOutputStream() << output;
152+
} else {
153+
llvm::Error error =
154+
valobj.Dump(result.GetOutputStream(), dump_options);
155+
if (error) {
156+
result.AppendError(toString(std::move(error)));
157+
return;
158+
}
159+
}
160+
result.SetStatus(eReturnStatusSuccessFinishResult);
161+
};
162+
141163
// First, try `expr` as the name of a frame variable.
142164
if (frame) {
143165
auto valobj_sp = frame->FindVariable(ConstString(expr));
@@ -155,16 +177,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
155177
flags, expr);
156178
}
157179

158-
if (is_po) {
159-
StreamString temp_result_stream;
160-
valobj_sp->Dump(temp_result_stream, dump_options);
161-
llvm::StringRef output = temp_result_stream.GetString();
162-
maybe_add_hint(output);
163-
result.GetOutputStream() << output;
164-
} else {
165-
valobj_sp->Dump(result.GetOutputStream(), dump_options);
166-
}
167-
result.SetStatus(eReturnStatusSuccessFinishResult);
180+
dump_val_object(*valobj_sp);
168181
return;
169182
}
170183
}
@@ -211,8 +224,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
211224
if (auto *state = target.GetPersistentExpressionStateForLanguage(language))
212225
if (auto var_sp = state->GetVariable(expr))
213226
if (auto valobj_sp = var_sp->GetValueObject()) {
214-
valobj_sp->Dump(result.GetOutputStream(), dump_options);
215-
result.SetStatus(eReturnStatusSuccessFinishResult);
227+
dump_val_object(*valobj_sp);
216228
return;
217229
}
218230

@@ -233,43 +245,36 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
233245
error_stream << " " << fixed_expression << "\n";
234246
}
235247

236-
if (expr_result == eExpressionCompleted) {
237-
if (verbosity != eDWIMPrintVerbosityNone) {
238-
StringRef flags;
239-
if (args.HasArgs())
240-
flags = args.GetArgStringWithDelimiter();
241-
result.AppendMessageWithFormatv("note: ran `expression {0}{1}`", flags,
242-
expr);
243-
}
244-
245-
if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) {
246-
if (is_po) {
247-
StreamString temp_result_stream;
248-
valobj_sp->Dump(temp_result_stream, dump_options);
249-
llvm::StringRef output = temp_result_stream.GetString();
250-
maybe_add_hint(output);
251-
result.GetOutputStream() << output;
252-
} else {
253-
valobj_sp->Dump(result.GetOutputStream(), dump_options);
254-
}
255-
}
256-
257-
if (suppress_result)
258-
if (auto result_var_sp =
259-
target.GetPersistentVariable(valobj_sp->GetName())) {
260-
auto language = valobj_sp->GetPreferredDisplayLanguage();
261-
if (auto *persistent_state =
262-
target.GetPersistentExpressionStateForLanguage(language))
263-
persistent_state->RemovePersistentVariable(result_var_sp);
264-
}
265-
266-
result.SetStatus(eReturnStatusSuccessFinishResult);
267-
} else {
248+
// If the expression failed, return an error.
249+
if (expr_result != eExpressionCompleted) {
268250
if (valobj_sp)
269251
result.SetError(valobj_sp->GetError());
270252
else
271253
result.AppendErrorWithFormatv(
272254
"unknown error evaluating expression `{0}`", expr);
255+
return;
256+
}
257+
258+
if (verbosity != eDWIMPrintVerbosityNone) {
259+
StringRef flags;
260+
if (args.HasArgs())
261+
flags = args.GetArgStringWithDelimiter();
262+
result.AppendMessageWithFormatv("note: ran `expression {0}{1}`", flags,
263+
expr);
273264
}
265+
266+
if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
267+
dump_val_object(*valobj_sp);
268+
else
269+
result.SetStatus(eReturnStatusSuccessFinishResult);
270+
271+
if (suppress_result)
272+
if (auto result_var_sp =
273+
target.GetPersistentVariable(valobj_sp->GetName())) {
274+
auto language = valobj_sp->GetPreferredDisplayLanguage();
275+
if (auto *persistent_state =
276+
target.GetPersistentExpressionStateForLanguage(language))
277+
persistent_state->RemovePersistentVariable(result_var_sp);
278+
}
274279
}
275280
}

lldb/source/Commands/CommandObjectExpression.cpp

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

500-
result_valobj_sp->Dump(output_stream, options);
500+
if (llvm::Error error =
501+
result_valobj_sp->Dump(output_stream, options)) {
502+
result.AppendError(toString(std::move(error)));
503+
return false;
504+
}
501505

502506
if (suppress_result)
503507
if (auto result_var_sp =

lldb/source/Commands/CommandObjectFrame.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ class CommandObjectFrameDiagnose : public CommandObjectParsed {
182182
assert(valobj_sp.get() && "Must have a valid ValueObject to print");
183183
ValueObjectPrinter printer(*valobj_sp, &result.GetOutputStream(),
184184
options);
185-
printer.PrintValueObject();
185+
if (llvm::Error error = printer.PrintValueObject())
186+
result.AppendError(toString(std::move(error)));
186187
}
187188

188189
CommandOptions m_options;
@@ -609,7 +610,9 @@ may even involve JITing and running code in the target program.)");
609610
show_module))
610611
s.PutCString(": ");
611612
}
612-
valobj_sp->Dump(result.GetOutputStream(), options);
613+
auto &strm = result.GetOutputStream();
614+
if (llvm::Error error = valobj_sp->Dump(strm, options))
615+
result.AppendError(toString(std::move(error)));
613616
}
614617
}
615618
} else {
@@ -651,7 +654,8 @@ may even involve JITing and running code in the target program.)");
651654
Stream &output_stream = result.GetOutputStream();
652655
options.SetRootValueObjectName(
653656
valobj_sp->GetParent() ? entry.c_str() : nullptr);
654-
valobj_sp->Dump(output_stream, options);
657+
if (llvm::Error error = valobj_sp->Dump(output_stream, options))
658+
result.AppendError(toString(std::move(error)));
655659
} else {
656660
if (auto error_cstr = error.AsCString(nullptr))
657661
result.AppendError(error_cstr);
@@ -702,7 +706,9 @@ may even involve JITing and running code in the target program.)");
702706
valobj_sp->GetPreferredDisplayLanguage());
703707
options.SetRootValueObjectName(
704708
var_sp ? var_sp->GetName().AsCString() : nullptr);
705-
valobj_sp->Dump(result.GetOutputStream(), options);
709+
if (llvm::Error error =
710+
valobj_sp->Dump(result.GetOutputStream(), options))
711+
result.AppendError(toString(std::move(error)));
706712
}
707713
}
708714
}
@@ -723,7 +729,9 @@ may even involve JITing and running code in the target program.)");
723729
options.SetVariableFormatDisplayLanguage(
724730
rec_value_sp->GetPreferredDisplayLanguage());
725731
options.SetRootValueObjectName(rec_value_sp->GetName().AsCString());
726-
rec_value_sp->Dump(result.GetOutputStream(), options);
732+
if (llvm::Error error =
733+
rec_value_sp->Dump(result.GetOutputStream(), options))
734+
result.AppendError(toString(std::move(error)));
727735
}
728736
}
729737
}

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
@@ -812,7 +812,8 @@ class CommandObjectTargetVariable : public CommandObjectParsed {
812812

813813
options.SetRootValueObjectName(root_name);
814814

815-
valobj_sp->Dump(s, options);
815+
if (llvm::Error error = valobj_sp->Dump(s, options))
816+
s << "error: " << toString(std::move(error));
816817
}
817818

818819
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
@@ -1367,7 +1367,10 @@ class CommandObjectThreadException : public CommandObjectIterateOverThreads {
13671367
Stream &strm = result.GetOutputStream();
13681368
ValueObjectSP exception_object_sp = thread_sp->GetCurrentException();
13691369
if (exception_object_sp) {
1370-
exception_object_sp->Dump(strm);
1370+
if (llvm::Error error = exception_object_sp->Dump(strm)) {
1371+
result.AppendError(toString(std::move(error)));
1372+
return false;
1373+
}
13711374
}
13721375

13731376
ThreadSP exception_thread_sp = thread_sp->GetCurrentExceptionBacktrace();
@@ -1419,9 +1422,12 @@ class CommandObjectThreadSiginfo : public CommandObjectIterateOverThreads {
14191422
return false;
14201423
}
14211424
ValueObjectSP exception_object_sp = thread_sp->GetSiginfoValue();
1422-
if (exception_object_sp)
1423-
exception_object_sp->Dump(strm);
1424-
else
1425+
if (exception_object_sp) {
1426+
if (llvm::Error error = exception_object_sp->Dump(strm)) {
1427+
result.AppendError(toString(std::move(error)));
1428+
return false;
1429+
}
1430+
} else
14251431
strm.Printf("(no siginfo)\n");
14261432
strm.PutChar('\n');
14271433

0 commit comments

Comments
 (0)