Gdb和外部函数

时间:2014-03-21 06:35:42

标签: c debugging assembly gdb

所以我有以下代码

(gdb) list
#include<stdio.h>
#include<string.h>

int main()
{
char str_a[20];

strcpy(str_a,"Hello World!\n");
printf(str_a);
}

但是当我用gdb反汇编它时,没有引用strcpy。而是显示函数strcpy的内部。

(gdb) disassemble main
Dump of assembler code for function main:
0x00000000004004fd <+0>:     push   rbp
0x00000000004004fe <+1>:     mov    rbp,rsp
0x0000000000400501 <+4>:     sub    rsp,0x20
0x0000000000400505 <+8>:     lea    rax,[rbp-0x20]
0x0000000000400509 <+12>:    movabs rdx,0x6f57206f6c6c6548
0x0000000000400513 <+22>:    mov    QWORD PTR [rax],rdx
0x0000000000400516 <+25>:    mov    DWORD PTR [rax+0x8],0x21646c72
0x000000000040051d <+32>:    mov    WORD PTR [rax+0xc],0xa
0x0000000000400523 <+38>:    lea    rax,[rbp-0x20]
0x0000000000400527 <+42>:    mov    rdi,rax
0x000000000040052a <+45>:    mov    eax,0x0
0x000000000040052f <+50>:    call   0x4003e0 <printf@plt>
0x0000000000400534 <+55>:    leave  
0x0000000000400535 <+56>:    ret    
End of assembler dump.

如何让GDB以引用printf的方式引用strcpy? 我正在编写“gcc -g”

1 个答案:

答案 0 :(得分:2)

尝试使用-fno-builtin编译您的程序。

gcc中,strcpy是内置函数。另请参阅6.56 Other Built-in Functions Provided by GCC