如何在 QEMU 上的 GDB 中单步执行 ARM 程序集? [英] How to single step ARM assembly in GDB on QEMU?

查看:27
本文介绍了如何在 QEMU 上的 GDB 中单步执行 ARM 程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 GNU 汇编器了解 ARM 汇编器编程.我已经用 QEmu 设置了我的电脑,并且有一个 Debian ARM-HF chroot 环境.

如果我组装并链接我的测试程序:

.text.global _start_开始:移动 r0,#6bx lr

与:

as test.s -o test.old test.o -o 测试

然后将文件加载到 gdb 并在 _start 上设置断点:

<前>root@Latitude-E6420:/root# gdb 测试GNU gdb (GDB) 7.6.1 (Debian 7.6.1-1)版权所有 (C) 2013 Free Software Foundation, Inc.许可证 GPLv3+:GNU GPL 版本 3 或更高版本这是免费软件:您可以自由更改和重新分发它.在法律允许的范围内,不提供任何保证.输入显示复制"和显示保修"了解详情.这个 GDB 被配置为arm-linux-gnueabihf".有关错误报告的说明,请参阅:...从/root/test 读取符号...(未找到调试符号)...完成.(gdb) 中断 _start断点 1 位于 0x8054(gdb)

如何单步执行代码、显示汇编源代码和监控寄存器?我尝试了一些基本命令,但它们不起作用:

<前>(gdb) 中断 _start断点 1 位于 0x8054(gdb) 信息注册该程序现在没有寄存器.(gdb) stepi程序没有运行.(gdb) disas未选择任何帧.(gdb) r启动程序:/root/testqemu:不支持的系统调用:26qemu:未捕获的目标信号 11(分段错误)-核心已转储qemu:不支持的系统调用:26在启动过程中,程序以信号 SIGSEGV 终止,分段错误.(gdb)

解决方案

您的问题是您正在尝试在 QEMU 的用户模式仿真下运行 ARM gdb.QEMU 不支持 ptrace 系统调用(这就是 26 号系统调用),所以这永远不会起作用.

您需要做的是在 QEMU 下使用 QEMU 选项运行测试二进制文件,以启用 QEMU 自己的内置 gdb 存根,它将侦听 TCP 端口.然后,您可以运行编译为在您的主机系统上运行但支持 ARM 目标的 gdb,并告诉它连接到 TCP 端口.

(在 QEMU 中模拟 ptrace 在技术上非常棘手,它不会提供很多额外的功能,而这些功能是您无法通过 QEMU 内置的 gdbstub 实现的.它不太可能实现.)

I'm trying to learn about ARM assembler programming using the GNU assembler. I've setup my PC with QEmu and have a Debian ARM-HF chroot environment.

If I assemble and link my test program:

.text
.global _start
_start:
        mov     r0, #6
        bx      lr

with:

as test.s -o test.o
ld test.o -o test

Then load the file into gdb and set a breakpoint on _start:

root@Latitude-E6420:/root# gdb test
GNU gdb (GDB) 7.6.1 (Debian 7.6.1-1)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
For bug reporting instructions, please see:
...
Reading symbols from /root/test...(no debugging symbols found)...done.
(gdb) break _start
Breakpoint 1 at 0x8054
(gdb)

How do I single step the code, display the assembler source code and monitor the registers? I tried some basic commands and they did not work:

(gdb) break _start
Breakpoint 1 at 0x8054
(gdb) info regi
The program has no registers now.
(gdb) stepi
The program is not being run.
(gdb) disas
No frame selected.
(gdb) r
Starting program: /root/test 
qemu: Unsupported syscall: 26
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
qemu: Unsupported syscall: 26
During startup program terminated with signal SIGSEGV, Segmentation fault.
(gdb) 

解决方案

Your problem here is that you're trying to run an ARM gdb under QEMU's user-mode emulation. QEMU doesn't support the ptrace syscall (that's what syscall number 26 is), so this is never going to work.

What you need to do is run your test binary under QEMU with the QEMU options to enable QEMU's own builtin gdb stub which will listen on a TCP port. Then you can run a gdb compiled to run on your host system but with support for ARM targets, and tell that to connect to the TCP port.

(Emulating ptrace within QEMU is technically very tricky, and it would not provide much extra functionality that you can't already achieve via the QEMU builtin gdbstub. It's very unlikely it'll ever be implemented.)

这篇关于如何在 QEMU 上的 GDB 中单步执行 ARM 程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆