|
From: Rob H. <ti...@ge...> - 2005-08-16 17:28:07
|
Hi, I've uploaded a valgrind tool which I created out of bits of various existing tools. The code can be found here: http://dev.gentoo.org/~tigger/fc_main.c It's basically a 300 line no-op at the moment as it doesn't print anything. It's intended to keep track of what's on the heap. However, needs_malloc_replacement isn't having the effect which I expected. Namely, my replacements aren't being run. I can add a VG_(exit)(1); into the malloc routine and nothing changes. I'm a bit lost as to why it's not being used. Anyone have any idea? Thanks, Rob |
|
From: Nicholas N. <nj...@cs...> - 2005-08-16 18:47:38
|
On Tue, 16 Aug 2005, Rob Holland wrote: > I've uploaded a valgrind tool which I created out of bits of various > existing tools. > > The code can be found here: > > http://dev.gentoo.org/~tigger/fc_main.c > > It's basically a 300 line no-op at the moment as it doesn't print > anything. It's intended to keep track of what's on the heap. > > However, needs_malloc_replacement isn't having the effect which I > expected. Namely, my replacements aren't being run. > > I can add a VG_(exit)(1); into the malloc routine and nothing changes. > > I'm a bit lost as to why it's not being used. > > Anyone have any idea? I just tried running your code after inserting a VG_(printf)() statement into alloc_and_new_mem() and it was executed as expected. Is your program definitely calling malloc()? Try using --trace-malloc=yes to see if it is. Nb: You based the code off Helgrind, it might be worth instead basing it off Massif from the current SVN trunk; a few changes have gone in over the last few days that make this stuff a bit neater -- the VgHashTable type has changed a bit so you don't have to use as many casts, and you can use simple lookup() and remove() functions rather than the strange VG_(HT_get_node)() function. Your current code will still work, though, if you don't feel like changing it. Do you have a clear idea how you'll check format strings? I'd be interested to hear what you have planned. Hope this helps! Ask again if you have more problems. Nick |
|
From: Rob H. <ti...@ge...> - 2005-08-16 19:23:11
|
On Tue, 2005-08-16 at 13:47 -0500, Nicholas Nethercote wrote:
> I just tried running your code after inserting a VG_(printf)() statement
> into alloc_and_new_mem() and it was executed as expected. Is your program
> definitely calling malloc()? Try using --trace-malloc=yes to see if it
> is.
I was running it on "ls". Just to make 100% sure I did:
tigger@xahn % cat test.c
#include <stdio.h>
#include <malloc.h>
int main(int argc, char **argv) {
void *data;
data = malloc(2);
}
tigger@xahn % gcc test.c
tigger@xahn % valgrind --trace-malloc=yes --tool=formatcheck ./a.out
==20590== formatcheck, format string check.
==20590== Copyright (C) 2005, and GNU GPL'd, by Rob Holland.
==20590== Using LibVEX rev 1338, a library for dynamic binary
translation.
==20590== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==20590== Using valgrind-3.1.SVN, a dynamic binary instrumentation
framework.
==20590== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et
al.
==20590== For more details, rerun with: -v
==20590==
==20590==
tigger@xahn %
This was having done 'svn up; make'.
I don't get it :/
If it makes any difference, I'm on an amd64.
> Nb: You based the code off Helgrind, it might be worth instead basing it
> off Massif from the current SVN trunk; a few changes have gone in over
> the last few days that make this stuff a bit neater -- the VgHashTable
> type has changed a bit so you don't have to use as many casts, and you can
> use simple lookup() and remove() functions rather than the strange
> VG_(HT_get_node)() function. Your current code will still work, though,
> if you don't feel like changing it.
Cool, thanks for the hint.
> Do you have a clear idea how you'll check format strings? I'd be
> interested to hear what you have planned.
I'm attempting to turn the preload library written by the Gentoo Audit
Team into a valgrind tool so we can do more advanced checks. We'll be
generating a lot of noise (I hope to learn more about suppression
shortly ;) but basically we aim to warn about *printf without any format
specifiers, format strings which aren't string literals, that kind of
thing.
It's pretty noisy, but it's useful for spotting potential problems:
user-fed format strings, double expansion and so on.
Thanks for the help!
Rob
|
|
From: Rob H. <ti...@ge...> - 2005-08-16 20:06:45
|
On Tue, 2005-08-16 at 20:23 +0100, Rob Holland wrote: > On Tue, 2005-08-16 at 13:47 -0500, Nicholas Nethercote wrote: > > > I just tried running your code after inserting a VG_(printf)() statement > > into alloc_and_new_mem() and it was executed as expected. Is your program > > definitely calling malloc()? Try using --trace-malloc=yes to see if it > > is. > > I was running it on "ls". Just to make 100% sure I did: Sorry, misunderstood what you meant. If I run simply: 'valgrind --trace-malloc=yes ls' it does indeed print lots of malloc/frees properly. Still none the wiser as to why my code is broken :( Cheers, Rob |
|
From: Nicholas N. <nj...@cs...> - 2005-08-16 20:33:24
|
On Tue, 16 Aug 2005, Rob Holland wrote:
> tigger@xahn % valgrind --trace-malloc=yes --tool=formatcheck ./a.out
> ==20590== formatcheck, format string check.
> ==20590== Copyright (C) 2005, and GNU GPL'd, by Rob Holland.
> ==20590== Using LibVEX rev 1338, a library for dynamic binary
> translation.
> ==20590== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
> ==20590== Using valgrind-3.1.SVN, a dynamic binary instrumentation
> framework.
> ==20590== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et
> al.
> ==20590== For more details, rerun with: -v
> ==20590==
> ==20590==
> tigger@xahn %
>
> If I run simply: 'valgrind --trace-malloc=yes ls' it does indeed print
> lots of malloc/frees properly.
Valgrind's replacement versions of malloc et al aren't being called.
What does the Makefile.am in valgrind/formatcheck/ look like? It should
look like this:
include $(top_srcdir)/Makefile.tool.am
val_PROGRAMS = vgtool_formatcheck.so vgpreload_formatcheck.so
vgtool_formatcheck_so_SOURCES = fc_main.c
vgtool_formatcheck_so_LDFLAGS = -shared
vgpreload_formatcheck_so_SOURCES =
vgpreload_formatcheck_so_DEPENDENCIES = \
$(LIBREPLACEMALLOC)
vgpreload_formatcheck_so_LDFLAGS = -shared -Wl,-z,interpose,-z,initfirst \
-Wl,--whole-archive \
$(LIBREPLACEMALLOC) \
-Wl,--no-whole-archive
If I take out all the vg_preload_formatcheck_so parts, I get the same
behaviour as you.
Nick
|
|
From: Rob H. <ti...@ge...> - 2005-08-16 20:48:33
|
On Tue, 2005-08-16 at 15:33 -0500, Nicholas Nethercote wrote: > Valgrind's replacement versions of malloc et al aren't being called.=20 > What does the Makefile.am in valgrind/formatcheck/ look like? It should=20 > look like this: It didn't. I'd copied it from none/ and just substituted nl->fc :) > If I take out all the vg_preload_formatcheck_so parts, I get the same=20 > behaviour as you. Works now! Many thanks :) Now to switch it to the Massif model :) Rob --=20 - Rob Holland [ Gentoo Audit Team ] |