debugging a Packet Tunnel provider

I'm having a hard time figuring out how to debug a NetworkExtension Packet Tunnel type application extension. I'm running the SimpleTunnel example, and its connecting to the included tunnel_server (getting an address and route and showing the VPN icon and all that, so its definitely working), but I can't see any output from any of the print() calls in the PacketTunnel target. I have tried running the PacketTunnel target on my device, and then in "Choose an app to run..." I pick the SimpleTunnel container app, and then the output is just blank. Setting breakpoints on lines of code that I know get hit also does nothing in that scenario, and the extension doesn't show up in the process list of things I can attach to, even when I know its running. I've also added NSLog() calls, and those aren't showing up in the device log.


Do I have to rely on IPC to the container app, and hope that the container app is running when something log-worthy happens in the extension?

Replies

Try the device console. Open the Devices window in Xcode, click the device, and at the bottom left corner of the right-hand pane, click the little disclosure triangle. You should then see the combined spew from all running apps.

Thanks, but unfortunately, there is no output from the Packet Tunnel app extension in the device log. NSLog statements from the container app, and everything else, is in there, but nothing out of my app extension, and I am very confident that it is in fact hitting NSLog calls.

I did manage to attach the debugger, finally, but still no log/console output. The trick to attaching the debugger was to start the app extension target in Xcode, selecting the container app as the app to run, and then Debug->"Attach to Process by PID or Name...", and then type in the app extension target name (not the full bundle/app identifier). Breakpoints and such then seem to work just fine.

That's odd. NSLog calls in the provider should be showing up in the device console. Or at least they do for me.

Just to clarify, only NSLog messages are logged there. Calls to printf do not, nor do fprintf calls to stderr.

Right. I don't see NSLog output from the packet tunnel provider in there. Seems like a bug. Attaching the debugger is also very hit-or-miss, with it not working all of today.

I'm seeing NSLog output from the app extension with the latest round of betas (iOS 9 beta 4, OS X 10.11 beta 4, and Xcode 7 beta 4). So far, it looks like its fixed.

I have been trying to get the sample code to work. I got the proper provisioning from Apple. I can run the sample on my ipad-ios9 and create a VPN profile (and sample server is running) but I don't see the custom tunnel's attempts to connect to the server.


I see one log that indicates something is working: "Received response from the provider: Optional(Hello app)"


I don't trigger any breakpoint or other message and app just shows as "connecting" and never connects. I tried to telnet to the sample tunnel server and that works. So something is wrong with the sample for me. I also tried to recreate similar code in a new project and In the event observer I get an error saying "the operation couldn’t be completed. (NEVPNErrorDomain error 1.)" which i think it means invalid configuration or something because from the system UI it disables the connection immediately after I try to connect (which is similar to a real invalid configuration).


I hope someone can give me some more hints as to what I need to do to make this work. I hope it's not some environmental thing. I am running El Capitan on an external hard disk on the latest mac mini, working with iPad air 2 (latest ios9 beta).

I fixed my problem now.


https://forums.developer.apple.com/message/28596#28596


Thanks for the hints though.

Do I need to run Xcode 7 beta for on OSX 10.11 beta only? I am trying with OSX 10.10, no success as of now. so suspecting about the base OS.

Don't mix. You sould install El Capitan on a separate hard disk partition or external drive (like I do) then install xcode 7 beta.

Were you able to resolve the issue "NEVPNErrorDomain error 1" you mentioned in your previous post? because I am facing the same issue.

Excuse me, I ran ssh tunnel server on the terminal. Then I have tried running the PacketTunnel target on my device, and then in "Choose an app to run ..." I pick the SimpleTunnel container app. But when I turned on the connection time, VPN has been displaying "Connecting", then have been unable to connect, there is no VPN icon. I ask you how to run the VPN connection has been established it?