1

I have problem with gdb, it wasn't stop in one function. Can you explain why and how to stop program after calling strcpy?

grzes@trampek:~/poligon$ gdb ./char_array2 
GNU gdb (GDB) 7.2
Copyright (C) 2010 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-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/grzes/poligon/char_array2...done.
(gdb) list
1    #include <stdio.h>
2    #include <string.h>
3    
4    int main() {
5       char str_a[20];
6       printf("ssss");
7       strcpy(str_a, "Hello, world!\n");
8       printf(str_a); 
9    }
10    
(gdb) break main
Breakpoint 1 at 0x8048465: file char_array2.c, line 4.
(gdb) run
Starting program: /home/grzes/poligon/char_array2 

Breakpoint 1, main () at char_array2.c:4
4    int main() {
(gdb) break strcpy
Breakpoint 2 at 0x1a1205
(gdb) cont
Continuing.
ssssHello, world!

Program exited with code 016.
(gdb) q
grzes@trampek:~/poligon$ 

1 Answer 1

7

You may be using gcc's __builtin_strcpy. Compile with gcc -fno-builtin and see if that helps.

For more info see: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/C-Dialect-Options.html#C-Dialect-Options

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

2 Comments

yes, it helps - compiler changes strcpy into memcpy for optimization purpose using gcc's switches -fno-builtin prevents from such behave
@user480162: gcc will automatically use __builtin_strcpy in certain cases rather than calling the standard library strcpy unless you compile with -fno-builtin. Use gcc -S to see what's being generated in your case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.