tot dumps core

Poul-Henning Kamp phk at phk.freebsd.dk
Wed Jul 19 13:42:03 CEST 2006


In message <ujrac75et4i.fsf at cat.linpro.no>, Dag-Erling =?iso-8859-1?Q?Sm=F8rgra
v?= writes:
>"Poul-Henning Kamp" <phk at phk.freebsd.dk> writes:
>> As you've seen I've found the missing star.
>>
>> No, I'm not proud of that taking me a day to find.
>
>Shit happens.  The question is, what can we do to catch the next
>missing star faster?

I used a little thing I have that I call "miniobj.h".

It is a bunch of macros and a magic field in all structs with
a unique value:
	

	 struct object {        
	+       unsigned                magic;
	+#define OBJECT_MAGIC           0x32851d42
		[...]
	}


When you allocate a structure, you have to set the magic
field correctly:

		w->nobj = calloc(sizeof *w->nobj, 1);
                assert(w->nobj != NULL);
+               w->nobj->magic = OBJECT_MAGIC;

And then you can check that all over the place, but in particular
where void pointers have been used to carry your pointer:

                o = binheap_root(exp_heap);
+               if (o != NULL)
+                       CHECK_OBJ(o, OBJECT_MAGIC);


It's the kind of thing I wish I could get the compiler to do
(and it's part of the 'K' language thing I'm playing with)

I havn't quite decided if I want to commit this to Varnish
but I may do so later today.

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.



More information about the varnish-dev mailing list