-2

This has become much more common lately in Xcode 11 (Version 11.7). I'm stepping through code, but in one section po refuses to work and the variable display lists some variables as not available. These files are always in the proper target membership, so I attributed it to a threading issue since it often occurs in background threads.

Updated: after removing logging calls path is now accessible But in this case, I can po every variable in this func, except url created in the if statement. Specifically the line print(url) prints:

"this/is/my/path -- file:///"

but stopped at same line po url prints:

error: :3:1: error: use of unresolved identifier 'url'

while at same line po message prints:

"Player failed with error: Unknown.\nInternet: true, UserData: None\nURL: file://this/is/my/path"

final class MyVideoController: UIViewController {
    var testPathForURL: String? = "file://this/is/my/path"

    override func viewWillAppear(_ animated: Bool) {

       super.viewWillAppear(animated)
    
       // happens on main thread
       test(error: nil)
    }
}

extension MyVideoController {
    private func test(error: NSError?) {
        let errorString = error?.description ?? "Unknown"
        let errorSummary = "Player failed with error: \(errorString)"
        let userInfo = error?.userInfo.description ?? "None"
        let message: String = "\(errorSummary).\nInternet: \(true), UserData: \(userInfo)\nURL: \(testPathForURL ?? "NONE")"
        print(message)
        let filePrefix = "file://"
        if let fullPath = testPathForURL, fullPath.hasPrefix(filePrefix) {
            // Delete cached video so problem won't occur again.
            let path = String(fullPath.dropFirst(filePrefix.count))
            print(path)
            let url = URL(fileURLWithPath: path)
            do {
                print(url)
                try FileManager.default.removeItem(at: url)
            } catch {
                print(error)
            }
        }
    }
}

Update: Here's what happens when I stop on the try FileManager line and use alternatives to po:

(lldb) v url
(URL) url = <variable not available>

(lldb) e url
error: <EXPR>:3:1: error: use of unresolved identifier 'url'
url
^~~

(lldb) p url
error: <EXPR>:3:1: error: use of unresolved identifier 'url'
url
^~~

Also, I have cleaned and rebuilt, restarted Xcode, restarted my Mac, and reinstalled Xcode tools.

UPDATE

I recently built project with beta versions of Xcode 12 separately on this machine, but believe similar debugger incidents predated that.

One other possible symptom that I've been dealing with for a long while is that it occasionally takes a very long time (minutes) for debugger to load variable list when it stops at a breakpoint (6 core 2018 Mac mini with 32 Gb RAM). I thought that was only happening when debugging on my 5s test device, but it also is happening on simulator occasionally.

SafeFastExpressive
  • 3,637
  • 2
  • 32
  • 39
  • Have you tried force closing then reopening Xcode? I know it sounds stupid, but usually it does the trick for me. – Vlad Rusu Sep 16 '20 at 19:22
  • try `p`, `expr`, `v` too. I mean if the print works and you're breakpointing at the line that the print happens ie on the same thread then to me that's just an Xcode bug... – mfaani Sep 16 '20 at 19:26
  • 2
    A lot depends on where you are paused. We can't run the code you've given, so, shrug, there's nothing to say. Please give a reproducible example and say exactly how to reproduce the issue. Then we can talk about an actual case in point instead of all this vague hand-waving. – matt Sep 16 '20 at 19:27
  • also not that we know which version of Xcode is buggy. But it's best to mention the exact version of Xcode – mfaani Sep 16 '20 at 19:32
  • @matt as I put in my original question, paused on the print(path) line won't po path. And I've added the version (11.7) to the question. – SafeFastExpressive Sep 16 '20 at 19:38
  • 1
    I understand that, but I still can't try out that code. Please provide an example where I _can_ try out the code. – matt Sep 16 '20 at 20:35
  • @matt not sure what I can do to make it clearer. The first four lines declare some strings, then reports an error and calls a delegate, then it unwraps a an class object string variable (misnamed as lastVideoUrl by the original author, it's a path string). Changing the code makes it something new, and since this behavior only happens in weird random locations, could "fix" it by side-effect. – SafeFastExpressive Sep 16 '20 at 21:22
  • Stack Overflow is not your blog. It is a programming question / answer encyclopedia. It is clear what you say is happening to _you_. I’m asking you to tell how to make it happen to _me_. That is what would take this from a personal anecdote to a Stack Overflow question. – matt Sep 16 '20 at 21:26
  • @matt ok, Iv'e been able to shrink it down and remove all the proprietary stuff and it still happens. Updating shortly – SafeFastExpressive Sep 16 '20 at 21:41
  • Excellent, thank you! – matt Sep 16 '20 at 21:50
  • OK so I ran your code - I had to change your Logger stuff because that's something I don't have. I had a breakpoint on the `try` line. When we paused there, I said `po url` and got `this/is/my/path -- file:///`, which is the same thing that `print(url)` had already output. So, not able to reproduce yet. (Could your Logger be screwing things up somehow?) – matt Sep 16 '20 at 22:08
  • @matt Apologies for missing the logger calls. I'm still debugging the original problem and trying to get a build out. When done I will strip out the Logger calls and retest and let you know what happens when Id. – SafeFastExpressive Sep 16 '20 at 22:17
  • @matt I can still reproduce half of the problem after stripping out Logger calls. I'm beginning to wonder if it's a project related issue (fairly large project with around 70,000 lines of Swift and Objective C), or related to the project being built in Xcode 12 a couple times (though pretty sure incidents of this behavior predated that). – SafeFastExpressive Sep 16 '20 at 23:13
  • Correction, 115,000 lines of Swift/Objective C according to cloc. – SafeFastExpressive Sep 16 '20 at 23:24

1 Answers1

0

Turns out this is a known problem with Lldb debugger, probably aggravated by having such a large project.

https://forums.swift.org/t/lldb-is-slow-to-resolve-local-vars/32517/41

SafeFastExpressive
  • 3,637
  • 2
  • 32
  • 39