Skip to content

Cherry-pick changes on swift/master but not on swift/swift-5.2-branch #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/include/lldb/Host/Editline.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#define liblldb_Editline_h_
#if defined(__cplusplus)

#include "lldb/Host/Config.h"

#if LLDB_EDITLINE_USE_WCHAR
#include <codecvt>
#endif
Expand Down
1 change: 0 additions & 1 deletion lldb/lit/Swift/No.swiftmodule-ObjC.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# RUN: %target-swiftc -o %t/a.out %t/main.o %t/ObjCStuff.o
# RUN: %lldb %t/a.out -s %s | FileCheck %S/Inputs/No.swiftmodule-ObjC.swift

settings set symbols.use-swift-dwarfimporter true
breakpoint set -p "break here"
run
frame variable -d no-dynamic
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
"""
Test unicode handling in LLDB.
"""

import os

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test.lldbpexpect import PExpectTest

class TestCase(PExpectTest):

mydir = TestBase.compute_mydir(__file__)

# PExpect uses many timeouts internally and doesn't play well
# under ASAN on a loaded machine..
@skipIfAsan
def test_unicode_input(self):
self.launch()

# Send some unicode input to LLDB.
# We should get back that this is an invalid command with our character as UTF-8.
self.expect(u'\u1234', substrs=[u"error: '\u1234' is not a valid command.".encode('utf-8')])

self.quit()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS = -I$(SRCDIR)

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil
import os
import unittest2


class TestSwiftAnyType(lldbtest.TestBase):

mydir = lldbtest.TestBase.compute_mydir(__file__)

@swiftTest
def test_c_unions(self):
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'break here', lldb.SBFileSpec('main.swift'))
self.expect("target variable -- i", substrs=['42'])
self.expect("target variable -- d", substrs=['23'])
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import U

func use<T>(_ t : T) {}

let i = IntDoubleUnion(i: 42)
let d = IntDoubleUnion(d: 23)
use((i, d)) // break here
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module U { header "union.h" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
union IntDoubleUnion {
int i;
double d;
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,56 @@ def test_dwarf_importer(self):
lldbutil.check_variable(self,
target.FindFirstGlobalVariable("point"),
typename='__ObjC.Point', num_children=2)
self.expect("ta v point", substrs=["x = 1", "y = 2"])
self.expect("ta v enumerator", substrs=[".yellow"])
self.expect("ta v pureSwiftStruct", substrs=["pure swift"])
self.expect("ta v swiftStructCMember",
self.expect("target variable point", substrs=["x = 1", "y = 2"])
self.expect("target variable enumerator", substrs=[".yellow"])
self.expect("target variable pureSwiftStruct", substrs=["pure swift"])
self.expect("target variable swiftStructCMember",
substrs=["point", "x = 3", "y = 4",
"sub", "x = 1", "y = 2", "z = 3",
"swift struct c member"])
self.expect("ta v typedef", substrs=["x = 5", "y = 6"])
self.expect("ta v union", substrs=["(DoubleLongUnion)", "long_val = 42"])
self.expect("ta v fromSubmodule",
self.expect("target variable typedef", substrs=["x = 5", "y = 6"])
self.expect("target variable union",
substrs=["(DoubleLongUnion)", "long_val = 42"])
self.expect("target variable fromSubmodule",
substrs=["(FromSubmodule)", "x = 1", "y = 2", "z = 3"])
process.Clear()
target.Clear()
lldb.SBDebugger.MemoryPressureDetected()

@skipIf(archs=['ppc64le'], bugnumber='SR-10214')
@swiftTest
# This test needs a working Remote Mirrors implementation.
@skipIf(oslist=['linux', 'windows'])
def test_dwarf_importer_exprs(self):
lldb.SBDebugger.MemoryPressureDetected()
self.runCmd("settings set symbols.use-swift-dwarfimporter true")
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'break here', lldb.SBFileSpec('main.swift'))
lldbutil.check_variable(self,
target.FindFirstGlobalVariable("pureSwift"),
value="42")
lldbutil.check_variable(self,
target.FindFirstGlobalVariable("point"),
typename='__ObjC.Point', num_children=2)
self.expect("expr point", substrs=["x = 1", "y = 2"])
self.expect("expr enumerator", substrs=[".yellow"])
self.expect("expr pureSwiftStruct", substrs=["pure swift"])
self.expect("expr swiftStructCMember",
substrs=["point", "x = 3", "y = 4",
"sub", "x = 1", "y = 2", "z = 3",
"swift struct c member"])
self.expect("expr typedef", substrs=["x = 5", "y = 6"])
# FIXME: lookup fails for:
# a.union.unsafeMutableAddressor : __C.DoubleLongUnion
self.expect("expr union", error=True)
#self.expect("expr union", substrs=["(DoubleLongUnion)", "long_val = 42"])
self.expect("expr fromSubmodule",
substrs=["(FromSubmodule)", "x = 1", "y = 2", "z = 3"])
process.Clear()
target.Clear()
lldb.SBDebugger.MemoryPressureDetected()

@skipIf(archs=['ppc64le'], bugnumber='SR-10214')
@swiftTest
def test_negative(self):
Expand All @@ -81,7 +116,7 @@ def test_negative(self):
target.FindFirstGlobalVariable("point"),
typename="Point", num_children=2)
# This works as a Clang type.
self.expect("ta v point", substrs=["x = 1", "y = 2"])
self.expect("target variable point", substrs=["x = 1", "y = 2"])
# This can't be resolved.
lldbutil.check_variable(self,
target.FindFirstGlobalVariable("swiftStructCMember"),
Expand All @@ -97,4 +132,3 @@ def test_negative(self):
process.Clear()
target.Clear()
lldb.SBDebugger.MemoryPressureDetected()
self.runCmd("settings set symbols.use-swift-dwarfimporter true")
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def build(self):

@skipUnlessDarwin
@swiftTest
def test_dwarf_importer(self):
def test(self):
self.runCmd("settings set symbols.use-swift-dwarfimporter true")

self.build()
Expand All @@ -52,12 +52,32 @@ def test_dwarf_importer(self):
num_children=0)
self.expect("target var obj", substrs=["ObjCClass",
"private_ivar", "42"])
# FIXME: This triggers an assertion in ClangImporter:
# "ObjC property without getter"
#self.expect("target var swiftChild", substrs=["ObjCClass",
# "private_ivar", "42"])

self.expect("target var swiftChild", substrs=["ObjCClass",
"private_ivar", "42"])
# This is a Clang type, since Clang doesn't generate DWARF for protocols.
self.expect("target var -d no-dyn proto", substrs=["(id)", "proto"])
# This is a Swift type.
self.expect("target var -d run proto", substrs=["(ProtoImpl)", "proto"])
self.expect("target var -O proto", substrs=["<ProtoImpl"])

@skipUnlessDarwin
@swiftTest
def test_expr(self):
self.runCmd("settings set symbols.use-swift-dwarfimporter true")

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'break here', lldb.SBFileSpec('main.swift'))
lldbutil.check_variable(self,
target.FindFirstGlobalVariable("pureSwift"),
value="42")
lldbutil.check_variable(self,
target.FindFirstGlobalVariable("obj"),
typename="Swift.Optional<__ObjC.ObjCClass>",
num_children=0)
self.expect("expr obj", substrs=["ObjCClass",
"private_ivar", "42"])
# FIXME: Removing this makes the expression below fail!
self.expect("target var swiftChild")
self.expect("expr swiftChild!.number", substrs=["42"])
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ def do_check_visuals(self):
def do_check_api(self):
"""Check formatting for T? and T! when T is an ObjC type"""
optColor_Some = self.frame().FindVariable("optColor_Some")

# SwiftOptionalSyntheticFrontEnd passes GetNumChildren
# through to the .some object. NSColor has no children.
lldbutil.check_variable(
self,
optColor_Some,
use_dynamic=False,
num_children=1)
num_children=0)
uoptColor_Some = self.frame().FindVariable("uoptColor_Some")
lldbutil.check_variable(
self,
uoptColor_Some,
use_dynamic=False,
num_children=1)
num_children=0)

if __name__ == '__main__':
import atexit
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/CoreProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let Definition = "modulelist" in {
DefaultStringValue<"">,
Desc<"The path to the clang modules cache directory (-fmodules-cache-path).">;
def UseDWARFImporter: Property<"use-swift-dwarfimporter", "Boolean">,
DefaultFalse,
DefaultTrue,
Desc<"Reconstruct Clang module dependencies from DWARF when debugging Swift code">;
def SwiftModuleLoadingMode: Property<"swift-module-loading-mode", "Enum">,
DefaultEnumValue<"eSwiftModuleLoadingModePreferSerialized">,
Expand Down
74 changes: 35 additions & 39 deletions lldb/source/Plugins/Language/Swift/SwiftOptionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,39 @@ using namespace lldb_private;
using namespace lldb_private::formatters;
using namespace lldb_private::formatters::swift;

bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
WouldEvenConsiderFormatting(CompilerType clang_type) {
/// If this is a Clang enum wrapped in a Swift type, return the clang::EnumDecl.
static clang::EnumDecl *GetAsEnumDecl(CompilerType swift_type) {
if (!swift_type)
return nullptr;

SwiftASTContext *swift_ast_ctx =
llvm::dyn_cast_or_null<SwiftASTContext>(clang_type.GetTypeSystem());
llvm::dyn_cast_or_null<SwiftASTContext>(swift_type.GetTypeSystem());
if (!swift_ast_ctx)
return false;
return nullptr;

CompilerType clang_type;
if (!swift_ast_ctx->IsImportedType(swift_type, &clang_type))
return nullptr;

if (!clang_type.IsValid())
return nullptr;

if (!llvm::isa<ClangASTContext>(clang_type.GetTypeSystem()))
return nullptr;

auto qual_type =
clang::QualType::getFromOpaquePtr(clang_type.GetOpaqueQualType());
if (qual_type->getTypeClass() != clang::Type::TypeClass::Enum)
return nullptr;

if (const clang::EnumType *enum_type = qual_type->getAs<clang::EnumType>())
return enum_type->getDecl();
return nullptr;
}

return clang_type.IsValid() &&
swift_ast_ctx->IsImportedType(clang_type, nullptr);
bool lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
WouldEvenConsiderFormatting(CompilerType swift_type) {
return GetAsEnumDecl(swift_type);
}

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

static clang::EnumDecl *GetAsEnumDecl(const CompilerType &compiler_type) {
if (compiler_type.IsValid() &&
llvm::dyn_cast_or_null<ClangASTContext>(compiler_type.GetTypeSystem())) {
opaque_compiler_type_t clang_type = compiler_type.GetOpaqueQualType();
clang::QualType qual_type = clang::QualType::getFromOpaquePtr(clang_type);
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
switch (type_class) {
case clang::Type::TypeClass::Enum: {
if (const clang::EnumType *enum_type =
qual_type->getAs<clang::EnumType>())
return enum_type->getDecl();
break;
}
default:
break;
}
}

return nullptr;
}

void lldb_private::formatters::swift::SwiftOptionSetSummaryProvider::
FillCasesIfNeeded() {
if (m_cases.hasValue())
return;

m_cases = CasesVector();
SwiftASTContext *swift_ast_ctx =
llvm::dyn_cast_or_null<SwiftASTContext>(m_type.GetTypeSystem());

if (!swift_ast_ctx)
return;
CompilerType original_type;
if (!swift_ast_ctx->IsImportedType(m_type, &original_type))
return;
clang::EnumDecl *enum_decl = GetAsEnumDecl(original_type);
clang::EnumDecl *enum_decl = GetAsEnumDecl(m_type);
if (!enum_decl)
return;

SwiftASTContext *swift_ast_ctx =
llvm::dyn_cast_or_null<SwiftASTContext>(m_type.GetTypeSystem());
::swift::ClangImporter *clang_importer = swift_ast_ctx->GetClangImporter();
auto iter = enum_decl->enumerator_begin(), end = enum_decl->enumerator_end();
for (; iter != end; ++iter) {
clang::EnumConstantDecl *case_decl = *iter;
if (case_decl) {
llvm::APInt case_init_val(case_decl->getInitVal());
// extend all cases to 64 bits so that equality check is fast
// Extend all cases to 64 bits so that equality check is fast
// but if they are larger than 64, I am going to get out of that
// case
// and then pick it up again as unmatched data at the end
// case and then pick it up again as unmatched data at the end.
if (case_init_val.getBitWidth() < 64)
case_init_val = case_init_val.zext(64);
if (case_init_val.getBitWidth() > 64)
Expand Down
Loading