2011-11-13 5 views
2

私は読んでいるアセンブリの本から作業を簡単な例を取得しようとしています。私はNASMアセンブラでアセンブルしている簡単なアセンブリプログラムでgdbを動作させようとしています。以下は、コードとelf形式のオブジェクトファイルです。NASMとGDBのシンボル: "シンボルファイル内にコードセクションが見つかりません。"

; 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 

[email protected]:~/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 

I実行可能ファイルでGDBを実行する次

[email protected]:~/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 

私は-gフラグとNASMに指定されたデバッグシンボルを読み取るためにgdbを取得するために、私は上記のやっているものに加えて行うために何が必要ですか?

FYI

[email protected]:~/Code/AsmWork/eatsyscall$ cat /etc/*release* 
DISTRIB_ID=Ubuntu 
DISTRIB_RELEASE=11.10 
DISTRIB_CODENAME=oneiric 
DISTRIB_DESCRIPTION="Ubuntu 11.10" 
[email protected]:~/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 
[email protected]:~/Code/AsmWork/eatsyscall$ 

--Update--

私は、次のコマンドを使用して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:〜/コード/ AsmWork/eatsyscall $ ./eatsyscall のbash:./eatsyscall:バイナリファイルを実行することはできません mehogganする@ mehoggan:〜/コード/ AsmWork/eatsyscall $ objdumpの-s eatsyscall.o

eatsyscall.o:ファイル形式ELF64-x86-64のセクション.dataセクションの

内容:ジョーさんで食べる210aの 0000 45617420 6174204aの6f652773!
セクションの内容.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。
内容:スタブ: 0000 00000000 64000100 00000000 ......... .........
セクションの内容は、スタブ: 0000 00です。
mehogganする@ mehoggan:〜/コード/ AsmWork/eatsyscall $

答えて

3

どうsection .txtsection .text isteadを使用する方法について `

つまり:?

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フラグを使用します。

0

現在のCVSバージョンのGDB「GNU gdb(GDB)7.3.50.20111108-cvs」とGDB 7.2でもうまく動作するようです。

「Ubuntu/Linaro 7.3-0ubuntu2」のように壊れているようです。

1

私はあなたと同じ問題を抱えていると思います。ほとんど文字通り。私はDuntemannの本で同じ例を取り上げています。 (ソースコードの唯一の違いは、私がソースコードで作成した相違がコンパイルされた実行ファイルに期待される効果を持っていることを確認しようとしている間に、JoeからBobへの文字列の一部をBobに変更したことです)。

発見されたのはやや興味深い。私は2台のコンピュータを持っていて、同期されたDropboxディレクトリを使ってそれぞれ1台で交互に動作しています。古いマシンはUbuntu Karmicを実行しています。これはDuntemannの本の中の多くをサポートしているからです。私もKarmicを新しいマシンに入れようとしましたが、サポートされなくなったため、いくつかのものはインストールされません。だから、代わりにUbuntu Oneiricを実行しています。

ここが問題です。私は両方のマシンでexesをコンパイルして実行できます。しかし、Oneiricマシンでコンパイルされたものは、gdb/kdbg/Insightがうまく動作するシンボル情報が不足しているようです。 Karmicマシンでコンパイルされたものはうまく動作します。一度Karmicマシン上に構築され、Dropboxと同期されると、gdb/kdbg/InsightはOneiricマシンでそのexeを実行します。

問題は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. 

は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. 

あなたはその2見ることができますファイルが異なっています(作業中のOneiricファイルの最後にいくつかの余分なバイトがあります)。 Oneiricで何が行われていても、デバッガでは正しく動作していないようです。私が使用し が非準拠の.oファイルを編集するために祝福し、手動で対応する64のゼロ:

+0

の.textセクション/セグメントを使用してみてください.stabセクションの最後の 'd'。 この手動で変更されたファイルでexeを再構築した後、すべてが機能しました。 64ビットオブジェクトファイルを作成しようとしていますか? (Oneiricの私のバージョンは32ビットです。) – Kaitain

0

はちょうどこの上でフォローアップする代わりに、.txtファイルまたは.CODE :)

関連する問題