xcode debugging goes back and forth during stepping through the code - iphone

I have a really weird problem with Xcode 3.2.5
In a normal code sequence XCode steps couple of lines back then continues, then again sometimes back and continues again during step mode.
This only happens in one project, but there in all files. Here an example:
When jumping in this function Xcode goes through the lines in the following sequence:
2 -> 1 -> 2 -> 3 ->5 -> 8 -> 3 -> 4 -> 5 -> 6 -> 7 ->...
I dont understand what is going on here. Please do you have any idea?
Rebooting the machine and the iPhone doesn't help.
By the way, the complete code works fine and runs without errors. It seems that the cursor sometimes goes to lines where the code is not being executed. If a certain line is entered twice by the cursor, only the second time it changes the variables in assignments etc..
Really weird!
Thanks for any hint...
1 - (void)viewWillAppear:(BOOL)animated {
// D_IN;
2 [super viewWillAppear:animated];
//get the dataManager global Object, so we always have a structured accesss to the data!
3 WebiAppDelegate *mainDelegate = (WebiAppDelegate *)[[UIApplication sharedApplication]delegate];
4 self.webiDataManager = mainDelegate.webiDataManager;
5 message.hidden = YES;
6 message.text = #"";
7 message.userInteractionEnabled = NO;
...

I agree with the comments. It looks like you're trying to debug optimized code. Try compiling with no optimization and the debugger should behave more sensibly.
e.g. gcc -O0 ...

Related

One Line of Swift code works one day and doesn't the next (Only Xcode)

Very simply I need to get the power of an Integer and I have this code to do so below
import Darwin
var x = Int(pow(Double(3),Double(3)))
print(x)
For whatever reason this line of code worked one day and the next day when I came back to the project it did not work and instead of getting 27 I keep getting 3...?
What confuses me more is if I go into Swift Playgrounds(The App) it works fine but put it in Xcode and it doesn't work. I haven't changed the code at all and are just copy/paste into different programs with different results

Why this line is not covered? Xcode code coverage

I'm experiencing an issue with the report of code coverage in Xcode.
As you can see from this screenshot:
On the left tab, line 58 is "touched" from the break-point, and on the right tab, the test passes. While on the right tab, I'm running only the test on line 37.
Why does Xcode sign the line 58 in red, as not covered?
Line 53 is not "touched" (if I set a break-point there).
Using SQLite as a database.
The entire project is available here.
EDIT: Adding code:
Test.swift
func testAddFuelFail() {
fuelsManager.dropTable()
XCTAssertEqual(addFuel(), -1)
}
FuelsManager.swift
func addFuel(dateOfFuel: Date, mileageOnSave: Int, quantityOfFuel: Double, pricePerUnitOfFuel: Double) -> Int64 {
let insertFuel = fuelsTable.insert(date <- dateOfFuel, mileage <- mileageOnSave, quantity <- quantityOfFuel, pricePerUnit <- pricePerUnitOfFuel)
do {
let id = try database!.run(insertFuel)
return id
} catch {
print(error)
}
return -1
}
Actually its a bug reported here.
Coverage number varies between multiple runs on XC 10 on the same binary. Like in first run it shows x% vs in another run it will show y% keeping the same code.
Coverage number/Number of tests varies while running on 11.4 simulator and 12.0 simulator, both ran on XC 10
Number of tests also a little different like in some run it was 5507 tests vs in some runs it was 5506.
XC 10 certainly came with lots of bugs.
Take the breakpoint out and run the test. Once the test has finished running the coverage information should change.

Xcode 4 hanging while compiling

I am compiling a small application with hardly 10 lines of code in Xcode 4. While compiling it seems to be hanging. But when i compile a small Hello World application, it seems to work fine. Earlier today it was working fine with a larger application. Could someone please tell me whats happening? and how can i overcome this issue and allow it to compile faster like before??
BR,
Suppi
Edited:
Ok, Xcode version 4.0.2, Ram size is 2GB, MAC OS X version 10.6.8.
and my code for the program i am running:
I am basically checking to see how the interface between an Objective C and C works:
In my C file:
void helloWorld()
{
printf("hellow Woeld c");
hellowworldToObjC();
}
void hellowworldToObjC()
{
HelloWorldC();
}
and Objective C class:
id refToSelf;
- (id)init {
self = [super init];
if (self) {
refToSelf = self; // Saving self in pointer
}
return self;
}
-(void)HelloWorldObjc
{
NSLog(#"Hello World from Objc C");
[self HellowTestingC];
}
-(void)HellowTestingC
{
helloWorld();
}
#end
void HelloWorldC()
{
[refToSelf HelloWorldObjc];
}
Sample Xcode when it is "hanging" (and by "hanging", do you mean truly hanging or does it eventually work).
You also might want to leave top -u running in a terminal window and see how many pagein/pageout events occur when the "hang" happens. If you are paging, it'll feel like a hang.
0 pageouts meanings you aren't swapping (the pageins are just the source files that are #included being read).
Post the sample.
It was crazy with Xcode 4, the CPU was 190%, and Xcode 4 was not responding, so i went ahead and installed Xcode 3.2.6. Now all working fine :).

My own (new) class not found after xcode update

I'm developing iphone app. Yesterday I updated my xcode to to newest version and clean build folders (deleted it), then created new class (nothing special):
#interface EnemyFactory : NSObject {
}
+(Enemy *)properReferenceForName: (NSString *) name;
#end
Implementation is trivial and not important. What is happening now:
I've got sth like this:
Enemy *tempEnemy = [EnemyFactory properReferenceForName:#"enemyname"];
But code never reaches function properReferenceForName. I've got EXC_BAD_ACCESS with stack like this:
0 0x02a95e2b in realizeClass
1 0x02a96dad in _class_getNonMetaClass
2 0x02a90eb0 in _class_initialize
3 0x02a961f6 in prepareForMethodLookup
4 0x02a8f6c9 in lookUpMethod
5 0x02a8f836 in _class_lookupMethodAndLoadCache
6 0x02a9dad3 in objc_msgSend
7 0x0000595d in -[GameLayer newEnemy:] at GameLayer.m:368
Before update. Xcode gives no warning or error. Symbols are declared.
What is interesting though is that: everything goes fine, when I debug step by step whole invocation...
I'm stuck with it for 8 hours.
Update 1:
[[EnemyFactory alloc] init] throws the same error
Update 2:
When I do this:
[EnemyFactory alloc] in some master class during initialization everything goes in flying colours.
Take a look at GameLayer.m line 368 something to do with [GameLayer newEnemy:]. I don't see anything wrong with the code you posted.
If the code is never reaching your class method, the problem is where the stack trace starts, i.e. [GameLayer newEnemy:]
Look for objects that you may need to retain but are not retaining within the newEnemy method.

IF Statement Seems To Work Fine On Simulator, But Not On Device!

Ok, the problem is that when my app runs on the simulator it seems to work fine. On the device, however it does not update all the labels. I think the error is somewhere here:
- (IBAction)buttonclick1 {
self.startDate = [NSDate date];
double value = [self Level];
double value2 = [self Level2];
if ((value2 - value) >= 3.0) {
ifWork.text = #"DONE!";
ifWork.textColor = [UIColor yellowColor];
float noSeconds = (float) [self.startDate timeIntervalSinceNow];
}
}
I am new to this game. What I am looking for, is when the button is pressed, it times how long it takes for an event to happen. I then would like to use this time in calculations.
I know the IF statement is correct as it works on the simulator. However on the device, when value and value2 differ by 3 and then the button is pressed, nothing happens (the label ifWork doesn't change!).
Any help would be much appreciated,
Stu
Did you run the code in the debugger to see what happens? Maybe if the values depend on anything like CPU or network performance you may experience notable differences between the simulator and the actual device, so you cannot be sure that what works on the simulator works on the device.
There could be a few reasons.
Level1 or Level2 results could be different on device (using uninitialized memory which is different on device
value2 - value1 could be very close to 3.0 but just less than (doubles are often a little imprecise)
ifWork could be improperly set on the device (i.e. nil) so nothing happens.
The best solution is to debug on the device (step over this code line by line) and check if any of these things are true.