skia2/site/docs/dev/tools/android_gdb.md
Brian Osman f693b20c37 Add gdbserver instructions to site docs
Change-Id: I13ba477d5b390a0fc03cd4960b6a19bcaa4266d7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/482699
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
Commit-Queue: Joe Gregorio <jcgregorio@google.com>
2021-12-10 16:41:09 +00:00

2.2 KiB
Raw Blame History


title: "Debugging DM on Android" linkTitle: "Debugging DM on Android"


By default, we dont do Android builds with full symbols. Assuming you want more than callstacks, add the following to your GN args:

extra_cflags = [ "-g" ]

When you build, you need to have built the gdbserver target. Either build everything, or at least build both dm and gdbserver:

ninja -C out/android dm gdbserver

At this point, the Android gdb script should work. Try running:

platform_tools/android/bin/android_gdb_native -C out/android dm -i /data/local/tmp/resources <args>

You will end up in a command-line gdb session connected to dm on the device. Youre done, but you can do better. From here, Im assuming that you use VS Code. I strongly suspect that this could be adapted to other IDEs' GDB integration.

VS Code comes with lldb support, but this workflow needs a GDB extension. Search for 'Native Debug' in the extension browser and install it, the thing you want comes from https://github.com/WebFreak001/code-debug if youre unsure.

In your VS Code projects launch.json, add an entry that looks like the following. You'll need to replace <NDK_BUNDLE> with the path to your NDK bundle (ie $ANDROID_NDK_ROOT):

{
    "name": "Android GDB",
    "type": "gdb",
    "request": "attach",
    "target": ":5039",
    "remote": true,
    "gdbpath": "<NDK bundle>/prebuilt/linux-x86_64/bin/gdb",
    "executable": "out/android/android_gdb_tmp/dm",
    "cwd": "${workspaceRoot}",
    "autorun": [ "break main" ]
}

Rather than running android_gdb_native, run android_gdbserver in the same directory (and with the same arguments). This will do all of the same deployment, and run gdbserver on the device, but wont start command line gdb on your host.

Now, just 'Start Debugging' in VS Code (with the new configuration selected, if you have more than one). The VSC hosted gdb will connect to gdbserver, and youll have a somewhat interactive debugger where you can set breakpoints in your source windows, have panes for watches, locals, and the call stack, etc. Enjoy:

VS Code Debugger Screenshot