- Specify the debug tool using the
xmcImportFunctionSettingscommand. At the MATLAB® command prompt, type the following command:
>> xmcImportFunctionSettings(‘build’, ‘debug’);
- 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.
- Click on the gdb link, to invoke the Windows command
prompt and launch gdb.
- 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
(gdb) break calculating_roots.h:53Note: The “53” in the above command, tells the GDB debugger to stop the simulation at line 53 of your program.
- 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.
- To attach the MATLAB process to the GDB debugger, type the
(gdb) attach <process_ID>
<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.
contat the Windows command prompt.
- Now go to the
model and run the simulation by
clicking the Run button.
- 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
Now, type the command
listto view the lines of code around line 53.
- Now, type command
stepto continue the simulation one line to the next step.
(gdb) stepImportant: The following are some useful GDB commands for use in debugging:
(gdb) next(step over)
(gdb) step(step in)
(gdb) print <variable>
(gdb) watch <variable>
print rto view the values of variables at that simulation step. This gives the result as shown in the following figure.
- You can try using more gdb commands to debug and once you are done, type
quitto exit GDB, and observe that the Simulink model continues to run.