Solved

Segmentation fault accessing local variables

Posted on 2013-05-17
7
456 Views
Last Modified: 2013-05-20
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
0
Comment
Question by:sctccomm
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39176409
Could you post the code?
0
 

Author Comment

by:sctccomm
ID: 39176436
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..
0
 
LVL 86

Expert Comment

by:jkr
ID: 39176468
Maybe a snippet of that code?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:sctccomm
ID: 39176497
I'll start working on reducing it, but there is so much code it will probably take a couple of days.

Thanks !
0
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 39176547
>> I can no longer access any local (stack) variables without getting a segmentation fault
If you increased the size of an auto-array to exceed the stack size limit, you may experience the symptoms you described.
0
 

Author Closing Comment

by:sctccomm
ID: 39182141
Turns out here is a memcpy that is passed the wrong size parameter
0
 
LVL 32

Expert Comment

by:phoffric
ID: 39182365
nasty little bug.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now