I’ve got a memory leak in Upstart init process (pid 1), what options I have on debugging it?
EDIT: Suggest me some real tools for this, manually putting printfs or calculating memory allocations by hand isn’t gonna cut it. Also dumping init core and poking around that is not really an option.
UPD1: valgrind doesn’t work. Replacing /sbin/init on kernel command line with proper valgrind + init magic doesn’t seem to be an option as it tries to access /proc for self for smaps, but those isn’t available before init is ran.
UPD2: dmalloc doesn’t work either (doesn’t compile on ARM).
A poor man’s solution would be to just log every call
mallocandfree, then comb through the logs and look for pattern.ldprovides an amazing feature that could help here.Update
Just to be clear on how this is useful.
Like this:
Recompile upstart with debug symbols (
-g) so you can get some nice backtraces. You can still optimize (-O2/-O3) the code if you wish.Link Upstart with the extra
LD_FLAGS--wrap=malloc,--wrap=free.Now anywhere Upstart calls
mallocthe symbol will be magically resolved to your new symbol__wrap_malloc. Beautifully this is all transparent to the compiled code as it happens at link time.It’s like shimming or instrumenting with out any of the mess.
Run the recompiled Upstart as usual until you’re sure the leak has occured.
Look through the logs for mismatch
malloceds andaddrs.A couple of notes:
--wrap=symbolfeature does not work with function names that are actually macros. So watch out for#define malloc nih_malloc. The this is what libnih does you’d need to use--wrap=nih_mallocand__wrap_nih_mallocinstead.