diff --git a/br-ext/configs/gdbserver.conf b/br-ext/configs/gdbserver.conf new file mode 100644 index 0000000000000000000000000000000000000000..726736af83f3ba886f34b236d3f3959e67dadb89 --- /dev/null +++ b/br-ext/configs/gdbserver.conf @@ -0,0 +1,6 @@ +BR2_ENABLE_DEBUG=y +BR2_PACKAGE_GDB=y +BR2_PACKAGE_HOST_GDB=y +BR2_TOOLCHAIN_BUILDROOT_CXX=y +BR2_TOOLCHAIN_BUILDROOT_GLIBC=y +BR2_PACKAGE_GLIBC=y diff --git a/br-ext/configs/toolchain-br b/br-ext/configs/toolchain-br new file mode 100644 index 0000000000000000000000000000000000000000..c617d08fdcd2ee850c5b4ad95569b159ea2e63f0 --- /dev/null +++ b/br-ext/configs/toolchain-br @@ -0,0 +1,3 @@ +BR2_TOOLCHAIN_BUILDROOT=y +BR2_GCC_VERSION_6_X=y +BR2_KERNEL_HEADERS_4_10=y diff --git a/common.mk b/common.mk index f4232f96578749f6ef2367b7f4a804995027de13..c170f0b5eba4b4ed4ade483d2ccd2ca22f80e468 100644 --- a/common.mk +++ b/common.mk @@ -183,11 +183,17 @@ busybox-cleaner-common: # Build root ################################################################################ BUILDROOT_ARCH=aarch$(COMPILE_NS_USER) +ifeq ($(GDBSERVER),y) +BUILDROOT_TOOLCHAIN=toolchain-br # Use toolchain supplied by buildroot +DEFCONFIG_GDBSERVER=--br-defconfig build/br-ext/configs/gdbserver.conf +else +# Local toolchains (downloaded by "make toolchains") ifeq ($(COMPILE_LEGACY),) BUILDROOT_TOOLCHAIN=toolchain-aarch$(COMPILE_NS_USER) else BUILDROOT_TOOLCHAIN=toolchain-aarch$(COMPILE_NS_USER)-legacy endif +endif BUILDROOT_GETTY_PORT ?= \ $(if $(CFG_NW_CONSOLE_UART),ttyAMA$(CFG_NW_CONSOLE_UART),ttyAMA0) .PHONY: buildroot @@ -230,6 +236,7 @@ endif --br-defconfig build/br-ext/configs/optee_$(BUILDROOT_ARCH) \ --br-defconfig build/br-ext/configs/optee_generic \ --br-defconfig build/br-ext/configs/$(BUILDROOT_TOOLCHAIN) \ + $(DEFCONFIG_GDBSERVER) \ --br-defconfig out-br/extra.conf \ --make-cmd $(MAKE)) @$(MAKE) -C ../out-br all @@ -306,8 +313,12 @@ QEMU_EXTRA_ARGS +=\ -device virtio-9p-device,fsdev=fsdev0,mount_tag=host endif +ifeq ($(GDBSERVER),y) +HOSTFWD := ,hostfwd=tcp::12345-:12345 +endif # Enable QEMU SLiRP user networking -QEMU_EXTRA_ARGS += -netdev user,id=vmnic -device virtio-net-device,netdev=vmnic +QEMU_EXTRA_ARGS +=\ + -netdev user,id=vmnic$(HOSTFWD) -device virtio-net-device,netdev=vmnic define run-help @echo diff --git a/docs/qemu.md b/docs/qemu.md index f1cdc2c3b9126e1a36b4ebce85abc056dd324924..0d3f6123636eb5fcf859c70ede1bf8569965aa92 100644 --- a/docs/qemu.md +++ b/docs/qemu.md @@ -53,6 +53,38 @@ gateway to the host network [SLiRP]. Please note that ICMP won't work in the guest unless additional configuration is made, so the `ping` utility won't work. +# 6. Remote debugging of Normal World applications +If you need to debug a client application, using GDB in a remote debugging +configuration may be useful. Remote debugging means `gdb` runs on your PC, where +it can access the source code, while the program being debugged runs on the remote +system (in this case, in the QEMU environment in normal world). +Here is how to do that. On your PC, build with `GDBSERVER=y`: +``` +$ cd build +$ make -j8 run GDBSERVER=y +[...] +(qemu) c +``` +Inside QEMU, run your application with gdbserver (for example `xtest 4002`): +``` +# gdbserver :12345 xtest 4002 +Process xtest created; pid = 654 +Listening on port 12345 + +``` +Back on your PC, in another terminal, start GDB and connect to the target: +``` +$ ../out-br/host/bin/arm-buildroot-linux-gnueabihf-gdb +(gdb) set sysroot ../out-br/host/arm-buildroot-linux-gnueabihf/sysroot +(gdb) target remote :12345 +``` +Now GDB is connected to the remote application. You may use GDB normally. +``` +(gdb) b main +(gdb) c +etc. +``` + [bios]: https://github.com/linaro-swg/bios_qemu_tz_arm [README.md]: ../README.md [SLiRP]: https://wiki.qemu.org/Documentation/Networking#User_Networking_.28SLIRP.29