I am trying to run the following code:
1. NSURL *checkLicenseURL = [NSURL URLWithString:@"check_license.php?accesskey=&license_key="];
// call server API
2. NSError *err = nil;
3. NSXMLDocument *xmlResult = [[NSXMLDocument alloc] initWithContentsOfURL:checkLicenseURL options:NSXMLDocumentTidyXML error:&err];
But when looking at variables in gdb, after line 1 was executed, doing
p checkLicenseURL
returns
$1 = <variable optimized away by compiler>
It also causes line 3 to crash. Why is this happening and how do I fix this?
Just compile without optimizations turned on, or select a "debug" build if you used a wizard of some sort to build your project. I'm not sure where to turn off optimizations in XCode but you probably want these GCC command line options for debugging:
-O0 -fno-inline
Turning off optimizations for everything is one option. It is also possible to instruct the compiler that particular variables should not be optimized away. The way to do it is with the volatile
keyword:
volatile NSURL *checkLicenseURL = ...
Wikipedia entry on volatile variables
Another similar question: iPhone Variable Optimized Away by Compiler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With