Additional debugging library

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Fri Feb 20 23:42:37 UTC 2009


On Fri, 20 Feb 2009, Bernhard Reutner-Fischer wrote:

> On Fri, Feb 20, 2009 at 09:20:15PM +0100, Cristian Ionescu-Idbohrn wrote:
> >There are 2 CONFIG options available:
> >
> >	DMALLOC and EFENCE
> >
> >I don't seem to be able to get any one of them do what I expect them to :(
> >Is anyone using one or both and willing to share the magic?
>
> Not much of help i fear but I think that both worked in the 1.2.x era.
> What does not work?

Let's take electric-fence.  CONFIG instructions are:

	  Electric-fence support:
	  -----------------------
	  This enables compiling with Electric-fence support. Electric
	  fence is another very useful malloc debugging library which uses
	  your computer's virtual memory hardware to detect illegal memory
	  accesses. This support will make BusyBox be considerable larger
	  and run slower, so you should leave this option disabled unless
	  you are hunting a hard to find memory problem.

Makefile.flags has:

ifeq ($(CONFIG_EFENCE),y)
LDLIBS += efence
endif

After enabling that CONFIG and building a standalone ash, I see:

  LINK    busybox_unstripped
Trying libraries: crypt efence m
 Library crypt is not needed, excluding it
 Library efence is not needed, excluding it
 Library m is not needed, excluding it
Final link with: <none>


Same same but different with dmalloc.  CONFIG instructions talk about how
it could be used once the binary is built.  Thing is Makefile.flags would
need some more than only:

ifeq ($(CONFIG_DMALLOC),y)
LDLIBS += dmalloc
endif

Similar to efence:

  LINK    busybox_unstripped
Trying libraries: crypt dmalloc m
 Library crypt is not needed, excluding it
 Library dmalloc is not needed, excluding it
 Library m is not needed, excluding it
Final link with: <none>

I added some flag(s):

ifeq ($(CONFIG_DMALLOC),y)
CFLAGS += -DDMALLOC
#CFLAGS += -DDMALLOC_FUNC_CHECK
LDLIBS += dmalloc
endif

And got lots of these:

  CC      applets/applets.o
In file included from include/busybox.h:11,
                 from applets/applets.c:12:
include/libbb.h:541: error: expected declaration specifiers or '...'
before string constant
include/libbb.h:541: error: expected declaration specifiers or '...'
before numeric constant
include/libbb.h:541: error: expected declaration specifiers or '...'
before '(' token
include/libbb.h:541: error: expected declaration specifiers or '...'
before '-' token
include/libbb.h:541: error: expected declaration specifiers or '...'
before numeric constant
include/libbb.h:541: warning: function declaration isn't a prototype
include/libbb.h:541: error: conflicting types for 'dmalloc_strndup'
/usr/include/dmalloc.h:296: error: previous declaration of
'dmalloc_strndup' was here


Didn't dig any deeper, yet.

There's duma too:

Package: duma
Version: 2.5.14-2
Depends: libc6 (>= 2.7-1), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.1.1)
Description: library to detect buffer overruns and under-runs in C and C++
programs
 Open-source library to detect buffer overruns and under-runs
 in C and C++ programs.
 .
 This library is a fork of Bruce Perens Electric Fence library and adds
 some new features to it.

Did anyone play with it?

And all this investigation started up after running a simple script
with ash under valgrind:

$ valgrind --leak-check=full --show-reachable=yes ./ash ../ash-trap-exit.sh
==28795== Memcheck, a memory error detector.
==28795== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==28795== Using LibVEX rev 1878, a library for dynamic binary translation.
==28795== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==28795== Using valgrind-3.4.0-Debian, a dynamic binary instrumentation framework.
==28795== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==28795== For more details, rerun with: -v
==28795==
PID=28795
EXIT trap executed
==28795==
==28795== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 13 from 1)
==28795== malloc/free: in use at exit: 2,762 bytes in 63 blocks.
==28795== malloc/free: 64 allocs, 1 frees, 2,814 bytes allocated.
==28795== For counts of detected errors, rerun with: -v
==28795== searching for pointers to 63 not-freed blocks.
==28795== checked 71,412 bytes.
==28795==
==28795== 64 bytes in 2 blocks are still reachable in loss record 1 of 3
==28795==    at 0x402401E: malloc (vg_replace_malloc.c:207)
==28795==    by 0x40BC0EF: strdup (in /lib/i686/cmov/libc-2.7.so)
==28795==    by 0x804B0E7: ckstrdup (ash.c:1246)
==28795==    by 0x804A09C: (within .../busybox-ash/busybox_unstripped)
==28795==
==28795==
==28795== 902 bytes in 55 blocks are still reachable in loss record 2 of 3
==28795==    at 0x402401E: malloc (vg_replace_malloc.c:207)
==28795==    by 0x402419F: realloc (vg_replace_malloc.c:429)
==28795==    by 0x804B093: ckrealloc (ash.c:1222)
==28795==    by 0x804A09C: (within .../busybox-ash/busybox_unstripped)
==28795==
==28795==
==28795== 1,796 bytes in 6 blocks are still reachable in loss record 3 of 3
==28795==    at 0x402401E: malloc (vg_replace_malloc.c:207)
==28795==    by 0x804A76E: xmalloc (xfuncs_printf.c:47)
==28795==    by 0x804A09C: (within .../busybox-ash/busybox_unstripped)
==28795==
==28795== LEAK SUMMARY:
==28795==    definitely lost: 0 bytes in 0 blocks.
==28795==      possibly lost: 0 bytes in 0 blocks.
==28795==         suppressed: 0 bytes in 0 blocks.
==28795==    still reachable: 2,762 bytes in 63 blocks.
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Cheers,

-- 
Cristian


More information about the busybox mailing list