• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: GDB & static const variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GDB & static const variables


  • Subject: Re: GDB & static const variables
  • From: Eric Gorr <email@hidden>
  • Date: Thu, 16 Jul 2009 12:39:11 -0400


On Jul 16, 2009, at 12:29 PM, Fritz Anderson wrote:

On 16 Jul 2009, at 10:25 AM, Eric Gorr wrote:

Boolean TestFunction( void )
{
	static const int doubleByteDegreeMark = 42;
	static int anotherVar = 12;

	return ( doubleByteDegreeMark == 42 && anotherVar == 12 );
}

from GDB, if I do 'info locals' it prints out:

(gdb) info locals
anotherVar = 12

if I try to print out the value of doubleByteDegreeMark, it gives me the error message:

(gdb) print doubleByteDegreeMark
No symbol "doubleByteDegreeMark" in current context.

So, my (probably really simple) question is how can I print out the value of doubleByteDegreeMark from GDB?

Given that doubleByteDegreeMark is a constant, and referred to only within the function, gcc optimized by doing away with the storage, and substituted the literal value 42; and then it saw "42 == 42," and optimized that to true; and then saw "true && anotherVar == 12," and optimized that to "anotherVar == 12." I don't know why it didn't optimize that to simply "true." Maybe at the optimization level you chose, it didn't do the analysis to get that far.


There being no storage for doubleByteDegreeMark, gdb didn't have any stored value to display. I don't know the details of why it didn't know about it just as a constant; I've seen it display enum constants.

Thank you for your comments.

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?


_______________________________________________ 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
  • Follow-Ups:
    • Re: GDB & static const variables
      • From: Jim Ingham <email@hidden>
    • Re: GDB & static const variables
      • From: Quincey Morris <email@hidden>
References: 
 >GDB & static const variables (From: Eric Gorr <email@hidden>)
 >Re: GDB & static const variables (From: Fritz Anderson <email@hidden>)

  • Prev by Date: Re: GDB & static const variables
  • Next by Date: Re: #if on SDK_NAME
  • Previous by thread: Re: GDB & static const variables
  • Next by thread: Re: GDB & static const variables
  • Index(es):
    • Date
    • Thread