Add section on using the analyzer within Xcode.

llvm-svn: 96664
This commit is contained in:
Ted Kremenek 2010-02-19 08:14:02 +00:00
parent b4905cbd12
commit 926520489a
4 changed files with 240 additions and 23 deletions

View File

@ -47,6 +47,21 @@ IMG.img_slide {
/* Tables */
tr { vertical-align:top }
table.options thead {
background-color:#eee; color:#666666;
font-weight: bold; cursor: default;
text-align:left;
border-top: 2px solid #cccccc;
border-bottom: 2px solid #cccccc;
font-weight: bold; font-family: Verdana
}
table.options { border: 1px #cccccc solid }
table.options { border-collapse: collapse; border-spacing: 0px }
table.options { margin-left:0px; margin-top:20px; margin-bottom:20px }
table.options td { border-bottom: 1px #cccccc dotted }
table.options td { padding:5px; padding-left:8px; padding-right:8px }
table.options td { text-align:left; font-size:9pt }
/* Collapsing Trees: http://dbtree.megalingo.com/web/demo/simple-collapsible-tree.cfm */
#collapsetree, #collapsetree a:link, #collapsetree li a:link, #collapsetree a:visited, #collapsetree li a:visited{color:#000;text-decoration:none}
#collapsetree,#collapsetree ul{list-style-type:none; width:auto; margin:0; padding:0}
@ -60,4 +75,5 @@ tr { vertical-align:top }
#collapsetree ul li.click a{background:url(images/tree/bullet.gif) center left no-repeat}
#collapsetree li a.subMenu,#collapsetree ul li a.subMenu{background:url(images/tree/plus.gif) center left no-repeat}
#collapsetree li a.click{background:url(images/tree/minus.gif) center left no-repeat}
#collapsetree ul li a.click{background:url(images/tree/minus.gif) center left no-repeat}
#collapsetree ul li a.click{background:url(images/tree/minus.gif) center left no-repeat}

View File

@ -16,7 +16,12 @@
User Manual
<ul>
<li><a href="/installation.html">Obtaining the Analyzer</a></li>
<li><a href="/scan-build.html">Running the Analyzer</tt></a></li>
<li>Running the Analyzer
<ul>
<li><a href="/scan-build.html">Command line usage</a></li>
<li><a href="/xcode.html">Within Xcode</a></li>
</ul>
</li>
<li><a href="/available_checks.html">Available Checks</a></li>
<li><a href="/annotations.html">Source-level Annotations</a></li>
</ul>

View File

@ -5,7 +5,8 @@
<title>scan-build: running the analyzer from the command line</title>
<link type="text/css" rel="stylesheet" href="content.css" />
<link type="text/css" rel="stylesheet" href="menu.css" />
<script type="text/javascript" src="scripts/menu.js"></script>
<script type="text/javascript" src="scripts/menu.js"></script>
<script type="text/javascript" src="scripts/dbtree.js"></script>
</head>
<body>
@ -13,23 +14,6 @@
<!--#include virtual="menu.html.incl"-->
<div id="content">
<style>
table.options thead {
background-color:#eee; color:#666666;
font-weight: bold; cursor: default;
text-align:left;
border-top: 2px solid #cccccc;
border-bottom: 2px solid #cccccc;
font-weight: bold; font-family: Verdana
}
table.options { border: 1px #cccccc solid }
table.options { border-collapse: collapse; border-spacing: 0px }
table.options { margin-left:0px; margin-top:20px; margin-bottom:20px }
table.options td { border-bottom: 1px #cccccc dotted }
table.options td { padding:5px; padding-left:8px; padding-right:8px }
table.options td { text-align:left; font-size:9pt }
</style>
<h1>scan-build: running the analyzer from the command line</h1>
<table style="margin-top:0px" width="100%" border="0" cellpadding="0px" cellspacing="0">
@ -70,19 +54,22 @@ aforementioned hack fails to work.</p>
<h2>Contents</h2>
<ul>
<li><a href="#scanbuild">Getting Started</a></li>
<ul id="collapsetree" class="dbtree onclick multiple">
<li><a href="#scanbuild">Getting Started</a>
<ul>
<li><a href="#scanbuild_basicusage">Basic Usage</a></li>
<li><a href="#scanbuild_otheroptions">Other Options</a></li>
<li><a href="#scanbuild_output">Output of scan-build</a></li>
</ul>
<li><a href="#recommendedguidelines">Recommended Usage Guidelines</a></li>
</li>
<li><a href="#recommendedguidelines">Recommended Usage Guidelines</a>
<ul>
<li><a href="#recommended_debug">Always Analyze a Project in its &quot;Debug&quot; Configuration</a></li>
<li><a href="#recommended_verbose">Use Verbose Output when Debugging scan-build</a></li>
<li><a href="#recommended_autoconf">Run './configure' through scan-build</a></li>
</ul>
</li>
<li><a href="#iphone">Analyzing iPhone Projects</a></li>
</ul>
<h2 id="scanbuild">Getting Started</h2>
@ -276,6 +263,82 @@ the arguments over to <tt>gcc</tt>, but this may not work perfectly (please
report bugs of this kind).
-->
<h2 id="iphone">Analyzing iPhone Projects</h2>
<p>Conceptually Xcode projects for iPhone applications are nearly the same as
their cousins for desktop applications. <b>scan-build</b> can analyze these
projects as well, but users often encounter problems with just building their
iPhone projects from the command line because there are a few extra preparative
steps they need to take (e.g., setup code signing).</p>
<h3>Recommendation: use &quot;Build and Analyze&quot;</h3>
<p>The absolute easiest way to analyze iPhone projects is to use the <a
href="http://developer.apple.com/mac/library/featuredarticles/StaticAnalysis/index.html"><i>Build
and Analyze</i> feature in Xcode 3.2</a> (which is based on the Clang Static
Analyzer). There a user can analyze their project with the click of a button
without most of the setup described later.</p>
<p><a href="scan-build.html">Instructions are available</a> on this
website on how to use open source builds of the analyzer as a replacement for
the one bundled with Xcode.</p>
<h3>Using scan-build directly</h3>
<p>If you wish to use <b>scan-build</b> with your iPhone project, keep the
following things in mind:</p>
<ul>
<li>Analyze your project in the <tt>Debug</tt> configuration, either by setting
this as your configuration with Xcode or by passing <tt>-configuration
Debug</tt> to <tt>xcodebuild</tt>.</li>
<li>Analyze your project using the <tt>Simulator</tt> as your base SDK. It is
possible to analyze your code when targetting the device, but this is much
easier to do when using Xcode's <i>Build and Analyze</i> feature.</li>
<li>Check that your code signing SDK is set to the simulator SDK as well, and make sure this option is set to <tt>Don't Code Sign</tt>.</li>
</ul>
<p>Note that you can most of this without actually modifying your project. For
example, if your application targets iPhoneOS 2.2, you could run
<b>scan-build</b> in the following manner from the command line:</p>
<pre class="code_example">
$ scan-build xcodebuild -configuration Debug -sdk iphonesimulator2.2
</pre>
Alternatively, if your application targets iPhoneOS 3.0:
<pre class="code_example">
$ scan-build xcodebuild -configuration Debug -sdk iphonesimulator3.0
</pre>
<h3>Gotcha: using the right compiler</h3>
<p>Recall that <b>scan-build</b> analyzes your project by using <tt>gcc</tt> to
compile the project and <tt>clang</tt> to analyze your project. When analyzing
iPhone projects, <b>scan-build</b> may pick the wrong compiler than the one
Xcode would use to build your project. This is because multiple versions of
<tt>gcc</tt> may be installed on your system, especially if you are developing
for the iPhone.</p>
<p>Where this particularly might be a problem is if you are using Mac OS 10.5
(Leopard) to develop for iPhone OS 3.0. The default desktop compiler on Leopard
is gcc-4.0, while the compiler for iPhone OS 3.0 is gcc-4.2. When compiling your
application to run on the simulator, it is important that <b>scan-build</b>
finds the correct version of <tt>gcc</tt>. Otherwise, you may see strange build
errors that only happen when you run <tt>scan-build</tt>.
<p><b>scan-build</b> provides the <tt>--use-cc</tt> and <tt>--use-c++</tt>
options to hardwire which compiler scan-build should use for building your code.
Note that although you are chiefly interested in analyzing your project, keep in
mind that running the analyzer is intimately tied to the build, and not being
able to compile your code means it won't get fully analyzed (if at all).</p>
<p>If you aren't certain which compiler Xcode uses to build your project, try
just running <tt>xcodebuild</tt> (without <b>scan-build</b>). You should see the
full path to the compiler that Xcode is using, and use that as an argument to
<tt>--use-cc</tt>.</p>
</div>
</div>
</body>

View File

@ -0,0 +1,133 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Build and Analyze: running the analyzer within Xcode</title>
<link type="text/css" rel="stylesheet" href="content.css" />
<link type="text/css" rel="stylesheet" href="menu.css" />
<script type="text/javascript" src="scripts/menu.js"></script>
<script type="text/javascript" src="scripts/dbtree.js"></script>
</head>
<body>
<div id="page">
<!--#include virtual="menu.html.incl"-->
<div id="content">
<h1>Build and Analyze: running the analyzer within Xcode</h1>
<table style="margin-top:0px" width="100%" border="0" cellpadding="0px" cellspacing="0">
<tr><td>
<h3>What is it?</h3>
<p><i>Build and Analyze</i> is an Xcode feature (introduced in Xcode 3.2) that
allows users to run the Clang Static Analyzer <a
href="http://developer.apple.com/mac/library/featuredarticles/StaticAnalysis/index.html">directly
within Xcode</a>.</p>
<p>It integrates directly with the Xcode build system and
presents analysis results directly within Xcode's editor.</p>
<h3>Can I use the open source analyzer builds with Xcode?</h3>
<p><b>Yes</b>. Instructions are included below.</p>
</td>
<td style="padding-left:10px">
<center>
<a href="images/analyzer_html.png"><img src="images/analyzer_xcode.png" width="620px" border=0></a>
<br><b>Viewing static analyzer results in Xcode</b></center>
</td></tr></table>
<!-->
<h3>Key features:</h3>
<ul>
<li><b>Integrated workflow:</b> Results are integrated within Xcode. There is
no experience of using a separate tool, and activating the analyzer requires a
single keystroke or mouse click.</li>
<li><b>Transparency:</b> Works effortlessly with Xcode projects (including iPhone projects).
<li><b>Cons:</b> Doesn't work well with non-Xcode projects. For those,
consider using <a href="scan-build.html"><b>scan-build</b></a>.
</ul>
-->
<h2>Getting Started</h2>
<p>Xcode 3.2 is available as a free download from Apple, with <a
href="http://developer.apple.com/mac/library/featuredarticles/StaticAnalysis/index.html">instructions available</a>
for using <i>Build and Analyze</i>.</p>
<h2>Using open source analyzer builds with <i>Build and Analyze</i></h2>
<p>By default, Xcode uses the version of <tt>clang</tt> that came bundled with
it to provide the results for <i>Build and Analyze</i>. It is possible to change
Xcode's behavior to use an alternate version of <tt>clang</tt> for this purpose
while continuing to use the <tt>clang</tt> that came with Xcode for compiling
projects.</p>
<h3>Why try open source builds?</h3>
<p>The advantage of using open source analyzer builds (provided on this website)
is that they are often newer than the analyzer provided with Xcode, and thus can
contain bug fixes, new checks, or simply better analysis.</p>
<p>On the other hand, new checks can be experimental, with results of variable
quality. Users are encouraged to <a href="filing_bugs.html">file bug reports</a>
(for any version of the analyzer) where they encounter false positives or other
issues.</p>
<h3>set-xcode-analyzer</h3>
<p>Starting with analyzer build checker-234, analyzer builds contain a command
line utility called <tt>set-xcode-analyzer</tt> that allows users to change what
copy of <tt>clang</tt> that Xcode uses for <i>Build and Analyze</i>:</p>
<pre class="code_example">
$ <b>set-xcode-analyzer -h</b>
Usage: set-xcode-analyzer [options]
Options:
-h, --help show this help message and exit
--use-checker-build=PATH
Use the Clang located at the provided absolute path,
e.g. /Users/foo/checker-1
--use-xcode-clang Use the Clang bundled with Xcode
</pre>
<p>Operationally, <b>set-xcode-analyzer</b> edits Xcode's configuration files
(in <tt>/Developer</tt>) to point it to use the version of <tt>clang</tt> you
specify for static analysis. Within this model it provides you two basic modes:</p>
<ul>
<li><b>--use-xcode-clang</b>: Switch Xcode (back) to using the <tt>clang</tt> that came bundled with it for static analysis.</li>
<li><b>--use-checker-build</b>: Switch Xcode to using the <tt>clang</tt> provided by the specified analyzer build.</li>
</ul>
<h4>Examples</h4>
<p>Telling Xcode to use checker-235 for <i>Build and Analyze</i>:</p>
<pre class="code_example">
$ pwd
/tmp
$ tar xjf checker-235.tar.bz2
$ checker-235/set-xcode-analyzer --use-checker-build=/tmp/checker-235
</pre>
<p>Telling Xcode to use a very specific version of <tt>clang</tt>:</p>
<pre class="code_example">
$ set-xcode-analyzer --use-checker-build=~/mycrazyclangbuild/bin/clang
</pre>
<p>Resetting Xcode to its default behavior:</p>
<pre class="code_example">
$ set-xcode-analyzer -use-xcode-clang
</pre>
</div>
</div>
</body>
</html>