samples: debug: Add a simple gdbstub sample
Sample example built with gdbstub enabled. Two serials are used, one for normal output and another one that is used talk with gdb in the host machine. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
5408f3102d
commit
179e184e30
12
samples/debug/gdbstub/CMakeLists.txt
Normal file
12
samples/debug/gdbstub/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.13.1)
|
||||||
|
|
||||||
|
if(BOARD MATCHES "qemu_x86")
|
||||||
|
list(APPEND QEMU_EXTRA_FLAGS -serial tcp:127.0.0.1:1234,server)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(debug)
|
||||||
|
|
||||||
|
target_sources(app PRIVATE src/main.c)
|
31
samples/debug/gdbstub/README.rst
Normal file
31
samples/debug/gdbstub/README.rst
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
.. _debug_sample:
|
||||||
|
|
||||||
|
Debug Sample
|
||||||
|
############
|
||||||
|
|
||||||
|
Overview
|
||||||
|
********
|
||||||
|
|
||||||
|
A simple sample that can be used with qemu to show debug using gdb
|
||||||
|
remote serial protocol capabilities.
|
||||||
|
|
||||||
|
Building and Running
|
||||||
|
********************
|
||||||
|
|
||||||
|
This application can be built and executed on QEMU as follows:
|
||||||
|
|
||||||
|
.. zephyr-app-commands::
|
||||||
|
:zephyr-app: samples/debug
|
||||||
|
:host-os: unix
|
||||||
|
:board: qemu_x86
|
||||||
|
:goals: run
|
||||||
|
:compact:
|
||||||
|
|
||||||
|
Open a new terminal and use gdb to connect to the running qemu as follows:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
gdb build/zephyr/zephyr.elf
|
||||||
|
(gdb) target remote :1234
|
||||||
|
|
||||||
|
Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
|
4
samples/debug/gdbstub/prj.conf
Normal file
4
samples/debug/gdbstub/prj.conf
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
CONFIG_GDBSTUB=y
|
||||||
|
CONFIG_GDBSTUB_SERIAL_BACKEND_NAME="UART_1"
|
||||||
|
CONFIG_NO_OPTIMIZATIONS=y
|
||||||
|
CONFIG_USERSPACE=y
|
17
samples/debug/gdbstub/run.gdbinit
Normal file
17
samples/debug/gdbstub/run.gdbinit
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
set pagination off
|
||||||
|
symbol-file zephyr/zephyr.elf
|
||||||
|
target remote 127.0.0.1:1234
|
||||||
|
b test
|
||||||
|
b main.c:33
|
||||||
|
c
|
||||||
|
|
||||||
|
s
|
||||||
|
set var a = 2
|
||||||
|
c
|
||||||
|
if ret == 6
|
||||||
|
printf "PASSED\n"
|
||||||
|
quit 0
|
||||||
|
else
|
||||||
|
printf "FAILED\n"
|
||||||
|
quit 1
|
||||||
|
end
|
13
samples/debug/gdbstub/sample.yaml
Normal file
13
samples/debug/gdbstub/sample.yaml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020 intel Corporation.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
sample:
|
||||||
|
name: gdbstub sample
|
||||||
|
tests:
|
||||||
|
sample.debug.gdbstub:
|
||||||
|
build_only: true
|
||||||
|
platform_allow: qemu_x86
|
||||||
|
tags: debug
|
37
samples/debug/gdbstub/src/main.c
Normal file
37
samples/debug/gdbstub/src/main.c
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Intel Corporation.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr.h>
|
||||||
|
#include <sys/printk.h>
|
||||||
|
|
||||||
|
#define STACKSIZE 512
|
||||||
|
|
||||||
|
static int test(void)
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
|
||||||
|
a = 10;
|
||||||
|
b = a * 2;
|
||||||
|
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void thread_entry(void *p1, void *p2, void *p3)
|
||||||
|
{
|
||||||
|
printk("Hello from user thread!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = test();
|
||||||
|
printk("%d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
K_THREAD_DEFINE(thread, STACKSIZE, thread_entry, NULL, NULL, NULL,
|
||||||
|
7, K_USER, 0);
|
10
samples/debug/index.rst
Normal file
10
samples/debug/index.rst
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
.. _debug-samples:
|
||||||
|
|
||||||
|
Debug Samples
|
||||||
|
#################
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 1
|
||||||
|
:glob:
|
||||||
|
|
||||||
|
**/*
|
|
@ -27,6 +27,7 @@ Samples and Demos
|
||||||
scheduler/*
|
scheduler/*
|
||||||
smp/*
|
smp/*
|
||||||
tfm_integration/tfm_integration.rst
|
tfm_integration/tfm_integration.rst
|
||||||
|
debug/*
|
||||||
|
|
||||||
.. comment
|
.. comment
|
||||||
To add a new sample document, please use the template available under
|
To add a new sample document, please use the template available under
|
||||||
|
|
Loading…
Reference in a new issue