build: use target 'debugserver' for Qemu debugging

Use the existing debugserver target also for Qemu debugging. Qemu
should be maintained as one of many emulation/simulations platforms and
emulation should be abstracted in the Makefiles and not tied to Qemu.

qemugdb will still work, it is however being deprecated.

Change-Id: I0cd10fb66debb939b8f7f1304bf2ef4605da6a1d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2017-01-07 13:22:21 -05:00 committed by Anas Nashif
commit 6d9ed994aa
16 changed files with 89 additions and 38 deletions

View file

@ -1138,6 +1138,7 @@ help:
@echo ' qemugdb - Same as 'qemu' but start a GDB server on port 1234' @echo ' qemugdb - Same as 'qemu' but start a GDB server on port 1234'
@echo ' flash - Build and flash an application' @echo ' flash - Build and flash an application'
@echo ' debug - Build and debug an application using GDB' @echo ' debug - Build and debug an application using GDB'
@echo ' debugserver - Build and start a GDB server (port 1234 for Qemu targets)'
@echo ' ram_report - Build and create RAM usage report' @echo ' ram_report - Build and create RAM usage report'
@echo ' rom_report - Build and create ROM usage report' @echo ' rom_report - Build and create ROM usage report'
@echo '' @echo ''
@ -1256,22 +1257,25 @@ qemu: zephyr
$(if $(CONFIG_X86_IAMCU),python $(ZEPHYR_BASE)/scripts/qemu-machine-hack.py $(KERNEL_ELF_NAME)) $(if $(CONFIG_X86_IAMCU),python $(ZEPHYR_BASE)/scripts/qemu-machine-hack.py $(KERNEL_ELF_NAME))
$(Q)$(QEMU) $(QEMU_FLAGS) $(QEMU_EXTRA_FLAGS) -kernel $(KERNEL_ELF_NAME) $(Q)$(QEMU) $(QEMU_FLAGS) $(QEMU_EXTRA_FLAGS) -kernel $(KERNEL_ELF_NAME)
qemugdb: QEMU_EXTRA_FLAGS += -s -S # FIXME: Deprecated
qemugdb: qemu qemugdb: debugserver
-include $(srctree)/boards/$(ARCH)/$(BOARD_NAME)/Makefile.board -include $(srctree)/boards/$(ARCH)/$(BOARD_NAME)/Makefile.board
ifneq ($(FLASH_SCRIPT),) ifneq ($(FLASH_SCRIPT),)
flash: zephyr flash: zephyr
@echo "Flashing $(BOARD_NAME)" @echo "Flashing $(BOARD_NAME)"
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/support/$(FLASH_SCRIPT) flash $(Q)$(CONFIG_SHELL) $(srctree)/scripts/support/$(FLASH_SCRIPT) flash
debug: zephyr
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/support/$(FLASH_SCRIPT) debug
else else
flash: FORCE flash: FORCE
@echo Flashing not supported with this board. @echo Flashing not supported with this board.
@echo Please check the documentation for alternate instructions. @echo Please check the documentation for alternate instructions.
endif
ifneq ($(DEBUG_SCRIPT),)
debug: zephyr
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/support/$(DEBUG_SCRIPT) debug
else
debug: FORCE debug: FORCE
@echo Debugging not supported with this board. @echo Debugging not supported with this board.
@echo Please check the documentation for alternate instructions. @echo Please check the documentation for alternate instructions.

View file

@ -83,18 +83,19 @@ all: $(DOTCONFIG)
ifeq ($(findstring qemu_,$(BOARD)),) ifeq ($(findstring qemu_,$(BOARD)),)
qemu: qemu:
@echo "Emulation not available for this platform" @echo "Emulation not available for this board."
qemugdb: qemu qemugdb: qemu
else else
qemu: $(DOTCONFIG) qemu: $(DOTCONFIG)
$(Q)$(call zephyrmake,$(O),$@) $(Q)$(call zephyrmake,$(O),$@)
qemugdb: $(DOTCONFIG) qemugdb: debugserver
$(Q)$(call zephyrmake,$(O),$@) @echo "This target is deprecated, please use debugserver instead"
endif endif
debug: $(DOTCONFIG) debug: $(DOTCONFIG)
$(Q)$(call zephyrmake,$(O),$@) $(Q)$(call zephyrmake,$(O),$@)
flash: $(DOTCONFIG) flash: $(DOTCONFIG)
$(Q)$(call zephyrmake,$(O),$@) $(Q)$(call zephyrmake,$(O),$@)
@ -105,8 +106,9 @@ ARCH = $(notdir $(subst /$(BOARD),,$(wildcard $(ZEPHYR_BASE)/boards/*/$(BOARD)))
BOARD_NAME = $(BOARD) BOARD_NAME = $(BOARD)
export BOARD_NAME export BOARD_NAME
endif endif
debugserver: FORCE debugserver: FORCE
$(Q)$(CONFIG_SHELL) $(ZEPHYR_BASE)/scripts/support/$(FLASH_SCRIPT) debugserver $(Q)$(CONFIG_SHELL) $(ZEPHYR_BASE)/scripts/support/$(DEBUG_SCRIPT) debugserver
initconfig outputexports: $(DOTCONFIG) initconfig outputexports: $(DOTCONFIG)

View file

@ -1,4 +1,6 @@
FLASH_SCRIPT = openocd.sh FLASH_SCRIPT = openocd.sh
DEBUG_SCRIPT = openocd.sh
OPENOCD_PRE_CMD = "-c targets 1" OPENOCD_PRE_CMD = "-c targets 1"
OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} $(CONFIG_FLASH_BASE_ADDRESS)" OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} $(CONFIG_FLASH_BASE_ADDRESS)"
OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} $(CONFIG_FLASH_BASE_ADDRESS)" OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} $(CONFIG_FLASH_BASE_ADDRESS)"

View file

@ -1,4 +1,5 @@
FLASH_SCRIPT = openocd.sh FLASH_SCRIPT = openocd.sh
DEBUG_SCRIPT = openocd.sh
OPENOCD_PRE_CMD = "-c targets 1" OPENOCD_PRE_CMD = "-c targets 1"
OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} $(CONFIG_FLASH_BASE_ADDRESS)" OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} $(CONFIG_FLASH_BASE_ADDRESS)"
OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} $(CONFIG_FLASH_BASE_ADDRESS)" OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} $(CONFIG_FLASH_BASE_ADDRESS)"

View file

@ -1,4 +1,5 @@
FLASH_SCRIPT = openocd.sh FLASH_SCRIPT = openocd.sh
DEBUG_SCRIPT = openocd.sh
OPENOCD_LOAD_CMD = "flash write_image erase ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}" OPENOCD_LOAD_CMD = "flash write_image erase ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}"
OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}" OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}"

View file

@ -1,4 +1,5 @@
FLASH_SCRIPT = openocd.sh FLASH_SCRIPT = openocd.sh
DEBUG_SCRIPT = openocd.sh
OPENOCD_LOAD_CMD = "flash write_image erase ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}" OPENOCD_LOAD_CMD = "flash write_image erase ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}"
OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}" OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}"

View file

@ -1,4 +1,5 @@
FLASH_SCRIPT = openocd.sh FLASH_SCRIPT = openocd.sh
DEBUG_SCRIPT = openocd.sh
OPENOCD_LOAD_CMD = "flash write_image erase ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}" OPENOCD_LOAD_CMD = "flash write_image erase ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}"
OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}" OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}"

View file

@ -0,0 +1,5 @@
DEBUG_SCRIPT = qemu.sh
debugserver: QEMU_EXTRA_FLAGS += -s -S
debugserver: qemu

View file

@ -1,2 +1,3 @@
FLASH_SCRIPT = nios2.sh FLASH_SCRIPT = nios2.sh
DEBUG_SCRIPT = nios2.sh

View file

@ -1,2 +1,5 @@
FLASH_SCRIPT = nios2.sh
DEBUG_SCRIPT = qemu.sh
debugserver: QEMU_EXTRA_FLAGS += -s -S
debugserver: qemu

View file

@ -1,4 +1,5 @@
FLASH_SCRIPT = openocd.sh FLASH_SCRIPT = openocd.sh
DEBUG_SCRIPT = openocd.sh
OPENOCD_PRE_CMD = "-c targets 1" OPENOCD_PRE_CMD = "-c targets 1"
OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}" OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}"
OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}" OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}"

View file

@ -0,0 +1,5 @@
DEBUG_SCRIPT = qemu.sh
debugserver: QEMU_EXTRA_FLAGS += -s -S
debugserver: qemu

View file

@ -1,4 +1,5 @@
FLASH_SCRIPT = openocd.sh FLASH_SCRIPT = openocd.sh
DEBUG_SCRIPT = openocd.sh
OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}" OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}"
OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}" OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}"

View file

@ -1,4 +1,5 @@
FLASH_SCRIPT = openocd.sh FLASH_SCRIPT = openocd.sh
DEBUG_SCRIPT = openocd.sh
OPENOCD_PRE_CMD = "-c targets 1" OPENOCD_PRE_CMD = "-c targets 1"
OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}" OPENOCD_LOAD_CMD = "load_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}"
OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}" OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_PHYS_LOAD_ADDR}"

View file

@ -678,55 +678,54 @@ application with QEMU. Most content in this section is already covered on
.. _GNU_Debugger: http://www.gnu.org/software/gdb .. _GNU_Debugger: http://www.gnu.org/software/gdb
In this quick reference you find shortcuts, specific environmental variables In this quick reference you find shortcuts, specific environmental variables and
and parameters that can help you to quickly set up your debugging parameters that can help you to quickly set up your debugging environment.
environment.
The simplest way to debug an application running in QEMU is using the GNU The simplest way to debug an application running in QEMU is using the GNU
Debugger and setting a local GDB server in your development system Debugger and setting a local GDB server in your development system through QEMU.
through QEMU.
You will need an ELF binary image for debugging purposes. You will need an ELF binary image for debugging purposes. The build system
The build system generates the image in the output directory. generates the image in the output directory. By default, the kernel binary name
By default, the kernel binary name is :file:`zephyr.elf`. The name can be is :file:`zephyr.elf`. The name can be changed using a Kconfig option.
changed using a Kconfig option.
We will use the standard 1234 TCP port to open a :abbr:`GDB (GNU Debugger)` We will use the standard 1234 TCP port to open a :abbr:`GDB (GNU Debugger)`
server instance. This port number can be changed for a port that best suits the server instance. This port number can be changed for a port that best suits the
development system. development environment.
QEMU is the supported emulation system of the kernel. QEMU must be invoked You can run Qemu to listen for a "gdb connection" before it starts executing any
with the -s and -S options. code to debug it.
.. code-block:: bash
qemu -s -S <image>
will setup Qemu to listen on port 1234 and wait for a GDB connection to it.
The options used above have the following meaning:
* ``-S`` Do not start CPU at startup; rather, you must type 'c' in the * ``-S`` Do not start CPU at startup; rather, you must type 'c' in the
monitor. monitor.
* ``-s`` Shorthand for :literal:`-gdb tcp::1234`: open a GDB server on * ``-s`` Shorthand for :literal:`-gdb tcp::1234`: open a GDB server on
TCP port 1234. TCP port 1234.
The build system can build the elf binary and call the QEMU process with To debug with QEMU and to start a GDB server and wait for a remote connect, run
the :makevar:`qemu` target. The QEMU debug options can be set using the the following inside an application:
environment variable :envvar:`QEMU_EXTRA_FLAGS`. To set the ``-s`` and
``-S`` options:
.. code-block:: bash .. code-block:: bash
export QEMU_EXTRA_FLAGS="-s -S" make BOARD=qemu_x86 debugserver
The build and emulation processes are called with the Makefile ``qemu``
target:
.. code-block:: bash
make qemu
The build system will start a QEMU instance with the CPU halted at startup The build system will start a QEMU instance with the CPU halted at startup
and with a GDB server instance listening at the TCP port 1234. and with a GDB server instance listening at the TCP port 1234.
The :file:`.gdbinit` will help initialize your GDB instance on every run. Using a local GDB configuration :file:`.gdbinit` can help initialize your GDB
instance on every run.
In this example, the initialization file points to the GDB server instance. In this example, the initialization file points to the GDB server instance.
It configures a connection to a remote target at the local host on the TCP It configures a connection to a remote target at the local host on the TCP
port 1234. The initialization sets the kernel's root directory as a port 1234. The initialization sets the kernel's root directory as a
reference. The :file:`.gdbinit` file contains the following lines: reference.
The :file:`.gdbinit` file contains the following lines:
.. code-block:: bash .. code-block:: bash
@ -746,14 +745,21 @@ corresponds to :file:`zephyr.elf` file:
.. code-block:: bash .. code-block:: bash
gdb --tui zephyr.elf $ gdb --tui zephyr.elf
.. note:: .. note::
The GDB version on the development system might not support the --tui The GDB version on the development system might not support the --tui
option. option.
Finally, this command connects to the GDB server using the Data If you are not using a .gdbinit file, issue the following command inside GDB to
connect to the remove GDB server on port 1234:
.. code-block:: bash
(gdb) target remote localhost:1234
Finally, The command below connects to the GDB server using the Data
Displayer Debugger (:file:`ddd`). The command loads the symbol table from the Displayer Debugger (:file:`ddd`). The command loads the symbol table from the
elf binary file, in this instance, the :file:`zephyr.elf` file. elf binary file, in this instance, the :file:`zephyr.elf` file.

16
scripts/support/qemu.sh Executable file
View file

@ -0,0 +1,16 @@
#!/bin/sh
# Just a place holder for any custimizations.
do_debugserver() {
echo "Detached GDB server"
}
CMD="$1"
shift
case "${CMD}" in
debugserver)
do_debugserver "$@"
;;
esac