linker - Set a breakpoint into LibC with gdb -
why cannot set breakpoint (using gdb) in exported function within libc? being libc dynamically linked, must contains symbols of functions exports. shouldn't able set breakpoint of these functions?
i merely tried do:
(gdb) b _io_vfprintf@@glibc_2.2.5 function "_io_vfprintf@@glibc_2.2.5" not defined.
but looking @ dynamyc-symbols table in elf file symbol exist:
127: 0000000000049cf0 20904 func global default 12 _io_vfprintf@@glibc_2.2.5
i don't know how came symbol name using, here's see on system (ubuntu 14.04.1):
$ objdump --dynamic-syms /lib/x86_64-linux-gnu/libc.so.6 |grep vfprintf 0000000000049cf0 g df .text 00000000000051a8 glibc_2.2.5 _io_vfprintf 00000000001097e0 g df .text 0000000000000111 glibc_2.3.4 __vfprintf_chk 0000000000049cf0 g df .text 00000000000051a8 glibc_2.2.5 vfprintf
here's demonstration program:
#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; }
i found complains less if first run main()
, then set breakpoint b _io_vfprintf
.
$ 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 ./test...done. (gdb) b main breakpoint 1 @ 0x400635: file test.c, line 16. (gdb) run starting program: .../test breakpoint 1, main () @ test.c:16 16 myprintf( "hello world! %s %s %s\n", "abc", "def", "ghi" ); (gdb) b _io_vfprintf breakpoint 2 @ 0x7ffff7a5ecf4 (gdb) cont continuing. breakpoint 2, 0x00007ffff7a5ecf4 in vfprintf () /lib/x86_64-linux-gnu/libc.so.6
so yes, works...
taking next level -- can step through libc source applying following commands...
$ sudo apt-get install libc6-dbg ## debug symbols $ apt-get source libc-dev-bin ## download source (on ubuntu or similar) $ gdb --quiet --directory ./eglibc-2.19/stdio-common ./test
related notes here.
Comments
Post a Comment