?
Solved

Segmentation fault accessing local variables

Posted on 2013-05-17
7
Medium Priority
?
521 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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 

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 1500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

862 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