Xcode 3.2: Build & Analyze never finds any issues - xcode

I've used the Clang Static Analyzer from the command line before. I wanted to try Xcode's built-in version via Build & Analyze. I never get any negative results even though i specially prepared my code with very obvious issues Clang was always able to point out:
// over-releasing an object:
[label release];
[label release];
// uninitialized vars, allocating but not freeing an object
NSString* str;
int number;
CCLabel* newLabel = [[CCLabel alloc] initWithString:str fontName:str fontSize:number];
[newLabel setPosition:CGPointZero];
The result is always the same: a green checkbox, no issues.
I read that C++ code can cause issues. I'm running this with cocos2d that includes box2d. Could this be a cause? Did anyone get results from Build & Analyze with the cocos2d engine? What else could it be?
I also tried enabling the Static Analyzer Build Settings and then Build but the result was the same. I have restarted Xcode, cleaned all targets and emptied Xcode caches to no avail.
UPDATE: my issue could be caused by having added cocos2d as a cross-project reference to my project. Analyzing the cocos2d project itself seperately reveals some analyzer results.
In addition i found out that i get Analyzer results from my RELEASE build configurations but not from DEBUG builds.

I'm using Cocos2d and Box2d, and I get plenty of warnings from Build and Analyze. Check to make sure your project's compiler is set to GCC 4.2 under "Compiler Version" in the Build Settings.

For anyone that might come across this thread (and for the OP in case the problem persists):
I had this problem when building for the Simulator. However, switching to Device build got the Analyzer running.
This site might shed some more light on the issue: http://useyourloaf.com/blog/2010/10/5/xcode-build-and-analyze-broken-for-simulator.html

I also get plenty of Analyze warnings with my Cocos2d game. I cleaned most of them up, but cocos2d 0.99.1 has 3 built-in! (Which should be easily fixed.)
I have noticed that sometimes the analyzer doesn't find things unless I have that particular file open when I run it... go figure.

Related

Why does the Swift compiler mark errors pessimistically?

I find that Swift is quick to mark down changes i make as compiler errors in the side panel, and then when i compile, it decides i am right after all. Is Swift just pessimistic about my code?
Can I get the compiler to wait for me to finish the line before declaring it wrong?
There is nothing pessimistic. Xcode uses the same tool - the compiler - to get the errors. However, it usually compiles only one file, using cached compiled objects for the other files. It also doesn't invoke the compiler after every change in your code, so errors that are already fixed can stay there in the side panel.
Building the project fully forces Xcode to refresh the cache and get the current list of errors from the compiler. I do agree that Xcode has many imperfections and this is one of them. When you can't find an error, just rebuild the project.
Note that IDEs for other languages often rebuild the project automatically to solve such problems. This is currently not an option in Swift because it would take too much time.

`po` gives `error: <EXPR>:1:1: error: use of unresolved identifier`

I have this problem with po in the console where trying to output a function works in itself, but outputting a variable or constant doesn't.
As you can see here, although you'd think the var/let holds the content of bar.boy(), Swift somehow can't find it...
So it turns out there was probably a bug in the past that when you were adding a Swift file it would add/ask a Bridging header, but it wouldn't add that line to your project
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
which means you'd stay in this state
resulting in error: <EXPR>:1:1: error: use of unresolved identifier!
I could only find that out because I moved around files in my project and when I added ObjC files to the project, it asked me about a Bridging header (although I had one already!) and luckily added that SWIFT_OPTIMIZATION_LEVEL. One could consider this is a bug to consider the default value is fastest, but then again I guess this was only a bug in the past and got fixed now.
Still, I fixed now it might be a bug the other way around, if it add none in the release build. I can't test this right now because for testing this I only had a Debug build. I'll leave that as an exercise :) for Apple's Engineers.
I set Swift Complier to "-O"
SWIFT_OPTIMIZATION_LEVEL = "-O";
and set it back to "-Onone".
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Then it works.
Fixed after setting:
Optimization Level = None[-Onone] under Swift Compiler - Code Generation
Note that setting Optimization Level under Apple LLVM 8.0 - Code Generation has no effect
I bet that bug is due to the fact that foo has been optimized out during compilation and it's symbol does not exist anymore in the compiled code (even if it shouldn't have in debug and it's still an LLDB bug)
Probably if you add some usage of foo in the next lines (even a println) its symbol will hopefully be kept in the IR and you'll be able to po foo
(I agree that that's still a bug but at least if it works you'll have a workaround and some sense of explanation)
I encountered a similar issue but I already had the correct configuration, all optimisations set to None. However I still didn't get any values.
After some further digging I found out that the issue originated from Xcode being unable to the resolve the types:
(lldb) frame variable self
<could not resolve type>
That led me to this question: xcode 8 Debugger 'Could not resolve type' where the issue is described and the bridging header seems to cause issues.
With my project not having any bridging headers I studied the build settings once more and found this setting
This was initally set to YES. After changing the it to NO symbols are working again.
SWIFT_INSTALL_OBJC_HEADER = NO
If your project is using Swift, there are two separate "Optimization Level" settings in the project/target configuration. Its not only "SWIFT_OPTIMIZATION_LEVEL". Check this link: https://stackoverflow.com/a/32984193/2060180
I'll leave it here in case it's useful to someone.
For those who are using Swift framework in an Objective-c project, and wanna debug the Swift source files in that project: (In my case, I have a mixed-language module which managed by Cocoapods, I need to debug the swift module in my Objective-c Example project)
It works for me after I added an Empty Swift file in my Objective-c project.
Otherwise, those swift compiler options won't show up in the Build Settings.

Compiling Autotalent v2 Issues with Xcode 5.0.1 and Mavericks

I've been struggling to get Auto Talent from Oli Larkin to compile for some time now. I'm pretty new to Xcode and that may be the issue, but either way I figured I'd see if anyone could help me. I'm trying to compile this in order to make a 64 bit version.
Starting from the top:
I've traced down a few things that I thought were the issues.
Noticed that wdl sdk was missing. Downloaded it from https://github.com/olilarkin/wdl-ol. Added the wdl folder outside of the src folder.
Got some warnings when starting up Xcode 5.0.2. Let Xcode fix them.
Realized that the /Developer/Examples folder doesn't exist in Mavericks. Found https://developer.apple.com/library/mac/samplecode/CoreAudioUtilityClasses/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012328-Intro-DontLinkElementID_2, downloaded the sample code, linked to AUBase as I realized this path needed updating in the AU Build Settings (see screenshot).
iPlug.xcodeproj is in red. Not sure what to do about this. Any ideas? I'm assuming it's important.
Update: Based on the recent comments, I'm now getting somewhere. But, at the moment I'm getting the following errors. This has to do with not having a Lice SDK or something. Is this absolutely needed? If so, do you have the time to elaborate on this and where to get it? Thanks again for all of the help.
It looks like I'm getting another issue as well related to clang. Maybe related to Xcode - Command /Developer/usr/bin/clang failed with exit code 1, not sure.
Note: Before finally getting to the errors above, I had to...
Link CoreMIDI.framework "Frameworks and Libraries" -> "Linked Frameworks" -> App to /System/Library/Frameworks/CoreMIDI.framework.
Set compiler in the build settings to default compiler. Otherwise it said unsupported compiler and threw some warnings. Hopefully this didn't mess anything up.
Rename aeffect.h and aeffectx.h to aeffect.h and aeffectx.h from the VST3 SDK. You can find these files in public.sdk -> source -> vst2.x. Apparently 2.x isn't really supported anymore. After renaming them, I moved them to the VST_SDK folder in WDL as the readme instructed.
the source you have will not compile straight off with recent versions of WDL-OL, since lots has changed. The way to upgrade it is to strip out the pertinent source code (i.e. autotalent.h/cpp and the mayer fft stuff) and re-duplicate one of the template projects in WDL-OL and bring it in to the new folder.
I've done it for you:
https://github.com/olilarkin/autotalent
you can clone this repository into the IPlugExamples folder of WDL-OL, and provided you've put all the SDK files in place it should compile straight off.
oli

Breakpoints not working in xcode 4

I just started using Xcode to program a C++ openCV project.
The project is set up with an external makefile, /usr/bin/gnumake as build tool, and the program compiles and runs fine.
However, breakpoints gets skipped no matter what i do.
I have tried making a new project, selecting between gdb and LLDB, restarting Xcode++
There are numerous threads about this issue, but most talk about "Load Symbols Lazily", but as far as I know, this is not an issue in Xcode 4.5.2.
It is probably my limited Xcode knowledge that causes the error.
Help is greatly appreciated.
I could resolve my similar problem by disabling "Link-Time Optimization" for the Debug build settings.
Make sure that any kind of code optimization is disabled in your debug build settings (code stripping, optimization, etc). Then check that you really run the debug build and not the release version.
It would be great if XCode could automatically warn you when you have build settings that possible break the debugger...

Xcode debugger sometimes doesn't display variable values?

This happens to me pretty often. For example, right now I have the debugger stopped at a breakpoint in a method . . . and it isn't displaying any variable values at all. Other times, it displays some, but not others.
Can anyone explain?
The most common reason for this is that you're trying to debug code compiled with optimisation enabled and/or no debug symbols. Typically this will be because you're trying to debug a Release build rather than a Debug build but it can also happen with Debug builds if you've made inappropriate changes to the Debug build settings.
Another less common possibility is that you've hosed the stack.
I had this issue (using Swift), I spent ages crawling through my git commits to find where to problem started.
For me, I was using Facebook Tweaks library, but I was (unnecessarily) importing it from my project-bridging-header.h file.
Once I got rid of it, I got my debugging back.
for example, in my bridging header I had:
#ifndef PROJECT_Bridging_Header_h
#define PROJECT_Bridging_Header_h
// Facebook Tweaks
#import "FBTweak.h"
#import "FBTweakStore.h"
#import "FBTweakCategory.h"
#import "FBTweakCollection.h"
#import "FBTweakViewController.h"
#import "FBTweakShakeWindow.h"
#endif
I removed all the imports and just imported it as usual in my AppDelegate import Tweaks.
e.g:
#ifndef PROJECT_Bridging_Header_h
#define PROJECT_Bridging_Header_h
// Removed Facebook Tweaks
#endif
and in my AppDelegate.swift
import Tweaks
This fixed all my debugging issues, everything works as expected and I can also using Facebook Tweaks.
Note: I don't think this is an issue with Facebook Tweaks itself, you may have some other library causing the same issue. The idea is to remove things from your bridging-header one by one and see if you can narrow down the issue.
I think I read somewhere that if a library is causing many issues behind the scenes, this can stop your debugger working.
If this doesn't help, try crawling through your git commits and see at what stage the debugging stopped.
other similar issues on SO:
Xcode Debugging not showing values
Xcode debugger doesn't display variable information after installing CocoaPods Podfile
If you're having similar issues hope this helps! 👍
A possible solution is to set the Optimization Level for your current target Debug scheme to none.
Project -> Target -> Build settings -> Optimization level -> Debug (or whatever fits your project) -> None
Source:
https://stackoverflow.com/a/14948486/3590753
I've had similar issues using LLDB. Switching it back to GDB seems to address it. Obviously this isn't solving the problem, but its a workaround anyway
My issue was that I had address sanitizer enabled. Disabling sanitizer resolved my issue in XCode 8.2.1
You can get the value of any variable in the console by writing:
po name_of_an_objectCVar
or
print name_of_a_cVar
If your breakpoint has "automatically continue after evaluating options" set, then it won't write to the variable view - FYI
I know this is old, but i ran into same problem too. I could not see any summaries of any objects, just types and some address code. After 4 hours of struggling with compilers, debuggers and other solutions i was about to give up when by accident i found this option in debugger. "Show Summaries". Just by clicking it everything got fixed and now i see all variable summaries!
Had the same issue using Xcode 6.4 running the app on device. Running on simulator will show all variables on debugging variables panel.
There is a situation I have seen where Xcode can't cope with return value optimisation (RVO) -- if the compiler decides to apply RVO to a variable then it may not appear in the variables list. You can disable this in g++ and clang with the compiler flag -fno-elide-constructors
See also Understanding eliding rules with regard to c++11
For Swift mix OC Project which use pod
Fixing it by removing useless header(that import with framework by pod) xx-Bridging-Header.h
eg.
In the past I import header with #import "GCDAsyncSocket.h" which I was added in podfile
platform:ios, '8.0'
use_frameworks!
target "roocontrollerphone" do
pod 'CocoaAsyncSocket'
end
just remove it in that xx-Bridging-Header.h file
If you are using the #property feature of Objective-C 2.0 the debugger does not display those variables unless they are backed by explicit ivars in your Class interface. This is slated to be fixed in Xcode 4 as I understand it.
temporary solution when it happpen to me :
right click on the property
jump to definition (u can do it manually and scroll to the #synthesize in the top of the file)
now, if the line is like this :
#synthesize myObject = _myObject ;
set the mouse cursor on the "_myObjects". that what worked for me..when i have problems.
I figured out why it is not working in XCode 4.6 - all of the variables in my object, self, were declared in the .m file instead of the .h. When I moved one of them back to the .h file, it showed up in the debugger. Sounds like a bug with XCode in that it cannot "see" variables declared in the implementation file.
For me it works changing the content of display variables panel to Local Variables and then back to Auto.
This solution worked on XCode 6.3.2, Swift type project.
You need to disable two types of build optimizations in the build settings. By default, the "swift compiler - code generation" optimization level for debug build is set to fast. You need to set this to none. Also check that the "apple llvm 7.1 - code generation" optimization is set to none for debug build.
Finally, check that you are building the debug build in the "architectures" section of your build settings.
Hope this helps.
I have been stuck a while with this problem and finally find out a solution.
I think that many reason can causes this bug but in my case here is the solution.
While you are in the breakpoint position check the included classes.
I was including using double quote a file which was located using include path.
#include "MyClass.h"
instead of
#include <MyPorject/MyClasses/MyClass.h>
So if you have this problem try to double check your inclusion and import.
I know it seems weird but worked for me and I have been able to reproduce it by putting back the Double-Quote include.
One possible reason for the debugger displaying seemingly wrong values is that the variable type is of Any?.
E.g.
var a: Any? = 12
var b: Int? = a as? Int // b=13483920750
var c: Int = a as? Int ?? 0 // c=1
In the example above, b holds the correct value of 1 even though it is not displayed as such.
I've had the same issue and I fixed it by reinstalling all Pods. Just delete them and install again.

Resources