OLD | NEW |
---|---|
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 <http://www.gnu.org/software/gdb/>`_, and is located at | 207 <http://www.gnu.org/software/gdb/>`_, and is located at |
208 ``toolchain/<platform>_x86_newlib/bin/x86_64-nacl-gdb`` (where *<platform>* | 208 ``toolchain/<platform>_x86_newlib/bin/x86_64-nacl-gdb`` (where *<platform>* |
209 is the platform of your development machine: ``win``, ``mac``, or | 209 is the platform of your development machine: ``win``, ``mac``, or |
210 ``linux``). | 210 ``linux``). |
211 | 211 |
212 Note that this same copy of GDB can be used to debug any NaCl program, | 212 Note that this same copy of GDB can be used to debug any NaCl program, |
213 whether built using newlib or glibc for x86-32, x86-64 or ARM. In the SDK, | 213 whether built using newlib or glibc for x86-32, x86-64 or ARM. In the SDK, |
214 ``i686-nacl-gdb`` is an alias for ``x86_64-nacl-gdb``, and the ``newlib`` | 214 ``i686-nacl-gdb`` is an alias for ``x86_64-nacl-gdb``, and the ``newlib`` |
215 and ``glibc`` toolchains both contain the same version of GDB. | 215 and ``glibc`` toolchains both contain the same version of GDB. |
216 | 216 |
217 Debugging PNaCl pexes | 217 Debugging PNaCl pexes (with Pepper 35+) |
218 ~~~~~~~~~~~~~~~~~~~~~ | 218 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
219 | |
220 If you want to use GDB to debug a program that is compiled with the PNaCl | |
221 toolchain, you must have a copy of the pexe from **before** running | |
222 ``pnacl-finalize``. The ``pnacl-finalize`` tool converts LLVM bitcode | |
223 to the stable PNaCl bitcode format, but it also strips out debug | |
224 metadata, which we need for debugging. | |
225 | |
226 **Note** unlike the finalized copy of the pexe, the non-finalized debug copy | |
227 is not considered stable. This means that a debug copy of the PNaCl | |
228 application created by a Pepper N SDK is only guaranteed to run | |
229 with a matching Chrome version N. If the version of the debug bitcode pexe | |
230 does not match that of Chrome then the translation process may fail, and | |
231 you will see and error message in the JavaScript console. | |
232 | |
233 Also, make sure you are passing the ``-g`` :ref:`compile option | |
234 <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 | |
236 options, otherwise GDB not might be able to print variables' values when | |
237 debugging (this is more of a problem with the PNaCl/LLVM toolchain than | |
238 with GCC). | |
239 | |
240 Once you have built a non-stable debug copy of the pexe, list the URL of | |
241 that copy in your application's manifest file: | |
242 | |
243 .. naclcode:: | |
244 | |
245 { | |
246 "program": { | |
247 "pnacl-translate": { | |
248 "url": "release_version.pexe", | |
249 "optlevel": 2 | |
250 }, | |
251 "pnacl-debug": { | |
252 "url": "debug_version.bc", | |
253 "optlevel": 0 | |
254 } | |
255 } | |
256 } | |
257 | |
258 Copy the ``debug_version.bc`` and ``nmf`` files to the location that | |
259 your local web server serves files from. | |
260 | |
261 When you run Chrome with ``--enable-nacl-debug``, Chrome will translate | |
262 and run the ``debug_version.bc`` instead of ``release_version.pexe``. | |
263 Once the debug version is loaded, you are ready to :ref:`run nacl-gdb | |
264 <running_nacl_gdb>` | |
265 | |
266 Whether you publish the NMF file containing the debug URL to the release | |
267 web server, is up to you. One reason to avoid publishing the debug URL | |
268 is that it is only guaranteed to work for the Chrome version that matches | |
269 the SDK version. Developers who may have left the ``--enable-nacl-debug`` | |
270 flag turned on may end up loading the debug copy of your application | |
271 (which may or may not work, depending on their version of Chrome). | |
272 | |
273 | |
274 Debugging PNaCl pexes (with older Pepper toolchains) | |
jvoung (off chromium)
2014/03/28 22:05:42
My though is we can leave this for a few more rele
| |
275 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
219 | 276 |
220 If you want to use GDB to debug a program that is compiled with the PNaCl | 277 If you want to use GDB to debug a program that is compiled with the PNaCl |
221 toolchain, you must convert the ``pexe`` file to a ``nexe``. (You can skip | 278 toolchain, you must convert the ``pexe`` file to a ``nexe``. (You can skip |
222 this step if you are using the GCC toolchain.) | 279 this step if you are using the GCC toolchain, or if you are using |
280 pepper 35 or later.) | |
223 | 281 |
224 * Firstly, make sure you are passing the ``-g`` :ref:`compile option | 282 * Firstly, make sure you are passing the ``-g`` :ref:`compile option |
225 <compile_flags>` to ``pnacl-clang`` to enable generating debugging info. | 283 <compile_flags>` to ``pnacl-clang`` to enable generating debugging info. |
226 You might also want to omit ``-O2`` from the compile-time and link-time | 284 You might also want to omit ``-O2`` from the compile-time and link-time |
227 options, otherwise GDB not might be able to print variables' values when | 285 options. |
228 debugging (this is more of a problem with the PNaCl/LLVM toolchain than | |
229 with GCC). | |
230 | 286 |
231 * Secondly, use ``pnacl-translate`` to convert your ``pexe`` to one or more | 287 * Secondly, use ``pnacl-translate`` to convert your ``pexe`` to one or more |
232 ``nexe`` files. For example: | 288 ``nexe`` files. For example: |
233 | 289 |
234 .. naclcode:: | 290 .. naclcode:: |
235 :prettyprint: 0 | 291 :prettyprint: 0 |
236 | 292 |
237 <NACL_SDK_ROOT>/toolchain/win_pnacl/bin/pnacl-translate ^ | 293 <NACL_SDK_ROOT>/toolchain/win_pnacl/bin/pnacl-translate ^ |
238 --allow-llvm-bitcode-input hello_world.pexe -arch x86-32 -o hello_world_x8 6_32.nexe | 294 --allow-llvm-bitcode-input hello_world.pexe -arch x86-32 -o hello_world_x8 6_32.nexe |
239 <NACL_SDK_ROOT>/toolchain/win_pnacl/bin/pnacl-translate ^ | 295 <NACL_SDK_ROOT>/toolchain/win_pnacl/bin/pnacl-translate ^ |
(...skipping 28 matching lines...) Expand all Loading... | |
268 | 324 |
269 .. Note:: | 325 .. Note:: |
270 :class: note | 326 :class: note |
271 | 327 |
272 **Note:** If you know whether Chrome is using the x86-32 or x86-64 | 328 **Note:** If you know whether Chrome is using the x86-32 or x86-64 |
273 version of the NaCl sandbox on your system, you can translate the | 329 version of the NaCl sandbox on your system, you can translate the |
274 ``pexe`` once to a single x86-32 or x86-64 ``nexe``. Otherwise, you | 330 ``pexe`` once to a single x86-32 or x86-64 ``nexe``. Otherwise, you |
275 might find it easier to translate the ``pexe`` to both ``nexe`` | 331 might find it easier to translate the ``pexe`` to both ``nexe`` |
276 formats as described above. | 332 formats as described above. |
277 | 333 |
334 .. _running_nacl_gdb: | |
335 | |
278 Running nacl-gdb | 336 Running nacl-gdb |
279 ~~~~~~~~~~~~~~~~ | 337 ~~~~~~~~~~~~~~~~ |
280 | 338 |
281 Before you start using nacl-gdb, make sure you can :doc:`build <building>` your | 339 Before you start using nacl-gdb, make sure you can :doc:`build <building>` your |
282 module and :doc:`run <running>` your application normally. This will verify | 340 module and :doc:`run <running>` your application normally. This will verify |
283 that you have created all the required :doc:`application parts | 341 that you have created all the required :doc:`application parts |
284 <../coding/application-structure>` (.html, .nmf, and .nexe files, shared | 342 <../coding/application-structure>` (.html, .nmf, and .nexe files, shared |
285 libraries, etc.), that your server can access those resources, and that you've | 343 libraries, etc.), that your server can access those resources, and that you've |
286 configured Chrome correctly to run your application. The instructions below | 344 configured Chrome correctly to run your application. The instructions below |
287 assume that you are using a :ref:`local server <web_server>` to run your | 345 assume that you are using a :ref:`local server <web_server>` to run your |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 Prevents Chrome from displaying a warning when a tab is unresponsive. | 382 Prevents Chrome from displaying a warning when a tab is unresponsive. |
325 | 383 |
326 ``--user-data-dir=<directory>`` | 384 ``--user-data-dir=<directory>`` |
327 Specifies the `user data directory | 385 Specifies the `user data directory |
328 <http://www.chromium.org/user-experience/user-data-directory>`_ from which | 386 <http://www.chromium.org/user-experience/user-data-directory>`_ from which |
329 Chrome should load its state. You can specify a different user data | 387 Chrome should load its state. You can specify a different user data |
330 directory so that changes you make to Chrome in your debugging session do | 388 directory so that changes you make to Chrome in your debugging session do |
331 not affect your personal Chrome data (history, cookies, bookmarks, themes, | 389 not affect your personal Chrome data (history, cookies, bookmarks, themes, |
332 and settings). | 390 and settings). |
333 | 391 |
392 ``--nacl-debug-mask=<nmf_url_mask1,nmf_url_mask2,...>`` | |
393 Specifies a set of debug mask patterns. This allows you to selectively | |
394 choose to debug certain applications and not debug others. For example, | |
395 if you only want to debug the NMF files for your applications at | |
396 ``https://example.com/app``, and no other PNaCl applications found | |
397 on the web, specify ``--nacl-debug-mask=https://example.com/app/*.nmf``. | |
398 This helps accidentally debugging other PNaCl applications if you like | |
Sam Clegg
2014/03/28 22:18:29
Use say PNaCl here rather than NaCl. Is that inte
jvoung (off chromium)
2014/03/28 22:39:33
Not intentional -- It helps with NaCl as well, so
| |
399 to leave the ``--enable-nacl-debug`` flag turned on. | |
400 The pattern language for the mask follows `chrome extension match patterns | |
401 <http://developer.chrome.com/extensions/match_patterns>`_. | |
402 The pattern set can be inverted by prefixing the pattern set with | |
403 the ``!`` character. | |
404 | |
334 ``<URL>`` | 405 ``<URL>`` |
335 Specifies the URL Chrome should open when it launches. The local server | 406 Specifies the URL Chrome should open when it launches. The local server |
336 that comes with the SDK listens on port 5103 by default, so the URL when | 407 that comes with the SDK listens on port 5103 by default, so the URL when |
337 you're debugging is typically ``localhost:5103`` (assuming that your | 408 you're debugging is typically ``localhost:5103`` (assuming that your |
338 application's page is called index.html and that you run the local server | 409 application's page is called index.html and that you run the local server |
339 in the directory where that page is located). | 410 in the directory where that page is located). |
340 | 411 |
341 #. Navigate to your application's page in Chrome. (You don't need to do this if | 412 #. Navigate to your application's page in Chrome. (You don't need to do this if |
342 you specified a URL when you launched Chrome in the previous step.) Chrome | 413 you specified a URL when you launched Chrome in the previous step.) Chrome |
343 will start loading the application, then pause and wait until you start | 414 will start loading the application, then pause and wait until you start |
344 nacl-gdb and run the ``continue`` command. | 415 nacl-gdb and run the ``continue`` command. |
345 | 416 |
346 #. Go to the directory with your source code, and run nacl-gdb from there. For | 417 #. Go to the directory with your source code, and run nacl-gdb from there. For |
347 example:: | 418 example:: |
348 | 419 |
349 cd <NACL_SDK_ROOT>/examples/hello_world_gles | 420 cd <NACL_SDK_ROOT>/examples/hello_world_gles |
350 <NACL_SDK_ROOT>/toolchain/win_x86_newlib/bin/x86_64-nacl-gdb | 421 <NACL_SDK_ROOT>/toolchain/win_x86_newlib/bin/x86_64-nacl-gdb |
351 | 422 |
352 The debugger will start and show you a gdb prompt:: | 423 The debugger will start and show you a gdb prompt:: |
353 | 424 |
354 (gdb) | 425 (gdb) |
355 | 426 |
356 #. Run the following three commands from the gdb command line:: | 427 #. For debugging PNaCl pexes run the following gdb command lines |
428 (skip to the next item if you are using NaCl instead of PNaCl):: | |
357 | 429 |
430 (gdb) target remote localhost:4014 | |
431 (gdb) remote get nexe <path-to-save-translated-nexe-with-debug-info> | |
432 (gdb) file <path-to-save-translated-nexe-with-debug-info> | |
433 (gdb) remote get irt <path-to-save-NaCl-integrated-runtime> | |
434 (gdb) nacl-irt <path-to-saved-NaCl-integrated-runtime> | |
435 | |
436 #. For NaCl nexes, run the following commands from the gdb command line:: | |
437 | |
438 (gdb) target remote localhost:4014 | |
358 (gdb) nacl-manifest <path-to-your-.nmf-file> | 439 (gdb) nacl-manifest <path-to-your-.nmf-file> |
359 (gdb) nacl-irt <path-to-Chrome-NaCl-integrated-runtime> | 440 (gdb) remote get irt <path-to-save-NaCl-integrated-runtime> |
360 (gdb) target remote localhost:4014 | 441 (gdb) nacl-irt <path-to-saved-NaCl-integrated-runtime> |
361 | 442 |
362 These commands are described below: | 443 #. The command used for PNaCl and NaCl are described below: |
363 | |
364 ``nacl-manifest <path>`` | |
365 Tells the debugger about your Native Client application by pointing it to | |
366 the application's manifest (.nmf) file. The manifest file lists your | |
367 application's executable (.nexe) files, as well as any libraries that are | |
368 linked with the application dynamically. | |
369 | |
370 ``nacl-irt <path>`` | |
371 Tells the debugger where to find the Native Client Integrated Runtime | |
372 (IRT). The IRT is located in the same directory as the Chrome executable, | |
373 or in a subdirectory named after the Chrome version. For example, if | |
374 you're running Chrome canary on Windows, the path to the IRT typically | |
375 looks something like ``C:/Users/<username>/AppData/Local/Google/Chrome | |
376 SxS/Application/23.0.1247.1/nacl_irt_x86_64.nexe``. | |
377 | 444 |
378 ``target remote localhost:4014`` | 445 ``target remote localhost:4014`` |
379 Tells the debugger how to connect to the debug stub in the Native Client | 446 Tells the debugger how to connect to the debug stub in the Native Client |
380 application loader. This connection occurs through TCP port 4014 (note | 447 application loader. This connection occurs through TCP port 4014 (note |
381 that this port is distinct from the port which the local web server uses | 448 that this port is distinct from the port which the local web server uses |
382 to listen for incoming requests, typically port 5103). | 449 to listen for incoming requests, typically port 5103). If you are |
450 debugging multiple applications at the same time, the loader may choose | |
451 a port that is different from the default 4014 port. See the Chrome | |
452 task manager for the debug port. | |
453 | |
454 ``remote get nexe <path>`` | |
455 This saves the application's main executable (nexe) to ``<path>``. | |
456 For PNaCl, this provides a convenient way to access the nexe that is | |
457 a **result** of translating your pexe. This can then be loaded with | |
458 the ``file <path>`` command. | |
459 | |
460 ``nacl-manifest <path>`` | |
461 For NaCl (not PNaCl), this tells the debugger where to find your | |
462 application's executable (.nexe) files. The application's manifest | |
463 (.nmf) file lists your application's executable files, as well as any | |
464 libraries that are linked with the application dynamically. | |
465 | |
466 ``remote get irt <path>`` | |
467 This saves the Native Client Integrated Runtime (IRT). Normally, | |
468 the IRT is located in the same directory as the Chrome executable, | |
469 or in a subdirectory named after the Chrome version. For example, if | |
470 you're running Chrome canary on Windows, the path to the IRT typically | |
471 looks something like ``C:/Users/<username>/AppData/Local/Google/Chrome | |
472 SxS/Application/23.0.1247.1/nacl_irt_x86_64.nexe``. | |
473 The ``remote get irt <path>`` saves that to the current working | |
474 directory so that you do not need to find where exactly the IRT | |
475 is stored alongside Chrome. | |
476 | |
477 ``nacl-irt <path>`` | |
478 Tells the debugger where to find the Native Client Integrated Runtime | |
479 (IRT). ``<path>`` can either be the location of the copy saved by | |
480 ``remote get irt <path>`` or the copy that is installed alongside Chrome. | |
383 | 481 |
384 A couple of notes on how to specify path names in the nacl-gdb commands | 482 A couple of notes on how to specify path names in the nacl-gdb commands |
385 above: | 483 above: |
386 | 484 |
387 * You can use a forward slash to separate directories on Linux, Mac, and | 485 * You can use a forward slash to separate directories on Linux, Mac, and |
388 Windows. If you use a backslash to separate directories on Windows, you | 486 Windows. If you use a backslash to separate directories on Windows, you |
389 must escape the backslash by using a double backslash "\\" between | 487 must escape the backslash by using a double backslash "\\" between |
390 directories. | 488 directories. |
391 * If any directories in the path have spaces in their name, you must put | 489 * If any directories in the path have spaces in their name, you must put |
392 quotation marks around the path. | 490 quotation marks around the path. |
393 | 491 |
394 As an example, here is a what these nacl-gdb commands might look like on | 492 As an example, here is a what these nacl-gdb commands might look like on |
395 Windows:: | 493 Windows:: |
396 | 494 |
495 target remote localhost:4014 | |
397 nacl-manifest "C:/<NACL_SDK_ROOT>/examples/hello_world_gles/newlib/Debug/he llo_world_gles.nmf" | 496 nacl-manifest "C:/<NACL_SDK_ROOT>/examples/hello_world_gles/newlib/Debug/he llo_world_gles.nmf" |
398 nacl-irt "C:/Users/<username>/AppData/Local/Google/Chrome SxS/Application/2 3.0.1247.1/nacl_irt_x86_64.nexe" | 497 nacl-irt "C:/Users/<username>/AppData/Local/Google/Chrome SxS/Application/2 3.0.1247.1/nacl_irt_x86_64.nexe" |
Sam Clegg
2014/03/28 22:18:29
Is it recommended to set the remove before calling
jvoung (off chromium)
2014/03/28 22:39:33
I moved "target remote ..." earlier in case people
| |
399 target remote localhost:4014 | |
400 | 498 |
401 To save yourself some typing, you can put put these nacl-gdb commands in a | 499 To save yourself some typing, you can put put these nacl-gdb commands in a |
402 script file, and execute the file when you run nacl-gdb, like so:: | 500 script file, and execute the file when you run nacl-gdb, like so:: |
403 | 501 |
404 <NACL_SDK_ROOT>/toolchain/win_x86_newlib/bin/x86_64-nacl-gdb -x <nacl-scrip t-file> | 502 <NACL_SDK_ROOT>/toolchain/win_x86_newlib/bin/x86_64-nacl-gdb -x <nacl-scrip t-file> |
405 | 503 |
406 If nacl-gdb connects successfully to Chrome, it displays a message such as | 504 If nacl-gdb connects successfully to Chrome, it displays a message such as |
407 the one below, followed by a gdb prompt:: | 505 the one below, followed by a gdb prompt:: |
408 | 506 |
409 0x000000000fc00200 in _start () | 507 0x000000000fc00200 in _start () |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 <http://www.chromium.org/nativeclient>`_ that describe how to do profiling on | 588 <http://www.chromium.org/nativeclient>`_ that describe how to do profiling on |
491 `64-bit Windows | 589 `64-bit Windows |
492 <https://sites.google.com/a/chromium.org/dev/nativeclient/how-tos/profiling-nacl -apps-on-64-bit-windows>`_ | 590 <https://sites.google.com/a/chromium.org/dev/nativeclient/how-tos/profiling-nacl -apps-on-64-bit-windows>`_ |
493 and `Linux | 591 and `Linux |
494 <http://www.chromium.org/nativeclient/how-tos/limited-profiling-with-oprofile-on -x86-64>`_ | 592 <http://www.chromium.org/nativeclient/how-tos/limited-profiling-with-oprofile-on -x86-64>`_ |
495 machines. | 593 machines. |
496 | 594 |
497 | 595 |
498 .. |menu-icon| image:: /images/menu-icon.png | 596 .. |menu-icon| image:: /images/menu-icon.png |
499 .. |puzzle| image:: /images/puzzle.png | 597 .. |puzzle| image:: /images/puzzle.png |
OLD | NEW |