Using GDB script files with the FlasCC GDB

Posted on November 27, 2012 | Comments Off

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 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 sdk/usr/bin/gdb.exe (Win/Cygwin).

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:

#include <stdio.h>

int main(int argc, char **argv)
    int i = 0;
    printf("Hello World %d Time\n", i++);
    printf("Hello World %d Time\n", i++);

And the command to compile the debug SWF with FlasCC is:

sdk/usr/bin/gcc -g test.c -emit-swf -o test.swf

The FlasCC 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 gdb prompt:

(gdb) run
Starting program: hello.swf
Please set the FLASCC_GDB_RUNTIME environment variable to the path to a debugger player or browser.

The 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 gdb:

export FLASCC_GDB_RUNTIME=/Code/Flash\ Player\

Let’s take a look at my command line to see how to put this all together:

renaun$ sdk/usr/bin/gcc -g test.c -emit-swf -o test.swf
renaun$ export FLASCC_GDB_RUNTIME=/Code/Flash\ Player\
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 <>
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.
(gdb) run
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 gdb commands:

set breakpoint pending on
b main

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:

renaun$ sdk/usr/bin/gdb -x script.txt test.swf

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.