Can't step into string.h function with GDB

匿名 (未验证) 提交于 2019-12-03 02:29:01

问题:

Having trouble stepping into string.h in GDB 7.5. Here's a simple example program:

Source code:

#include  #include   int main() {     char str1[20];     strcpy(str1, "STEP INTO ME\n");     printf(str1); }

Compiled: ~$ gcc -g foo.c

Invoked: ~$ gdb -q ./a.out

GDB:

(gdb) break 5 Breakpoint 1 at 0x8048471: file foo.c, line 6. (gdb) break strcpy Function "strcpy" not defined. Make breakpoint pending on future shared library load? (y or [n]) y  Breakpoint 2 (strcpy) pending. (gdb) run  Starting program: /home/user/a.out   Breakpoint 1, main () at foo.c:6 6               strcpy(str_a, "Hello, world!\n"); (gdb) step 7               printf(str_a);

Shouldn't I be in the string library at this point? Instead it continues to the printf().


EDIT:

Scott's suggestion "worked", but not in the expected manner.

Breakpoint 1, main () at foo.c:6 6               strcpy(str_a, "Hello, world!\n"); (gdb) i r $eip eip            0x80484a1        0x80484a1 
(gdb) step Breakpoint 2, __strcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/strcpy-ssse3.S:78 78 ../sysdeps/i386/i686/multiarch/strcpy-ssse3.S: No such file or directory. (gdb) i r $eip eip 0xb7e9c820 0xb7e9c820 <__strcpy_ssse3>
+21>

I am surprised at the directory in 78... expected something like: /lib/.../cmov/libc.so.6. And the claim that there is no such file or directory.

回答1:

Recompile your code with gcc -fno-builtin -g foo.c and the gdb step command will work. (See -fno-builtin documentation). Otherwise small strcpy(), memcpy() calls would often be translated into open coded data movement instructions, e.g. on x86-64:

4   int main() {    0x000000000040052c <+0>: push   %rbp    0x000000000040052d <+1>: mov    %rsp,%rbp    0x0000000000400530 <+4>: sub    $0x20,%rsp  5       char str1[20]; 6       strcpy(str1, "STEP INTO ME\n");    0x0000000000400534 <+8>: lea    -0x20(%rbp),%rax    0x0000000000400538 <+12>:    movl   $0x50455453,(%rax)    0x000000000040053e <+18>:    movl   $0x544e4920,0x4(%rax)    0x0000000000400545 <+25>:    movl   $0x454d204f,0x8(%rax)    0x000000000040054c <+32>:    movw   $0xa,0xc(%rax)  7       printf(str1);    0x0000000000400552 <+38>:    lea    -0x20(%rbp),%rax    0x0000000000400556 <+42>:    mov    %rax,%rdi    0x0000000000400559 <+45>:    mov    $0x0,%eax    0x000000000040055e <+50>:    callq  0x400410   8   }    0x0000000000400563 <+55>:    leaveq     0x0000000000400564 <+  
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!