Using GDB script files with the FlasCC GDB
The Flash C++ Compiler (FlasCC) provides a complete BSD-like C/C++ development environment based on GCC that lets you compile your C/C++ code to target the Adobe® Flash® Runtime (Flash Player and AIR®). With FlasCC you can port almost any existing C/C++ code to the web, across browsers. FlasCC includes tools for building, testing, and debugging C/C++ projects, example projects with source code, and documentation. You can get FlasCC today on the http://gaming.adobe.com/technologies/flascc/ page.
Today I want to share a quick FlasCC debugging tip. The FlasCC based
gdb tool is located in the FlasCC download under
sdk/usr/bin/gdb (Mac) or
Before trying this out we need a simple C app to debug. Go ahead and create a file called test.c and put the following code inside:
And the command to compile the debug SWF with FlasCC is:
gdb relies on an environmental variable called
FLASCC_GDB_RUNTIME, if you do not set it before running
gdb you’ll see the following message inside of the
Starting program: hello.swf
Please set the FLASCC_GDB_RUNTIME environment variable to the path to a debugger player or browser.
FLASCC_GDB_RUNTIME needs to be set to the standalone debug Flash Player or to a browser that has a debug Flash Player. I recommend for the first time that you try using the FlasCC
gdb to download a standalone debug Flash Player from here and use it. I downloaded the Mac version and put in a folder called /Code, which means I would run this command in Terminal before I call
Let’s take a look at my command line to see how to put this all together:
renaun$ export FLASCC_GDB_RUNTIME=/Code/Flash\ Player\ Debugger.app
renaun$ sdk/usr/bin/gdb test.swf
GNU gdb (GDB) 7.3
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=avm2-elf".
For bug reporting instructions, please see:
(gdb) b main
No symbol table is loaded. Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (main) pending.
Starting program: test.swf
0xdddddddd in ?? ()
Breakpoint 1, 0xf0000051 in main (argc=0, argv=0x200ff0) at test.c:5
5 int i = 0;
So I set up export to the debug Flash Player and then ran the gdb against the SWF. But once in side the
gdb command prompt I still need to set a break point. When trying to set a break point before starting the SWF it will display another warning which needs a yes response. After responding with a yes I can then type run.
Here is the trick, by using
gdb -x script.txt we can run it all in one command. Instead of having to type in my break point each time or responding yes. This is how it works, create a script.txt file and put in the following
The first line sets the default warning option to be yes so you dont have to worry about it not being set. The second command sets a break point at the main function. And the last command runs the
gdb, telling it to start. The command to use the
gdb script is below:
Another handy command to put in script.txt is the
set as3namespace com.renaun.test command. This is needed if you create a FlasCC SWC with a custom namespace.