1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns=
"http://www.w3.org/1999/xhtml">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
5 <title>Native Client: Debugging Tips
</title>
6 <link href=
"stylesheet.css" type=
"text/css" rel=
"stylesheet"></link>
12 <a href=
"../README.html">Back to README
</a>
15 <h1>Debugging Tips
</h1>
18 This page describes strategies you can use to debug your modules.
22 Currently, you can't easily use interactive debuggers
23 with Native Client modules.
24 One reason is that Native Client modules' use of
25 segmented memory protection confuses
26 the kernel exception handler,
27 which in turn interferes with handling breakpoints.
29 the segmented structure of the Native Client address space
30 interferes with symbol resolution.
34 We're actively working on improving the debuggability of Native Client modules.
35 If you'd like to help, please volunteer!
44 <li> <a href=
"#standalone">Design your module to run standalone
</a>
46 <li> <a href=
"#compile">Catch errors at compile time
</a>
48 <li> <a href=
"#printf">Use printf and assert if necessary
</a>
50 <li> <a href=
"#print-examples">Examples
</a>
51 <li> <a href=
"#launchbrowser">Launching the browser from the command line
</a>
53 <li> <a href=
"#output">Platform-specific output locations
</a>
59 <h2><a name=
"standalone" id=
"standalone"> </a> Design your module to run standalone
</h2>
62 If your module can run both as a standalone Linux or Mac application
63 <em>and
</em> within Native Client,
64 then you can use a debugger such as GDB, KDbg, or Xcode
65 to debug the standalone form of your application.
69 <strong>Note:
</strong>
70 Building standalone applications is not supported on Windows.
74 For examples of creating a module that also works standalone,
75 see the
<code>earth
</code>,
<code>life
</code>,
<code>tone
</code>,
76 and
<code>voronoi
</code> examples under
<code>native_client/tests
</code>.
79 <h2><a name=
"compile"> </a> Catch errors at compile time
</h2>
82 It's easier to fix bugs you find at compile time
83 than those you find at runtime.
84 When you compile your module,
85 use
<code>gcc
</code> flags such as
86 <code>-Werror
</code> and
<code>-Wall
</code>
87 to help ensure that your code is as clean as possible.
92 <kbd>nacl-g++ earth.cc
<b>-Wall -Werror
</b> -O3 -mfpmath=sse -msse -fomit-frame-pointer -lpthread -lm -o earth_release.nexe
</kbd>
95 <h2> <a name=
"printf"> </a> Use printf and assert if necessary
</h2>
98 If a bug doesn't appear in the standalone app version of a module,
100 <code>printf
</code> and
<code>assert
</code>
101 to debug your module when it runs in Native Client.
106 Using
<code>printf
</code> can be useful on Linux and Mac,
107 but it's more difficult on Windows.
108 For the latest Windows testing tips, see the wiki page
109 <a href=
"http://code.google.com/p/nativeclient/wiki/DebuggingModulesOnWindows">DebuggingModulesOnWindows
</a>.
114 <code>printf
</code> and
<code>assert
</code>:
118 <li> On Linux and Mac, if you
119 <a href=
"#launchbrowser">launch the browser from the command line
</a>,
120 you can see the output in the window where you entered the command.
121 Otherwise, the output goes to a
122 <a href=
"#output">platform-specific location
</a>.
124 <li> We recommend that you call
<code>printf
</code> from only one thread.
126 <li> <code>assert
</code> does not generate core dumps.
128 <li> Alongside your
<code>printf
</code> and
<code>assert
</code> output,
129 you might see debugging output from other processes
—
130 the plug-in and
<code>sel_ldr
</code>.
134 <h3> <a name=
"print-examples"></a> Examples
</h3>
137 Here's an example of using
<code>printf
</code>:
141 #include
<stdio.h
>
143 printf(
"Multimedia system failed to initialize! errno: %d\n", errno);
147 Here's an example of using
<code>assert
</code>:
151 #include
<assert.h
>
159 <h3> <a name=
"launchbrowser"></a>Launching the browser from the command line
</h3>
162 On Linux and Mac, if you launch your browser from the command line,
163 the output of
<code>printf
</code> and
<code>assert
</code> goes
164 to the window you used to enter the command.
165 Make sure the window has a large scroll buffer,
166 so you don't lose output.
167 Better yet, use the GNU Screen program
169 so you can easily search the output.
173 <table summary=
"platform-specific instructions for launching Firefox from the command line">
175 <th>Platform
</th> <th>How to launch Firefox from the command line
</th>
178 <td valign=
"top">Linux
</td>
179 <td> <code>/usr/bin/firefox2
</code> </td>
182 <td valign=
"top">Mac
</td>
183 <td> <code>/Applications/Firefox.app/Contents/MacOS/firefox-bin
</code></td>
187 <td valign="top">Windows</td>
190 <code>/cygdrive/c/Program\ Files/Mozilla\ Firefox/firefox.exe</code>
193 <code>"C:\Program Files\Mozilla Firefox\firefox.exe"</code>
201 <h3> <a name=
"output"></a>Platform-specific output locations
</h3>
204 If you launch the browser using a menu, button, or icon
205 (rather than from the
206 <a href=
"#launchbrowser">command line
</a>)
207 the output of
<code>printf
</code> or
<code>assert
</code> goes to a
208 location that depends on the platform you're using.
212 <table summary=
"platform-specific browser output locations">
214 <th>Platform
</th> <th>Default output location
</th>
217 <td>Linux
</td> <td> <code>$HOME/.xsession-errors
</code> </td>
220 <td>Mac
</td> <td><code>/var/log/system.log
</code></td>
224 <td>Windows</td> <td> <span class="comment">[PENDING: ?]</span> </td>
233 <a href=
"http://code.google.com/policies.html#restrictions">noted
</a>,
234 the content of this page is licensed under a
235 <a href=
"http://creativecommons.org/licenses/by/2.5/">Creative Commons
236 Attribution
2.5 license
</a>.