Skip to content

Commit c47b992

Browse files
authored
Merge pull request #492 from adrian-prantl/master-cherry-picks
Cherry-pick changes on swift/master but not on swift/swift-5.2-branch
2 parents 4be640f + dc9bd48 commit c47b992

File tree

14 files changed

+215
-57
lines changed

14 files changed

+215
-57
lines changed

lldb/include/lldb/Host/Editline.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define liblldb_Editline_h_
3333
#if defined(__cplusplus)
3434

35+
#include "lldb/Host/Config.h"
36+
3537
#if LLDB_EDITLINE_USE_WCHAR
3638
#include <codecvt>
3739
#endif

lldb/lit/Swift/No.swiftmodule-ObjC.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# RUN: %target-swiftc -o %t/a.out %t/main.o %t/ObjCStuff.o
1212
# RUN: %lldb %t/a.out -s %s | FileCheck %S/Inputs/No.swiftmodule-ObjC.swift
1313

14-
settings set symbols.use-swift-dwarfimporter true
1514
breakpoint set -p "break here"
1615
run
1716
frame variable -d no-dynamic
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Test unicode handling in LLDB.
4+
"""
5+
6+
import os
7+
8+
import lldb
9+
from lldbsuite.test.decorators import *
10+
from lldbsuite.test.lldbtest import *
11+
from lldbsuite.test.lldbpexpect import PExpectTest
12+
13+
class TestCase(PExpectTest):
14+
15+
mydir = TestBase.compute_mydir(__file__)
16+
17+
# PExpect uses many timeouts internally and doesn't play well
18+
# under ASAN on a loaded machine..
19+
@skipIfAsan
20+
def test_unicode_input(self):
21+
self.launch()
22+
23+
# Send some unicode input to LLDB.
24+
# We should get back that this is an invalid command with our character as UTF-8.
25+
self.expect(u'\u1234', substrs=[u"error: '\u1234' is not a valid command.".encode('utf-8')])
26+
27+
self.quit()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS = -I$(SRCDIR)
3+
4+
include Makefile.rules
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import os
6+
import unittest2
7+
8+
9+
class TestSwiftAnyType(lldbtest.TestBase):
10+
11+
mydir = lldbtest.TestBase.compute_mydir(__file__)
12+
13+
@swiftTest
14+
def test_c_unions(self):
15+
self.build()
16+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
17+
self, 'break here', lldb.SBFileSpec('main.swift'))
18+
self.expect("target variable -- i", substrs=['42'])
19+
self.expect("target variable -- d", substrs=['23'])
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import U
2+
3+
func use<T>(_ t : T) {}
4+
5+
let i = IntDoubleUnion(i: 42)
6+
let d = IntDoubleUnion(d: 23)
7+
use((i, d)) // break here
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module U { header "union.h" }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
union IntDoubleUnion {
2+
int i;
3+
double d;
4+
};

lldb/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/TestSwiftDWARFImporterC.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,56 @@ def test_dwarf_importer(self):
5151
lldbutil.check_variable(self,
5252
target.FindFirstGlobalVariable("point"),
5353
typename='__ObjC.Point', num_children=2)
54-
self.expect("ta v point", substrs=["x = 1", "y = 2"])
55-
self.expect("ta v enumerator", substrs=[".yellow"])
56-
self.expect("ta v pureSwiftStruct", substrs=["pure swift"])
57-
self.expect("ta v swiftStructCMember",
54+
self.expect("target variable point", substrs=["x = 1", "y = 2"])
55+
self.expect("target variable enumerator", substrs=[".yellow"])
56+
self.expect("target variable pureSwiftStruct", substrs=["pure swift"])
57+
self.expect("target variable swiftStructCMember",
5858
substrs=["point", "x = 3", "y = 4",
5959
"sub", "x = 1", "y = 2", "z = 3",
6060
"swift struct c member"])
61-
self.expect("ta v typedef", substrs=["x = 5", "y = 6"])
62-
self.expect("ta v union", substrs=["(DoubleLongUnion)", "long_val = 42"])
63-
self.expect("ta v fromSubmodule",
61+
self.expect("target variable typedef", substrs=["x = 5", "y = 6"])
62+
self.expect("target variable union",
63+
substrs=["(DoubleLongUnion)", "long_val = 42"])
64+
self.expect("target variable fromSubmodule",
6465
substrs=["(FromSubmodule)", "x = 1", "y = 2", "z = 3"])
6566
process.Clear()
6667
target.Clear()
6768
lldb.SBDebugger.MemoryPressureDetected()
6869

70+
@skipIf(archs=['ppc64le'], bugnumber='SR-10214')
71+
@swiftTest
72+
# This test needs a working Remote Mirrors implementation.
73+
@skipIf(oslist=['linux', 'windows'])
74+
def test_dwarf_importer_exprs(self):
75+
lldb.SBDebugger.MemoryPressureDetected()
76+
self.runCmd("settings set symbols.use-swift-dwarfimporter true")
77+
self.build()
78+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
79+
self, 'break here', lldb.SBFileSpec('main.swift'))
80+
lldbutil.check_variable(self,
81+
target.FindFirstGlobalVariable("pureSwift"),
82+
value="42")
83+
lldbutil.check_variable(self,
84+
target.FindFirstGlobalVariable("point"),
85+
typename='__ObjC.Point', num_children=2)
86+
self.expect("expr point", substrs=["x = 1", "y = 2"])
87+
self.expect("expr enumerator", substrs=[".yellow"])
88+
self.expect("expr pureSwiftStruct", substrs=["pure swift"])
89+
self.expect("expr swiftStructCMember",
90+
substrs=["point", "x = 3", "y = 4",
91+
"sub", "x = 1", "y = 2", "z = 3",
92+
"swift struct c member"])
93+
self.expect("expr typedef", substrs=["x = 5", "y = 6"])
94+
# FIXME: lookup fails for:
95+
# a.union.unsafeMutableAddressor : __C.DoubleLongUnion
96+
self.expect("expr union", error=True)
97+
#self.expect("expr union", substrs=["(DoubleLongUnion)", "long_val = 42"])
98+
self.expect("expr fromSubmodule",
99+
substrs=["(FromSubmodule)", "x = 1", "y = 2", "z = 3"])
100+
process.Clear()
101+
target.Clear()
102+
lldb.SBDebugger.MemoryPressureDetected()
103+
69104
@skipIf(archs=['ppc64le'], bugnumber='SR-10214')
70105
@swiftTest
71106
def test_negative(self):
@@ -81,7 +116,7 @@ def test_negative(self):
81116
target.FindFirstGlobalVariable("point"),
82117
typename="Point", num_children=2)
83118
# This works as a Clang type.
84-
self.expect("ta v point", substrs=["x = 1", "y = 2"])
119+
self.expect("target variable point", substrs=["x = 1", "y = 2"])
85120
# This can't be resolved.
86121
lldbutil.check_variable(self,
87122
target.FindFirstGlobalVariable("swiftStructCMember"),
@@ -97,4 +132,3 @@ def test_negative(self):
97132
process.Clear()
98133
target.Clear()
99134
lldb.SBDebugger.MemoryPressureDetected()
100-
self.runCmd("settings set symbols.use-swift-dwarfimporter true")

lldb/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/Objective-C/TestSwiftDWARFImporterObjC.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def build(self):
3737

3838
@skipUnlessDarwin
3939
@swiftTest
40-
def test_dwarf_importer(self):
40+
def test(self):
4141
self.runCmd("settings set symbols.use-swift-dwarfimporter true")
4242

4343
self.build()
@@ -52,12 +52,32 @@ def test_dwarf_importer(self):
5252
num_children=0)
5353
self.expect("target var obj", substrs=["ObjCClass",
5454
"private_ivar", "42"])
55-
# FIXME: This triggers an assertion in ClangImporter:
56-
# "ObjC property without getter"
57-
#self.expect("target var swiftChild", substrs=["ObjCClass",
58-
# "private_ivar", "42"])
55+
56+
self.expect("target var swiftChild", substrs=["ObjCClass",
57+
"private_ivar", "42"])
5958
# This is a Clang type, since Clang doesn't generate DWARF for protocols.
6059
self.expect("target var -d no-dyn proto", substrs=["(id)", "proto"])
6160
# This is a Swift type.
6261
self.expect("target var -d run proto", substrs=["(ProtoImpl)", "proto"])
6362
self.expect("target var -O proto", substrs=["<ProtoImpl"])
63+
64+
@skipUnlessDarwin
65+
@swiftTest
66+
def test_expr(self):
67+
self.runCmd("settings set symbols.use-swift-dwarfimporter true")
68+
69+
self.build()
70+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
71+
self, 'break here', lldb.SBFileSpec('main.swift'))
72+
lldbutil.check_variable(self,
73+
target.FindFirstGlobalVariable("pureSwift"),
74+
value="42")
75+
lldbutil.check_variable(self,
76+
target.FindFirstGlobalVariable("obj"),
77+
typename="Swift.Optional<__ObjC.ObjCClass>",
78+
num_children=0)
79+
self.expect("expr obj", substrs=["ObjCClass",
80+
"private_ivar", "42"])
81+
# FIXME: Removing this makes the expression below fail!
82+
self.expect("target var swiftChild")
83+
self.expect("expr swiftChild!.number", substrs=["42"])

lldb/packages/Python/lldbsuite/test/lang/swift/variables/objc_optionals/TestSwiftObjCOptionals.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ def do_check_visuals(self):
5656
def do_check_api(self):
5757
"""Check formatting for T? and T! when T is an ObjC type"""
5858
optColor_Some = self.frame().FindVariable("optColor_Some")
59+
60+
# SwiftOptionalSyntheticFrontEnd passes GetNumChildren
61+
# through to the .some object. NSColor has no children.
5962
lldbutil.check_variable(
6063
self,
6164
optColor_Some,
6265
use_dynamic=False,
63-
num_children=1)
66+
num_children=0)
6467
uoptColor_Some = self.frame().FindVariable("uoptColor_Some")
6568
lldbutil.check_variable(
6669
self,
6770
uoptColor_Some,
6871
use_dynamic=False,
69-
num_children=1)
72+
num_children=0)
7073

7174
if __name__ == '__main__':
7275
import atexit

lldb/source/Core/CoreProperties.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let Definition = "modulelist" in {
1010
DefaultStringValue<"">,
1111
Desc<"The path to the clang modules cache directory (-fmodules-cache-path).">;
1212
def UseDWARFImporter: Property<"use-swift-dwarfimporter", "Boolean">,
13-
DefaultFalse,
13+
DefaultTrue,
1414
Desc<"Reconstruct Clang module dependencies from DWARF when debugging Swift code">;
1515
def SwiftModuleLoadingMode: Property<"swift-module-loading-mode", "Enum">,
1616
DefaultEnumValue<"eSwiftModuleLoadingModePreferSerialized">,

lldb/source/Plugins/Language/Swift/SwiftOptionSet.cpp

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,39 @@ using namespace lldb_private;
2828
using namespace lldb_private::formatters;
2929
using namespace lldb_private::formatters::swift;
3030

31-
bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
32-
WouldEvenConsiderFormatting(CompilerType clang_type) {
31+
/// If this is a Clang enum wrapped in a Swift type, return the clang::EnumDecl.
32+
static clang::EnumDecl *GetAsEnumDecl(CompilerType swift_type) {
33+
if (!swift_type)
34+
return nullptr;
35+
3336
SwiftASTContext *swift_ast_ctx =
34-
llvm::dyn_cast_or_null<SwiftASTContext>(clang_type.GetTypeSystem());
37+
llvm::dyn_cast_or_null<SwiftASTContext>(swift_type.GetTypeSystem());
3538
if (!swift_ast_ctx)
36-
return false;
39+
return nullptr;
40+
41+
CompilerType clang_type;
42+
if (!swift_ast_ctx->IsImportedType(swift_type, &clang_type))
43+
return nullptr;
44+
45+
if (!clang_type.IsValid())
46+
return nullptr;
47+
48+
if (!llvm::isa<ClangASTContext>(clang_type.GetTypeSystem()))
49+
return nullptr;
50+
51+
auto qual_type =
52+
clang::QualType::getFromOpaquePtr(clang_type.GetOpaqueQualType());
53+
if (qual_type->getTypeClass() != clang::Type::TypeClass::Enum)
54+
return nullptr;
55+
56+
if (const clang::EnumType *enum_type = qual_type->getAs<clang::EnumType>())
57+
return enum_type->getDecl();
58+
return nullptr;
59+
}
3760

38-
return clang_type.IsValid() &&
39-
swift_ast_ctx->IsImportedType(clang_type, nullptr);
61+
bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
62+
WouldEvenConsiderFormatting(CompilerType swift_type) {
63+
return GetAsEnumDecl(swift_type);
4064
}
4165

4266
lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
@@ -56,55 +80,27 @@ static ConstString GetDisplayCaseName(::swift::ClangImporter *clang_importer,
5680
return ConstString(case_decl->getName());
5781
}
5882

59-
static clang::EnumDecl *GetAsEnumDecl(const CompilerType &compiler_type) {
60-
if (compiler_type.IsValid() &&
61-
llvm::dyn_cast_or_null<ClangASTContext>(compiler_type.GetTypeSystem())) {
62-
opaque_compiler_type_t clang_type = compiler_type.GetOpaqueQualType();
63-
clang::QualType qual_type = clang::QualType::getFromOpaquePtr(clang_type);
64-
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
65-
switch (type_class) {
66-
case clang::Type::TypeClass::Enum: {
67-
if (const clang::EnumType *enum_type =
68-
qual_type->getAs<clang::EnumType>())
69-
return enum_type->getDecl();
70-
break;
71-
}
72-
default:
73-
break;
74-
}
75-
}
76-
77-
return nullptr;
78-
}
79-
8083
void lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
8184
FillCasesIfNeeded() {
8285
if (m_cases.hasValue())
8386
return;
8487

8588
m_cases = CasesVector();
86-
SwiftASTContext *swift_ast_ctx =
87-
llvm::dyn_cast_or_null<SwiftASTContext>(m_type.GetTypeSystem());
88-
89-
if (!swift_ast_ctx)
90-
return;
91-
CompilerType original_type;
92-
if (!swift_ast_ctx->IsImportedType(m_type, &original_type))
93-
return;
94-
clang::EnumDecl *enum_decl = GetAsEnumDecl(original_type);
89+
clang::EnumDecl *enum_decl = GetAsEnumDecl(m_type);
9590
if (!enum_decl)
9691
return;
9792

93+
SwiftASTContext *swift_ast_ctx =
94+
llvm::dyn_cast_or_null<SwiftASTContext>(m_type.GetTypeSystem());
9895
::swift::ClangImporter *clang_importer = swift_ast_ctx->GetClangImporter();
9996
auto iter = enum_decl->enumerator_begin(), end = enum_decl->enumerator_end();
10097
for (; iter != end; ++iter) {
10198
clang::EnumConstantDecl *case_decl = *iter;
10299
if (case_decl) {
103100
llvm::APInt case_init_val(case_decl->getInitVal());
104-
// extend all cases to 64 bits so that equality check is fast
101+
// Extend all cases to 64 bits so that equality check is fast
105102
// but if they are larger than 64, I am going to get out of that
106-
// case
107-
// and then pick it up again as unmatched data at the end
103+
// case and then pick it up again as unmatched data at the end.
108104
if (case_init_val.getBitWidth() < 64)
109105
case_init_val = case_init_val.zext(64);
110106
if (case_init_val.getBitWidth() > 64)

0 commit comments

Comments
 (0)