diff --git a/apps/starry/gdb-smoke/README.md b/apps/starry/gdb-smoke/README.md index 5056f3c194..3e8b7a8e4e 100644 --- a/apps/starry/gdb-smoke/README.md +++ b/apps/starry/gdb-smoke/README.md @@ -3,7 +3,7 @@ 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. +aarch64, loongarch64, and x86_64. ## Batch Native GDB Smoke @@ -25,6 +25,12 @@ For the current LoongArch native GDB baseline: cargo xtask starry app qemu -t gdb-smoke --arch loongarch64 ``` +For the current x86_64 native GDB baseline: + +```bash +cargo xtask starry app qemu -t gdb-smoke --arch x86_64 +``` + The batch script runs: ```gdb @@ -129,6 +135,13 @@ cargo xtask starry app qemu -t gdb-smoke --arch loongarch64 \ --qemu-config qemu-loongarch64-gdbserver.toml ``` +For x86_64: + +```bash +cargo xtask starry app qemu -t gdb-smoke --arch x86_64 \ + --qemu-config qemu-x86_64-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. @@ -186,6 +199,13 @@ cargo xtask starry app qemu -t gdb-smoke --arch loongarch64 \ --qemu-config qemu-loongarch64-gdbserver-manual.toml ``` +For x86_64: + +```bash +cargo xtask starry app qemu -t gdb-smoke --arch x86_64 \ + --qemu-config qemu-x86_64-gdbserver-manual.toml +``` + When running through the long-lived Docker container, keep stdin and a TTY attached: @@ -228,10 +248,17 @@ gdb-multiarch -q -x apps/starry/gdb-smoke/gdbserver/host-manual-loongarch64.gdb target/gdb-smoke-host/loongarch64/gdbserver-smoke-target ``` +For x86_64: + +```bash +gdb-multiarch -q -x apps/starry/gdb-smoke/gdbserver/host-manual-x86_64.gdb \ + target/gdb-smoke-host/x86_64/gdbserver-smoke-target +``` + `host-manual.gdb` sets the riscv64 remote debugging defaults and connects to -`: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. +`:1234`; `host-manual-aarch64.gdb`, `host-manual-loongarch64.gdb`, and +`host-manual-x86_64.gdb` do the same for aarch64, LoongArch, and x86_64. All +scripts leave you at the GDB prompt for manual commands. Inside host GDB: @@ -270,6 +297,13 @@ cargo xtask starry app qemu -t gdb-smoke --arch loongarch64 \ --qemu-config qemu-loongarch64-gdbserver-host.toml ``` +For x86_64: + +```bash +cargo xtask starry app qemu -t gdb-smoke --arch x86_64 \ + --qemu-config qemu-x86_64-gdbserver-host.toml +``` + This automatic config starts guest `gdbserver` for you and is intended for repeatable logs rather than manual interaction. @@ -294,4 +328,11 @@ gdb-multiarch -q -batch -x apps/starry/gdb-smoke/gdbserver/host-remote-loongarch target/gdb-smoke-host/loongarch64/gdbserver-smoke-target ``` +For x86_64: + +```bash +gdb-multiarch -q -batch -x apps/starry/gdb-smoke/gdbserver/host-remote-x86_64.gdb \ + target/gdb-smoke-host/x86_64/gdbserver-smoke-target +``` + `-batch` runs the scripted host GDB flow and exits after the marker output. diff --git a/apps/starry/gdb-smoke/build-x86_64-unknown-none.toml b/apps/starry/gdb-smoke/build-x86_64-unknown-none.toml new file mode 100644 index 0000000000..48a1da9258 --- /dev/null +++ b/apps/starry/gdb-smoke/build-x86_64-unknown-none.toml @@ -0,0 +1,9 @@ +features = [ + "ax-driver/virtio-blk", + "ax-driver/virtio-net", + "ax-driver/virtio-gpu", + "ax-driver/virtio-input", + "ax-driver/virtio-socket", +] +log = "Warn" +target = "x86_64-unknown-none" diff --git a/apps/starry/gdb-smoke/gdbserver/host-manual-x86_64.gdb b/apps/starry/gdb-smoke/gdbserver/host-manual-x86_64.gdb new file mode 100644 index 0000000000..3b5a442b58 --- /dev/null +++ b/apps/starry/gdb-smoke/gdbserver/host-manual-x86_64.gdb @@ -0,0 +1,10 @@ +set pagination off +set confirm off +set debuginfod enabled off +set architecture i386:x86-64 +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 diff --git a/apps/starry/gdb-smoke/gdbserver/host-remote-x86_64.gdb b/apps/starry/gdb-smoke/gdbserver/host-remote-x86_64.gdb new file mode 100644 index 0000000000..f97d09552f --- /dev/null +++ b/apps/starry/gdb-smoke/gdbserver/host-remote-x86_64.gdb @@ -0,0 +1,18 @@ +set pagination off +set confirm off +set debuginfod enabled off +set architecture i386:x86-64 +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 diff --git a/apps/starry/gdb-smoke/prebuild.sh b/apps/starry/gdb-smoke/prebuild.sh index 9047d7b1ec..6686074c9d 100755 --- a/apps/starry/gdb-smoke/prebuild.sh +++ b/apps/starry/gdb-smoke/prebuild.sh @@ -13,6 +13,7 @@ qemu_runner="" linux_target="" lld_linker="" lld_linker_dir="" +gcc_install_dir="" require_env() { local name="$1" @@ -76,6 +77,10 @@ find_qemu_runner() { qemu_name=qemu-loongarch64 linux_target=loongarch64-linux-musl ;; + x86_64) + qemu_name=qemu-x86_64 + linux_target=x86_64-linux-musl + ;; *) echo "error: unsupported gdb-smoke arch: $arch" >&2 exit 1 @@ -112,6 +117,14 @@ run_guest_apk_with_retry() { done } +find_gcc_install_dir() { + gcc_install_dir="$(find "$staging_root/usr/lib/gcc" -name 'crtbeginT.o' -exec dirname {} \; 2>/dev/null | head -1)" + if [[ -z "$gcc_install_dir" ]]; then + echo "error: could not locate GCC crt objects in staging root" >&2 + exit 1 + fi +} + install_guest_packages() { local guest_apk="$staging_root/sbin/apk" @@ -149,6 +162,8 @@ compile_target() { --target="$linux_target" \ --sysroot="$staging_root" \ --gcc-toolchain="$staging_root/usr" \ + -B"$gcc_install_dir" \ + -L"$gcc_install_dir" \ --ld-path="$lld_linker" \ -static \ "$@" \ @@ -272,4 +287,5 @@ ensure_host_packages extract_base_rootfs find_qemu_runner install_guest_packages +find_gcc_install_dir populate_overlay diff --git a/apps/starry/gdb-smoke/qemu-x86_64-gdbserver-host.toml b/apps/starry/gdb-smoke/qemu-x86_64-gdbserver-host.toml new file mode 100644 index 0000000000..865fb44930 --- /dev/null +++ b/apps/starry/gdb-smoke/qemu-x86_64-gdbserver-host.toml @@ -0,0 +1,27 @@ +args = [ + "-nographic", + "-m", "512M", + "-cpu", "max", + "-device", "virtio-blk-pci,drive=disk0", + "-drive", "id=disk0,if=none,format=raw,file=${workspace}/tmp/axbuild/rootfs/rootfs-x86_64-alpine.img", + "-device", "virtio-net-pci,netdev=net0", + "-netdev", "user,id=net0,hostfwd=tcp::1234-:1234", +] +uefi = false +to_bin = false +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 diff --git a/apps/starry/gdb-smoke/qemu-x86_64-gdbserver-manual.toml b/apps/starry/gdb-smoke/qemu-x86_64-gdbserver-manual.toml new file mode 100644 index 0000000000..2a87a38d8f --- /dev/null +++ b/apps/starry/gdb-smoke/qemu-x86_64-gdbserver-manual.toml @@ -0,0 +1,19 @@ +args = [ + "-nographic", + "-m", "512M", + "-cpu", "max", + "-device", "virtio-blk-pci,drive=disk0", + "-drive", "id=disk0,if=none,format=raw,file=${workspace}/tmp/axbuild/rootfs/rootfs-x86_64-alpine.img", + "-device", "virtio-net-pci,netdev=net0", + "-netdev", "user,id=net0,hostfwd=tcp::1234-:1234", +] +uefi = false +to_bin = false +shell_prefix = "root@starry:" +success_regex = [] +fail_regex = [ + '(?i)\bpanic(?:ked)?\b', + '(?m)FAIL', + 'gdbserver: not found', +] +timeout = 0 diff --git a/apps/starry/gdb-smoke/qemu-x86_64-gdbserver.toml b/apps/starry/gdb-smoke/qemu-x86_64-gdbserver.toml new file mode 100644 index 0000000000..7054fabc6e --- /dev/null +++ b/apps/starry/gdb-smoke/qemu-x86_64-gdbserver.toml @@ -0,0 +1,28 @@ +args = [ + "-nographic", + "-m", "512M", + "-cpu", "max", + "-device", "virtio-blk-pci,drive=disk0", + "-drive", "id=disk0,if=none,format=raw,file=${workspace}/tmp/axbuild/rootfs/rootfs-x86_64-alpine.img", + "-device", "virtio-net-pci,netdev=net0", + "-netdev", "user,id=net0", +] +uefi = false +to_bin = false +shell_prefix = "root@starry:" +shell_init_cmd = "/usr/bin/gdbserver-smoke.sh" +success_regex = ["GDBSERVER_SMOKE_DONE"] +fail_regex = [ + '(?i)\bpanic(?:ked)?\b', + '(?m)FAIL', + 'gdb: not found', + 'Python Exception', + 'Python initialization failed', + 'Cannot insert breakpoint', + 'Remote communication error', + 'ptrace: Function not implemented', + 'No stack', + 'Program received signal SIGSEGV', + '(?i)Segmentation fault', +] +timeout = 180 diff --git a/apps/starry/gdb-smoke/qemu-x86_64.toml b/apps/starry/gdb-smoke/qemu-x86_64.toml new file mode 100644 index 0000000000..9f16841ed6 --- /dev/null +++ b/apps/starry/gdb-smoke/qemu-x86_64.toml @@ -0,0 +1,25 @@ +args = [ + "-nographic", + "-m", "512M", + "-cpu", "max", + "-device", "virtio-blk-pci,drive=disk0", + "-drive", "id=disk0,if=none,format=raw,file=${workspace}/tmp/axbuild/rootfs/rootfs-x86_64-alpine.img", + "-device", "virtio-net-pci,netdev=net0", + "-netdev", "user,id=net0", +] +uefi = false +to_bin = false +shell_prefix = "root@starry:" +shell_init_cmd = "/usr/bin/gdb -q -batch -x /usr/bin/gdb-native-smoke.gdb /usr/bin/gdb-native-smoke-target" +success_regex = ["GDB_NATIVE_SMOKE_DONE"] +fail_regex = [ + '(?i)\bpanic(?:ked)?\b', + '(?m)FAIL', + 'gdb: not found', + 'Python Exception', + 'Python initialization failed', + 'Cannot insert breakpoint', + 'ptrace: Function not implemented', + 'No stack', +] +timeout = 120 diff --git a/os/StarryOS/kernel/src/syscall/task/ptrace.rs b/os/StarryOS/kernel/src/syscall/task/ptrace.rs index a9e0a59d58..f2e487f33a 100644 --- a/os/StarryOS/kernel/src/syscall/task/ptrace.rs +++ b/os/StarryOS/kernel/src/syscall/task/ptrace.rs @@ -2163,7 +2163,7 @@ fn loongarch_unpack_fcc(packed: u64) -> [u8; 8] { // --------------------------------------------------------------------------- #[cfg(target_arch = "x86_64")] -const X86_64_USER_DEBUGREG_OFFSET: usize = 912; +const X86_64_USER_DEBUGREG_OFFSET: usize = 848; #[cfg(target_arch = "x86_64")] const X86_64_USER_DEBUGREG_COUNT: usize = 8; #[cfg(target_arch = "x86_64")]