Metaliinuxite
Metaliinuxite

Reputation: 41

Gdb and external functions

So I have the following code

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

int main()
{
char str_a[20];

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

But when I disassemble it with gdb, strcpy isn't referenced. Instead the inside of the function strcpy is shown.

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

How can I get GDB to reference strcpy the way it references printf? I'm compiling with "gcc -g"

Upvotes: 1

Views: 597

Answers (1)

Lee Duhem
Lee Duhem

Reputation: 15111

Try compiling your program with -fno-builtin.

In your gcc, strcpy is a builtin function. See also 6.56 Other Built-in Functions Provided by GCC.

Upvotes: 3

Related Questions