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

NASM和GDB符号:“;Can';在符号文件中找不到任何代码节。”;,gdb,nasm,ld,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, u

我试图从我正在阅读的一本组装书中得到一个简单的示例。我正试图让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

我正在使用以下命令进行组装:

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

--更新--

即使使用以下命令执行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

第节内容。数据: 0000 45617420 6174204a 6f652773 210a在乔家吃饭
txt节的内容: 0000 9048b804 000000000000 48BB010000.H…..H。。。。 0010 00000000 0048b900 00000000 00000000 48…..小时…..小时 0020 ba0e0000 00000000 CD8048 B801000。。。。 0030 00000000 0048bb00 00000000 CD…..小时。。。。。。。。。。 004080.
第.stab节的内容: 0000 00000000 64000100 00000000…d……
第节的内容: 0000 000。

mehoggan@mehoggan:~/Code/AsmWork/eatsyscall$

如何使用section.textistead ofsection.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的当前CVS版本:“GNU gdb(gdb)7.3.50.20111108-CVS”,以及gdb 7.2


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

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

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

事情是这样的。我可以在两台机器上编译和运行EXE。但在Oneiric机器上编译的任何东西似乎都缺少gdb/kdbg/Insight乐于使用的符号信息。在业力机器上编译的东西运行良好。一旦建立在Karmic机器上并与Dropbox同步,gdb/kdbg/Insight将在Oneiric机器上很好地运行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.
$ 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对象文件的转储:

$ 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.
$ 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上做什么,调试器似乎都无法正常运行。

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

只是为了跟进这个问题:我使用Bless编辑了不兼容的.o文件,并手动将.stab部分中与最终“d”相对应的64位归零。用这个手动修改的文件重建exe后,一切正常。这是不是说它正在尝试创建一个64位的对象文件?(我的Oneiric版本是32位。)