2010-10-19 130 views
1

我有gdb問題,它並沒有停在一個函數中。你能解釋調用strcpy之後爲什麼以及如何停止程序嗎?如何使用共享庫函數在gdb中設置斷點

[email protected]:~/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 
[email protected]:~/poligon$ 

回答

7

您可能正在使用gcc的__builtin_strcpy。編譯gcc -fno-builtin,看看是否有幫助。

欲瞭解更多信息,請參閱:http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/C-Dialect-Options.html#C-Dialect-Options

+0

是的,它可以幫助 - 使用gcc的交換機-fno-內置從這樣的行爲阻止@ – user480162 2010-10-19 08:59:02

+0

編譯user480162 strcpy的變化將memcpy的優化目的:GCC會自動在一定的使用'__builtin_strcpy'而不是調用標準庫'strcpy',除非用'-fno-builtin'編譯。使用'gcc -S'來查看您的案例中正在生成的內容。 – 2010-10-19 09:01:39