我如何用一个终端调试Qemu?
我正在为卡内基·梅隆大学(Carnegie Mellon University)的月球漫游车工作,该大学将于明年推出。具体来说,我正在使用一台名为ISIS OBC(在计算机上)的飞行计算机,我正在尝试找出如何在后台在终端中首次运行QEMU,然后运行GDB以连接到QEMU实例,我只是背景。我尝试使用&
在后台运行QEMU,并使用flag -daemonize
,但这会导致QEMU的GDB服务器根本不起作用。
总体目标是能够在一个终端窗口中在GDB中调试我们的飞行软件,以便我可以从安装在存储库根上的docker容器内部运行它。需要一些设置才能使我们的代码进行调试,并具有一些与较新版本的GCC不兼容之类的陷阱,因此能够运行代码并从Docker内部进行调试(它具有我们所有其他开发也必须安装依赖项)。
我目前的解决方案是在我在Docker容器外部完全初始化的另一个Gnome端子中运行QEMU,但这是出于明显的原因而在Docker中不起作用。这是该代码在其他上下文是有帮助的情况下:
#!/bin/bash
#The goal of the below code is to get the stdout from QEMU piped into GDB.
#Unfourtunately it appears that QEMU must be started as the FG in its own window so that it will
#start its GDB server, so an additional window is required.
my_tty=$(tty)
gnome-terminal -- bash -c './../obc-emulation-resources/obc-qemu/iobc-loader -f sdram build/app.isis-obc-rtos.bin -s sdram -o pmc-mclk -- -serial stdio -monitor none -s -S > /tmp/qemu-gdb; $SHELL' --name="QEMU-iOBC" --title="QEMU-iOBC" -p
tail -f /tmp/qemu-gdb > $my_tty&
./third_party/gcc-arm-none-eabi-10.3-2021.07/bin/arm-none-eabi-gdb -ex='target remote localhost:1234' -ex='symbol-file build/isis-obc-rtos.elf'
# Kill any leftover qemu debugging sessions
kill $(ps aux | grep '[i]obc-loader' | awk '{print $2}')
# Delete intermediate file
rm -f /tmp/qemu-gdb
# Get's rid of any extra text that may occur
echo ""
clear
我更愿意运行这样的目标来实现我的目标:
./../obc-emulation-resources/obc-qemu/iobc-loader -f sdram build/app.isis-obc-rtos.bin -s sdram -o pmc-mclk -- -serial stdio -monitor none -s -S > /tmp/qemu-gdb
而不是我现在正在运行的内容:
gnome-terminal -- bash -c './../obc-emulation-resources/obc-qemu/iobc-loader -f sdram build/app.isis-obc-rtos.bin -s sdram -o pmc-mclk -- -serial stdio -monitor none -s -S > /tmp/qemu-gdb; $SHELL' --name="QEMU-iOBC" --title="QEMU-iOBC" -p
“ IOBC-loader”是用于运行QEMU命令的包装器方式。“ app.isis-obc-rtos.bin”当然是我要运行的二进制文件,“ isis-obc-rtos.elf”包含用于调试它的符号。抱歉,如果答案很明显,我是学生!
I am working on a moon rover for Carnegie Mellon University which will be launching next year. Specifically, I am working on a flight computer called the ISIS OBC (On Board Computer) and I am trying to find out how to first run QEMU in a terminal in the background, and then run GDB to connect to the QEMU instance I just backgrounded. I have tried running QEMU in the background with &
as well as using the flag -daemonize
but this causes QEMU's GDB server to not work at all.
The overarching goal is to be able to debug our flight software in GDB in one terminal window so that I can run it from inside a Docker container mounted on the repository's root. It takes a bit of setup to get be able to debug our code, with a couple of gotchas like incompatibility with newer versions of GCC, so being able to run the CODE and debug it from inside a Docker container (which has all our other development dependencies installed too) is a must.
My current solution was to just run QEMU in another gnome-terminal I initialized in the startup script completely outside of the docker container, but this will not work in Docker for obvious reasons. Here is that code in case the additional context is helpful:
#!/bin/bash
#The goal of the below code is to get the stdout from QEMU piped into GDB.
#Unfourtunately it appears that QEMU must be started as the FG in its own window so that it will
#start its GDB server, so an additional window is required.
my_tty=$(tty)
gnome-terminal -- bash -c './../obc-emulation-resources/obc-qemu/iobc-loader -f sdram build/app.isis-obc-rtos.bin -s sdram -o pmc-mclk -- -serial stdio -monitor none -s -S > /tmp/qemu-gdb; $SHELL' --name="QEMU-iOBC" --title="QEMU-iOBC" -p
tail -f /tmp/qemu-gdb > $my_tty&
./third_party/gcc-arm-none-eabi-10.3-2021.07/bin/arm-none-eabi-gdb -ex='target remote localhost:1234' -ex='symbol-file build/isis-obc-rtos.elf'
# Kill any leftover qemu debugging sessions
kill $(ps aux | grep '[i]obc-loader' | awk '{print $2}')
# Delete intermediate file
rm -f /tmp/qemu-gdb
# Get's rid of any extra text that may occur
echo ""
clear
I would much prefer to run something like this to achieve my goal:
./../obc-emulation-resources/obc-qemu/iobc-loader -f sdram build/app.isis-obc-rtos.bin -s sdram -o pmc-mclk -- -serial stdio -monitor none -s -S > /tmp/qemu-gdb
rather than what I am running now:
gnome-terminal -- bash -c './../obc-emulation-resources/obc-qemu/iobc-loader -f sdram build/app.isis-obc-rtos.bin -s sdram -o pmc-mclk -- -serial stdio -monitor none -s -S > /tmp/qemu-gdb; $SHELL' --name="QEMU-iOBC" --title="QEMU-iOBC" -p
"iobc-loader" is a wrapper used to run the QEMU command by the way."app.isis-obc-rtos.bin" is of course the binary I am trying to run and "isis-obc-rtos.elf" contains the symbols used to debug it. Apologies if the answer is obvious, I am a student!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用终端多路复用器,例如
屏幕
或tmux
,它允许您在单独的虚拟终端中在前景中运行每个命令。您还可以创建窗格,例如使用tmux按
ctrl+b“
进行水平拆分屏幕或ctrl+b%
以垂直分开,然后ctrl+ b o
在它们之间循环。You can try using a terminal multiplexer like
screen
ortmux
, which allow you to run each command in foreground in a separate virtual terminal.You can also create panes, for example with tmux press
Ctrl+b "
to split the screen horizontally orCtrl+b %
to split it vertically, thenCtrl+b o
to cycle between them.使用
tmux
绝对是最简单的方法,尤其是在内置CLI支持的情况下。您可以编写一个与此类似的脚本:
其中
cmd1
是您的QEMU执行脚本,cmd2
是另一个运行您要用于调试的Docker的脚本。Using
tmux
is definitely the easiest approach, especially with its built in CLI support.You could write a script similar to this one:
Where
cmd1
is your QEMU execution script, andcmd2
is another script that runs the docker you want to use for debugging.