From: Balazs R. <ba...@ra...> - 2004-01-17 21:37:19
|
First of all let me thank you guys for valgrind; it's been a life saver many times for me, begining C programmer. There's only one thing I cannot figure out: I get this error in my program: ==7819== Warning: client switching stacks? %esp: 0xBFFFF4FC --> 0xBFC2EBB4 ==7819== 1 errors in context 1 of 24: ==7819== Invalid write of size 4 ==7819== at 0x8049F69: create_cache_file (test.c:480) ==7819== Address 0xBFC2EBD0 is on thread 1's stack I'm not using any threads; my program crunches numbers. I get these errors after malloc-ing a huge chunk of memory; that's what triggers the 'client switching stacks' message. Is it a glitch in valgrind or am I compiling my program with incorrect switches ? I've got valgrind-2.0.0 and a stock Mandrake 9.1 system with 2.4.21-0.13mdk kernel. Thanks, Balazs |
From: Tom H. <th...@cy...> - 2004-01-17 22:49:00
|
In message <200...@ra...> Balazs Rauznitz <ba...@ra...> wrote: > There's only one thing I cannot figure out: I get this error in my > program: > > ==7819== Warning: client switching stacks? %esp: 0xBFFFF4FC --> 0xBFC2EBB4 > ==7819== 1 errors in context 1 of 24: > ==7819== Invalid write of size 4 > ==7819== at 0x8049F69: create_cache_file (test.c:480) > ==7819== Address 0xBFC2EBD0 is on thread 1's stack > > I'm not using any threads; my program crunches numbers. I get these > errors after malloc-ing a huge chunk of memory; that's what triggers > the 'client switching stacks' message. Is it a glitch in valgrind or am > I compiling my program with incorrect switches ? Thread 1 is the main thread, so you always have that, so it isn't odd that valgrind is talking about an address being on thread 1's stack. Are you sure you mallocing this very large chunk of memory and not allocating it on the stack? perhaps with alloca? That might cause valgrind to think the client had switched stacks, which might in turn cause it to think the large chunk of memory was not addressable. Tom -- Tom Hughes (th...@cy...) Software Engineer, Cyberscience Corporation http://www.cyberscience.com/ |
From: Balazs R. <ba...@ra...> - 2004-01-17 23:19:09
|
On Sat, Jan 17, 2004 at 10:49:10PM +0000, Tom Hughes wrote: > In message <200...@ra...> > Balazs Rauznitz <ba...@ra...> wrote: > > > There's only one thing I cannot figure out: I get this error in my > > program: > > > > ==7819== Warning: client switching stacks? %esp: 0xBFFFF4FC --> 0xBFC2EBB4 > > ==7819== 1 errors in context 1 of 24: > > ==7819== Invalid write of size 4 > > ==7819== at 0x8049F69: create_cache_file (test.c:480) > > ==7819== Address 0xBFC2EBD0 is on thread 1's stack > > > > I'm not using any threads; my program crunches numbers. I get these > > errors after malloc-ing a huge chunk of memory; that's what triggers > > the 'client switching stacks' message. Is it a glitch in valgrind or am > > I compiling my program with incorrect switches ? > > Thread 1 is the main thread, so you always have that, so it isn't odd > that valgrind is talking about an address being on thread 1's stack. > > Are you sure you mallocing this very large chunk of memory and not > allocating it on the stack? perhaps with alloca? That might cause > valgrind to think the client had switched stacks, which might in turn > cause it to think the large chunk of memory was not addressable. I'm both mallocing a huge chunk and allocating memory on the stack. The error masseges can be reproduced just with this: main() { int i[1000000], j; j = 0; } I just read this in the docs: Warning: client switching stacks? Valgrind spotted such a large change in the stack pointer, %esp, that it guesses the client is switching to a different stack. At this point it makes a kludgey guess where the base of the new stack is, and sets memory permissions accordingly. You may get many bogus error messages following this, if Valgrind guesses wrong. At the moment "large change" is defined as a change of more that 2000000 in the value of the %esp (stack pointer) register. I guess that explains. Do you have suggestions how to avoid such errors ? Is there are gcc flag to work around this problem ? Is it bad programming practice to have so huge stack ? Maybe it's harmless... Balazs |
From: Julian S. <js...@ac...> - 2004-01-18 02:56:27
|
> Valgrind spotted such a large change in the stack pointer, %esp, that > it guesses the client is switching to a different stack. At this point > it makes a kludgey guess where the base of the new stack is, and sets > memory permissions accordingly. You may get many bogus error messages > following this, if Valgrind guesses wrong. At the moment "large change" > is defined as a change of more that 2000000 in the value of the %esp > (stack pointer) register. > > > I guess that explains. Do you have suggestions how to avoid such errors > ? Is there are gcc flag to work around this problem ? Is it bad > programming practice to have so huge stack ? Maybe it's harmless... Yes, it's your int i[1000000] causing this. Either allocate it with malloc (the best option) or make it global (works, but V will not be able to check it so carefully). Having huge stuff on the stack is not really a good thing; some systems don't offer you huge stacks and so you might have portability problems. J |