Debug PacketTunnelProvider in OSX

I've been working a lot recently with the NetworkExtension framework in iOS. I've been able to debug the process using the device log for my iOS device. However, now that I've started developing an app for OSX using the same framework, I'm unable to debug the provider as there's no device log for OSX machines.


I can't attatch to the process since it dies before I'm able to, so I'd like to know how I should go about debugging this specifically for OSX.


(I cannot stress enough the fact that this is for OSX and NOT iOS)


Thanks in advance

Accepted Reply

(I cannot stress enough the fact that this is for OSX and NOT iOS)

I think you mean macOS here (-;

However, now that I've started developing an app for OSX using the same framework, I'm unable to debug the provider as there's no device log for OSX machines.

You can view the system log on macOS using the Console utility (in

/Applications/Utilities/
). On macOS you also have command line access to this via the
log
tool.

The Console utility will also show the system log for attached iOS devices. I generally use this when looking at iOS logs because it has much better filtering facilities than Xcode’s Devices window.

Also, be aware that once a Network Extension provider is started you can attach to it via Xcode’s Debug > Attach to Process feature. That’s useful in some situations, but logging is also very useful. It’s a question of using the right tool for the job.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

(I cannot stress enough the fact that this is for OSX and NOT iOS)

I think you mean macOS here (-;

However, now that I've started developing an app for OSX using the same framework, I'm unable to debug the provider as there's no device log for OSX machines.

You can view the system log on macOS using the Console utility (in

/Applications/Utilities/
). On macOS you also have command line access to this via the
log
tool.

The Console utility will also show the system log for attached iOS devices. I generally use this when looking at iOS logs because it has much better filtering facilities than Xcode’s Devices window.

Also, be aware that once a Network Extension provider is started you can attach to it via Xcode’s Debug > Attach to Process feature. That’s useful in some situations, but logging is also very useful. It’s a question of using the right tool for the job.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'd like to also point out that if you're trying to debug the initialization of your PacketTunnelProvider and can't attatch a debugger fast enough to catch the debug information, what I've found helpful is adding a `sleep(15);` on the first line of the PacketTunnelProvider initialization which effectively gives me enough time to attatch a debugger.

Yep, that’s a cool trick. I tend to use

pause
for this. That’s documented to wait indefinitely until the process receives a signal, but attaching with the debugger also unblocks it [1]. And I put a log line immediately before the
pause
so I remember that I’ve done it (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] I’m not sure whether that’s because it actually generates a signal — back in the day UNIX debuggers used to be all signal based but that’s not really the case on Darwin kernels — but it certainly has the same effect.