2011-11-13 3 views
2

제가 읽은 어셈블리 책에서 간단한 예제를 얻으려고합니다. gdb가 NASM 어셈블러를 사용하여 어셈블하는 간단한 어셈블리 프로그램과 함께 작동하도록하려고합니다. 아래 코드와 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를 얻을 수 위 뭐하는 거지 이외에 어떻게해야합니까?

참고

[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 stats eatsyscall.asm ~/Code/AsmWork/eatsyscall $ ld -o eatsyscall eatsyscall.o -melf_x86_64,363,210 mehoggan의 @의 mehoggan : ~/코드/AsmWork/eatsyscall $ ./eatsyscall 배쉬 : ./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 .... ..........
내용의 섹션 .stabstr : 0000 00.
mehoggan의 @의 mehoggan : ~/코드/AsmWork 즉 section .txtsection .text istead 사용에 대한`

방법/eatsyscall $

답변

3

:

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

GDB의 현재 CVS 버전 "GNU gdb (GDB) 7.3.50.20111108-cvs"와 GDB 7.2에서 잘 작동하는 것 같습니다.

"Ubuntu/Linaro 7.3-0ubuntu2"가 어떤 식 으로든 부러진 것처럼 들립니다.

1

나는 당신과 같은 문제가 있다고 생각합니다. 거의 말 그대로. Duntemann 책에서 같은 예제를 통해 작업하고 있습니다. (소스 코드의 유일한 차이점은 내가 소스 코드에서 만든 차이점이 컴파일 된 실행 파일에 예상되는 영향을 미쳤음을 확인하는 동안 Joe에서 Bob으로 문자열의 일부를 변경했다는 것입니다.)

발견 된 것은 약간 궁금합니다. 나는 두 대의 컴퓨터를 갖고 있으며, 하나씩 동기화 된 보관 용 계정 디렉토리를 사용하여 교대로 작업하고 있습니다. 구형 컴퓨터는 Duntemann의 책에서 많은 것을 가장 잘 지원하기 때문에 Ubuntu Karmic을 사용하고 있습니다. 나는 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. 

당신이 볼 수있는 두 파일이 다릅니다 (작동하지 않는 Oneiric 파일 끝에 몇 개의 여분의 바이트가 있음). Oneiric에서 수행중인 모든 nasm이 디버거와 제대로 작동하지 않는 것 같습니다. 내가 사용 가 비 호환 .o 인 파일을 편집 축복, 수동으로 해당하는 64 제로 :

+0

의 텍스트 섹션/세그먼트를 사용해보십시오 .stab 섹션의 마지막 'd'. 이 수동으로 변경된 파일로 exe 파일을 다시 작성한 후에 모든 것이 올바르게 수행되었습니다. 64 비트 오브젝트 파일을 만들려고한다고 말하는가? (내 Oneiric 버전은 32 비트입니다.) – Kaitain

0

것은 바로이 후속 대신 .txt 또는 .CODE :