This is the mail archive of the
gdb@sourceware.cygnus.com
mailing list for the GDB project.
Re: automatic adding of memory access breakpoints
- To: Erik Thiele <erikyyy at erikyyy dot de>, gdb at sourceware dot cygnus dot com
- Subject: Re: automatic adding of memory access breakpoints
- From: Kevin Buettner <kevinb at cygnus dot com>
- Date: Wed, 7 Jun 2000 09:40:09 -0700
- References: <20000607145409.A6582@vulcain.yyydom>
On Jun 7, 2:54pm, Erik Thiele wrote:
> i have program that automatically creates blocks in memory
> where the debugger shall break once someone accesses the block
> both reading or writing.
>
> yes this is a malloc debugger.
>
> the idea:
>
> if you do void *pt = malloc (1000);
> you get:
>
> KILLERBLOCK data KILLERBLOCK
> ^
> \_ pt
>
> if you do free(pt);
> he will check if one of the killerblocks has changed.
>
> but then i cannot say anymore when they were changed.
> to quit once they are changed i need debugger help.
> how can my program automatically add such blocks into gdb???
>
> or is there some way to do this linux level?
> i.e. any mmap tricks ?
>
> all i need is a segfault or buserror or whatsoever
> right in the moment someone accesses the KILLERBLOCKs.
You should look at the way that Electric Fence is implemented. It too
is a malloc debugger which may be used to check buffer underruns and
overruns. You can even arrange things so that it will detect *any*
attempt to access previously freed memory.
Electric Fence uses mmap() to allocate memory and mprotect() to create
the barriers that you call "KILLERBLOCKs". All you need to do is
disable read and write access (via mprotect()) to that page of memory
and the OS will give you a SIGSEGV should your program touch the
"KILLERBLOCK".
Kevin