Link to home
Start Free TrialLog in
Avatar of sctccomm
sctccomm

asked on

Segmentation fault accessing local variables

Hello There Experts,

I'm seeing a very strange problem with my multi-threaded C++ application. After calling a certain function (in main()) I can no longer access any local (stack) variables without getting a segmentation fault. Also, calling return() produces the same results. Moving the variables to the heap makes it run. The function called is not passed any of the local variables, but it does create several new threads. I'm suspecting stack corruption, so got the stack pointer using 'register int stackp asm("r1")' and printed out 50 nearest dwords with addresses higher than the stack pointer, but its the same. I set a local variable to a specific value and was able to see it in the print-out, so my method looks like its right.

I'm a C-guy so I'm not sure if I'm missing some C++ thing here or what's going on.

Any advice or help is appreciated,

Thanks

/SC

Btw, I'm using the following

ARCH: Microblaze
Linux 3.6.0
GCC 4.6.4
Binutils  2.22.90
egLibc 2.14.90
Avatar of jkr
jkr
Flag of Germany image

Could you post the code?
Avatar of sctccomm
sctccomm

ASKER

I wish, its 5 megabytes of fairly complicated source code. I'll try to distill it down.

I did discover something new though. I'm no expert on this but looking at the assembly code it looks like r19 is used to point to the stack base. The problem is that this value's most significant byte is wiped out after calling that function I mentioned earlier.

R19 Before: 0xbf945db8
R19 After:   0x00945db8

The crash happens as soon as a "load word immediate" instruction is called with r19 as a pointer. Very strange..
Maybe a snippet of that code?
I'll start working on reducing it, but there is so much code it will probably take a couple of days.

Thanks !
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Turns out here is a memcpy that is passed the wrong size parameter
nasty little bug.