views:

133

answers:

1

I am trying to profile my application. For this I compiled my code with -pg and -lc_p option, it compiled successfully

During run time I am getting the following error. in free(): error: junk pointer, too high to make sense Segmentation fault: 11 (core dumped)

Doing GDB gives error as.

(gdb) b main
Breakpoint 1 at 0x5124d4:
(gdb) r
warning: Unable to get location for thread creation breakpoint: generic error
[New LWP 100085]
cacheIp in free(): error: junk pointer, too high to make sense

Program received signal SIGSEGV, Segmentation fault.
[Switching to LWP 100085]
0x00000000006c3a1f in pthread_sigmask ()

My application is multi threaded and is a combination of C and C++ code.

uname -a
FreeBSD 6.3-RELEASE FreeBSD 6.3-RELEASE #0: Wed Jan 16 01:43:02 UTC 2008    [email protected]:/usr/obj/usr/src/sys/SMP amd64

The code is working fine without the -pg option. Why is the code crashing with -pg. Am I missing something.

+1  A: 

You probably have one or more latent bugs in your code which are only manifesting themselves now that you are trying to profile with gprof. Try running your code under valgrind to flush out any bugs - fix those bugs - and then try profiling again.

Paul R
FYI, valgrind doesn't work with amd 64 Freebsd.
Mayank
Then either spend some time tracking down the bug or build on a system that does support valgrind. ;-)
Martin York
Do you have access to a Linux machine where you could run Valgrind? It does sound somewhat like lurking memory bugs. Also try explicitly compiling an x86 32 bit binary just to see if that changes things.
Mark B
@Mayank: your first priority needs to be to fix any memory-related bugs - it will probably be quicker to debug with valgrind on a system that supports it, but failing that you'll just have to debug the *old skool* way on your current system.
Paul R
@Paul R: sprtintf debugging! Yay!
John Dibling