Linker 使用gdb在LibC中设置断点

Linker 使用gdb在LibC中设置断点,linker,gdb,debug-symbols,libc,Linker,Gdb,Debug Symbols,Libc,为什么我不能在LibC中的导出函数中设置断点(使用gdb)?作为动态链接的Libc,它必须包含它导出的函数的符号。难道我不能为这些函数中的任何一个设置断点吗 我只是想做: (gdb) b _IO_vfprintf@@GLIBC_2.2.5 Function "_IO_vfprintf@@GLIBC_2.2.5" not defined. 但查看ELF文件中的dynamyc symbols表,该符号确实存在: 127: 0000000000049cf0 20904 FUNC GLOBAL

为什么我不能在LibC中的导出函数中设置断点(使用gdb)?作为动态链接的Libc,它必须包含它导出的函数的符号。难道我不能为这些函数中的任何一个设置断点吗

我只是想做:

(gdb) b _IO_vfprintf@@GLIBC_2.2.5
Function "_IO_vfprintf@@GLIBC_2.2.5" not defined.
但查看ELF文件中的dynamyc symbols表,该符号确实存在:

 127: 0000000000049cf0 20904 FUNC    GLOBAL DEFAULT   12 _IO_vfprintf@@GLIBC_2.2.5

我不知道你是如何想出你正在使用的符号名的,但以下是我在我的系统(Ubuntu 14.04.1)上看到的:


下面是一个演示程序:

   #include <stdio.h>
   #include <stdarg.h>

int myprintf( const char *format, ... )
   {
   va_list ap;
   va_start( ap, format );
   int result = _IO_vfprintf( stderr, format, ap );
   va_end(ap);
   return result;
   }

int main()
   {
   myprintf( "hello world! %s %s %s\n", "abc", "def", "ghi" );
   myprintf( "goodbye world! %d %d\n", 123, 456 );
   return 0;
   }
所以是的,它是有效的


将其提升到下一个级别--您可以通过应用以下命令逐步了解libc源代码

$ sudo apt-get install libc6-dbg ## get the debug symbols
$ apt-get source libc-dev-bin ## download the source (on Ubuntu or similar)
$ gdb --quiet --directory ./eglibc-2.19/stdio-common ./test

相关注释。

你说得对。如果我启动这个程序,那么我就可以使用它的符号作为断点值进入Libc。我想这是因为我运行gdb时库还没有加载。它们仅在我运行程序时加载。谢谢
$ make CFLAGS="-Wall -Werror -g" test && ./test

$ objdump --disassemble test |grep vfprintf ## verify call isn't inlined
0000000000400480 <_IO_vfprintf@plt>:
  40061e:   e8 5d fe ff ff          callq  400480 <_IO_vfprintf@plt>

$ gdb --quiet ./test
Reading symbols from ./test...done.

(gdb) b main
Breakpoint 1 at 0x400635: file test.c, line 16.

(gdb) run
Starting program: .../test 

Breakpoint 1, main () at test.c:16
16     myprintf( "hello world! %s %s %s\n", "abc", "def", "ghi" );

(gdb) b _IO_vfprintf
Breakpoint 2 at 0x7ffff7a5ecf4

(gdb) cont
Continuing.

Breakpoint 2, 0x00007ffff7a5ecf4 in vfprintf () from /lib/x86_64-linux-gnu/libc.so.6
$ sudo apt-get install libc6-dbg ## get the debug symbols
$ apt-get source libc-dev-bin ## download the source (on Ubuntu or similar)
$ gdb --quiet --directory ./eglibc-2.19/stdio-common ./test