NASM和GDB符号:“在符号文件中找不到任何代码段。”

时间:2011-11-13 06:01:04

标签: gdb nasm ld

我正在尝试从我正在阅读的装配书中找到一个简单的例子。我正在尝试让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的调试符号?

FYI

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 stabs 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在Joe's吃饭! 部分内容.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:〜/代码/ AsmWork / eatsyscall $

4 个答案:

答案 0 :(得分:3)

如何使用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标志。

答案 1 :(得分:1)

我想我和你有同样的问题。差不多字面上。我在Duntemann书中正在研究相同的例子。 (源代码的唯一区别是我将部分字符串从Joe更改为Bob,同时尝试确认我在源代码中所做的差异对编译的可执行文件产生了预期的影响。)

我发现的有点好奇。我有两台计算机,我正在使用同步的Dropbox目录交替工作。旧机器正在运行Ubuntu Karmic,因为它对Duntemann的书中的大部分内容都有最好的支持。我试图将Karmic放在新机器上,但有些东西根本不会安装在它上面,因为它不再受支持。所以我正在运行Ubuntu Oneiric。

这就是事情。我可以在两台机器上编译和运行exes。但是在Oneiric机器上编译的任何内容似乎都缺少gdb / kdbg / Insight很乐意使用的符号信息。在Karmic机器上编译的东西工作正常。一旦在Karmic机器上构建并与Dropbox同步,gdb / kdbg / Insight将在Oneiric机器上运行THAT exe。

所以问题似乎是Oneiric上的编译过程。它缺少或改变某些因素会影响调试器正确使用它的能力。


以下是Karmic目标文件的转储:

$ cat karmic.txt           

eatsyscall.o:     file format elf32-i38

Contents of section .data:
 0000 45617420 61742042 6f622773 210a      Eat at Bob's!.  

Contents of section .text:
 0000 90b80400 0000bb01 000000b9 00000000  ................
 0010 ba0e0000 00cd80b8 01000000 bb000000  ................
 0020 00cd80                               ...       

Contents of section .comment:
 0000 00546865 204e6574 77696465 20417373  .The Netwide Ass
 0010 656d626c 65722032 2e30352e 303100    embler 2.05.01.

Contents of section .stab:
 0000 01000000 00000a00 02000000 01000000  ................
 0010 64000000 00000000 00000000 44001a00  d...........D...
 0020 00000000 00000000 44001b00 01000000  ........D.......
 0030 00000000 44001c00 06000000 00000000  ....D...........
 0040 44001d00 0b000000 00000000 44001e00  D...........D...
 0050 10000000 00000000 44001f00 15000000  ........D.......
 0060 00000000 44002100 17000000 00000000  ....D.!.........
 0070 44002200 1c000000 00000000 44002300  D.".........D.#.
 0080 21000000                             !...           

Contents of section .stabstr:
 0000 00656174 73797363 616c6c2e 61736d00  .eatsyscall.asm.

以下是Oneiric目标文件的转储:

$ cat oneiric.txt           

eatsyscall.o:     file format elf32-i386

Contents of section .data:
 0000 45617420 61742042 6f622773 210a      Eat at Bob's!.  

Contents of section .text:
 0000 90b80400 0000bb01 000000b9 00000000  ................
 0010 ba0e0000 00cd80b8 01000000 bb000000  ................
 0020 00cd80                               ...  

Contents of section .stab:
 0000 01000000 00000b00 02000000 01000000  ................
 0010 64000000 00000000 00000000 44001a00  d...........D...
 0020 00000000 00000000 44001b00 01000000  ........D.......
 0030 00000000 44001c00 06000000 00000000  ....D...........
 0040 44001d00 0b000000 00000000 44001e00  D...........D...
 0050 10000000 00000000 44001f00 15000000  ........D.......
 0060 00000000 44002100 17000000 00000000  ....D.!.........
 0070 44002200 1c000000 00000000 44002300  D.".........D.#.
 0080 21000000 00000000 64000000 00000000  !.......d.......

Contents of section .stabstr:
 0000 00656174 73797363 616c6c2e 61736d00  .eatsyscall.asm.

您可以看到两个文件不同(在非工作的Oneiric文件的末尾有几个额外的字节)。无论nasm在Oneiric上做什么都不能正常使用调试器,看起来似乎是这样。

答案 2 :(得分:0)

似乎可以正常使用GDB的CVS版本:“GNU gdb(GDB)7.3.50.20111108-cvs”,以及GDB 7.2。

听起来“Ubuntu / Linaro 7.3-0ubuntu2”在某种程度上被打破了。

答案 3 :(得分:0)

尝试使用section / segment .text而不是.txt或.code:)

相关问题