gpt4 book ai didi

linux - 如何逐步调试没有符号或部分的程序集二进制文件?

转载 作者:太空狗 更新时间:2023-10-29 12:05:14 27 4
gpt4 key购买 nike

考虑以下 NASM 代码:

  BITS 32

org 0x08048000

ehdr: ; Elf32_Ehdr
db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident
times 8 db 0
dw 2 ; e_type
dw 3 ; e_machine
dd 1 ; e_version
dd _start ; e_entry
dd phdr - $$ ; e_phoff
dd 0 ; e_shoff
dd 0 ; e_flags
dw ehdrsize ; e_ehsize
dw phdrsize ; e_phentsize
dw 1 ; e_phnum
dw 0 ; e_shentsize
dw 0 ; e_shnum
dw 0 ; e_shstrndx

ehdrsize equ $ - ehdr

phdr: ; Elf32_Phdr
dd 1 ; p_type
dd 0 ; p_offset
dd $$ ; p_vaddr
dd $$ ; p_paddr
dd filesize ; p_filesz
dd filesize ; p_memsz
dd 5 ; p_flags
dd 0x1000 ; p_align

phdrsize equ $ - phdr

_start:

xor eax, eax ;now just return to system with ebx
inc eax
int 0x80


; your program here

filesize equ $ - $$

如何调试这样结构的程序?最可取的是,我正在寻找一个 GDB 解决方案,它可以让我分步运行汇编指令,允许在每一步预览寄存器。下面是当我想在那里设置基于内存的断点时发生的情况:

[localhost.localdomain][/tmp] $ gdb ./a.out 
GNU gdb (GDB) Fedora (7.5.1-37.fc18)
Copyright (C) 2012 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/a.out...(no debugging symbols found)...done.
(gdb) break 0x08048054
No symbol table is loaded. Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) list breakpoints
No symbol table is loaded. Use the "file" command.

最佳答案

在您的示例中,在特定地址设置断点的命令应该是 break *0x08048054。对于二进制文件的单步执行,您可以使用 stepi(步进指令)命令。

关于linux - 如何逐步调试没有符号或部分的程序集二进制文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15974462/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com