2014-07-14 2 views
-1

gcc를 사용합니다. 나는 각 코드 라인의 주소를 알고 싶다. 조립하는 방법으로 그것을 얻는 방법이 있는가? 디스 어셈블 된 출력의 첫 번째 열은 내게 주소처럼 보이지만 확실하지 않습니다.어셈블 할 때 주소를 알 수 있습니까?

#include <stdio.h> 
#include <string.h> 

int main() 
{ 
    char name[20],address[500]; 
    printf("enter your name::: \n"); 
    fgets(name, sizeof(name), stdin); 
    printf("name you entered is:: %s \n", name); 
    printf("enter your name::: \n"); 
    fgets(address, sizeof(address), stdin); 
    printf("address you entered is:: %s \n", address); 
} 

위 예의 경우 각 줄마다 주소를 알고 싶습니다.

+0

당신은'objdump -S -d '를 사용하고 싶습니다. – indiv

답변

1

당신은 (내 GDB에 main() 기능)이 같은 gdb을 사용하여 어느 dissasembly 출력을 볼 수

(gdb) disas /m main 
Dump of assembler code for function main: 
5 { 
    0x000000000040066d <+0>: push %rbp 
    0x000000000040066e <+1>: mov %rsp,%rbp 
    0x0000000000400671 <+4>: sub $0x220,%rsp 
    0x0000000000400678 <+11>: mov %fs:0x28,%rax 
    0x0000000000400681 <+20>: mov %rax,-0x8(%rbp) 
    0x0000000000400685 <+24>: xor %eax,%eax 

6  char name[20],address[500]; 
7  printf("enter your name::: \n"); 
    0x0000000000400687 <+26>: mov $0x4007a4,%edi 
    0x000000000040068c <+31>: callq 0x400520 <[email protected]> 

8  fgets(name, sizeof(name), stdin); 
    0x0000000000400691 <+36>: mov 0x2009c0(%rip),%rdx  # 0x601058 <[email protected]@GLIBC_2.2.5> 
    0x0000000000400698 <+43>: lea -0x220(%rbp),%rax 
    0x000000000040069f <+50>: mov $0x14,%esi 
    0x00000000004006a4 <+55>: mov %rax,%rdi 
    0x00000000004006a7 <+58>: callq 0x400560 <[email protected]> 

9  printf("name you entered is:: %s \n", name); 
    0x00000000004006ac <+63>: lea -0x220(%rbp),%rax 
    0x00000000004006b3 <+70>: mov %rax,%rsi 
    0x00000000004006b6 <+73>: mov $0x4007b8,%edi 
    0x00000000004006bb <+78>: mov $0x0,%eax 
    0x00000000004006c0 <+83>: callq 0x400540 <[email protected]> 

10  printf("enter your name::: \n"); 
    0x00000000004006c5 <+88>: mov $0x4007a4,%edi 
    0x00000000004006ca <+93>: callq 0x400520 <[email protected]> 

11  fgets(address, sizeof(address), stdin); 
    0x00000000004006cf <+98>: mov 0x200982(%rip),%rdx  # 0x601058 <[email protected]@GLIBC_2.2.5> 
    0x00000000004006d6 <+105>: lea -0x200(%rbp),%rax 
    0x00000000004006dd <+112>: mov $0x1f4,%esi 
    0x00000000004006e2 <+117>: mov %rax,%rdi 
    0x00000000004006e5 <+120>: callq 0x400560 <[email protected]> 

12  printf("address you entered is:: %s \n", address); 
    0x00000000004006ea <+125>: lea -0x200(%rbp),%rax 
    0x00000000004006f1 <+132>: mov %rax,%rsi 
    0x00000000004006f4 <+135>: mov $0x4007d3,%edi 
    0x00000000004006f9 <+140>: mov $0x0,%eax 
    0x00000000004006fe <+145>: callq 0x400540 <[email protected]> 

13 } 
    0x0000000000400703 <+150>: mov -0x8(%rbp),%rcx 
    0x0000000000400707 <+154>: xor %fs:0x28,%rcx 
    0x0000000000400710 <+163>: je  0x400717 <main+170> 
    0x0000000000400712 <+165>: callq 0x400530 <[email protected]> 
    0x0000000000400717 <+170>: leaveq 
    0x0000000000400718 <+171>: retq 

End of assembler dump. 

또는에 의해 일부 분해 유틸리티를 사용하여 objdump (test 내 실행 파일을 컴파일의 결과입니다처럼 프로그램) :

$ objdump -S test 
int main() 
{ 
    40066d:  55      push %rbp 
    40066e:  48 89 e5    mov %rsp,%rbp 
    400671:  48 81 ec 20 02 00 00 sub $0x220,%rsp 
    400678:  64 48 8b 04 25 28 00 mov %fs:0x28,%rax 
    40067f:  00 00 
    400681:  48 89 45 f8    mov %rax,-0x8(%rbp) 
    400685:  31 c0     xor %eax,%eax 
    char name[20],address[500]; 
    printf("enter your name::: \n"); 
    400687:  bf a4 07 40 00   mov $0x4007a4,%edi 
    40068c:  e8 8f fe ff ff   callq 400520 <[email protected]> 
    fgets(name, sizeof(name), stdin); 
    400691:  48 8b 15 c0 09 20 00 mov 0x2009c0(%rip),%rdx  # 601058 <__TMC_END__> 
    400698:  48 8d 85 e0 fd ff ff lea -0x220(%rbp),%rax 
    40069f:  be 14 00 00 00   mov $0x14,%esi 
    4006a4:  48 89 c7    mov %rax,%rdi 
    4006a7:  e8 b4 fe ff ff   callq 400560 <[email protected]> 
    printf("name you entered is:: %s \n", name); 
    4006ac:  48 8d 85 e0 fd ff ff lea -0x220(%rbp),%rax 
    4006b3:  48 89 c6    mov %rax,%rsi 
    4006b6:  bf b8 07 40 00   mov $0x4007b8,%edi 
    4006bb:  b8 00 00 00 00   mov $0x0,%eax 
    4006c0:  e8 7b fe ff ff   callq 400540 <[email protected]> 
    printf("enter your name::: \n"); 
    4006c5:  bf a4 07 40 00   mov $0x4007a4,%edi 
    4006ca:  e8 51 fe ff ff   callq 400520 <[email protected]> 
    fgets(address, sizeof(address), stdin); 
    4006cf:  48 8b 15 82 09 20 00 mov 0x200982(%rip),%rdx  # 601058 <__TMC_END__> 
    4006d6:  48 8d 85 00 fe ff ff lea -0x200(%rbp),%rax 
    4006dd:  be f4 01 00 00   mov $0x1f4,%esi 
    4006e2:  48 89 c7    mov %rax,%rdi 
    4006e5:  e8 76 fe ff ff   callq 400560 <[email protected]> 
    printf("address you entered is:: %s \n", address); 
    4006ea:  48 8d 85 00 fe ff ff lea -0x200(%rbp),%rax 
    4006f1:  48 89 c6    mov %rax,%rsi 
    4006f4:  bf d3 07 40 00   mov $0x4007d3,%edi 
    4006f9:  b8 00 00 00 00   mov $0x0,%eax 
    4006fe:  e8 3d fe ff ff   callq 400540 <[email protected]> 
} 

둘 다의 출력은 단지 설명입니다. 꽤 광범위하기 때문에 나는 그것을 빼먹었습니다 ...

관련 문제