Skip to content

Commit 8fed7dc

Browse files
committed
Adapt Swift plugin for upstream API changes
1 parent ce80043 commit 8fed7dc

File tree

7 files changed

+54
-35
lines changed

7 files changed

+54
-35
lines changed

lldb/source/Expression/REPL.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,25 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
407407
[[fallthrough]];
408408
case lldb::eExpressionDiscarded:
409409
// FIXME: BEGIN SWIFT
410-
if (error.Success() && result_valobj_sp)
411-
error_sp->Printf("%s\n",
412-
result_valobj_sp->GetError().AsCString());
413-
else
414-
// END SWIFT
415-
error_sp->Printf("%s\n", error.AsCString());
410+
if (error.Success() && result_valobj_sp) {
411+
// The color detection in RenderDiagnosticDetails doesn't work
412+
// with error_sp.
413+
StreamString diag_stream(useColors);
414+
std::vector<DiagnosticDetail> diags;
415+
llvm::Error error = result_valobj_sp->GetError().ToError();
416+
error = llvm::handleErrors(
417+
std::move(error),
418+
[&](DiagnosticError &error) { diags = error.GetDetails(); });
419+
// FIXME: Only correct for the first 999 lines.
420+
unsigned prompt_len =
421+
llvm::StringRef(io_handler.GetPrompt()).size() + 3;
422+
RenderDiagnosticDetails(diag_stream, prompt_len, true, diags);
423+
*error_sp << diag_stream.GetString();
424+
if (error)
425+
*error_sp << toString(std::move(error));
426+
} else
427+
// END SWIFT
428+
error_sp->Printf("%s\n", error.AsCString());
416429
break;
417430

418431
case lldb::eExpressionCompleted:

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "lldb/Symbol/VariableList.h"
4343
#include "lldb/Target/RegisterContext.h"
4444
#include "lldb/Target/UnwindLLDB.h"
45+
#include "lldb/Utility/ErrorMessages.h"
4546
#include "lldb/Utility/LLDBLog.h"
4647
#include "lldb/Utility/Log.h"
4748
#include "lldb/Utility/OptionParsing.h"
@@ -1068,30 +1069,21 @@ llvm::Error SwiftLanguageRuntimeImpl::RunObjectDescriptionExpr(
10681069
frame_sp.get(),
10691070
result_sp, eval_options);
10701071

1071-
if (log) {
1072-
const char *eval_result_str = ExpressionResultAsCString(eval_result);
1073-
log->Printf("[RunObjectDescriptionExpr] %s", eval_result_str);
1074-
}
1072+
LLDB_LOG(log, "[RunObjectDescriptionExpr] {0}", toString(eval_result));
10751073

10761074
// Sanity check the result of the expression before moving forward
10771075
if (!result_sp) {
1078-
if (log)
1079-
log->Printf(
1080-
"[RunObjectDescriptionExpr] expression generated no result");
1081-
1076+
LLDB_LOG(log, "[RunObjectDescriptionExpr] expression generated no result");
10821077
return llvm::createStringError("expression produced no result");
10831078
}
10841079
if (result_sp->GetError().Fail()) {
1085-
if (log)
1086-
log->Printf(
1087-
"[RunObjectDescriptionExpr] expression generated error: %s",
1088-
result_sp->GetError().AsCString());
1080+
LLDB_LOG(log, "[RunObjectDescriptionExpr] expression generated error: {0}",
1081+
result_sp->GetError().AsCString());
10891082

10901083
return result_sp->GetError().ToError();
10911084
}
10921085
if (!result_sp->GetCompilerType().IsValid()) {
1093-
if (log)
1094-
log->Printf("[RunObjectDescriptionExpr] expression generated "
1086+
LLDB_LOG(log, "[RunObjectDescriptionExpr] expression generated "
10951087
"invalid type");
10961088

10971089
return llvm::createStringError("expression produced invalid result type");
@@ -1107,14 +1099,13 @@ llvm::Error SwiftLanguageRuntimeImpl::RunObjectDescriptionExpr(
11071099
.SetLanguage(lldb::eLanguageTypeSwift)
11081100
.SetCapping(eTypeSummaryUncapped),
11091101
dump_options)) {
1110-
if (log)
1111-
log->Printf("[RunObjectDescriptionExpr] expression completed "
1112-
"successfully");
1102+
LLDB_LOG(log,
1103+
"[RunObjectDescriptionExpr] expression completed successfully");
11131104
return llvm::Error::success();
11141105
}
1115-
if (log)
1116-
log->Printf("[RunObjectDescriptionExpr] expression generated "
1117-
"invalid string data");
1106+
LLDB_LOG(
1107+
log,
1108+
"[RunObjectDescriptionExpr] expression generated invalid string data");
11181109

11191110
return llvm::createStringError("expression produced unprintable string");
11201111
}

lldb/source/Plugins/TypeSystem/Swift/StoringDiagnosticConsumer.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,20 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
149149
}
150150
return;
151151
}
152-
// FIXME: extract this from ranges!
153-
uint16_t len = 0;
152+
// FXIME: This is a heuristic.
153+
uint16_t len = info.Ranges.size() ? info.Ranges.front().getByteLength() : 0;
154154
bool in_user_input = false;
155155
// FIXME: improve this!
156-
if (buffer_name == "<REPL>" || buffer_name.starts_with("<user expression"))
156+
if (buffer_name == "<REPL>" || buffer_name == "<EXPR>" ||
157+
buffer_name == "repl.swift" ||
158+
buffer_name.starts_with("<user expression"))
157159
in_user_input = true;
158-
DiagnosticDetail::SourceLocation loc = {
159-
FileSpec{buffer_name.str()}, line_col.first, (uint16_t)line_col.second,
160-
len, in_user_input};
160+
DiagnosticDetail::SourceLocation loc = {FileSpec{buffer_name.str()},
161+
line_col.first,
162+
(uint16_t)line_col.second,
163+
len,
164+
!in_user_input,
165+
in_user_input};
161166
DiagnosticDetail detail = {loc, severity, raw_text, formatted_text};
162167
RawDiagnostic diagnostic(
163168
detail, buffer_id,

lldb/test/API/lang/swift/foundation_value_types/notification/TestSwiftFoundationTypeNotification.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def test(self):
1414
self.build()
1515
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
1616
self, 'break here', lldb.SBFileSpec('main.swift'))
17-
self.expect("log enable lldb types -v")
1817
# global
1918
self.expect("target variable -d run g_notification",
2019
substrs=['name = ', '"MyNotification"',
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# REQUIRES: swift
2+
# RUN: rm -rf %t && mkdir %t && cd %t
3+
# RUN: %target-swiftc -g %S/Inputs/Global.swift
4+
# RUN: %lldb Global -s %s | FileCheck --strict-whitespace %s
5+
6+
b main
7+
run
8+
expr foo+bar
9+
# (lldb) expr foo+bar
10+
# CHECK: ^~~ ^~~
11+
# CHECK: | error: cannot find 'bar' in scope
12+
# CHECK: error: cannot find 'foo' in scope

lldb/test/Shell/SwiftREPL/LookupWithAttributedImport.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let y = Bar(baz: 123)
1515
// CHECK: baz = 123
1616

1717
let x = Foo(bar:42)
18-
// CHECK: repl.swift:{{.*}}: cannot find 'Foo' in scope
18+
// CHECK: error: cannot find 'Foo' in scope
1919

2020
@testable import Test
2121

lldb/test/Shell/SwiftREPL/PropertyWrapperTopLevel.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@
3535
@A var anA: Int = 1
3636

3737
// CHECK: property wrappers are not yet supported in top-level code
38-
// CHECK-NEXT: @A var anA: Int = 1

0 commit comments

Comments
 (0)