Debugger Efficiency Tips

Execute Commands Automatically When the Debugger Starts

If you want to execute one or more commands in the debugger immediately after initializing the model, you can include those commands when you invoke sedebug. You might find executing commands automatically to be useful for setting the same breakpoints or detail settings across multiple debugging sessions, or helping someone reproduce a problem that you are seeing in a model.

To start a debugger session that executes commands automatically:

  1. Outside the debugger, create an empty options structure using the se_getdbopts function.

    opts_struct = se_getdbopts;
  2. Define the StartFcn field of the options structure as a cell array of strings, where each string is an individual command that you want to execute after initializing the model. Here is an example:

    opts_struct.StartFcn = {'detail(''cal'',1)', 'tbreak 5'};
  3. Start a debugger session using the sedebug function with the options structure as the second input argument. Here is an example:

    sedebug('sedemo_preempt_policy', opts_struct)
  4. End the debugger session. At the sedebug>> prompt, enter:


For an example, see the se_getdbopts reference page.

Tips for Creating a StartFcn Cell Array

  • If you want to execute commands and then exit the debugging session automatically, include the string 'quit' at the end of the StartFcn array. If you want to execute commands automatically and then interact with the debugger, do not include the string 'quit' in the StartFcn array.

  • If you want to set breakpoints at the beginning of the debugging session, have just ended a debugging session on the same model and have not changed the model, you can use the identifiers that occurred in the previous debugging session.

Create Shortcuts for Debugger Commands

If you use a particular debugger command frequently, such as step or step over, a shortcut you can click might provide an efficient way to issue the command repeatedly. To learn about shortcuts, see Create Shortcuts to Rerun Commands.

Was this topic helpful?