Hello,
I am looking at the DynInst API to instrument applications to
detect memory errors. Very impressed with the platform
independence of the API thus far.
Studying the maxarg.C tutorial code on
http://www.paradyn.org/tutorial/ with
DynInst 9.2.0 on Ubuntu 16.04 Desktop and gcc 5.3.1, I encounter
two issues, the second blocking me:
1) The maxarg tutorial tries to add a snippet to malloc() in
libc.so. It tries to find the malloc function in the module with
substring "libc" using findModule(). As I understand the API,
this will find the module of libc.so.6, but malloc() may well be
implemented in a separate source file, and hence another module
name. I corrected the example by first obtaining the libc.so.6
BPatch_object, and then using findFunction on the object, which
walks over all modules in the libc.so.6. A findObject()
convenience function on the BPatch_image would be nice here.
2) Still, the example cannot find the function malloc() in
the libc object. obj->findFunction("malloc") works on all
modules in the libc object, but fails to find malloc. It does
work for free(), returning "__GI___libc_free" as the function
name in /lib/x86_64-linux-gnu/libc-2.23.so.
malloc seems to be present in libc:
$ readelf -s /lib/x86_64-linux-gnu/
libc-2.23.so | grep malloc
443: 0000000000083550 414 FUNC GLOBAL DEFAULT 13
__libc_malloc@@GLIBC_2.2.5
550: 0000000000086e70 24 FUNC WEAK DEFAULT 13
malloc_info@@GLIBC_2.10
820: 0000000000086560 474 FUNC WEAK DEFAULT 13
malloc_stats@@GLIBC_2.2.5
992: 0000000000083850 539 FUNC WEAK DEFAULT 13
malloc_get_state@@GLIBC_2.2.5
1088: 00000000003c3b10 8 OBJECT WEAK DEFAULT 33
__malloc_hook@@GLIBC_2.2.5
1185: 0000000000083550 414 FUNC GLOBAL DEFAULT 13
malloc@@GLIBC_2.2.5
1221: 00000000000845f0 498 FUNC WEAK DEFAULT 13
malloc_usable_size@@GLIBC_2.2.5
1467: 0000000000086170 705 FUNC WEAK DEFAULT 13
malloc_trim@@GLIBC_2.2.5
1787: 00000000003c57b0 8 OBJECT WEAK DEFAULT 34
__malloc_initialize_hook@@GLIBC_2.2.5
2087: 00000000000856b0 1320 FUNC WEAK DEFAULT 13
malloc_set_state@@GLIBC_2.2.5
And my test program explicitly calls malloc:
$ nm -g test1/test |grep malloc
U malloc@@GLIBC_2.2.5
Any ideas what I do wrong here to try to find and instrument
malloc()? I hope you can help me further.
Thanks,
Martijn
martijn@xxxxxxxxxxxxxxxxx