1# Debugging guest kernels with gdb
2
3Note: this feature is only available on android14-5.15 and newer host kernels.
4
5Starting with Android U it is possible to attach a gdb to the guest kernel, when
6starting a debuggable and non-protected guest VM.
7
8You can do this by passing `--gdb <port>` argument to the `vm run`, `vm run-app`
9and `vm run-microdroid` commands. The `crosvm` will start the gdb server on the
10provided port. It will wait for the gdb client to connect to it before
11proceeding with the VM boot.
12
13Here is an example invocation:
14
15```shell
16adb forward tcp:3456 tcp:3456
17adb shell /apex/com.android.virt/bin/vm run-microdroid --gdb 3456
18```
19
20Then in another shell:
21
22```shell
23gdb vmlinux
24(gdb) target remote :3456
25(gdb) hbreak start_kernel
26(gdb) c
27```
28
29The [kernel documentation](
30https://www.kernel.org/doc/html/latest/dev-tools/gdb-kernel-debugging.html) has
31some general techniques on how to debug kernel with gdb.
32
33## Obtaining vmlinux for Microdroid kernels
34
35If you are debugging Microdroid kernel that you have built [locally](
36../../microdroid/kernel/README.md), then look for `out/dist/vmlinux` in your
37kernel repository.
38
39If you are debugging Microdroid kernel bundled with the `com.android.virt` APEX,
40then you need to obtain the build ID of this kernel. You can do this by
41checking the prebuilt-info.txt file in the
42`packages/modules/Virtualization/microdroid/kernel/arm64` or
43`packages/modules/Virtualization/microdroid/kernel/x86_64` directories.
44
45Using that build ID you can download the vmlinux from the build server via:
46https://ci.android.com/builds/submitted/${BUILD_ID}/kernel_microdroid_aarch64/latest/vmlinux
47