Memory corruption problem

Sam Halliday fommil@yahoo.ie
Thu Oct 24 13:26:00 GMT 2002


On Thu, 24 Oct 2002 15:29:47 -0400 ducharme@uqo.ca wrote:
> I am using gcc 2.95 on Sun SPARC Solaris 8.
poor you...

> I am experimenting a memory corruption problem in a C++
> program.  I have put in some traces and I know exactly
> where the memory corrruption happens but, at that point,
> I have most likely already overwritten some memory.
> The program terminates normally but outputs partially
> corrupted data.
> I have been through my source code but I cannot seem to
> find where I could be writing to some unallocated memory.
have you broke your algos into tiny standalone programs and seen if any
of them show the effects individually?

> I was wondering if there was some library routines which
> could help me locate where I am overwriting unaloocated
> memory.
there certainly are... try Taj Khattra's mpr package at
ftp://metalab.unc.edu/pub/Linux/devel/lang/c/mpr-2.2.tar.gz
read the docs about it, essentially you build this static lib and build
with it (making sure to use -g), set some environment variables and run
your program. the output when you run your program will gove you no info
at all.. but use the output  with the mprlk program in the same
package... a shortcut would be
export MPRPC='mprpc <your program name>'
export MPRFI='cat > badmem.log'
mpr -f -l <your program name> < badmem.log | mprlk
i've never used it myself, but a programming book i once read spoke well
of its uses...

or you can use electric fence at
ftp://metalab.unc.edu/pub/Linux/devel/lang/c/ElectricFence-2.0.5.tar.gz

or use a lint brush like splint
http://www.splint.org/

i have only ever used splint.. which is nice the first few time syou run
it and learn a bit, but annoying afterwards....

im afraid its a lot of RTFM form there as i cant help any more than
this...

cheers,
Sam
-- 
If you aren't rich you should always look useful.
-- Louis-Ferdinand Celine



More information about the Gcc-help mailing list