Microsoft Visual C++ Debugger (MSVC)
The Microsoft Visual C++ debugger (MSVC) is commonly used on Windows platforms. Because it offers a way to control and examine the execution of source code, it is a useful supplement to the OPNET Debugger. With it, you can perform detailed debugging of process model code in the context of an active simulation.
Attaching MSVC to a Simulation
Before attaching MSVC to a simulation, make sure MSVC is installed on the computer that will run the simulation.
Procedure 4: Attaching MSVC to a Simulation from the GUI
-
To attach the debugger before entering the simulation:
1.1 On the OPNET Debugger page of the Configure/Run DES dialog box, select the “Attach source code debugger” checkbox.
-
To attach the debugger while the simulation is executing:
2.1 Run the development simulation kernel with ODB enabled. 2.2 From the menu bar in the Simulation Execution dialog box, choose Simulation > Attach GDB.
*Result:* GDB is attached to the simulation and the Simulation Console expands to support GDB operation (see [Simulation Console (ODB and Source-Level Debugger)](des-debug-086-09.md)). **Note:** The menu item changes from Attach GDB to Detach GDB; use this operation again if you need to detach GDB.
Procedure 5: Attaching MSVC to a Simulation from the Command Line
-
Run the development simulation kernel with ODB enabled.
-
After the simulation stops at the initial ODB prompt (or after a breakpoint set before the error of interest occurs), attach MSVC as follows:
2.1 Run Microsoft Visual C++. 2.2 Choose Build > Start Debug > Attach to Process… 2.3 Select op_runsim_dev from the process list and click OK.
-
At this point, the source debugger controls the simulation. You can set breakpoints, examine variables and source code, and do other operations.
-
To pass control to ODB, let the source level debugger continue execution with the
contcommand. -
ODB now controls execution of the simulation and you can use ODB commands to move on.
-
If you had set breakpoints in a source debugger, control will go back to the source debugger when one of those breakpoints is hit. Otherwise, simulation control remains with ODB.
-
If you want to defer setting breakpoints in the source debugger (for example, until after a certain event number), use ODB to go to the event of interest. Then pass control to the source debugger by pressing <Control>+<c> in the source debugger shell window.
Procedure 6: Invoking MSVC When a Simulation Crashes
-
In the scenario to be simulated, open the Configure/Run DES dialog box.
-
On the Execution > Troubleshooting page, select the Yes radio button for “Prevent OPNET from handling and logging its exceptions”.
-
Run the simulation.
-
When the simulation crashes, click the Cancel button in the Application Error dialog box that appears.
Result: The MSVC debugger starts.
Using MSVC
When using MSVC with ODB, observe the following guidelines.
-
To view your model source code in MSVC, compile custom model code with the /Zi /Od options in the "comp_flags_devel" preference.
Note— /Zi produces a program database (.pdb file) that contains type information and symbolic debugging information used by the debugger.
-
Avoid using ODB commands within events (for example, at an MSVC breakpoint). Although this will generally work, the simulation could crash if incomplete actions exist.
For general information on using MSVC, refer to the Microsoft Visual C++ documentation.