Step 2: Debugging C/C++ Code Using GDB Debugger - 2020.2 English

Vivado Design Suite Tutorial: Model-Based DSP Design using Add-on for MATLAB and Simulink (UG1498)

Document ID
UG1498
Release Date
2021-01-22
Version
2020.2 English
  1. Specify the debug tool using the xmcImportFunctionSettings command. At the MATLAB® command prompt, type the following command:
    >> xmcImportFunctionSettings(‘build’, ‘debug’);
  2. Press Enter to see the applied settings in command window, as shown in the following figure.

    Note the gdb link that you will use to invoke the debugger tool, and the MATLAB process ID that you will use to attach the process to the debugger.

  3. Click on the gdb link, to invoke the Windows command prompt and launch gdb.

  4. At the Windows command prompt, use the following command to specify the breakpoint in the calculating_roots.h file where you want the code to stop executing. Press Enter to run the command.
    (gdb) break calculating_roots.h:53 
    Note: The “53” in the above command, tells the GDB debugger to stop the simulation at line 53 of your program.


  5. Once the command runs, you can see a pending breakpoint in the command window. This is shown in the following figure.

    If you see any questions from GDB, answer “yes” and press Enter.

  6. To attach the MATLAB process to the GDB debugger, type the following:
    (gdb) attach <process_ID> 

    Enter the <process ID> you saw in step 2. For example “15972”.

    As soon as the MATLAB process is attached, the MATLAB application gets frozen and becomes unresponsive.



  7. Type cont at the Windows command prompt.

  8. Now go to the Simulink® model and run the simulation by clicking the Run button.

  9. The model takes some time to initialize. As the simulation starts, you see the simulation come to the breakpoint at line 53 in the Windows command prompt.

    Now, type the command list to view the lines of code around line 53.

    (gdb) list
  10. Now, type command step to continue the simulation one line to the next step.
    (gdb) step
    Important: The following are some useful GDB commands for use in debugging:
    • (gdb) list
    • (gdb) next (step over)
    • (gdb) step (step in)
    • (gdb) print <variable>
    • (gdb) watch <variable>
  11. Type print r to view the values of variables at that simulation step. This gives the result as shown in the following figure.

  12. You can try using more gdb commands to debug and once you are done, type quit to exit GDB, and observe that the Simulink model continues to run.