Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: native_client_sdk/doc_generated/devguide/devcycle/debugging.html

Issue 618823003: Add debugging information for nacl_io library. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor fixes. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 {{+bindTo:partials.standard_nacl_article}} 1 {{+bindTo:partials.standard_nacl_article}}
2 2
3 <section id="debugging"> 3 <section id="debugging">
4 <span id="devcycle-debugging"></span><h1 id="debugging"><span id="devcycle-debug ging"></span>Debugging</h1> 4 <span id="devcycle-debugging"></span><h1 id="debugging"><span id="devcycle-debug ging"></span>Debugging</h1>
5 <p>This document describes tools and techniques you can use to debug, monitor, 5 <p>This document describes tools and techniques you can use to debug, monitor,
6 and measure your application&#8217;s performance.</p> 6 and measure your application&#8217;s performance.</p>
7 <div class="contents local" id="table-of-contents" style="display: none"> 7 <div class="contents local" id="table-of-contents" style="display: none">
8 <p class="topic-title first">Table Of Contents</p> 8 <p class="topic-title first">Table Of Contents</p>
9 <ul class="small-gap"> 9 <ul class="small-gap">
10 <li><p class="first"><a class="reference internal" href="#diagnostic-information " id="id2">Diagnostic information</a></p> 10 <li><p class="first"><a class="reference internal" href="#diagnostic-information " id="id2">Diagnostic information</a></p>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 #include &lt;stdio.h&gt; 84 #include &lt;stdio.h&gt;
85 void logmsg(const char* pMsg){ 85 void logmsg(const char* pMsg){
86 fprintf(stdout,&quot;logmsg: %s\n&quot;,pMsg); 86 fprintf(stdout,&quot;logmsg: %s\n&quot;,pMsg);
87 } 87 }
88 void errormsg(const char* pMsg){ 88 void errormsg(const char* pMsg){
89 fprintf(stderr,&quot;logerr: %s\n&quot;,pMsg); 89 fprintf(stderr,&quot;logerr: %s\n&quot;,pMsg);
90 } 90 }
91 </pre> 91 </pre>
92 <p>By default stdout and stderr will appear in Chrome&#8217;s stdout and stderr stream 92 <p>By default stdout and stderr will appear in Chrome&#8217;s stdout and stderr stream
93 but they can also be redirected as described below.</p> 93 but they can also be redirected as described below.</p>
94 <h4 id="redirecting-output-to-log-files">Redirecting output to log files</h4> 94 <p>The stderr from the process is by default visible in the terminal that launch ed
95 chrome (at least on mac and linux). Be sure that when you launch chrome it
96 doesn&#8217;t attach to an existing instance. One simple way to do this is to pa ss a
97 new directory to chrome as your user data directory (<code>chrome
98 --user-data-dir=&lt;newdir&gt;</code>). It&#8217;s also possible to redirect the NaCl&#8217;s stderr to
99 other places such as, for example, <a class="reference internal" href="#redirect ing-output-to-log"><em>log files</em></a>.</p>
100 <h4 id="redirecting-output-to-log-files"><span id="redirecting-output-to-log"></ span>Redirecting output to log files</h4>
95 <p>You can redirect stdout and stderr to output files by setting these environme nt 101 <p>You can redirect stdout and stderr to output files by setting these environme nt
96 variables:</p> 102 variables:</p>
97 <ul class="small-gap"> 103 <ul class="small-gap">
98 <li><code>NACL_EXE_STDOUT=c:\nacl_stdout.log</code></li> 104 <li><code>NACL_EXE_STDOUT=c:\nacl_stdout.log</code></li>
99 <li><code>NACL_EXE_STDERR=c:\nacl_stderr.log</code></li> 105 <li><code>NACL_EXE_STDERR=c:\nacl_stderr.log</code></li>
100 </ul> 106 </ul>
101 <p>There is another variable, <code>NACLLOG</code>, that you can use to redirect Native 107 <p>There is another variable, <code>NACLLOG</code>, that you can use to redirect Native
102 Client&#8217;s internally-generated messages. This variable is set to stderr by 108 Client&#8217;s internally-generated messages. This variable is set to stderr by
103 default; you can redirect these messages to an output file by setting the 109 default; you can redirect these messages to an output file by setting the
104 variable as follows:</p> 110 variable as follows:</p>
105 <ul class="small-gap"> 111 <ul class="small-gap">
106 <li><code>NACLLOG=c:\nacl.log</code></li> 112 <li><code>NACLLOG=c:\nacl.log</code></li>
107 </ul> 113 </ul>
114 <p>The exception to this is the <a class="reference internal" href="/native-clie nt/devguide/coding/nacl_io.html"><em>nacl_io library</em></a> which
115 logs directly to the stderr stream.</p>
108 <aside class="note"> 116 <aside class="note">
109 <strong>Note:</strong> If you set the <code>NACL_EXE_STDOUT</code>, <code>NACL_E XE_STDERR</code>, or 117 <strong>Note:</strong> If you set the <code>NACL_EXE_STDOUT</code>, <code>NACL_E XE_STDERR</code>, or
110 <code>NACLLOG</code> variables to redirect output to a file, you must run Chrome with 118 <code>NACLLOG</code> variables to redirect output to a file, you must run Chrome with
111 the <code>--no-sandbox</code> flag. You must also be careful that each variable points 119 the <code>--no-sandbox</code> flag. You must also be careful that each variable points
112 to a different file. 120 to a different file.
113 </aside> 121 </aside>
114 <h3 id="logging-calls-to-pepper-interfaces">Logging calls to Pepper interfaces</ h3> 122 <h3 id="logging-calls-to-pepper-interfaces">Logging calls to Pepper interfaces</ h3>
115 <p>You can log all Pepper calls your module makes by passing the following flags 123 <p>You can log all Pepper calls your module makes by passing the following flags
116 to Chrome on startup:</p> 124 to Chrome on startup:</p>
117 <pre class="prettyprint"> 125 <pre class="prettyprint">
(...skipping 29 matching lines...) Expand all
147 metadata, which we need for debugging. In this section we&#8217;ll give the 155 metadata, which we need for debugging. In this section we&#8217;ll give the
148 LLVM bitcode file a <code>.bc</code> file extension, and the PNaCl bitcode file 156 LLVM bitcode file a <code>.bc</code> file extension, and the PNaCl bitcode file
149 a <code>.pexe</code> file extension. The actual extension should not matter, but 157 a <code>.pexe</code> file extension. The actual extension should not matter, but
150 it helps distinguish between the two types of files.</p> 158 it helps distinguish between the two types of files.</p>
151 <p><strong>Note</strong> unlike the finalized copy of the pexe, the non-finalize d debug copy 159 <p><strong>Note</strong> unlike the finalized copy of the pexe, the non-finalize d debug copy
152 is not considered stable. This means that a debug copy of the PNaCl 160 is not considered stable. This means that a debug copy of the PNaCl
153 application created by a Pepper N SDK is only guaranteed to run 161 application created by a Pepper N SDK is only guaranteed to run
154 with a matching Chrome version N. If the version of the debug bitcode pexe 162 with a matching Chrome version N. If the version of the debug bitcode pexe
155 does not match that of Chrome then the translation process may fail, and 163 does not match that of Chrome then the translation process may fail, and
156 you will see an error message in the JavaScript console.</p> 164 you will see an error message in the JavaScript console.</p>
157 <p>Also, make sure you are passing the <code>-g</code> <a class="reference inter nal" href="/native-client/devguide/devcycle/building.html#compile-flags"><em>com pile option</em></a> to <code>pnacl-clang</code> to enable generating debugging info. 165 <p>Also, make sure you are passing the <code>-g</code> <a class="reference inter nal" href="/native-client/devguide/devcycle/building.html#compile-flags"><em>com pile option</em></a>
158 You might also want to omit <code>-O2</code> from the compile-time and link-time 166 to <code>pnacl-clang</code> to enable generating debugging info. You might also want to
159 options, otherwise GDB not might be able to print variables&#8217; values when 167 omit <code>-O2</code> from the compile-time and link-time options, otherwise GDB not
160 debugging (this is more of a problem with the PNaCl/LLVM toolchain than 168 might be able to print variables&#8217; values when debugging (this is more of a
161 with GCC).</p> 169 problem with the PNaCl/LLVM toolchain than with GCC).</p>
162 <p>Once you have built a non-stable debug copy of the pexe, list the URL of 170 <p>Once you have built a non-stable debug copy of the pexe, list the URL of
163 that copy in your application&#8217;s manifest file:</p> 171 that copy in your application&#8217;s manifest file:</p>
164 <pre class="prettyprint"> 172 <pre class="prettyprint">
165 { 173 {
166 &quot;program&quot;: { 174 &quot;program&quot;: {
167 &quot;portable&quot;: { 175 &quot;portable&quot;: {
168 &quot;pnacl-translate&quot;: { 176 &quot;pnacl-translate&quot;: {
169 &quot;url&quot;: &quot;release_version.pexe&quot;, 177 &quot;url&quot;: &quot;release_version.pexe&quot;,
170 &quot;optlevel&quot;: 2 178 &quot;optlevel&quot;: 2
171 }, 179 },
172 &quot;pnacl-debug&quot;: { 180 &quot;pnacl-debug&quot;: {
173 &quot;url&quot;: &quot;debug_version.bc&quot;, 181 &quot;url&quot;: &quot;debug_version.bc&quot;,
174 &quot;optlevel&quot;: 0 182 &quot;optlevel&quot;: 0
175 } 183 }
176 } 184 }
177 } 185 }
178 } 186 }
179 </pre> 187 </pre>
180 <p>Copy the <code>debug_version.bc</code> and <code>nmf</code> files to the loca tion that 188 <p>Copy the <code>debug_version.bc</code> and <code>nmf</code> files to the loca tion that
181 your local web server serves files from.</p> 189 your local web server serves files from.</p>
182 <p>When you run Chrome with <code>--enable-nacl-debug</code>, Chrome will transl ate 190 <p>When you run Chrome with <code>--enable-nacl-debug</code>, Chrome will transl ate
183 and run the <code>debug_version.bc</code> instead of <code>release_version.pexe< /code>. 191 and run the <code>debug_version.bc</code> instead of <code>release_version.pexe< /code>.
184 Once the debug version is loaded, you are ready to <a class="reference internal" href="#running-nacl-gdb"><em>run nacl-gdb</em></a></p> 192 Once the debug version is loaded, you are ready to <a class="reference internal" href="#running-nacl-gdb"><em>run nacl-gdb</em></a></p>
185 <p>Whether you publish the NMF file containing the debug URL to the release 193 <p>Whether you publish the NMF file containing the debug URL to the
186 web server, is up to you. One reason to avoid publishing the debug URL 194 release web server, is up to you. One reason to avoid publishing the
187 is that it is only guaranteed to work for the Chrome version that matches 195 debug URL is that it is only guaranteed to work for the Chrome version
188 the SDK version. Developers who may have left the <code>--enable-nacl-debug</cod e> 196 that matches the SDK version. Developers who may have left the
189 flag turned on may end up loading the debug copy of your application 197 <code>--enable-nacl-debug</code> flag turned on may end up loading the debug
190 (which may or may not work, depending on their version of Chrome).</p> 198 copy of your application (which may or may not work, depending on
199 their version of Chrome).</p>
191 <h4 id="debugging-pnacl-pexes-with-older-pepper-toolchains">Debugging PNaCl pexe s (with older Pepper toolchains)</h4> 200 <h4 id="debugging-pnacl-pexes-with-older-pepper-toolchains">Debugging PNaCl pexe s (with older Pepper toolchains)</h4>
192 <p>If you want to use GDB to debug a program that is compiled with the PNaCl 201 <p>If you want to use GDB to debug a program that is compiled with the PNaCl
193 toolchain, you must convert the <code>pexe</code> file to a <code>nexe</code>. (You can skip 202 toolchain, you must convert the <code>pexe</code> file to a <code>nexe</code>. (You can skip
194 this step if you are using the GCC toolchain, or if you are using 203 this step if you are using the GCC toolchain, or if you are using
195 pepper 35 or later.)</p> 204 pepper 35 or later.)</p>
196 <ul class="small-gap"> 205 <ul class="small-gap">
197 <li>Firstly, make sure you are passing the <code>-g</code> <a class="reference i nternal" href="/native-client/devguide/devcycle/building.html#compile-flags"><em >compile option</em></a> to <code>pnacl-clang</code> to enable generating debugg ing info. 206 <li>Firstly, make sure you are passing the <code>-g</code> <a class="reference i nternal" href="/native-client/devguide/devcycle/building.html#compile-flags"><em >compile option</em></a> to <code>pnacl-clang</code> to enable generating debugg ing info.
198 You might also want to omit <code>-O2</code> from the compile-time and link-time 207 You might also want to omit <code>-O2</code> from the compile-time and link-time
199 options.</li> 208 options.</li>
200 <li><p class="first">Secondly, use <code>pnacl-translate</code> to convert your <code>pexe</code> to one or more 209 <li><p class="first">Secondly, use <code>pnacl-translate</code> to convert your <code>pexe</code> to one or more</p>
201 <code>nexe</code> files. For example:</p> 210 <p><code>nexe</code> files. For example:</p>
202 <pre> 211 <pre>
203 nacl_sdk/pepper_&lt;version&gt;/toolchain/win_pnacl/bin/pnacl-translate \ 212 nacl_sdk/pepper_&lt;version&gt;/toolchain/win_pnacl/bin/pnacl-translate \
204 --allow-llvm-bitcode-input hello_world.pexe -arch x86-32 \ 213 --allow-llvm-bitcode-input hello_world.pexe -arch x86-32 \
205 -o hello_world_x86_32.nexe 214 -o hello_world_x86_32.nexe
206 nacl_sdk/pepper_&lt;version&gt;/toolchain/win_pnacl/bin/pnacl-translate \ 215 nacl_sdk/pepper_&lt;version&gt;/toolchain/win_pnacl/bin/pnacl-translate \
207 --allow-llvm-bitcode-input hello_world.pexe -arch x86-64 \ 216 --allow-llvm-bitcode-input hello_world.pexe -arch x86-64 \
208 -o hello_world_x86_64.nexe 217 -o hello_world_x86_64.nexe
209 </pre> 218 </pre>
210 <p>For this, use the non-finalized <code>pexe</code> file produced by 219 <p>For this, use the non-finalized <code>pexe</code> file produced by
211 <code>pnacl-clang</code>, not the <code>pexe</code> file produced by <code>pnacl -finalize</code>. 220 <code>pnacl-clang</code>, not the <code>pexe</code> file produced by <code>pnacl -finalize</code>.
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 debugging, close the Chrome window and type <code>q</code> to quit gdb.</p> 468 debugging, close the Chrome window and type <code>q</code> to quit gdb.</p>
460 <h2 id="debugging-with-other-tools">Debugging with other tools</h2> 469 <h2 id="debugging-with-other-tools">Debugging with other tools</h2>
461 <p>If you cannot use the <a class="reference internal" href="#visual-studio"><em >Visual Studio add-in</em></a>, or you want 470 <p>If you cannot use the <a class="reference internal" href="#visual-studio"><em >Visual Studio add-in</em></a>, or you want
462 to use a debugger other than nacl-gdb, you must manually build your module as a 471 to use a debugger other than nacl-gdb, you must manually build your module as a
463 Pepper plugin (sometimes referred to as a &#8220;<a class="reference external" h ref="http://www.chromium.org/nativeclient/getting-started/getting-started-backgr ound-and-basics#TOC-Trusted-vs-Untrusted">trusted</a>&#8221; 472 Pepper plugin (sometimes referred to as a &#8220;<a class="reference external" h ref="http://www.chromium.org/nativeclient/getting-started/getting-started-backgr ound-and-basics#TOC-Trusted-vs-Untrusted">trusted</a>&#8221;
464 or &#8220;in-process&#8221; plugin). Pepper plugins (.DLL files on Windows; .so files on 473 or &#8220;in-process&#8221; plugin). Pepper plugins (.DLL files on Windows; .so files on
465 Linux; .bundle files on Mac) are loaded directly in either the Chrome renderer 474 Linux; .bundle files on Mac) are loaded directly in either the Chrome renderer
466 process or a separate plugin process, rather than in Native Client. Building a 475 process or a separate plugin process, rather than in Native Client. Building a
467 module as a trusted Pepper plugin allows you to use standard debuggers and 476 module as a trusted Pepper plugin allows you to use standard debuggers and
468 development tools on your system, but when you&#8217;re finished developing the 477 development tools on your system, but when you&#8217;re finished developing the
469 plugin, you need to port it to Native Client (i.e., build the module with one 478 plugin, you need to port it to Native Client (i.e., build the module with one of
470 of the toolchains in the NaCl SDK so that the module runs in Native Client). 479 the toolchains in the NaCl SDK so that the module runs in Native Client). For
471 For details on this advanced development technique, see <a class="reference exte rnal" href="http://www.chromium.org/nativeclient/how-tos/debugging-documentation /debugging-a-trusted-plugin">Debugging a Trusted 480 details on this advanced development technique, see <a class="reference external " href="http://www.chromium.org/nativeclient/how-tos/debugging-documentation/deb ugging-a-trusted-plugin">Debugging a Trusted Plugin</a>.
472 Plugin</a>.
473 Note that starting with the <code>pepper_22</code> bundle, the NaCl SDK for Wind ows 481 Note that starting with the <code>pepper_22</code> bundle, the NaCl SDK for Wind ows
474 includes pre-built libraries and library source code, making it much easier to 482 includes pre-built libraries and library source code, making it much easier to
475 build a module into a .DLL.</p> 483 build a module into a .DLL.</p>
476 </section> 484 </section>
477 485
478 {{/partials.standard_nacl_article}} 486 {{/partials.standard_nacl_article}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698