HowTo debug on android with gdb

Hey,

I am trying to debug an openfl/lime project using gdb (the reason, it causes ANR from time to time when resuming).

So I copied the gdbserver to the Export/android/bin/libs/armeabi/ folder, run the program in debug mode and start the gdbserver like this:

PID=`adb shell ps | grep <my-app-name> | awk '{print $2}'`
adb shell run-as <my-app-name> /data/data/org.woodengames.kulamiducks/lib/gdbserver :5039 --attach $PID

That worked! So I am trying to run gdb:

/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb Export/android/obj/libApplicationMain-debug-v7.so

Now, what I am really unsure about is the “libApplicationMain-debug-v7.so”. Is that the “executable” to debug with?

Anyhow, now I am connecting and trying to get a stack trace:

(gdb) target remote :5039
(gdb) bt
#0  0xb6e70b10 in ?? ()
#1  0xb6e4833c in ?? ()
#2  0xb6e4833c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

So … something is wrong. But what? Am I using the wrong “application exectuable”? Which should I use?

Or something else?
Thanks!
Nathan

1 Like

I’ve used this tool successfully. It was relatively easy to use, at least once I figured out how to set a breakpoint.

Apparently it does not want to know the full path to each source file. So, instead of “com/example/Main.hx”, you’d type “Main.hx”.

You got hxcpp-debugger running on android? Using remote or local debugging?
I don’t know how I could use local debugging, and with remote I get this error: https://github.com/HaxeFoundation/hxcpp-debugger/issues/5 :frowning:

Oh, oops. I didn’t read the “Android” part of the question. All I did was run it on the Windows build.

Um… ok, let’s try getting libApplicationMain.so to work. Normally this file is stripped of line data, making it hard or impossible to debug, but I managed to get it working.

Step 1: add the following to .hxcpp_config.xml. This file should be in your home folder, and the code should go in the “exes” section.

<compiler id="android-gcc" exe="arm-linux-androideabi-g++" if="android">
    <flag value="-g" />
</compiler>

Step 2: add these two environment variables.

<setenv name="nostrip" if="android" />
<setenv name="CFLAGS_g" if="android" />

This should compile a version of libApplicationMain with a bunch of extra debug data, but it’s possible I’m forgetting a step. (I set this up ages ago and haven’t needed to change it since.)

Note: disable nostrip before release. Otherwise, it’ll be easier to decompile your app.

Hey,

Thanks for the answer. Unfortunately it did not help :-(. I get the same problem.

I see in the compiler output, that it passes “-fomit-frame-pointer”. Doesn’t that destory debug possibilities?
Can I tell hxcpp/haxe/openfl/lime not to use that parameter?

Try checking HXCPP, there’s an “android-toolchain.xml” that controls which flags are used when compiling, we can make an improvement if you find anything