Skip to content

Commit

Permalink
Merge pull request #145 from dkohlbre/debugscript-fix
Browse files Browse the repository at this point in the history
Debugscript fix. Added back the debug script flag, cleaned up run-qemu script generation, removed old run-qemu script.
  • Loading branch information
dkohlbre committed Feb 10, 2020
2 parents 65b2e92 + 38e14f8 commit 8d6d4a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 46 deletions.
36 changes: 14 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,46 +215,38 @@ add_custom_target("image" DEPENDS "sm" "tests" ${buildroot_srcdir} ${buildroot_w
set(scripts ${CMAKE_BINARY_DIR}/scripts)
add_custom_command(OUTPUT ${scripts} COMMAND mkdir -p ${scripts})

# if initramfs is false, we need to tell qemu where to find the block device
if(initramfs)
add_custom_command(OUTPUT ${scripts}/run-qemu.sh DEPENDS ${scripts}
WORKING_DIRECTORY ${scripts}
COMMAND echo "\
export HOST_PORT=\${HOST_PORT:=\"\$((3000 + RANDOM % 3000))\"}; \
echo \"**** Running QEMU SSH on port \${HOST_PORT} ****\"; \
${qemu_system} \
-m 2G \
-nographic \
-machine virt \
-bios ${bootrom_wrkdir}/bootrom.bin \
-kernel ${sm_wrkdir}/bbl \
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::\$\{HOST_PORT\}-:22 \
-device virtio-net-device,netdev=net0" > run-qemu.sh
VERBATIM
COMMAND
chmod +x run-qemu.sh
)
set(extra_qemu_options "")
else()
add_custom_command(OUTPUT ${scripts}/run-qemu.sh DEPENDS ${scripts}
set(extra_qemu_options "\
-append \"console=ttyS0 ro root=/dev/vda\" \
-drive file=${buildroot_wrkdir}/images/rootfs.ext2,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
")
endif()

# generate the qemu runscript, using the above options
add_custom_command(OUTPUT ${scripts}/run-qemu.sh DEPENDS ${scripts}
WORKING_DIRECTORY ${scripts}
COMMAND echo "\
export HOST_PORT=\${HOST_PORT:=\"\$((3000 + RANDOM % 3000))\"}; \
echo \"**** Running QEMU SSH on port \${HOST_PORT} ****\"; \
DEBUG=\"\" \\n while [ \"$1\" != \"\" ]; do \\n if [ \"$1\" = \"-debug\" ]; then \\n DEBUG=\"-s -S -d in_asm -D debug.log\" \\n shift \\n fi \\n done \\n \
${qemu_system} \
\$DEBUG \
-m 2G \
-nographic \
-machine virt \
-bios ${bootrom_wrkdir}/bootrom.bin \
-kernel ${sm_wrkdir}/bbl \
-append \"console=ttyS0 ro root=/dev/vda\" \
-drive file=${buildroot_wrkdir}/images/rootfs.ext2,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
${extra_qemu_options} \
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::\$\{HOST_PORT\}-:22 \
-device virtio-net-device,netdev=net0" > run-qemu.sh
VERBATIM
COMMAND
chmod +x run-qemu.sh
)
endif()
add_custom_command(OUTPUT ${scripts}/test-qemu.sh DEPENDS ${CMAKE_SOURCE_DIR}/scripts ${scripts}
COMMAND cp ${CMAKE_SOURCE_DIR}/scripts/test-qemu.sh ${scripts})
add_custom_command(OUTPUT ${scripts}/travis.sh DEPENDS ${CMAKE_SOURCE_DIR}/scripts ${scripts}
Expand Down
2 changes: 2 additions & 0 deletions docs/source/Getting-Started/How-to-Debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
We use QEMU+GDB to debug the security monitor or the kernel.
QEMU is an effective way to debug them.

From your `build` directory where you ran `make`, use:

```bash
./scripts/run-qemu.sh -debug
```
Expand Down
24 changes: 0 additions & 24 deletions scripts/run-qemu.sh

This file was deleted.

0 comments on commit 8d6d4a6

Please sign in to comment.