This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: automatic adding of memory access breakpoints

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:
>             ^
> 	    \_ 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]