xref: /aosp_15_r20/external/skia/site/docs/dev/tools/android_gdb.md (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1
2---
3title: "Debugging DM on Android"
4linkTitle: "Debugging DM on Android"
5
6---
7
8By default, we don’t do Android builds with full symbols. Assuming you want more than callstacks,
9add the following to your GN args:
10
11~~~
12extra_cflags = [ "-g" ]
13~~~
14
15When you build, you need to have built the `gdbserver` target. Either build everything, or at least
16build both `dm` and `gdbserver`:
17
18<!--?prettify lang=sh?-->
19
20    ninja -C out/android dm gdbserver
21
22At this point, the Android gdb script should work. Try running:
23
24<!--?prettify lang=sh?-->
25
26    platform_tools/android/bin/android_gdb_native -C out/android dm -i /data/local/tmp/resources <args>
27
28You will end up in a command-line gdb session connected to dm on the device. You’re done, but you
29can do better. From here, I’m assuming that you use VS Code. I strongly suspect that this could be
30adapted to other IDEs' GDB integration.
31
32VS Code comes with lldb support, but this workflow needs a GDB extension. Search for 'Native Debug'
33in the extension browser and install it, the thing you want comes from
34https://github.com/WebFreak001/code-debug if you’re unsure.
35
36In your VS Code project’s `launch.json`, add an entry that looks like the following. You'll need to
37replace <NDK_BUNDLE> with the path to your NDK bundle (ie $ANDROID_NDK_HOME):
38
39~~~
40{
41    "name": "Android GDB",
42    "type": "gdb",
43    "request": "attach",
44    "target": ":5039",
45    "remote": true,
46    "gdbpath": "<NDK bundle>/prebuilt/linux-x86_64/bin/gdb",
47    "executable": "out/android/android_gdb_tmp/dm",
48    "cwd": "${workspaceRoot}",
49    "autorun": [ "break main" ]
50}
51~~~
52
53Rather than running `android_gdb_native`, run `android_gdbserver` in the same directory (and with
54the same arguments). This will do all of the same deployment, and run `gdbserver` on the device,
55but won’t start command line gdb on your host.
56
57Now, just 'Start Debugging' in VS Code (with the new configuration selected, if you have more than
58one). The VSC hosted gdb will connect to gdbserver, and you’ll have a somewhat interactive debugger
59where you can set breakpoints in your source windows, have panes for watches, locals, and the call
60stack, etc. Enjoy:
61
62![VS Code Debugger Screenshot](../android_gdb.png)
63