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

Side by Side Diff: native_client_sdk/src/doc/devguide/devcycle/debugging.rst

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 .. _devcycle-debugging: 1 .. _devcycle-debugging:
2 2
3 ######### 3 #########
4 Debugging 4 Debugging
5 ######### 5 #########
6 6
7 This document describes tools and techniques you can use to debug, monitor, 7 This document describes tools and techniques you can use to debug, monitor,
8 and measure your application's performance. 8 and measure your application's performance.
9 9
10 .. contents:: Table Of Contents 10 .. contents:: Table Of Contents
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 void logmsg(const char* pMsg){ 82 void logmsg(const char* pMsg){
83 fprintf(stdout,"logmsg: %s\n",pMsg); 83 fprintf(stdout,"logmsg: %s\n",pMsg);
84 } 84 }
85 void errormsg(const char* pMsg){ 85 void errormsg(const char* pMsg){
86 fprintf(stderr,"logerr: %s\n",pMsg); 86 fprintf(stderr,"logerr: %s\n",pMsg);
87 } 87 }
88 88
89 By default stdout and stderr will appear in Chrome's stdout and stderr stream 89 By default stdout and stderr will appear in Chrome's stdout and stderr stream
90 but they can also be redirected as described below. 90 but they can also be redirected as described below.
91 91
92 The stderr from the process is by default visible in the terminal that launched
93 chrome (at least on mac and linux). Be sure that when you launch chrome it
Sam Clegg 2014/10/01 21:52:15 The stderr and stderr streams for chrome are avail
jpmedley 2014/10/07 17:01:43 Done.
94 doesn't attach to an existing instance. One simple way to do this is to pass a
95 new directory to chrome as your user data directory (``chrome
96 --user-data-dir=<newdir>``). It's also possible to redirect the NaCl's stderr to
97 other places such as, for example, :ref:`log files
98 <redirecting-output-to-log>`.
Sam Clegg 2014/10/01 21:52:15 This last sentence is duplicated from the previous
jpmedley 2014/10/07 17:01:43 Done.
99
100 .. _redirecting-output-to-log:
92 101
93 Redirecting output to log files 102 Redirecting output to log files
94 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 103 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95 104
96 You can redirect stdout and stderr to output files by setting these environment 105 You can redirect stdout and stderr to output files by setting these environment
97 variables: 106 variables:
98 107
99 * ``NACL_EXE_STDOUT=c:\nacl_stdout.log`` 108 * ``NACL_EXE_STDOUT=c:\nacl_stdout.log``
100 * ``NACL_EXE_STDERR=c:\nacl_stderr.log`` 109 * ``NACL_EXE_STDERR=c:\nacl_stderr.log``
101 110
102 There is another variable, ``NACLLOG``, that you can use to redirect Native 111 There is another variable, ``NACLLOG``, that you can use to redirect Native
103 Client's internally-generated messages. This variable is set to stderr by 112 Client's internally-generated messages. This variable is set to stderr by
104 default; you can redirect these messages to an output file by setting the 113 default; you can redirect these messages to an output file by setting the
105 variable as follows: 114 variable as follows:
106 115
107 * ``NACLLOG=c:\nacl.log`` 116 * ``NACLLOG=c:\nacl.log``
108 117
118 The exception to this is the :doc:`nacl_io library <../coding/nacl_io>` which
119 logs directly to the stderr stream.
Sam Clegg 2014/10/01 21:52:14 I would drop this sentence. nacl_io is just like
jpmedley 2014/10/07 17:01:43 Done.
120
109 .. Note:: 121 .. Note::
110 :class: note 122 :class: note
111 123
112 **Note:** If you set the ``NACL_EXE_STDOUT``, ``NACL_EXE_STDERR``, or 124 **Note:** If you set the ``NACL_EXE_STDOUT``, ``NACL_EXE_STDERR``, or
113 ``NACLLOG`` variables to redirect output to a file, you must run Chrome with 125 ``NACLLOG`` variables to redirect output to a file, you must run Chrome with
114 the ``--no-sandbox`` flag. You must also be careful that each variable points 126 the ``--no-sandbox`` flag. You must also be careful that each variable points
115 to a different file. 127 to a different file.
116 128
117 Logging calls to Pepper interfaces 129 Logging calls to Pepper interfaces
118 ---------------------------------- 130 ----------------------------------
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 a ``.pexe`` file extension. The actual extension should not matter, but 184 a ``.pexe`` file extension. The actual extension should not matter, but
173 it helps distinguish between the two types of files. 185 it helps distinguish between the two types of files.
174 186
175 **Note** unlike the finalized copy of the pexe, the non-finalized debug copy 187 **Note** unlike the finalized copy of the pexe, the non-finalized debug copy
176 is not considered stable. This means that a debug copy of the PNaCl 188 is not considered stable. This means that a debug copy of the PNaCl
177 application created by a Pepper N SDK is only guaranteed to run 189 application created by a Pepper N SDK is only guaranteed to run
178 with a matching Chrome version N. If the version of the debug bitcode pexe 190 with a matching Chrome version N. If the version of the debug bitcode pexe
179 does not match that of Chrome then the translation process may fail, and 191 does not match that of Chrome then the translation process may fail, and
180 you will see an error message in the JavaScript console. 192 you will see an error message in the JavaScript console.
181 193
182 Also, make sure you are passing the ``-g`` :ref:`compile option 194 Also, make sure you are passing the ``-g`` :ref:`compile option <compile_flags>`
183 <compile_flags>` to ``pnacl-clang`` to enable generating debugging info. 195 to ``pnacl-clang`` to enable generating debugging info. You might also want to
184 You might also want to omit ``-O2`` from the compile-time and link-time 196 omit ``-O2`` from the compile-time and link-time options, otherwise GDB not
185 options, otherwise GDB not might be able to print variables' values when 197 might be able to print variables' values when debugging (this is more of a
186 debugging (this is more of a problem with the PNaCl/LLVM toolchain than 198 problem with the PNaCl/LLVM toolchain than with GCC).
187 with GCC).
188 199
189 Once you have built a non-stable debug copy of the pexe, list the URL of 200 Once you have built a non-stable debug copy of the pexe, list the URL of
190 that copy in your application's manifest file: 201 that copy in your application's manifest file:
191 202
192 .. naclcode:: 203 .. naclcode::
193 204
194 { 205 {
195 "program": { 206 "program": {
196 "portable": { 207 "portable": {
197 "pnacl-translate": { 208 "pnacl-translate": {
198 "url": "release_version.pexe", 209 "url": "release_version.pexe",
199 "optlevel": 2 210 "optlevel": 2
200 }, 211 },
201 "pnacl-debug": { 212 "pnacl-debug": {
202 "url": "debug_version.bc", 213 "url": "debug_version.bc",
203 "optlevel": 0 214 "optlevel": 0
204 } 215 }
205 } 216 }
206 } 217 }
207 } 218 }
208 219
209 Copy the ``debug_version.bc`` and ``nmf`` files to the location that 220 Copy the ``debug_version.bc`` and ``nmf`` files to the location that
210 your local web server serves files from. 221 your local web server serves files from.
211 222
212 When you run Chrome with ``--enable-nacl-debug``, Chrome will translate 223 When you run Chrome with ``--enable-nacl-debug``, Chrome will translate
213 and run the ``debug_version.bc`` instead of ``release_version.pexe``. 224 and run the ``debug_version.bc`` instead of ``release_version.pexe``.
214 Once the debug version is loaded, you are ready to :ref:`run nacl-gdb 225 Once the debug version is loaded, you are ready to :ref:`run nacl-gdb
215 <running_nacl_gdb>` 226 <running_nacl_gdb>`
216 227
217 Whether you publish the NMF file containing the debug URL to the release 228 Whether you publish the NMF file containing the debug URL to the
218 web server, is up to you. One reason to avoid publishing the debug URL 229 release web server, is up to you. One reason to avoid publishing the
219 is that it is only guaranteed to work for the Chrome version that matches 230 debug URL is that it is only guaranteed to work for the Chrome version
220 the SDK version. Developers who may have left the ``--enable-nacl-debug`` 231 that matches the SDK version. Developers who may have left the
221 flag turned on may end up loading the debug copy of your application 232 ``--enable-nacl-debug`` flag turned on may end up loading the debug
222 (which may or may not work, depending on their version of Chrome). 233 copy of your application (which may or may not work, depending on
234 their version of Chrome).
223 235
224 236
225 Debugging PNaCl pexes (with older Pepper toolchains) 237 Debugging PNaCl pexes (with older Pepper toolchains)
226 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 238 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
227 239
228 If you want to use GDB to debug a program that is compiled with the PNaCl 240 If you want to use GDB to debug a program that is compiled with the PNaCl
229 toolchain, you must convert the ``pexe`` file to a ``nexe``. (You can skip 241 toolchain, you must convert the ``pexe`` file to a ``nexe``. (You can skip
230 this step if you are using the GCC toolchain, or if you are using 242 this step if you are using the GCC toolchain, or if you are using
231 pepper 35 or later.) 243 pepper 35 or later.)
232 244
233 * Firstly, make sure you are passing the ``-g`` :ref:`compile option 245 * Firstly, make sure you are passing the ``-g`` :ref:`compile option
234 <compile_flags>` to ``pnacl-clang`` to enable generating debugging info. 246 <compile_flags>` to ``pnacl-clang`` to enable generating debugging info.
235 You might also want to omit ``-O2`` from the compile-time and link-time 247 You might also want to omit ``-O2`` from the compile-time and link-time
236 options. 248 options.
237 249
238 * Secondly, use ``pnacl-translate`` to convert your ``pexe`` to one or more 250 * Secondly, use ``pnacl-translate`` to convert your ``pexe`` to one or more
251
239 ``nexe`` files. For example: 252 ``nexe`` files. For example:
240 253
241 .. naclcode:: 254 .. naclcode::
242 :prettyprint: 0 255 :prettyprint: 0
243 256
244 nacl_sdk/pepper_<version>/toolchain/win_pnacl/bin/pnacl-translate \ 257 nacl_sdk/pepper_<version>/toolchain/win_pnacl/bin/pnacl-translate \
245 --allow-llvm-bitcode-input hello_world.pexe -arch x86-32 \ 258 --allow-llvm-bitcode-input hello_world.pexe -arch x86-32 \
246 -o hello_world_x86_32.nexe 259 -o hello_world_x86_32.nexe
247 nacl_sdk/pepper_<version>/toolchain/win_pnacl/bin/pnacl-translate \ 260 nacl_sdk/pepper_<version>/toolchain/win_pnacl/bin/pnacl-translate \
248 --allow-llvm-bitcode-input hello_world.pexe -arch x86-64 \ 261 --allow-llvm-bitcode-input hello_world.pexe -arch x86-64 \
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 531
519 If you cannot use the :ref:`Visual Studio add-in <visual_studio>`, or you want 532 If you cannot use the :ref:`Visual Studio add-in <visual_studio>`, or you want
520 to use a debugger other than nacl-gdb, you must manually build your module as a 533 to use a debugger other than nacl-gdb, you must manually build your module as a
521 Pepper plugin (sometimes referred to as a "`trusted 534 Pepper plugin (sometimes referred to as a "`trusted
522 <http://www.chromium.org/nativeclient/getting-started/getting-started-background -and-basics#TOC-Trusted-vs-Untrusted>`_" 535 <http://www.chromium.org/nativeclient/getting-started/getting-started-background -and-basics#TOC-Trusted-vs-Untrusted>`_"
523 or "in-process" plugin). Pepper plugins (.DLL files on Windows; .so files on 536 or "in-process" plugin). Pepper plugins (.DLL files on Windows; .so files on
524 Linux; .bundle files on Mac) are loaded directly in either the Chrome renderer 537 Linux; .bundle files on Mac) are loaded directly in either the Chrome renderer
525 process or a separate plugin process, rather than in Native Client. Building a 538 process or a separate plugin process, rather than in Native Client. Building a
526 module as a trusted Pepper plugin allows you to use standard debuggers and 539 module as a trusted Pepper plugin allows you to use standard debuggers and
527 development tools on your system, but when you're finished developing the 540 development tools on your system, but when you're finished developing the
528 plugin, you need to port it to Native Client (i.e., build the module with one 541 plugin, you need to port it to Native Client (i.e., build the module with one of
529 of the toolchains in the NaCl SDK so that the module runs in Native Client). 542 the toolchains in the NaCl SDK so that the module runs in Native Client). For
530 For details on this advanced development technique, see `Debugging a Trusted 543 details on this advanced development technique, see `Debugging a Trusted Plugin
531 Plugin
532 <http://www.chromium.org/nativeclient/how-tos/debugging-documentation/debugging- a-trusted-plugin>`_. 544 <http://www.chromium.org/nativeclient/how-tos/debugging-documentation/debugging- a-trusted-plugin>`_.
533 Note that starting with the ``pepper_22`` bundle, the NaCl SDK for Windows 545 Note that starting with the ``pepper_22`` bundle, the NaCl SDK for Windows
534 includes pre-built libraries and library source code, making it much easier to 546 includes pre-built libraries and library source code, making it much easier to
535 build a module into a .DLL. 547 build a module into a .DLL.
536 548
537
538 .. |menu-icon| image:: /images/menu-icon.png 549 .. |menu-icon| image:: /images/menu-icon.png
539 .. |puzzle| image:: /images/puzzle.png 550 .. |puzzle| image:: /images/puzzle.png
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698