Tutorial: Debugging Native Extensions

I've written before about how to create your own native extensions for Adobe AIR, but what if you need to debug your extension? If you're doing anything but the simplest of projects, you're going to want to be able to debug the code on the native side, in addition to your AS3 code. The ActionScript side is (hopefully!) already taken care of by your IDE so this tutorial will focus on the native code. It's a pretty short tutorial, but also incredibly useful!

For this tutorial, I'm using Visual Studio 2012 Express, which you can get for free from Microsoft and a slightly modified version of the NativeAdd extension from the tutorial linked above.

First, you'll want to have your AIR project running. Then switch over to Visual Studio and set a break point (f9 or click the side bar) on the line you want to investigate (shown below).

Next, select Debug > Attach to Process from the Visual Studio menu. If you're using Visual Studio 2010 and you don't see this option, first click Tools > Settings > Expert Settings.

This will bring up a window with a list of running processes on your PC. In this list find the adl.exe process, select it and click the Attach button.

Once the debugger has attached itself to the process, go back to your AIR application and have it call into the native function where you added your break point. In this case, I'm using the NativeAdd extension from a previous tutorial. I modified it a bit so that when the stage is clicked, it calls the doAdd function on the native side. With the debugger attached, when I click the stage, my breakpoint gets hit as shown here:

You can now take a look at the values of your native code variables and monitor them as you step through the code using the Visual Studio debugger tools. Here's a sample shot of the watch window with the NativeAdd extension.

If you run into an issue where Visual Studio seems to stop hitting breakpoints, try going to Tools > Options > Debugging and uncheck the box next to "Require source files to exactly match the original version". This can happen if you make changes to the native library, but haven't updated the AIR project or even just copying the files to another machine. Visual Studio 2012 seems to be much better about handling this; it's one of the main reasons I decided to switch from 2010.

That's all there is to it; happy debugging!

Bookmark and Share

Leave a Reply

Subscribe to RSS feed FGS5 Badge