Debugging C++ Unit Tests on Android

With help from Dan Mosedale (dmose), JimDB now has the ability to debug C++ unit tests running on your Android device [1]. To get started, first update your JimDB Python scripts by running git pull under the utils directory.

The process is fairly automatic. After launching JimDB, choose the second option to debug C++ tests,

Fennec GDB utilities
1. Debug Fennec (default)
2. Debug compiled-code unit test
Enter number from above: 2

Then after choosing the object directory, the actual test is specified along with any environmental variables and arguments. Environmental variables can also be preset in the gdbinit file in the utils directory.

Enter path of unit test (use tab-completion to see possibilities)
    path can be relative to $objdir/dist/bin or absolute
    environmental variables and arguments are supported
    e.g. FOO=bar TestFooBar arg1 arg2
: TestRefPtr

Next, the test can be started simply through the continue command,

Ready. Use "continue" to start execution.
(gdb) c
Continuing.

Output from the test is redirected to the terminal running GDB,

out> BEGIN unit tests for |nsRefPtr|, compiled Dec 10 2012
out> >>main()
out> sizeof(nsRefPtr<Foo>) --> 4
out> >>CreateBar() -->   new Foo@0x43f02098 [#1]
out>   new Bar@0x43f02098
out> Bar@0x43f02098
out> Foo@0x43f02098::AddRef(), refcount --> 1
out> <<CreateBar()
out> Bar@0x43f02098::QueryInterface()
out> Foo@0x43f02098::AddRef(), refcount --> 2
out> total constructions/destructions --> 1/0
out> Foo@0x43f02098::Release(), refcount --> 1
out> >>Foo@0x43f02098::Release(), refcount --> 0
out>   delete Foo@0x43f02098
out> <<Foo@0x43f02098::Release()
out> Bar@0x43f02098::~Bar()
out> Foo@0x43f02098::~Foo() [#1]
out> >>CreateBar() -->   new Foo@0x43f02098 [#2]
out>   new Bar@0x43f02098
out> Bar@0x43f02098
out> Foo@0x43f02098::AddRef(), refcount --> 1
out> <<CreateBar()
out> Bar@0x43f02098::QueryInterface()
out> Foo@0x43f02098::AddRef(), refcount --> 2
out> total constructions/destructions --> 2/1
out> Foo@0x43f02098::Release(), refcount --> 1
out> >>Foo@0x43f02098::Release(), refcount --> 0
out>   delete Foo@0x43f02098
out> <<Foo@0x43f02098::Release()
out> Bar@0x43f02098::~Bar()
out> Foo@0x43f02098::~Foo() [#2]
out> 
out> ### Test  1: will a |nsCOMPtr| call |AddRef| on a pointer assigned into it?
out>   new Foo@0x43f02098 [#3]
out> Foo@0x43f02098::QueryInterface()
out> Foo@0x43f02098::AddRef(), refcount --> 1
...

Support is limited to C++ unit tests for now, but the plan is to include more types of tests that you can debug (mochitest, reftests, etc.). Stay tuned! Feel free to ping me (jchen) on IRC #mobile if you have questions, or file bugs under the Firefox for Android > JimDB component on Bugzilla.