首页 > 编程语言 >0157-使用 QEMU 执行汇编一

0157-使用 QEMU 执行汇编一

时间:2023-01-31 16:46:22浏览次数:43  
标签:1234 汇编 target i8086 GDB 0157 gdb QEMU

环境

  • Time 2022-11-06
  • WSL-Ubuntu 22.04
  • QEMU 6.2.0
  • NASM 2.15.05

前言

说明

参考:《x86汇编语言:从实模式到保护模式》李忠

目标

使用 QEMU 模拟器,加载编写好的文件,在启动时执行汇编指令。

启动命令

qemu-system-i386 -s -S -drive format=raw,file=main --nographic

其中 -s 表示在 1234 端口开启 GDB 调试端口。-S 表示在加电后停止 CPU。
main 是之前生成的启动文件,nographic 表示不需要图形界面。
raw 表示是一个原始的机器码文件,没有文件格式信息。

启动 GDB

启动命令:gdb

root@jiangbo12490:~/git/game# gdb
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".

设置 8086 模式

设置命令:set architecture i8086

(gdb) set architecture i8086
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default i8086 settings.

The target architecture is set to "i8086".

连接 QEMU 模拟器

刚刚启动 QEMU 时,在 1234 打开调试端口,连接上去查看,命令:target remote localhost:1234

(gdb) target remote localhost:1234
Remote debugging using localhost:1234
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x0000fff0 in ?? ()
(gdb)

总结

通过给 QEMU 传递编写的文件,已经正常启动,并且可以进入调试。

附录

标签:1234,汇编,target,i8086,GDB,0157,gdb,QEMU
From: https://www.cnblogs.com/jiangbo4444/p/17079707.html

相关文章