Skip to content

Commit 8abb8f7

Browse files
committed
tracing: add semihosting backend
Using semihosting on supported architectures (arm, xtensa, riscv) it now possible to generate tracing giles easily and without being restricted by size. Using qemu for example, it is now possible to generate the tracing file simply by running: west build -p -b mps2/an385 tests/kernel/msgq/msgq_api/ \ -t run --snippet semihost-tracing This will generate a tracing file in the build/ directory which can be viewed with babeltrace. Signed-off-by: Anas Nashif <[email protected]>
1 parent 27c7cea commit 8abb8f7

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

subsys/tracing/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ zephyr_sources_ifdef(
2222
tracing_backend_usb.c
2323
)
2424

25+
zephyr_sources_ifdef(
26+
CONFIG_TRACING_BACKEND_SEMIHOST
27+
tracing_backend_semihosting.c
28+
)
29+
2530
zephyr_sources_ifdef(
2631
CONFIG_TRACING_BACKEND_UART
2732
tracing_backend_uart.c

subsys/tracing/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ config TRACING_BACKEND_RAM
159159
be dumped to a file at runtime with a debugger.
160160
See gdb dump binary memory documentation for example.
161161

162+
config TRACING_BACKEND_SEMIHOST
163+
bool "Semihost backend"
164+
depends on SEMIHOST
165+
help
166+
Use semihosting to output tracing data. This is useful
167+
for debugging on a host machine, such as when using QEMU.
168+
162169
config TRACING_BACKEND_ADSP_MEMORY_WINDOW
163170
bool "Memory window in RAM"
164171
depends on SOC_FAMILY_INTEL_ADSP
@@ -174,6 +181,7 @@ config TRACING_BACKEND_NAME
174181
default "tracing_backend_usb" if TRACING_BACKEND_USB
175182
default "tracing_backend_posix" if TRACING_BACKEND_POSIX
176183
default "tracing_backend_ram" if TRACING_BACKEND_RAM
184+
default "tracing_backend_semihost" if TRACING_BACKEND_SEMIHOST
177185
default "tracing_backend_adsp_memory_window" if TRACING_BACKEND_ADSP_MEMORY_WINDOW
178186

179187
config RAM_TRACING_BUFFER_SIZE
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2021 IoT.bzh
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <ctype.h>
8+
#include <zephyr/kernel.h>
9+
#include <tracing_core.h>
10+
#include <tracing_backend.h>
11+
#include <zephyr/arch/common/semihost.h>
12+
13+
static int tracing_fd = -1;
14+
15+
static void tracing_backend_semihost_output(
16+
const struct tracing_backend *backend,
17+
uint8_t *data, uint32_t length)
18+
{
19+
semihost_write(tracing_fd, data, length);
20+
}
21+
22+
static void tracing_backend_semihost_init(void)
23+
{
24+
const char *tracing_file = "./tracing.bin";
25+
tracing_fd = semihost_open(tracing_file, SEMIHOST_OPEN_AB_PLUS);
26+
__ASSERT(tracing_fd >= 0, "semihost_open() returned %d", tracing_fd);
27+
if (tracing_fd < 0) {
28+
k_panic();
29+
}
30+
}
31+
32+
const struct tracing_backend_api tracing_backend_semihost_api = {
33+
.init = tracing_backend_semihost_init,
34+
.output = tracing_backend_semihost_output
35+
};
36+
37+
TRACING_BACKEND_DEFINE(tracing_backend_semihost, tracing_backend_semihost_api);

0 commit comments

Comments
 (0)