IDE 🐛 Debugging - EPFL-MICRO-315/TPs-Wiki GitHub Wiki

🔨 Compilation

  • Before trying to debug, the code must be compiled into a file executable by the STM32: a file with the .elf extension
  • To compile, you can either:
    • type Ctrl + Shift + P, then type run task, and finally select the Make task
    • click on the Maketask in the Task Runner tab under the Explorer
    • ⚠ There are 2 make and clean tasks on the picture because the opened folder (EPuck2_Workplace/Lib) has tasks for testing the e-puck2_main-processor and ST libraries

🚀 Launch debugging

  • First you must specify the port to which the gdb-server is connected, click here for more info
  • First make sure to be in the Run and Debug tab (1)
  • Open the choice box (2) and select the corresponding launch configuration at (3) among
    • BMP launch to main, launch and stop the program at the start of the main function
    • BMP launch to reset, launch and stop the program at the very beginning of the program (where the PC=0)
    • BMP attach, connect (attach) to an epuck2 already running the program
    • ⚠ There are 6 launch configurations on the picture because the opened folder (EPuck2_Workplace/Lib) has configurations for testing the e-puck2_main-processor and ST libraries
    • And finally launch the selected configuration by pressing the green ▷ (4)

🌌 Usage of the debugger

  • It is possible to debug in many different ways once the debugger is connected to the EPuck2
    • Breakpoint: to stop the program once the PC reaches a specific line, click on the left of the line, manage all breakpoints in
    • Restart or Reset: the EPuck2: Has the same effect as if the hardware reset button is pressed
    • Continue: un-freeze the execution of the program
    • Step over: the PC runs until it hits the next line of source file
    • Step in: the PC jumps into the sub-routine of the current line
    • Step out: the PC jumps out of the sub-routine and goes back to the parent sub-routine
    • Stop: disconnects the debugger from the EPuck2; the EPuck2 will continue to run the program on its own
  • There are many ways to monitor information using the debugger
    1. Variables: displays registers, local, global and static variables
    2. Watch: displays variable content, support C syntax (&i displays the address of the i variable, i/1000 displays the value i / 1000)
    3. Call stack: keeps track of the currently active sub-routines
    4. Breakpoints:
    5. Cortex Peripherals: displays the cortex peripherals registers' values
    6. Cortex registers: display the cortex's registers
  • It is possible to see the assembly code of your program, you can either:
    1. View the assembly code of a single function
      • Open the Command Palette (Ctrl + Shift + p)
      • select Cortex-Debug: View Disassembly (Function)
      • specify the function name to analyze (ex: main)
      • the function assembly code will then be diplayed
    2. View the assembly code of the currently executed intructions
      • Open the Command Palette (Ctrl + Shift + p)
      • select Open Disassembly View
      • the currently executed instructions will be displayed in C and in assembly
  • It is possible to check the memory content
    • Open the Command Palette (Ctrl + Shift + p)
    • select Cortex-Debug: View Memory
    • specify the start and the lenght of the memory segment to be analyzed

🛶 Example

  • In this example, we put a breakpoint on the line 47
  • Once the PC reaches this breakpoint, we click on Step into
  • the PC then jumps in the content of the sub-routine gpio_toggle()
  • In the Call stack tab, you can see currently active sub-routines
    • the active sub-routine is the one on the top of the list
  • to go out of this sub-routine and be back in the main function, we can either:
    • Click on Step out
    • Click on Step over until the PC reaches the end of the sub-routine

💡 Further readings