1

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"

3
  • Try compiling with -O0. Call strcpy() might have optimized to make it as inline function. Commented Mar 21, 2014 at 6:42
  • 1
    According to gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html strcpy is a function that can be replaced with a builtin function. Commented Mar 21, 2014 at 6:46
  • Looks to me like the compiler is free to do just about anything with your code, given the undefined behaviour from accessing uninitialised memory after char str_a[20];. Commented Mar 21, 2014 at 15:28

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.