Solved

Segmentation fault accessing local variables

Posted on 2013-05-17
7
459 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

911 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

21 Experts available now in Live!

Get 1:1 Help Now