Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 93 additions & 3 deletions apps/starry/gdb-smoke/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# StarryOS GDB Smoke

This app prepares a RISC-V Alpine rootfs overlay with guest `gdb`, `gdbserver`,
and tiny target programs for StarryOS user-space debugger smoke testing.
This app prepares an Alpine rootfs overlay with guest `gdb`, `gdbserver`, and
tiny target programs for StarryOS user-space debugger smoke testing. The native
GDB smoke and the single-process gdbserver smoke are available on riscv64,
aarch64, and loongarch64.

## Batch Native GDB Smoke

Expand All @@ -11,6 +13,18 @@ Use this command for the automated native GDB batch smoke:
cargo xtask starry app qemu -t gdb-smoke --arch riscv64
```

For the current aarch64 native GDB baseline:

```bash
cargo xtask starry app qemu -t gdb-smoke --arch aarch64
```

For the current LoongArch native GDB baseline:

```bash
cargo xtask starry app qemu -t gdb-smoke --arch loongarch64
```

The batch script runs:

```gdb
Expand Down Expand Up @@ -101,10 +115,28 @@ cargo xtask starry app qemu -t gdb-smoke --arch riscv64 \
--qemu-config qemu-riscv64-gdbserver.toml
```

For aarch64:

```bash
cargo xtask starry app qemu -t gdb-smoke --arch aarch64 \
--qemu-config qemu-aarch64-gdbserver.toml
```

For LoongArch:

```bash
cargo xtask starry app qemu -t gdb-smoke --arch loongarch64 \
--qemu-config qemu-loongarch64-gdbserver.toml
```

The default gdbserver script connects to `127.0.0.1:1234`, breaks on
`compute_value`, prints a backtrace, deletes the breakpoint, and continues the
remote target.

On LoongArch, gdbserver can print legacy regset warnings while probing
unsupported optional register paths. The single-process smoke still passes when
breakpoint, backtrace, continue, and target exit markers complete.

Remote pthread gdbserver coverage is opt-in because it is slower and exercises
the heavier clone/thread event path:

Expand Down Expand Up @@ -140,6 +172,20 @@ cargo xtask starry app qemu -t gdb-smoke --arch riscv64 \
--qemu-config qemu-riscv64-gdbserver-manual.toml
```

For aarch64:

```bash
cargo xtask starry app qemu -t gdb-smoke --arch aarch64 \
--qemu-config qemu-aarch64-gdbserver-manual.toml
```

For LoongArch:

```bash
cargo xtask starry app qemu -t gdb-smoke --arch loongarch64 \
--qemu-config qemu-loongarch64-gdbserver-manual.toml
```

When running through the long-lived Docker container, keep stdin and a TTY
attached:

Expand Down Expand Up @@ -168,8 +214,24 @@ gdb-multiarch -q -x apps/starry/gdb-smoke/gdbserver/host-manual.gdb \
target/gdb-smoke-host/gdbserver-smoke-target
```

For aarch64, use the architecture-specific script and symbol copy:

```bash
gdb-multiarch -q -x apps/starry/gdb-smoke/gdbserver/host-manual-aarch64.gdb \
target/gdb-smoke-host/aarch64/gdbserver-smoke-target
```

For LoongArch:

```bash
gdb-multiarch -q -x apps/starry/gdb-smoke/gdbserver/host-manual-loongarch64.gdb \
target/gdb-smoke-host/loongarch64/gdbserver-smoke-target
```

`host-manual.gdb` sets the riscv64 remote debugging defaults and connects to
`:1234`, but leaves you at the GDB prompt for manual commands.
`:1234`; `host-manual-aarch64.gdb` and `host-manual-loongarch64.gdb` do the
same for aarch64 and LoongArch. All scripts leave you at the GDB prompt for
manual commands.

Inside host GDB:

Expand All @@ -194,6 +256,20 @@ cargo xtask starry app qemu -t gdb-smoke --arch riscv64 \
--qemu-config qemu-riscv64-gdbserver-host.toml
```

For aarch64:

```bash
cargo xtask starry app qemu -t gdb-smoke --arch aarch64 \
--qemu-config qemu-aarch64-gdbserver-host.toml
```

For LoongArch:

```bash
cargo xtask starry app qemu -t gdb-smoke --arch loongarch64 \
--qemu-config qemu-loongarch64-gdbserver-host.toml
```

This automatic config starts guest `gdbserver` for you and is intended for
repeatable logs rather than manual interaction.

Expand All @@ -204,4 +280,18 @@ gdb-multiarch -q -batch -x apps/starry/gdb-smoke/gdbserver/host-remote.gdb \
target/gdb-smoke-host/gdbserver-smoke-target
```

For aarch64:

```bash
gdb-multiarch -q -batch -x apps/starry/gdb-smoke/gdbserver/host-remote-aarch64.gdb \
target/gdb-smoke-host/aarch64/gdbserver-smoke-target
```

For LoongArch:

```bash
gdb-multiarch -q -batch -x apps/starry/gdb-smoke/gdbserver/host-remote-loongarch64.gdb \
target/gdb-smoke-host/loongarch64/gdbserver-smoke-target
```

`-batch` runs the scripted host GDB flow and exits after the marker output.
12 changes: 12 additions & 0 deletions apps/starry/gdb-smoke/build-aarch64-unknown-none-softfloat.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
features = [
"qemu",
"ax-driver/virtio-blk",
"ax-driver/virtio-net",
"ax-driver/virtio-gpu",
"ax-driver/virtio-input",
"ax-driver/virtio-socket",
"starry-kernel/input",
"starry-kernel/vsock",
]
log = "Warn"
target = "aarch64-unknown-none-softfloat"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
target = "loongarch64-unknown-none-softfloat"
log = "Warn"
features = [
"ax-hal/loongarch64-qemu-virt",
"qemu",
"ax-driver/plat-static",
"ax-driver/virtio-blk",
"ax-driver/virtio-net",
"ax-driver/virtio-gpu",
"ax-driver/virtio-input",
"ax-driver/virtio-socket",
"starry-kernel/input",
"starry-kernel/vsock",
]
plat_dyn = false
Comment thread
ZR233 marked this conversation as resolved.
10 changes: 10 additions & 0 deletions apps/starry/gdb-smoke/gdbserver/host-manual-aarch64.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set pagination off
set confirm off
set debuginfod enabled off
set architecture aarch64
set sysroot /
set solib-search-path /lib:/usr/lib
set remotetimeout 10
set remote hostio-open-packet off
set remote hostio-pread-packet off
target remote :1234
10 changes: 10 additions & 0 deletions apps/starry/gdb-smoke/gdbserver/host-manual-loongarch64.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set pagination off
set confirm off
set debuginfod enabled off
set architecture Loongarch64
set sysroot /
set solib-search-path /lib:/usr/lib
set remotetimeout 10
set remote hostio-open-packet off
set remote hostio-pread-packet off
target remote :1234
18 changes: 18 additions & 0 deletions apps/starry/gdb-smoke/gdbserver/host-remote-aarch64.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set pagination off
set confirm off
set debuginfod enabled off
set architecture aarch64
set sysroot /
set solib-search-path /lib:/usr/lib
set remotetimeout 10
set remote hostio-open-packet off
set remote hostio-pread-packet off
target remote :1234
echo HOST_GDB_REMOTE_CONNECTED\n
break compute_value
continue
bt
echo HOST_GDB_REMOTE_BT_DONE\n
detach
echo HOST_GDB_REMOTE_DETACH_DONE\n
quit
18 changes: 18 additions & 0 deletions apps/starry/gdb-smoke/gdbserver/host-remote-loongarch64.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set pagination off
set confirm off
set debuginfod enabled off
set architecture Loongarch64
set sysroot /
set solib-search-path /lib:/usr/lib
set remotetimeout 10
set remote hostio-open-packet off
set remote hostio-pread-packet off
target remote :1234
echo HOST_GDB_REMOTE_CONNECTED\n
break compute_value
continue
bt
echo HOST_GDB_REMOTE_BT_DONE\n
detach
echo HOST_GDB_REMOTE_DETACH_DONE\n
quit
4 changes: 4 additions & 0 deletions apps/starry/gdb-smoke/gdbserver/src/main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <sys/auxv.h>
#include <stdio.h>

#if defined(__riscv)
#define RISCV_HWCAP_ISA_D (1UL << ('D' - 'A'))
#endif

__attribute__((noinline)) static int compute_value(void)
{
Expand All @@ -11,10 +13,12 @@ __attribute__((noinline)) static int compute_value(void)
int main(void)
{
unsigned long hwcap = getauxval(AT_HWCAP);
#if defined(__riscv)
if ((hwcap & RISCV_HWCAP_ISA_D) == 0) {
printf("gdbserver-smoke-target missing riscv D hwcap: %#lx\n", hwcap);
return 1;
}
#endif

int value = compute_value();
printf("gdbserver-smoke-target value=%d hwcap=%#lx\n", value, hwcap);
Expand Down
43 changes: 35 additions & 8 deletions apps/starry/gdb-smoke/prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ app_dir="${STARRY_APP_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
base_rootfs="${STARRY_ROOTFS:-}"
staging_root="${STARRY_STAGING_ROOT:-}"
overlay_dir="${STARRY_OVERLAY_DIR:-}"
apk_cache="${STARRY_WORKSPACE:-$(cd "$app_dir/../../.." && pwd)}/target/gdb-smoke-apk-cache"
host_artifact_dir="${STARRY_WORKSPACE:-$(cd "$app_dir/../../.." && pwd)}/target/gdb-smoke-host"
arch="${STARRY_ARCH:-}"
workspace="${STARRY_WORKSPACE:-$(cd "$app_dir/../../.." && pwd)}"
apk_cache="$workspace/target/gdb-smoke-apk-cache/${arch:-unknown}"
host_artifact_dir="$workspace/target/gdb-smoke-host"
qemu_runner=""
linux_target=""
lld_linker=""
lld_linker_dir=""

Expand Down Expand Up @@ -58,12 +61,33 @@ extract_base_rootfs() {
}

find_qemu_runner() {
if command -v qemu-riscv64-static >/dev/null 2>&1; then
qemu_runner="$(command -v qemu-riscv64-static)"
elif command -v qemu-riscv64 >/dev/null 2>&1; then
qemu_runner="$(command -v qemu-riscv64)"
local qemu_name

case "$arch" in
riscv64)
qemu_name=qemu-riscv64
linux_target=riscv64-linux-musl
;;
aarch64)
qemu_name=qemu-aarch64
linux_target=aarch64-linux-musl
;;
loongarch64)
qemu_name=qemu-loongarch64
linux_target=loongarch64-linux-musl
;;
*)
echo "error: unsupported gdb-smoke arch: $arch" >&2
exit 1
;;
esac

if command -v "${qemu_name}-static" >/dev/null 2>&1; then
qemu_runner="$(command -v "${qemu_name}-static")"
elif command -v "$qemu_name" >/dev/null 2>&1; then
qemu_runner="$(command -v "$qemu_name")"
else
echo "error: qemu-riscv64-static or qemu-riscv64 is required" >&2
echo "error: ${qemu_name}-static or ${qemu_name} is required" >&2
exit 1
fi
}
Expand Down Expand Up @@ -122,7 +146,7 @@ compile_target() {

install -d "$(dirname "$overlay_dir$output")"
clang \
--target=riscv64-linux-musl \
--target="$linux_target" \
--sysroot="$staging_root" \
--gcc-toolchain="$staging_root/usr" \
--ld-path="$lld_linker" \
Expand Down Expand Up @@ -211,6 +235,8 @@ populate_overlay() {
-Wall -Wextra -Werror -O0 -g -pthread
install -Dm0755 "$overlay_dir/usr/bin/gdbserver-smoke-target" \
"$host_artifact_dir/gdbserver-smoke-target"
install -Dm0755 "$overlay_dir/usr/bin/gdbserver-smoke-target" \
"$host_artifact_dir/$arch/gdbserver-smoke-target"

copy_file_to_overlay /usr/bin/gdb 0755
copy_file_to_overlay /usr/bin/gdbserver 0755
Expand Down Expand Up @@ -240,6 +266,7 @@ populate_overlay() {
require_env STARRY_ROOTFS "$base_rootfs"
require_env STARRY_STAGING_ROOT "$staging_root"
require_env STARRY_OVERLAY_DIR "$overlay_dir"
require_env STARRY_ARCH "$arch"

ensure_host_packages
extract_base_rootfs
Expand Down
33 changes: 33 additions & 0 deletions apps/starry/gdb-smoke/qemu-aarch64-gdbserver-host.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
args = [
"-nographic",
"-m",
"512M",
"-cpu",
"cortex-a53",
"-device",
"virtio-blk-pci,drive=disk0",
"-drive",
"id=disk0,if=none,format=raw,file=${workspace}/tmp/axbuild/rootfs/rootfs-aarch64-alpine.img",
"-device",
"virtio-net-pci,netdev=net0",
"-netdev",
"user,id=net0,hostfwd=tcp::1234-:1234",
]
uefi = false
to_bin = true
shell_prefix = "root@starry:"
shell_init_cmd = "gdbserver 0.0.0.0:1234 /usr/bin/gdbserver-smoke-target; echo __HOST_REMOTE_GDBSERVER_DONE__"
success_regex = [
"(?m)^__HOST_REMOTE_GDBSERVER_DONE__$",
]
fail_regex = [
'(?i)\bpanic(?:ked)?\b',
'(?m)FAIL',
'gdbserver: not found',
'Cannot insert breakpoint',
'Remote communication error',
'ptrace: Function not implemented',
'Program received signal SIGSEGV',
'(?i)Segmentation fault',
]
timeout = 240
25 changes: 25 additions & 0 deletions apps/starry/gdb-smoke/qemu-aarch64-gdbserver-manual.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
args = [
"-nographic",
"-m",
"512M",
"-cpu",
"cortex-a53",
"-device",
"virtio-blk-pci,drive=disk0",
"-drive",
"id=disk0,if=none,format=raw,file=${workspace}/tmp/axbuild/rootfs/rootfs-aarch64-alpine.img",
"-device",
"virtio-net-pci,netdev=net0",
"-netdev",
"user,id=net0,hostfwd=tcp::1234-:1234",
]
uefi = false
to_bin = true
shell_prefix = "root@starry:"
success_regex = []
fail_regex = [
'(?i)\bpanic(?:ked)?\b',
'(?m)FAIL',
'gdbserver: not found',
]
timeout = 0
Loading