Re: GDB & static const variables
Re: GDB & static const variables
- Subject: Re: GDB & static const variables
- From: Quincey Morris <email@hidden>
- Date: Thu, 16 Jul 2009 10:15:41 -0700
On Jul 16, 2009, at 09:39, Eric Gorr wrote:
I still see the same problem if change the test function to:
Boolean TestFunction( int val )
{
static const int doubleByteDegreeMark = 42;
static int anotherVar = 12;
return ( val == doubleByteDegreeMark || val == anotherVar );
}
Now, I suppose it is still possible that the compiler will have
simply optimized this to:
Boolean TestFunction( int val )
{
static int anotherVar = 12;
return ( val == 42 || val == anotherVar );
}
or something.
This is the debug build with all optimizations turned off.
Under other circumstances, should 'info locals' display
doubleByteDegreeMark? Should I be able to print doubleByteDegreeMark?
Not necessarily.
There are actually 5 issues here, all of them pretty trivial:
1. The gcc compiler isn't 'gdb-aware', in the sense that it doesn't
try to preserve the source code "environment" precisely in the symbol
information that gdb will use. It puts out as little as it can, which
means that it may leave out a symbol that's been optimized away.
Sometimes this is really annoying for debugging, but it's a limitation
of the design choices made in the overall Xcode architecture.
2. Due to optimizations, gcc may terminate a symbol lifetime early --
before the end of enclosing scope -- which means the symbol
information may be there but the debugger won't show it because it
thinks it's out of scope.
Sometimes this is really annoying for debugging, but ...
3. There's no way of turning "all optimizations" off in the sense you
means. Instead, there are only ways of turning higher levels of
optimization on. The gcc compiler may choose do what you'd call
optimizations regardless of the option setting.
4. It's the "const" that's causing the different results between the
two variables.
5. Your use of "Boolean" over "BOOL" suggests this might be C++
instead of C. In C++, const variables are supposed to be the modern,
type-safe replacement for #define, so "const" tends to cause much more
aggressive optimization than in C. (For example, the C spec might
require a global to be allocated a memory address for a const static
int, while the C++ spec might not. You'd have to check the specs to
find out.)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden