From: Lunaixsky Date: Sun, 16 Mar 2025 16:22:43 +0000 (+0000) Subject: refine the live_debug.sh, move gdb to new tmux window X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/commitdiff_plain/2d0cfde0212549bb2745688fadbb9c37652d3ab2?hp=71e44ac5296a7819554ce50b79129d64fd740e8f refine the live_debug.sh, move gdb to new tmux window add some informative logging output --- diff --git a/lunaix-os/live_debug.sh b/lunaix-os/live_debug.sh index d70c54d..39f9841 100755 --- a/lunaix-os/live_debug.sh +++ b/lunaix-os/live_debug.sh @@ -4,20 +4,47 @@ hmp_port=45454 gdb_port=1234 default_cmd="console=/dev/ttyS0" -make ARCH=${ARCH} MODE=${MODE:-debug} all -j5 || exit -1 - -./scripts/qemu.py \ - scripts/qemus/qemu_x86_dev.json \ - --qemu-dir "${QEMU_DIR}" \ - -v QMPORT=${hmp_port} \ - -v GDB_PORT=${gdb_port} \ - -v ROOTFS=lunaix_rootfs.ext2 \ - -v ARCH=${ARCH} \ - -v KBIN=build/bin/kernel.bin \ - -v "KCMD=${default_cmd} rootfs=/dev/block/sda init=/bin/init" \ - -- \ - -nographic & - -QMPORT=${hmp_port} gdb-multiarch \ - build/bin/kernel.bin \ - -ex "target remote localhost:${gdb_port}" \ No newline at end of file +if [[ -z "${ARCH}" ]]; then + echo "error: please specify ARCH=" + exit 1 +fi + +make ARCH="${ARCH}" MODE="${MODE:-debug}" all -j"$(nproc)" || exit 1 + +launch_script=._launch_debug.sh + +cat << EOF > ${launch_script} && chmod +x ${launch_script} +#!/usr/bin/env sh +./scripts/qemu.py \\ + scripts/qemus/qemu_x86_dev.json \\ + --qemu-dir "${QEMU_DIR}" \\ + -v QMPORT=${hmp_port} \\ + -v GDB_PORT=${gdb_port} \\ + -v ROOTFS=lunaix_rootfs.ext2 \\ + -v ARCH=${ARCH} \\ + -v KBIN=build/bin/kernel.bin \\ + -v "KCMD=${default_cmd} rootfs=/dev/block/sda init=/bin/init" \\ + -- \\ + -nographic || exit 1 & + +AUTOQEMU_DAEMON=\$! +echo "autoqemu daemon launched (pid=\$AUTOQEMU_DAEMON)" + +gdb-multiarch \\ + build/bin/kernel.bin \\ + -ex "target remote localhost:${gdb_port}" + +if ps -p \$AUTOQEMU_DAEMON > /dev/null +then + kill -9 \$AUTOQEMU_DAEMON +fi +EOF + +echo "debugger launch script written to: ${launch_script}" + +if [[ -z "${TMUX}" ]]; then + echo "for best effect, use tmux" + GDB_NOSPLIT=1 "./${launch_script}" +else + tmux new-window -a -n "[lunaix-debug]" -e "QMPORT=${hmp_port}" "./${launch_script}" +fi diff --git a/lunaix-os/scripts/qemu.py b/lunaix-os/scripts/qemu.py index fca6da9..edd5cdc 100755 --- a/lunaix-os/scripts/qemu.py +++ b/lunaix-os/scripts/qemu.py @@ -346,13 +346,14 @@ class QEMUExec: cmds += dev.get_qemu_opts() cmds += extras - print(" ".join(cmds), "\n") + logger.info(" ".join(cmds)) if dryrun: logger.info("[DRY RUN] QEMU not invoked") return handle = subprocess.Popen(cmds) + logger.info(f"QEMU launched (pid={handle.pid})") while True: ret_code = handle.poll()