Академический Документы
Профессиональный Документы
Культура Документы
Agenda
1502 - Debugging Simulation Models Review Why use a C/C++ debugger Understanding process model code How to debug a program abort Scientific approach to debugging Using a C/C++ debugger with ODB Advanced C/C++ debugger techniques Using execution traces to validate changes Memory leak tracking
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
Event Number
Hierarchical Name
|----------------------------------------------------------------| | This node does not have any valid IP interfaces | | Assign a valid address to at least one interface | | T (0), EV (1593), MOD (top.DCI Network.FR_Cloud.ip), | | PROC (ip_dispatch_intf_table_create (total_interfaces)) | |----------------------------------------------------------------|
Simulation Time
Function Name
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
Using FIN without FOUT / FRET in C results in Standard Function Stack Imbalance error message No overhead when models compiled with comp_trace_info preference set to FALSE (Optimized Kernel compile) FIN required in Function Block functions if using state variables
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
Caveats
Requires familiarity with C/C++ Requires familiarity with OPNET generated code
Proper C/C++ compilation flags for debugging are set by default automatically when working with development kernel NOTE: C/C++ Debugger also referred to as Symbolic Debugger or Source-Level Debugger
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
Example Debuggers
Name
CDB GDB Visual Studio
Platform
Windows Linux Windows
Use
Integrated w/OPNET GUI Integrated w/OPNET GUI Separate GUI
Tutorial
This session OPNETWORK 2006 OPNETWORK 2005
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
Header Block State Variable Structure State Variable Macros Function Block void <model name> () Temporary Variables Finite State Machine _op_<model name>_diag ()
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
Process Model Code Structure (cont.) Header block inserted at top of file
Header file #includes Global definitions (variables, typedefs, etc.)
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
10
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
11
Process Model Code Structure (cont.) Function block inserted above primary function
State variable definitions available
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
12
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
13
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
14
Process Model Code Structure (cont.) Diagnostic, termination blocks helper functions
Temporary variable block local variables Other helper functions generated by OPNET
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
15
Compiler Warnings
Results of kept in:
<home>/op_admin/tmp/cc_err_<compiled process id>
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
16
Make sure code is compiled with debugging symbols (automatic in development kernel). CDB/GDB
Run simulation with development kernel and ODB enabled In simulation execution window, select Windows: Simulation > Attach Windows Debugger (CDB) Linux: Simulation > Attach GDB Hit Continue button in console window, source code will appear on abort
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
17
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
18
Recap
C/C++ debuggers can help tracking down program aborts by bringing you to the point of the abort
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
19
Agenda
1502 - Debugging Simulation Models Review Why use a C/C++ debugger Understanding process model code How to debug a program abort Scientific approach to debugging Using a C/C++ debugger with ODB Advanced C/C++ debugger techniques Using execution traces to validate changes Memory leak tracking
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
20
Establish the knowns (define the error) Collect circumstantial evidence Develop hypotheses Design experiments
Understand what each experiment will answer Does it or does it not confirm hypothesis?
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
21
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
22
Debugging Techniques
Goal: Make the problem occur at an earlier time and systematically Approach: Destabilize the system Techniques
Vary simulation seed Change object order (cut/paste) Change attribute or parameter values Change environment (OS, 32/64 bit, compiler version) -mem_optimize FALSE (Disable OPNET memory management optimizations) -mem_shred TRUE (Set contents of freed memory to 0xDF) Use third-party memory corruption detection tools such as purify, valgrind etc. Make sure to use -mem_optimize FALSE Search OPNET FAQs for particular tool integration instructions
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
23
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
24
Conditional Breakpoints
Problem:
You want to set a breakpoint at a line of code that is executed quite often. You only want to break on line of code under a certain situation
CDB
Command: bp Example:
GDB
Command: break to set a breakpoint, followed by cond to assign a condition Example:
break my_process.pr.c:383 cond <breakpoint ID> (op_sv_ptr->my_process_id == 49)
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
25
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
26
Watchpoints
Problem: You want simulation to stop when a variable value changes unexpectedly; this is a common source of bugs Solution: Use watchpoints. They stop execution of a simulation when a chosen variable value changes How to set a watchpoint on a state variable CDB (refer to Lab 2) GDB (refer to OPNETWORK 2006 Lab 3)
GDB> print &op_sv_ptr->my_tpal_objid <address> GDB> watch *((int *) <address>)
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
27
Watchpoints (cont.)
Visual Studio
Define a new breakpoint (Ctrl-B, or click on New in the Breakpoint window) Select the Data tab Enter expression to watch in the Variable: field Example: *(int *) 0x038472fc
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
28
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
29
Difficult error: bug and error message are separated by many events
Long lab with tricky parts The most advanced lab at this conference
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
30
Lab 2: Recap
Error reported when models was run Developed two hypotheses:
Variable initialized improperly (demonstrated to be false) Variable changed unexpectedly elsewhere (demonstrated to be true)
Used conditional breakpoint to stop at a particular process Used watchpoint facility to pinpoint when bug occurred Conditional breakpoints and watchpoints can turn good debuggers into expert debuggers
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
31
Agenda
1502 - Debugging Simulation Models Review Why use a C/C++ debugger Understanding process model code How to debug a program abort Scientific approach to debugging Using a C/C++ debugger with ODB Advanced C/C++ debugger techniques Using execution traces to validate changes Memory leak tracking
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
32
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
33
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
34
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
35
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
36
Agenda
1502 - Debugging Simulation Models Review Why use a C/C++ debugger Understanding process model code How to debug a program abort Scientific approach to debugging Using a C/C++ debugger with ODB Advanced C/C++ debugger techniques Using execution traces to validate changes Memory leak tracking
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
37
Use the Memory Usage and Memory Stats tabs in Simulation dialog
Statistics are updated live in the Simulation Progress Window as simulation runs
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
38
View source of memory allocation by process state / function Sort by Bytes to identify largest memory users Default grouping by process state machine source Invert function call stack to group by offending KP
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
39
40
41
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
42
Documentation References
ODB in the Simulation Execution chapter of the External Interfaces Manual Process Model Domain Definition, Modeling Concepts Manual Your C/C++ debugger manual
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
43
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
44
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
45
Consider Linux
Reach set of free and reliable software development tools GDB commands are more intuitive than CDB commands Checkpoint / Restart simulation feature is only available on Linux Virtual Machine is an efficient way of using the same PC for both bureaucracy under Windows and serious simulation debugging under Linux Same OPNET license covers all platforms
OPNET license server can serve the same OPNET licenses to both Windows and Linux clients
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
46
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
47
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
48
Take-Away Points
Any OPNET simulation is easily debugged with a source code debugger Take advantage of the ODB and source debugger integration Analyze errors to start the debugging process Use the Scientific Method to debug Advanced debugger features (conditional breakpoints, watchpoints) turn a difficult debugging problem into an easy debugging problem Execution tracing is a powerful model change validation tool Memory tracking is a useful tool for detecting memory leaks Next steps:
Build simulation with debug information Next bug that comes up will put you in the debugger
CONFIDENTIAL RESTRICTED ACCESS: This information may not be disclosed, copied, or transmitted in any format without the prior written consent of OPNET Technologies, Inc. 2008 OPNET Technologies, Inc.
49