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-6831] LLDB get wrong variable in an enum #4500

Closed
swift-ci opened this issue Jan 24, 2018 · 7 comments
Closed

[SR-6831] LLDB get wrong variable in an enum #4500

swift-ci opened this issue Jan 24, 2018 · 7 comments
Assignees
Labels
bug Something isn't working LLDB for Swift

Comments

@swift-ci
Copy link

Previous ID SR-6831
Radar rdar://problem/36835797
Original Reporter TheSnowFox (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

High Sierra: 10.13 (17A405)

Xcode: 9.2 (9C40b)

Framework created with:

swift package init --type library

App created with:

swift package init --type executable
//Edit package.swift
swift package update
swift package generate-xcodeproj
Additional Detail from JIRA
Votes 0
Component/s LLDB for Swift
Labels Bug
Assignee @dcci
Priority Medium

md5: da766bcf40e5048a35ae1f3a526742dd

Issue Description:

Hi,

As I explained here, I have weird reaction of Xcode (or LLDB) when I pause my app at a breakpoint and look for variables.

Here is the struct in framework :

import Foundation

public struct MyStruct {
    
    public var type: MyTypeEnum
    public var item: MyItem
    
    public enum MyTypeEnum {
        case a
        case b
        case utility
    }
    
    public init(type: MyTypeEnum, itemType: MyItemTypeEnum, data: Data? = nil) {
        self.type = type
        self.item = MyItem(type: itemType, data: data)
    }
    
    public struct MyItem {
        public var type: MyItemTypeEnum
        public var data: Data?
    }
    
    public enum MyItemTypeEnum {
        case itemA
        case itemB
        case utility
    }
}

Here at the breakpoint in a test app, myStruct > item > type should be .utility not itemA :

It works fine if the code is executed in main.swift but bug if in another file...

As asked in the forum, here is a ZIP of this test project: Test.zip

Hope this will help !

@swift-ci
Copy link
Author

Comment by Jim Ingham (JIRA)

@swift-ci create

@swift-ci
Copy link
Author

Comment by Jim Ingham (JIRA)

I see this in the swift-4.0 branch of lldb, but I don't see the same behavior when using tools from the swift-4.1 development branch.

@swift-ci
Copy link
Author

Comment by Thomas Dougnac-Galant (JIRA)

Ah. I'm currently developing and debugging my app only with Xcode release.

Could this bug change the behaviour of accessing the data (inside item struct) ?

@swift-ci
Copy link
Author

Comment by Jim Ingham (JIRA)

BTW, it looks like the bug is when you have a let variable with a struct within a struct. Changing myStruct to a var fixes the problem. Also, if you copying myStruct.item to a local var, the original still prints incorrectly but the copy prints correctly.

@swift-ci
Copy link
Author

Comment by Thomas Dougnac-Galant (JIRA)

ok thanks

@swift-ci
Copy link
Author

Comment by Jim Ingham (JIRA)

I don't think so. I suspect this is an artifact of some special magic the compiler does to make let variables be visible to the debugger after the compiler would have discarded them. It makes a "shadow copy" at -Onone and points the debugger at that. That doesn't affect the actual code behavior, however, since "real code" doesn't use this shadow copy.

Also, the code in question actually behaves correctly, so it looks like it is a debugger-only failure.

@dcci
Copy link
Mannequin

dcci mannequin commented Mar 5, 2018

TheSnowFox (JIRA User) Hello, I was able to reproduce this with a release version of Xcode, but not with a nightly toolchain.
You might consider getting a snapshot from here https://swift.org/download/#releases
and verify this works as you expect. Thanks for your report.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 7, 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 LLDB for Swift
Projects
None yet
Development

No branches or pull requests

1 participant