- Specify the debug tool using the
xmcImportFunctionSettings
command. At the MATLAB® command prompt, type the following command:>> xmcImportFunctionSettings(‘build’, ‘debug’);
Tip: You can restore the release build environment, using therelease
value of thebuild
option:xmcImportFunctionSettings('build','release')
. - 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
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.
- 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
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.
Note: During the debug process, if prompted to press 'c' to continue, type 'c' and hit Enter. - Type
cont
at the Windows command prompt.
- Now go to the
Simulink®
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
prompt.
Now, type the command
list
to view the lines of code around line 53.(gdb) list
- 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>
- Type
print r
to view the values of variables at that simulation step. This gives the result as shown in the following figure.(gdb) print r $1 = 421
- 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.