using-debugger.rst 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. Using Debugger
  2. --------------
  3. This section covers configuration and running debugger either from :ref:`jtag-debugging-using-debugger-eclipse`
  4. or :ref:`jtag-debugging-using-debugger-command-line`. It is recommended to first check if debugger works from :ref:`jtag-debugging-using-debugger-command-line` and then move to using Eclipse.
  5. .. _jtag-debugging-using-debugger-eclipse:
  6. Eclipse
  7. ^^^^^^^
  8. Debugging functionality is provided out of box in standard Eclipse installation. Another option is to use pluggins like "GDB Hardware Debugging" plugin. We have found this plugin quite convenient and decided to use throughout this guide.
  9. To begin with, install "GDB Hardware Debugging" plugin by opening Eclipse and going to `Help` > `Install` New Software.
  10. Once installation is complete, configure debugging session following steps below. Please note that some of configuration parameters are generic and some are project specific. This will be shown below by configuring debugging for "blink" example project. If not done already, add this project to Eclipse workspace following guidance in section :doc:`Build and Flash with Eclipse IDE <../../get-started/eclipse-setup>`. The source of :example:`get-started/blink` application is available in :idf:`examples` directory of ESP-IDF repository.
  11. 1. In Eclipse go to `Run` > `Debug Configuration`. A new window will open. In the window's left pane double click "GDB Hardware Debugging" (or select "GDB Hardware Debugging" and press the "New" button) to create a new configuration.
  12. 2. In a form that will show up on the right, enter the "Name:" of this configuration, e.g. "Blink checking".
  13. 3. On the "Main" tab below, under "Project:", press "Browse" button and select the "blink" project.
  14. 4. In next line "C/C++ Application:" press "Browse" button and select "blink.elf" file. If "blink.elf" is not there, then likely this project has not been build yet. See :doc:`Build and Flash with Eclipse IDE <../../get-started/eclipse-setup>` how to do it.
  15. 5. Finally, under "Build (if required) before launching" click "Disable auto build".
  16. A sample window with settings entered in points 1 - 5 is shown below.
  17. .. figure:: ../../_static/hw-debugging-main-tab.jpg
  18. :align: center
  19. :alt: Configuration of GDB Hardware Debugging - Main tab
  20. :figclass: align-center
  21. Configuration of GDB Hardware Debugging - Main tab
  22. 6. Click "Debugger" tab. In field "GDB Command" enter ``xtensa-esp32-elf-gdb`` to invoke debugger.
  23. 7. Change default configuration of "Remote host" by entering ``3333`` under the "Port number".
  24. Configuration entered in points 6 and 7 is shown on the following picture.
  25. .. figure:: ../../_static/hw-debugging-debugger-tab.jpg
  26. :align: center
  27. :alt: Configuration of GDB Hardware Debugging - Debugger tab
  28. :figclass: align-center
  29. Configuration of GDB Hardware Debugging - Debugger tab
  30. 8. The last tab to that requires changing of default configuration is "Startup". Under "Initialization Commands" uncheck "Reset and Delay (seconds)" and "Halt"". Then, in entry field below, type ``mon reset halt`` and ``x $a1=0`` (in two separate lines).
  31. .. note::
  32. If you want to update image in the flash automatically before starting new debug session add the following lines of commands at the beginning of "Initialization Commands" textbox::
  33. mon reset halt
  34. mon program_esp32 ${workspace_loc:blink/build/blink.bin} 0x10000 verify
  35. For description of ``program_esp32`` command see :ref:`jtag-upload-app-debug`.
  36. 9. Under "Load Image and Symbols" uncheck "Load image" option.
  37. 10. Further down on the same tab, establish an initial breakpoint to halt CPUs after they are reset by debugger. The plugin will set this breakpoint at the beginning of the function entered under "Set break point at:". Checkout this option and enter ``app_main`` in provided field.
  38. 11. Checkout "Resume" option. This will make the program to resume after ``mon reset halt`` is invoked per point 8. The program will then stop at breakpoint inserted at ``app_main``.
  39. Configuration described in points 8 - 11 is shown below.
  40. .. figure:: ../../_static/hw-debugging-startup-tab.jpg
  41. :align: center
  42. :alt: Configuration of GDB Hardware Debugging - Startup tab
  43. :figclass: align-center
  44. Configuration of GDB Hardware Debugging - Startup tab
  45. If the "Startup" sequence looks convoluted and respective "Initialization Commands" are not clear to you, check :ref:`jtag-debugging-tip-debugger-startup-commands` for additional explanation.
  46. 12. If you previously completed :ref:`jtag-debugging-configuring-esp32-target` steps described above, so the target is running and ready to talk to debugger, go right to debugging by pressing "Debug" button. Otherwise press "Apply" to save changes, go back to :ref:`jtag-debugging-configuring-esp32-target` and return here to start debugging.
  47. Once all 1 - 12 configuration steps are satisfied, the new Eclipse perspective called "Debug" will open as shown on example picture below.
  48. .. figure:: ../../_static/debug-perspective.jpg
  49. :align: center
  50. :alt: Debug Perspective in Eclipse
  51. :figclass: align-center
  52. Debug Perspective in Eclipse
  53. If you are not quite sure how to use GDB, check :ref:`jtag-debugging-examples-eclipse` example debugging session in section :ref:`jtag-debugging-examples`.
  54. .. _jtag-debugging-using-debugger-command-line:
  55. Command Line
  56. ^^^^^^^^^^^^
  57. 1. To be able start debugging session, the target should be up and running. If not done already, complete steps described under :ref:`jtag-debugging-configuring-esp32-target`.
  58. .. highlight:: bash
  59. 2. Open a new terminal session and go to directory that contains project for debugging, e.g.
  60. ::
  61. cd ~/esp/blink
  62. .. highlight:: none
  63. 3. When launching a debugger, you will need to provide couple of configuration parameters and commands. Instead of entering them one by one in command line, create a configuration file and name it ``gdbinit``:
  64. ::
  65. target remote :3333
  66. mon reset halt
  67. thb app_main
  68. x $a1=0
  69. c
  70. Save this file in current directory.
  71. For more details what's inside ``gdbinit`` file, see :ref:`jtag-debugging-tip-debugger-startup-commands`
  72. .. highlight:: bash
  73. 4. Now you are ready to launch GDB. Type the following in terminal:
  74. ::
  75. xtensa-esp32-elf-gdb -x gdbinit build/blink.elf
  76. .. highlight:: none
  77. 5. If previous steps have been done correctly, you will see a similar log concluded with ``(gdb)`` prompt:
  78. ::
  79. user-name@computer-name:~/esp/blink$ xtensa-esp32-elf-gdb -x gdbinit build/blink.elf
  80. GNU gdb (crosstool-NG crosstool-ng-1.22.0-61-gab8375a) 7.10
  81. Copyright (C) 2015 Free Software Foundation, Inc.
  82. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  83. This is free software: you are free to change and redistribute it.
  84. There is NO WARRANTY, to the extent permitted by law. Type "show copying"
  85. and "show warranty" for details.
  86. This GDB was configured as "--host=x86_64-build_pc-linux-gnu --target=xtensa-esp32-elf".
  87. Type "show configuration" for configuration details.
  88. For bug reporting instructions, please see:
  89. <http://www.gnu.org/software/gdb/bugs/>.
  90. Find the GDB manual and other documentation resources online at:
  91. <http://www.gnu.org/software/gdb/documentation/>.
  92. For help, type "help".
  93. Type "apropos word" to search for commands related to "word"...
  94. Reading symbols from build/blink.elf...done.
  95. 0x400d10d8 in esp_vApplicationIdleHook () at /home/user-name/esp/esp-idf/components/esp32/./freertos_hooks.c:52
  96. 52 asm("waiti 0");
  97. JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
  98. JTAG tap: esp32.slave tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
  99. esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
  100. esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
  101. Target halted. PRO_CPU: PC=0x5000004B (active) APP_CPU: PC=0x00000000
  102. esp32: target state: halted
  103. esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
  104. Target halted. PRO_CPU: PC=0x40000400 (active) APP_CPU: PC=0x40000400
  105. esp32: target state: halted
  106. Hardware assisted breakpoint 1 at 0x400db717: file /home/user-name/esp/blink/main/./blink.c, line 43.
  107. 0x0: 0x00000000
  108. Target halted. PRO_CPU: PC=0x400DB717 (active) APP_CPU: PC=0x400D10D8
  109. [New Thread 1073428656]
  110. [New Thread 1073413708]
  111. [New Thread 1073431316]
  112. [New Thread 1073410672]
  113. [New Thread 1073408876]
  114. [New Thread 1073432196]
  115. [New Thread 1073411552]
  116. [Switching to Thread 1073411996]
  117. Temporary breakpoint 1, app_main () at /home/user-name/esp/blink/main/./blink.c:43
  118. 43 xTaskCreate(&blink_task, "blink_task", 512, NULL, 5, NULL);
  119. (gdb)
  120. Note the third line from bottom that shows debugger halting at breakpoint established in ``gdbinit`` file at function ``app_main()``. Since the processor is halted, the LED should not be blinking. If this is what you see as well, you are ready to start debugging.
  121. If you are not quite sure how to use GDB, check :ref:`jtag-debugging-examples-command-line` example debugging session in section :ref:`jtag-debugging-examples`.