0

I think I am experiencing a stack overflow issue when running my unit-tests through gdb within emacs on Windows.

I run exactly the same unit-tests on linux with no problems

I am also aware that I am using a horrendously memory inefficient stack-based .ini file parser within these unit-tests so it would seem to be a reasonable possibility that stack overflow is occuring.

I have noticed a few unit tests faling on Windows that passed on Linux. Further investigation reveals a (stack-based) counter in a for loop resetting itself to zero at random points in the for loops execution and the (stack-based) values in the arrays that the for loop is inspecting change for the same index value

I noticed that gdb seems to be allocated its own thread of execution under Windows - is there any way of finding out how much stack space the thread is allocated?

2 Answers 2

2

One of the differences between Linux and Windows is that on Windows the stack-size has to be set at compile-time (there are two sizes, initial and a predefined reserved limit). Not sure what the default is with the compiler you are using, but you might try to increase it using --stack parameter (gcc).

On Linux the stack-size is dynamic up to the limits, generally set by the sysadmin.

Sign up to request clarification or add additional context in comments.

5 Comments

using mingw from within emacs so that should work - i'll give it a go. out of interest how could you find out what the default value of --stack parameter is?
I guess that is RTFM for gcc. For Visual Studio the initial limit is 4KB and the reserved limit is 1MB, if I had to guess then gcc is probably similar.
haha RTFM always the last resort - 4KB seems surprisingly small for MSVC
RTFM meaning "Read The Fine Manual", of course. Yes, 4KB is small, and these limits are the same for the default process heap as well.
On 32-bit machines, no, it is only 1MB. Yes, I have had occasion to increase it.
0

Well then, perhaps Windows has tighter restrictions on the maximum amount of stack per process than Linux does?

This page details how to debug a stack overflow in Windows. It's not based on gdb, but perhaps you can still infer something.

1 Comment

is there any user control on the amount of stack allocated by gdb, or just running an exe from the cmd line for that matter?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.