1 # <a id="debug"></a> Debug Icinga 2
5 > If you are planning to build your own development environment,
6 > please consult the `INSTALL.md` file from the source tree.
8 ## <a id="debug-requirements"></a> Debug Requirements
10 Make sure that the debug symbols are available for Icinga 2.
11 The Icinga 2 packages provide a debug package which must be
12 installed separately for all involved binaries, like `icinga2-bin`
13 or `icinga2-ido-mysql`.
17 # apt-get install icinga2-dbg
21 # yum install icinga2-debuginfo
25 # zypper install icinga2-bin-debuginfo icinga2-ido-mysql-debuginfo
28 Furthermore, you may also have to install debug symbols for Boost and your C library.
30 If you're building your own binaries you should use the `-DCMAKE_BUILD_TYPE=Debug` cmake
31 build flag for debug builds.
34 ## <a id="development-debug-gdb"></a> GDB
51 Install the `boost`, `python` and `icinga2` pretty printers. Absolute paths are required,
52 so please make sure to update the installation paths accordingly (`pwd`).
54 Boost Pretty Printers:
56 $ mkdir -p ~/.gdb_printers && cd ~/.gdb_printers
57 $ git clone https://github.com/ruediger/Boost-Pretty-Printer.git && cd Boost-Pretty-Printer
59 /home/michi/.gdb_printers/Boost-Pretty-Printer
61 Python Pretty Printers:
64 $ svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
66 Icinga 2 Pretty Printers:
68 $ mkdir -p ~/.gdb_printers/icinga2 && cd ~/.gdb_printers/icinga2
69 $ wget https://raw.githubusercontent.com/Icinga/icinga2/master/tools/debug/gdb/icingadbg.py
71 Now you'll need to modify/setup your `~/.gdbinit` configuration file.
72 You can download the one from Icinga 2 and modify all paths.
76 $ wget https://raw.githubusercontent.com/Icinga/icinga2/master/tools/debug/gdb/gdbinit -O ~/.gdbinit
83 sys.path.insert(0, '/home/michi/.gdb_printers/icinga2')
84 from icingadbg import register_icinga_printers
85 register_icinga_printers()
90 sys.path.insert(0, '/home/michi/.gdb_printers/python')
91 from libstdcxx.v6.printers import register_libstdcxx_printers
92 register_libstdcxx_printers(None)
97 sys.path.insert(0, '/home/michi/.gdb_printers/Boost-Pretty-Printer')
98 from boost.printers import register_printer_gen
99 register_printer_gen(None)
102 If you are getting the following error when running gdb, the `libstdcxx`
103 printers are already preloaded in your environment and you can remove
104 the duplicate import in your `~/.gdbinit` file.
106 RuntimeError: pretty-printer already registered: libstdc++-v6
108 ### <a id="development-debug-gdb-run"></a> GDB Run
110 Call GDB with the binary and all arguments and run it in foreground.
112 # gdb --args /usr/sbin/icinga2 daemon -x debug
116 > If gdb tells you it's missing debug symbols, quit gdb and install
117 > them: `Missing separate debuginfos, use: debuginfo-install ...`
123 Kill the running application.
127 Continue after breakpoint.
131 ### <a id="development-debug-gdb-backtrace"></a> GDB Backtrace
133 If Icinga 2 aborted its operation abnormally, generate a backtrace.
140 > If you're opening an issue at [https://dev.icinga.org] make sure
141 > to attach as much detail as possible.
144 ### <a id="development-debug-gdb-backtrace-stepping"></a> GDB Backtrace Stepping
146 Identifying the problem may require stepping into the backtrace, analysing
147 the current scope, attributes, and possible unmet requirements. `p` prints
148 the value of the selected variable or function call result.
153 (gdb) p checkable.px->m_Name
156 ### <a id="development-debug-gdb-breakpoint"></a> GDB Breakpoints
158 To set a breakpoint to a specific function call, or file specific line.
160 (gdb) b checkable.cpp:125
161 (gdb) b icinga::Checkable::SetEnablePerfdata
163 GDB will ask about loading the required symbols later, select `yes` instead
166 Then run Icinga 2 until it reaches the first breakpoint. Continue with `c`
172 If you want to delete all breakpoints, use `d` and select `yes`.
178 > When debugging exceptions, set your breakpoint like this: `b __cxa_throw`.
187 #11 0x00007ffff7cbf9ff in icinga::Utility::GlobRecursive(icinga::String const&, icinga::String const&, boost::function<void (icinga::String const&)> const&, int) (path=..., pattern=..., callback=..., type=1)
188 at /home/michi/coding/icinga/icinga2/lib/base/utility.cpp:609
192 605 #endif /* _WIN32 */
194 607 std::sort(files.begin(), files.end());
195 608 BOOST_FOREACH(const String& cpath, files) {
199 612 std::sort(dirs.begin(), dirs.end());
200 613 BOOST_FOREACH(const String& cpath, dirs) {
202 $3 = std::vector of length 11, capacity 16 = {{static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/agent.conf"}, {static NPos = 18446744073709551615,
203 m_Data = "/etc/icinga2/conf.d/commands.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/downtimes.conf"}, {static NPos = 18446744073709551615,
204 m_Data = "/etc/icinga2/conf.d/groups.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/notifications.conf"}, {static NPos = 18446744073709551615,
205 m_Data = "/etc/icinga2/conf.d/satellite.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/services.conf"}, {static NPos = 18446744073709551615,
206 m_Data = "/etc/icinga2/conf.d/templates.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/test.conf"}, {static NPos = 18446744073709551615,
207 m_Data = "/etc/icinga2/conf.d/timeperiods.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/users.conf"}}