Debugger woes


(Maury Markowitz) #1

I hope this is the right place to ask this:

I'm using Xcode Version 8.2.1 (8C1002) and I'm trying to find out what's going wrong in my Swift3 app. Here's the code:

    let background = sceneView.snapshot().cgImage!
    let cropped = background.cropping(to: overlayView.frame)
    UIGraphicsBeginImageContextWithOptions(overlayView.frame.size, false, 1.0)

I have a breakpoint on the first line. When it trips I F6 to the next line and examine background:

(lldb) p background
(CGImage) $R0 = 0x00000001741d4370 {}
Printing description of background:
<CGImage 0x1741d4370>
  <<CGColorSpace 0x170024480> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)>
    width = 640, height = 998, bpc = 8, bpp = 32, row bytes = 2560

Now I hit F6 again and do the same thing:

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

This happens to pretty much every variable in the app, after running another line or two, it apparently disappears. This is particularly annoying in this case, because QuickLook fails almost every time, which makes debugging image work somewhat difficult.

I've cleaned and rebooted and it keeps coming back. Any suggestions?


(Jim Ingham) #2

From the symptoms, it looks like the compiler is not holding onto "background" because it is no longer used. That's a desirable thing to do for optimized code, but not at -O0.

What happens if you rewrite this to:

    let background = sceneView.snapshot().cgImage!
    let cropped = background.cropping(to: overlayView.frame)
    UIGraphicsBeginImageContextWithOptions(overlayView.frame.size, false, 1.0)
                print(background)

When you step to the UIGraphics... line, are you still able to print the variable? If so, that's quite likely what is going on, and it would be great if you could file a bug about this.

Jim

···

On Jan 31, 2017, at 10:54 AM, Maury Markowitz via swift-users <swift-users@swift.org> wrote:

I hope this is the right place to ask this:

I'm using Xcode Version 8.2.1 (8C1002) and I'm trying to find out what's going wrong in my Swift3 app. Here's the code:

    let background = sceneView.snapshot().cgImage!
    let cropped = background.cropping(to: overlayView.frame)
    UIGraphicsBeginImageContextWithOptions(overlayView.frame.size, false, 1.0)

I have a breakpoint on the first line. When it trips I F6 to the next line and examine background:

(lldb) p background
(CGImage) $R0 = 0x00000001741d4370 {}
Printing description of background:
<CGImage 0x1741d4370>
  <<CGColorSpace 0x170024480> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)>
    width = 640, height = 998, bpc = 8, bpp = 32, row bytes = 2560

Now I hit F6 again and do the same thing:

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

This happens to pretty much every variable in the app, after running another line or two, it apparently disappears. This is particularly annoying in this case, because QuickLook fails almost every time, which makes debugging image work somewhat difficult.

I've cleaned and rebooted and it keeps coming back. Any suggestions?
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Jon Shier) #3

This is pretty normal debugger behavior for me. Issues with printing variables clearly in scope, using types or operators from other modules, and poor performance happen every time I try to debug Swift under Xcode. I’ve never found anything that works reliably.

Jon

···

On Jan 31, 2017, at 1:54 PM, Maury Markowitz via swift-users <swift-users@swift.org> wrote:

I hope this is the right place to ask this:

I'm using Xcode Version 8.2.1 (8C1002) and I'm trying to find out what's going wrong in my Swift3 app. Here's the code:

    let background = sceneView.snapshot().cgImage!
    let cropped = background.cropping(to: overlayView.frame)
    UIGraphicsBeginImageContextWithOptions(overlayView.frame.size, false, 1.0)

I have a breakpoint on the first line. When it trips I F6 to the next line and examine background:

(lldb) p background
(CGImage) $R0 = 0x00000001741d4370 {}
Printing description of background:
<CGImage 0x1741d4370>
  <<CGColorSpace 0x170024480> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)>
    width = 640, height = 998, bpc = 8, bpp = 32, row bytes = 2560

Now I hit F6 again and do the same thing:

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

This happens to pretty much every variable in the app, after running another line or two, it apparently disappears. This is particularly annoying in this case, because QuickLook fails almost every time, which makes debugging image work somewhat difficult.

I've cleaned and rebooted and it keeps coming back. Any suggestions?
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Maury Markowitz) #4

I've been battling H3N2 so I only got a chance to try this now. Indeed, the 'background' variable is "alive" in this version, I assume because of the print() that follows?

Should I file through the normal Apple Bug Reporter, or is there a better mechanism for Swift-related issues?

···

On Jan 31, 2017, at 1:59 PM, Jim Ingham <jingham@apple.com> wrote:

From the symptoms, it looks like the compiler is not holding onto "background" because it is no longer used. That's a desirable thing to do for optimized code, but not at -O0.

What happens if you rewrite this to:

    let background = sceneView.snapshot().cgImage!
    let cropped = background.cropping(to: overlayView.frame)
    UIGraphicsBeginImageContextWithOptions(overlayView.frame.size, false, 1.0)
               print(background)


(Jim Ingham) #5

From the symptoms, it looks like the compiler is not holding onto "background" because it is no longer used. That's a desirable thing to do for optimized code, but not at -O0.

What happens if you rewrite this to:

    let background = sceneView.snapshot().cgImage!
    let cropped = background.cropping(to: overlayView.frame)
    UIGraphicsBeginImageContextWithOptions(overlayView.frame.size, false, 1.0)
              print(background)

I've been battling H3N2 so I only got a chance to try this now. Indeed, the 'background' variable is "alive" in this version, I assume because of the print() that follows?

Yes, that's most likely right.

Should I file through the normal Apple Bug Reporter, or is there a better mechanism for Swift-related issues?

The official word on that is:

https://swift.org/contributing/#reporting-bugs

Jim

···

On Feb 3, 2017, at 6:55 AM, Maury Markowitz <maury.markowitz@gmail.com> wrote:

On Jan 31, 2017, at 1:59 PM, Jim Ingham <jingham@apple.com> wrote: