GNU Debugger (GDB)
The GNU Debugger (GDB) is commonly used on Linux platforms. Because GDB offers a way to control and examine the execution of source code, it is a useful supplement to the OPNET Debugger. With GDB attached, you can perform detailed debugging of process model code in the context of an active simulation.
Attaching GDB to a Simulation
Before attaching GDB to a simulation, make sure GDB is installed on the computer that will run the simulation.
Procedure 2: Attaching GDB 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 3: Attaching GDB 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), use a separate shell to determine the process ID of the
op_runsim_devprocess (orop_runsim_dev64, if running a 64-bit kernel):% ps -Aef | grep op_runsim_dev -
Run GDB.
-
Attach the symbolic debugger to a running simulation. For GDB, use:
attach <process_id_obtained_in_step_2> -
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.
Note: When debugging process model code, you can check the value of a model state variable with the following command:
(gdb) print op_sv_ptr-><state_var_name>
Using GDB
When using GDB with ODB, observe the following guidelines.
- To view your model source code in GDB, compile custom model code with the
-goption in the "comp_flags_devel" preference. - Avoid using ODB commands within events (for example, at a GDB breakpoint). Although this will generally work, the simulation could crash if incomplete actions exist.
For general information on using GDB, refer to the GNU Project Debugger website at www.gnu.org/software/gdb/ or to one of the many printed reference books.