在GDB中获取地址和硬币

  • 本文关键字:硬币 地址 获取 GDB gdb
  • 更新时间 :
  • 英文 :


我在ASM(NASM(中有一个程序,我想获取一个地址,但是当我使用GDB进行调试时发生了一些奇怪的错误(我输入了"next"并且程序退出了(。GDB 中是否存在一些错误?

测试.asm

BITS 32
section .text
global _start
_start:
call function
mov eax,0x41414141

function:
# esi get the address of "mov eax,0x41414141"
pop esi
# Exit
xor eax,eax
xor ebx,ebx
mov al,0x01
int 0x80

调试

$ nasm  -f elf test.asm
$ ld test.o -o test
$ gdb -q ./test
Reading symbols from /root/Desktop/test...(no debugging symbols found)...done.
(gdb) info functions
All defined functions:
Non-debugging symbols:
0x08048060  _start
0x0804806a  function
(gdb) b function
Breakpoint 1 at 0x804806a
(gdb) run # Execute _start
Starting program: /root/Desktop/test 
Breakpoint 1, 0x0804806a in function ()
(gdb) # We're going to execute "pop esi" now
(gdb) next # Execute only 1 instruction
Single stepping until exit from function function,
which has no line number information.
[Inferior 1 (process 26492) exited normally]
# WHY EXIT? We was going to execute "pop esi" !!

您使用了"next",它告诉gdb执行源代码级别的步骤(移动到源代码中的下一行(。由于您没有使用包含的调试信息构建可执行文件,因此 gdb 不知道如何执行此操作。有两种解决方案:

  1. 在启用调试信息的情况下生成。我不知道 nasm,但看起来它使用通常的 -g 开关来启用调试信息。组装时添加此内容。
  2. 在 gdb 中使用 nexti。这将只执行下一个汇编指令,而不关心源代码。

最新更新