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:
C:
And the command to compile the debug SWF with FlasCC is:CODE:
The FlasCC sdk/usr/bin/gcc -g test.c -emit-swf -o test.swf
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:CODE:
The (gdb) run
Starting program: hello.swf
Please set the FLASCC_GDB_RUNTIME environment variable to the path to a debugger player or browser.
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 us it. I downloaded the Mac version and put in a folder called /Code, which means I would run this command in Ternimal before I call gdb
:CODE:
Lets take a look at my command line to see how to put this all together:export FLASCC_GDB_RUNTIME=/Code/Flash\ Player\ Debugger.app
CODE:
So I setup export to the debug Flash Player and then ran the gdb against the SWF. But once in side the renaun$ sdk/usr/bin/gcc -g test.c -emit-swf -o test.swf
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:
<http://www.gnu.org/software/gdb/bugs/>...
(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;
(gdb)
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:
<http://www.gnu.org/software/gdb/bugs/>...
(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;
(gdb)
gdb
command prompt I still need to setup a break point. When trying to setup 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:CODE:
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 set breakpoint pending on
b main
r
b main
r
gdb
, telling it to start. The command to use the gdb
script is below:CODE:
Another handy command to put in script.txt is the renaun$ sdk/usr/bin/gdb -x script.txt test.swf
set as3namespace com.renaun.test
command. This is needed if you create a FlasCC SWC with a custom namespace.Read more: Using GDB script files with the FlasCC GDB
No comments:
Post a Comment