2010-02-19 16:14:02 +08:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
|
|
"http://www.w3.org/TR/html4/strict.dtd">
|
|
|
|
<html>
|
|
|
|
<head>
|
2013-01-09 03:29:37 +08:00
|
|
|
<title>Running the analyzer within Xcode</title>
|
2012-01-15 23:26:07 +08:00
|
|
|
<link type="text/css" rel="stylesheet" href="content.css">
|
|
|
|
<link type="text/css" rel="stylesheet" href="menu.css">
|
2010-02-19 16:14:02 +08:00
|
|
|
<script type="text/javascript" src="scripts/menu.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div id="page">
|
|
|
|
<!--#include virtual="menu.html.incl"-->
|
|
|
|
<div id="content">
|
|
|
|
|
2013-01-09 03:29:37 +08:00
|
|
|
<h1>Running the analyzer within Xcode</h1>
|
2010-02-19 16:14:02 +08:00
|
|
|
|
|
|
|
<table style="margin-top:0px" width="100%" border="0" cellpadding="0px" cellspacing="0">
|
|
|
|
<tr><td>
|
|
|
|
|
|
|
|
<h3>What is it?</h3>
|
2013-01-09 03:29:37 +08:00
|
|
|
|
|
|
|
<p>Since Xcode 3.2, users have been able to run the Clang Static Analyzer
|
|
|
|
<a
|
|
|
|
href="https://developer.apple.com/library/mac/documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/060-Debug_Your_App/debug_app.html#//apple_ref/doc/uid/TP40010215-CH3-SW17">directly
|
2010-02-19 16:14:02 +08:00
|
|
|
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>
|
2012-01-15 23:26:07 +08:00
|
|
|
<td style="padding-left:10px; text-align:center">
|
|
|
|
<a href="images/analyzer_xcode.png"><img src="images/analyzer_xcode.png" width="620px" alt="analyzer in xcode"></a>
|
|
|
|
<br><b>Viewing static analyzer results in Xcode</b>
|
2010-02-19 16:14:02 +08:00
|
|
|
</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,
|
2013-01-09 03:29:37 +08:00
|
|
|
consider using <a href="scan-build.html"><b>scan-build</b></a>.
|
2010-02-19 16:14:02 +08:00
|
|
|
</ul>
|
2010-02-20 01:33:30 +08:00
|
|
|
|
2010-02-19 16:14:02 +08:00
|
|
|
|
|
|
|
<h2>Getting Started</h2>
|
|
|
|
|
2013-01-09 03:29:37 +08:00
|
|
|
<p>Xcode is available as a free download from Apple on the <a
|
|
|
|
href="https://itunes.apple.com/us/app/xcode/id497799835?mt=12">Mac
|
|
|
|
App Store</a>, with <a
|
|
|
|
href="https://developer.apple.com/library/mac/documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/060-Debug_Your_App/debug_app.html#//apple_ref/doc/uid/TP40010215-CH3-SW17">instructions
|
|
|
|
available</a> for using the analyzer.</p>
|
2010-02-19 16:14:02 +08:00
|
|
|
|
2013-01-09 03:29:37 +08:00
|
|
|
<h2>Using open source analyzer builds with Xcode</h2>
|
2010-02-19 16:14:02 +08:00
|
|
|
|
|
|
|
<p>By default, Xcode uses the version of <tt>clang</tt> that came bundled with
|
2013-01-09 03:29:37 +08:00
|
|
|
it to analyze your code. 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>
|
2010-02-19 16:14:02 +08:00
|
|
|
|
|
|
|
<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
|
2013-01-09 03:29:37 +08:00
|
|
|
copy of <tt>clang</tt> that Xcode uses for analysis:</p>
|
2010-02-19 16:14:02 +08:00
|
|
|
|
|
|
|
<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
|
2013-01-09 03:29:37 +08:00
|
|
|
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>
|
2010-02-19 16:14:02 +08:00
|
|
|
|
|
|
|
<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>
|
|
|
|
|
2011-02-01 04:45:38 +08:00
|
|
|
<h4>Things to keep in mind</h4>
|
|
|
|
|
|
|
|
<ul>
|
2013-01-09 03:29:37 +08:00
|
|
|
<li>You should quit Xcode prior to running <tt>set-xcode-analyzer</tt>.</li> <li>You will need to run <tt>set-xcode-analyzer</tt> under
|
|
|
|
<b><tt>sudo</tt></b> in order to have write privileges to modify the Xcode
|
|
|
|
configuration files.</li>
|
2011-02-01 04:45:38 +08:00
|
|
|
</ul>
|
|
|
|
|
2010-02-19 16:14:02 +08:00
|
|
|
<h4>Examples</h4>
|
|
|
|
|
2013-01-09 03:29:37 +08:00
|
|
|
<p><b>Example 1</b>: Telling Xcode to use checker-235:</p>
|
2010-02-19 16:14:02 +08:00
|
|
|
|
|
|
|
<pre class="code_example">
|
|
|
|
$ pwd
|
|
|
|
/tmp
|
|
|
|
$ tar xjf checker-235.tar.bz2
|
2011-02-01 04:45:38 +08:00
|
|
|
$ sudo checker-235/set-xcode-analyzer --use-checker-build=/tmp/checker-235
|
2010-02-19 16:14:02 +08:00
|
|
|
</pre>
|
|
|
|
|
2010-02-19 16:24:37 +08:00
|
|
|
<p>Note that you typically won't install an analyzer build in <tt>/tmp</tt>, but
|
|
|
|
the point of this example is that <tt>set-xcode-analyzer</tt> just wants a full
|
|
|
|
path to an untarred analyzer build.</p>
|
|
|
|
|
|
|
|
<p><b>Example 2</b>: Telling Xcode to use a very specific version of <tt>clang</tt>:</p>
|
2010-02-19 16:14:02 +08:00
|
|
|
|
|
|
|
<pre class="code_example">
|
2011-02-01 04:45:38 +08:00
|
|
|
$ sudo set-xcode-analyzer --use-checker-build=~/mycrazyclangbuild/bin/clang
|
2010-02-19 16:14:02 +08:00
|
|
|
</pre>
|
|
|
|
|
2010-02-19 16:24:37 +08:00
|
|
|
<p><b>Example 3</b>: Resetting Xcode to its default behavior:</p>
|
2010-02-19 16:14:02 +08:00
|
|
|
|
|
|
|
<pre class="code_example">
|
2011-02-01 04:45:38 +08:00
|
|
|
$ sudo set-xcode-analyzer --use-xcode-clang
|
2010-02-19 16:14:02 +08:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|