Skip to content
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

[SR-10471] LLDB RPC Server crash when trying to print generic type variable #4439

Closed
NSExceptional opened this issue Apr 12, 2019 · 7 comments
Assignees
Labels
bug Something isn't working Generics LLDB for Swift

Comments

@NSExceptional
Copy link

Previous ID SR-10471
Radar None
Original Reporter @NSExceptional
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 10.2 (10E125)
Swift 5
macOS Mojave 10.14.4 (18E226)

Additional Detail from JIRA
Votes 0
Component/s LLDB for Swift
Labels Bug, Generics, LLDBCrash
Assignee @dcci
Priority Medium

md5: bca43475329f6fd1e57f82755a1c9ebc

Issue Description:

I have attached the original project, and both of my attempts at reducing the crash case. Each project contains a unit tests target with a breakpoint just below the offending line. Print type in lldb to see the crash or error.

The original project (Runtime) crashes when trying to print the let type = T.self variable. The first (BetterJSONDecoder) attempt at a reduction merely prints the error below, as does the second (LLDB-Generic-T.self-Crash) attempt:

Printing description of type:
expression produced error: error: /var/folders/5w/p6xmgh695cz9q6qshw92kddr0000gn/T/expr1-1d8dd6..swift:1:66: error: this attribute is not supported
Swift._DebuggerSupport.stringForPrintObject(Swift.UnsafePointer<@thick T.Type>(bitPattern: 0x119b01030)!.pointee)
                                                                 ^

error: /var/folders/5w/p6xmgh695cz9q6qshw92kddr0000gn/T/expr1-1d8dd6..swift:1:72: error: use of undeclared type 'T'
Swift._DebuggerSupport.stringForPrintObject(Swift.UnsafePointer<@thick T.Type>(bitPattern: 0x119b01030)!.pointee)

I recall both of the reductions also crashing lldb at one point, and then beginning to merely print that error, but that might be a mistake on my part.

My final reduction, which prints the above error, is so short that I can just paste it here:

func cast<T>(_ value: Any) -> T {
    let type = T.self
    return value as! T
}

let dict: [String: Any] = ["a": 1, "b": 2]
let casted: [String: Int] = cast(dict)

Any of my attempts at reducing the crash to a more trivial case has managed to avoid the crash somehow. I haven't done this sort of thing a lot, any advice on reducing it further?

@belkadan
Copy link

cc @dcci

@dcci
Copy link
Mannequin

dcci mannequin commented Apr 22, 2019

(lldb) r
Process 54319 launched: '/Users/local/swift/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64/bin/pat' (x86_64)
Process 54319 stopped
* thread #&#8203;1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
 frame #&#8203;0: 0x0000000100000d90 pat`cast<T>(value=2 key/value pairs) at pat.swift:3:12
1    func cast<T>(_ value: Any) -> T {
2        let type = T.self
-> 3        return value as! T
4    }
5    
6    let dict: [String: Any] = ["a": 1, "b": 2]
7    let casted: [String: Int] = cast(dict)
Target 0: (pat) stopped.
(lldb) frame var type
(@thick [String : Int].Type) type = [String : Int]
(lldb) p type
(@thick [String : Int].Type) $R0 = [String : Int]

@dcci
Copy link
Mannequin

dcci mannequin commented Apr 22, 2019

@NSExceptional thanks for your report. Can you please try with the latest snapshot and see if you can reproduce? (I can't, see the comment above).

@dcci
Copy link
Mannequin

dcci mannequin commented Apr 22, 2019

My swift/lldb/clang version for reference

% ../../lldb-macosx-x86_64/bin/lldb --version
lldb version 7.0.0 (https://github.com/apple/swift-lldb.git revision 5d22087eec8eb6b35ae3ca3f909701820be110b0)
Swift version 5.0-dev (LLVM 079934c3f6, Swift 904ba9bafe)

@NSExceptional
Copy link
Author

I've been unable to test it in my Runtime project, since it tries to use Swift 5.0 instead of the 5.0.1 toolchain. This error is produced (paraphrasing):

cannot import module compiled with Swift 5.0 into target set for 5.0.1

I tried to follow these instructions to allow changing it to 5.0.1, but 5.0.1 doesn't appear in the list after trying this. However, I tried to compile it again after this anyway, and while my "conflicting Swift versions" error disappeared, I'm left with this error:

ld: file not found: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-04-16-a.xctoolchain/usr/lib/arc/libarclite_macosx.a

@belkadan
Copy link

The compiler version and the language version aren't the same thing; the important thing is that all targets need to use the same compiler. The arclite error is something we're figuring out elsewhere, but you can work around it for now by setting your deployment target to 10.11 or newer for all targets.

@NSExceptional
Copy link
Author

Gotcha, thanks for clarifying that for me; it's a distinction I often forget even exists.

@dcci, I was just able to test this and it is indeed fixed. Thank you all!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Generics LLDB for Swift
Projects
None yet
Development

No branches or pull requests

2 participants