Skip to content

Commit b8380a9

Browse files
author
Alex J Lennon
committed
test(zephyr): multi-printf app + E2E step/next + gdbserver log asserts
- scripts/zephyr_multi_printf_app: three RSGDB_E2E printf lines - e2e: west -s in-repo app, break line 9, next x2, grep log for line 1/2 - set debuginfod off in gdb batch; capture gdbserver stdout to file Made-with: Cursor
1 parent e297f7c commit b8380a9

6 files changed

Lines changed: 70 additions & 29 deletions

File tree

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ To debug a **real Zephyr app** (still RSP/gdbserver) without QEMU or hardware, b
6969

7070
Requires a full [Zephyr west workspace](https://docs.zephyrproject.org/latest/develop/getting_started/index.html) (`ZEPHYR_WORKSPACE` with `.west/` and `zephyr/`). See [native_sim](https://docs.zephyrproject.org/latest/boards/native/native_sim/doc/index.html). The script builds **`native_sim/native/64`** by default (LP64 host binary); the plain `native_sim` target is 32-bit and needs multilib on x86_64.
7171

72+
The app under **`scripts/zephyr_multi_printf_app/`** (in this repo) has three `printf` lines with markers `RSGDB_E2E line 1``3`. The E2E script sets a breakpoint on the **first** `printf`, runs **`next`** twice, and asserts **`RSGDB_E2E line 1`** and **`line 2`** appear in the **gdbserver** log (inferior stdout). Override the app path with **`ZEPHYR_APP_SOURCE_DIR`** if needed.
73+
7274
```bash
7375
export ZEPHYR_WORKSPACE=/path/to/zephyrproject
7476
cargo build --release

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ rsgdb/
216216
├── tests/ # Integration tests
217217
├── scripts/validate_local.sh
218218
├── scripts/e2e_gdb_smoke.sh # gdbserver → rsgdb → gdb (batch); CI E2E job
219-
├── scripts/e2e_zephyr_native_sim.sh # optional: west build native_sim → same chain
219+
├── scripts/e2e_zephyr_native_sim.sh # optional: west build native_sim + multi-printf stepping test
220+
├── scripts/zephyr_multi_printf_app/ # tiny Zephyr app for that script (west -s)
220221
├── rsgdb.toml.example
221222
└── .github/workflows/
222223
```

scripts/e2e_zephyr_native_sim.sh

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env bash
2-
# Build Zephyr hello_world for native_sim (runs as a normal Linux process), then:
3-
# gdbserver -> rsgdb -> GDB (batch).
4-
#
5-
# Use this to exercise rsgdb against a real embedded-style ELF without hardware.
2+
# Build a tiny Zephyr app (scripts/zephyr_multi_printf_app) for native_sim, then:
3+
# gdbserver -> rsgdb -> GDB (batch): break first printf, next, next; check RSGDB_E2E log lines.
64
#
75
# Prerequisites (host):
86
# - Zephyr west workspace with SDK / toolchain (Getting Started guide).
@@ -13,11 +11,11 @@
1311
# ./scripts/e2e_zephyr_native_sim.sh
1412
#
1513
# Optional:
16-
# ZEPHYR_APP=zephyr/samples/hello_world (path relative to workspace root)
17-
# ZEPHYR_BOARD=native_sim/native/64 (default: 64-bit LP64 — works on typical x86_64 Linux without gcc-multilib)
18-
# RSGDB, GDB_PORT, PROXY_PORT — same as e2e_gdb_smoke.sh
14+
# ZEPHYR_APP_SOURCE_DIR=/abs/path/to/app (west -s; default: rsgdb/scripts/zephyr_multi_printf_app)
15+
# ZEPHYR_BOARD=native_sim/native/64
16+
# RSGDB, GDB_PORT, PROXY_PORT
1917
#
20-
# CI: not run by default (heavy); set RUN_E2E_ZEPHYR_NATIVE=1 in validate_local.sh locally.
18+
# CI: not run by default; set RUN_E2E_ZEPHYR_NATIVE=1 in validate_local.sh locally.
2119
set -euo pipefail
2220

2321
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -47,26 +45,34 @@ for cmd in gdb gdbserver west; do
4745
fi
4846
done
4947

50-
# native_sim links with host gcc; ensure a C compiler exists for the Zephyr build.
5148
if ! command -v gcc >/dev/null 2>&1 && ! command -v clang >/dev/null 2>&1; then
5249
echo "error: need a host C compiler (gcc or clang) for native_sim." >&2
5350
exit 1
5451
fi
5552

56-
ZEPHYR_APP="${ZEPHYR_APP:-zephyr/samples/hello_world}"
57-
# Default board is 64-bit native_sim so linking does not require 32-bit multilib (-m32 + libgcc).
53+
ZEPHYR_APP_SOURCE_DIR="${ZEPHYR_APP_SOURCE_DIR:-$ROOT/scripts/zephyr_multi_printf_app}"
5854
ZEPHYR_BOARD="${ZEPHYR_BOARD:-native_sim/native/64}"
55+
# First printf() in zephyr_multi_printf_app/src/main.c (keep in sync with that file).
56+
FIRST_PRINTF_LINE=9
57+
58+
APP_MAIN_SRC="$ZEPHYR_APP_SOURCE_DIR/src/main.c"
59+
if [[ ! -f "$APP_MAIN_SRC" ]]; then
60+
echo "error: missing $APP_MAIN_SRC" >&2
61+
exit 1
62+
fi
63+
5964
WORKDIR="$(mktemp -d)"
6065
trap 'rm -rf "$WORKDIR"; kill ${RSGDB_PID:-0} ${GDBSERVER_PID:-0} 2>/dev/null || true' EXIT
6166

6267
GDB_PORT="${GDB_PORT:-13335}"
6368
PROXY_PORT="${PROXY_PORT:-13336}"
6469
BUILD_DIR="$WORKDIR/native_sim_build"
70+
GDBSERVER_LOG="$WORKDIR/gdbserver.log"
6571

66-
echo "==> west build -b $ZEPHYR_BOARD (first run can take several minutes)"
72+
echo "==> west build -b $ZEPHYR_BOARD -s $ZEPHYR_APP_SOURCE_DIR (first run can take several minutes)"
6773
(
6874
cd "$ZEPHYR_WORKSPACE"
69-
west build -b "$ZEPHYR_BOARD" -p auto -d "$BUILD_DIR" "$ZEPHYR_APP" -- \
75+
west build -b "$ZEPHYR_BOARD" -p auto -d "$BUILD_DIR" -s "$ZEPHYR_APP_SOURCE_DIR" -- \
7076
-DCONFIG_NO_OPTIMIZATIONS=y
7177
)
7278

@@ -95,8 +101,8 @@ wait_listen() {
95101
return 1
96102
}
97103

98-
echo "==> gdbserver 127.0.0.1:$GDB_PORT (Zephyr native_sim zephyr.exe)"
99-
gdbserver "127.0.0.1:$GDB_PORT" "$ZEPHYR_EXE" &
104+
echo "==> gdbserver 127.0.0.1:$GDB_PORT (log: $GDBSERVER_LOG)"
105+
gdbserver "127.0.0.1:$GDB_PORT" "$ZEPHYR_EXE" >"$GDBSERVER_LOG" 2>&1 &
100106
GDBSERVER_PID=$!
101107
wait_listen "$GDB_PORT"
102108

@@ -105,33 +111,42 @@ echo "==> rsgdb :$PROXY_PORT -> 127.0.0.1:$GDB_PORT"
105111
RSGDB_PID=$!
106112
wait_listen "$PROXY_PORT"
107113

108-
# hello_world sample: printf is on line 11 of src/main.c (see Zephyr tree).
109-
HELLO_SRC="$ZEPHYR_WORKSPACE/zephyr/samples/hello_world/src/main.c"
110-
if [[ ! -f "$HELLO_SRC" ]]; then
111-
echo "error: expected $HELLO_SRC (hello_world sample)" >&2
112-
exit 1
113-
fi
114-
115-
echo "==> gdb batch (host gdb — breakpoint on hello_world printf line)"
114+
echo "==> gdb batch: break first printf (line $FIRST_PRINTF_LINE), continue, next, next"
116115
OUT=$(gdb -nx --batch \
117116
-ex "set pagination off" \
117+
-ex "set debuginfod enabled off" \
118118
-ex "target extended-remote 127.0.0.1:$PROXY_PORT" \
119-
-ex "break \"$HELLO_SRC\":11" \
119+
-ex "break \"$APP_MAIN_SRC\":$FIRST_PRINTF_LINE" \
120120
-ex "continue" \
121-
-ex "list" \
121+
-ex "next" \
122+
-ex "next" \
122123
-ex "quit" \
123124
"$ZEPHYR_EXE" 2>&1) || true
124125

126+
echo "--- gdb output ---"
125127
echo "$OUT"
128+
echo "--- gdbserver / inferior log ($GDBSERVER_LOG) ---"
129+
cat "$GDBSERVER_LOG"
130+
echo "--- end logs ---"
126131

127132
if ! echo "$OUT" | grep -qE 'Breakpoint|Temporary breakpoint'; then
128133
echo "error: expected GDB to set a breakpoint" >&2
129134
exit 1
130135
fi
131136

132-
if ! echo "$OUT" | grep -qE 'hello_world/src/main\.c:11|main\.c:11'; then
133-
echo "error: expected GDB to stop at hello_world/src/main.c line 11 (printf)" >&2
137+
if ! echo "$OUT" | grep -qF "main.c:$FIRST_PRINTF_LINE"; then
138+
echo "error: expected GDB to reference main.c:$FIRST_PRINTF_LINE" >&2
139+
exit 1
140+
fi
141+
142+
if ! grep -qF 'RSGDB_E2E line 1' "$GDBSERVER_LOG"; then
143+
echo "error: expected inferior log to contain RSGDB_E2E line 1 (after first next)" >&2
144+
exit 1
145+
fi
146+
147+
if ! grep -qF 'RSGDB_E2E line 2' "$GDBSERVER_LOG"; then
148+
echo "error: expected inferior log to contain RSGDB_E2E line 2 (after second next)" >&2
134149
exit 1
135150
fi
136151

137-
echo "==> OK — Zephyr native_sim debug session through rsgdb succeeded."
152+
echo "==> OK — Zephyr native_sim stepped printfs through rsgdb; log markers matched."
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Minimal Zephyr app for rsgdb E2E (native_sim). Built with:
3+
# west build -b native_sim/native/64 -s /path/to/zephyr_multi_printf_app
4+
5+
cmake_minimum_required(VERSION 3.20.0)
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7+
project(multi_printf_rsgdb)
8+
9+
target_sources(app PRIVATE src/main.c)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Intentionally minimal; native_sim picks up console + libc for printf.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* rsgdb E2E: multiple printf lines — GDB breaks on first, steps over the next.
4+
*/
5+
#include <stdio.h>
6+
7+
int main(void)
8+
{
9+
printf("RSGDB_E2E line 1\n");
10+
printf("RSGDB_E2E line 2\n");
11+
printf("RSGDB_E2E line 3\n");
12+
return 0;
13+
}

0 commit comments

Comments
 (0)