我正在尝试从我正在阅读的一本汇编书中获取一个简单的示例。我正在尝试让 gdb 与我使用 NASM 汇编器组装的简单汇编程序一起工作。下面是代码,以及elf格式的目标文件。
; Version : 1.0
; Created Date : 11/12/2011
; Last Update : 11/12/2011
; Author : Jeff Duntemann
; Description : A simple assembly app for Linux, using NASM 2.05,
; demonstrating the use of Linux INT 80H syscalls
; to display text.
; Build using these commands:
; nasm -f elf -g -F stabs eatsyscall.asm
; ld -o eatsyscall eatsyscall.o
;
SECTION .data ; Section containing initialized data
EatMsg: db "Eat at Joe's!",10
EatLen: equ $-EatMsg
SECTION .bss ; Section containing uninitialized data
SECTION .txt ; Section containing code
global _start ; Linker needs this to find the entry point!
_start:
nop ; This no_op keeps gdb happy (see text)
mov eax,4 ; Specify sys_write syscall
mov ebx,1 ; Specify File Descriptor 1: Standard Output
mov ecx,EatMsg ; Pass offset of the message
mov edx,EatLen ; Pass the length of the mesage
int 80H ; Make syscall to output the text to stdout
mov eax,1 ; Specify Exit syscall
mov ebx,0 ; Return a code of zero
int 80H ; Make syscall to terminate the program
和
mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$ objdump -s ./eatsyscall.o
./eatsyscall.o: file format elf32-i386
Contents of section .data:
0000 45617420 6174204a 6f652773 210a Eat at Joe's!.
Contents of section .txt:
0000 90b80400 0000bb01 000000b9 00000000 ................
0010 ba0e0000 00cd80b8 01000000 bb000000 ................
0020 00cd80 ...
Contents of section .stab:
0000 00000000 64000100 00000000 ....d.......
Contents of section .stabstr:
0000 00
我使用以下命令进行组装:
nasm -f elf -g -F stabs eatsyscall.asm
我使用以下命令进行链接:
ld -o eatsyscall eatsyscall.o
当我在可执行文件上运行 GDB 时,我得到以下信息:
mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$ gdb eatsyscall
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 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 "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/mehoggan/Code/AsmWork/eatsyscall/eatsyscall...Can't find any code sections in symbol file
(gdb) quit
除了上面所做的事情之外,我还需要做什么才能让 gdb 读取使用 -g 标志指定给 NASM 的调试符号?
仅供引用
mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$ cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu 11.10"
mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$ uname -a
Linux mehoggan 3.0.0-12-generic-pae #20-Ubuntu SMP Fri Oct 7 16:37:17 UTC 2011 i686 i686 i386 GNU/Linux
mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$
--更新--
即使我使用以下命令采用 64 位路线,我仍然没有成功:
mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$ nasm -f elf64 -g -F 刺 eatsyscall.asm mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$ ld -o eatsyscall eatsyscall.o -melf_x86_64 mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$ ./eatsyscall bash: ./eatsyscall: 无法执行二进制文件 mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$ objdump -s eatsyscall.o
eatsyscall.o:文件格式 elf64-x86-64
.data 节的内容:
0000 45617420 6174204a 6f652773 210a 在乔家吃饭!
.txt 部分的内容:
0000 9048b804 00000000 00000048 bb010000 .H.........H....
0010 00000000 0048b900 00000000 00000048 .....H.........H
0020 ba0e0000 00000000 00cd8048 b8010000 ........................H....
0030 00000000 0048bb00 00000000 000000cd .....H........................
0040 80 .
.stab 部分的内容:
0000 00000000 64000100 00000000 ....d.......
.stabstr 部分的内容:
0000 00 .
mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$
最佳答案
使用section .text
代替section .txt
怎么样?`
即:
SECTION .data ; Section containing initialized data
EatMsg: db "Eat at Joe's!",10
EatLen: equ $-EatMsg
SECTION .bss ; Section containing uninitialized data
SECTION .text ; instead of .txt
之后在 gdb 中应该可以正常工作,如果您使用的是 x64 架构,请使用 x64 标志。
关于gdb - NASM 和 GDB 符号 : "Can' t find any code sections in symbol file. ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8109950/