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

  1. 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.

  2. 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

  1. Run the development simulation kernel with ODB enabled.

  2. 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_dev process (or op_runsim_dev64, if running a 64-bit kernel):

    % ps -Aef | grep op_runsim_dev
    
  3. Run GDB.

  4. Attach the symbolic debugger to a running simulation. For GDB, use:

    attach <process_id_obtained_in_step_2>
    
  5. At this point, the source debugger controls the simulation. You can set breakpoints, examine variables and source code, and do other operations.

  6. To pass control to ODB, let the source level debugger continue execution with the cont command.

  7. ODB now controls execution of the simulation and you can use ODB commands to move on.

  8. 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.

  9. 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 -g option 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.

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com