Debugging » History » Revision 2
« Previous |
Revision 2/4
(diff)
| Next »
Ole Hansen, 08/27/2022 12:12 PM
Debugging¶
Advanced users may be interested in creating a debug build. To do so, build the analyzer with the CMake build type "Debug":
cmake -B build-debug -S . -DCMAKE_BUILD_TYPE=Debug cmake --build build-debug -j
You might also want to use a debug version of ROOT or install an appropriate debuginfo package (e.g. root-debuginfo on RedHat systems using EPEL).
A true debug version of ROOT requires building ROOT from source, again using
CMAKE_BUILD_TYPE=Debug
, which is beyond the scope of this document.
Also, be sure to install glibc-debuginfo and glibc-debuginfo-common to get debug support for STL classes and other standard library features. This is not necessary on macOS, where the relevant bundles come with the required symbol tables included.
The recommended debugger is gdb
on Linux and lldb
on newer macOS versions. To avoid problems with macOS's System Integrity Protection when using lldb, it may be helpful to not use /usr/bin/lldb directly, but instead create an alias to the command-line tools version, which isn't a specially-protected executable:
alias lldb='/Library/Developer/CommandLineTools/usr/bin/lldb'
The analyzer may be run directly from the build location under the debugger of your choice:
% ./build-debug/apps/analyzer
In a second terminal, find out the PID of this analyzer process, then attach the debugger, which will stop the analzyer and allow you to configure the debugger, e.g. to set break points, etc. For example, on Linux using
gdb
:% ps a | grep analyzer 13643 pts/3 S+ 0:00 ./build-debug/apps/analyzer % gdb GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7 ... (gdb) attach 13643 ... (gdb) break THaRun::THaRun Breakpoint 1 at 0x7fab342a10a7: THaRun::THaRun. (3 locations) (gdb) continue Continuing.
This sets a breakpoint for all versions of the
THaRun
constructor. The continue
command (shorthand c
) resumes execution of the program.
Go back to the analyzer prompt and create a THaRun
object. The process will stop and print information (in the debugger window), allowing you to inspect data, single step through the code, etc.:
analyzer [0] r = new THaRun("/data/raw/run_7211.evio.0")
In the debugger window, you'll see
Breakpoint 1, THaRun::THaRun (this=0x503bb20, fname=0x7fab188f002c "/data/raw/run_7211.evio.0", description=0x7fab188f004f "") at /home/ole/Develop/analyzer/Podd/THaRun.cxx:39 39 fSegment(-1), fStream(-1) (gdb) p fname $1 = 0x7fab188f002c "/data/raw/run_7211.evio.0" (gdb)
Here, we printed (shorthand
p
) the contents of the variable fname
. To end the session, type q
in the debugger window.
The process is very similar under macOS with lldb
, although the syntax of some lldb
commands differes from that of gdb
. You can find side-by-side comparisons of equivalent commands online. Obviously, this only scratches the surface of what is possible with a debugger. If you are unfamiliar with gdb
or lldb
, there are plenty of tutorials available online that should get you started quickly.
Updated by Ole Hansen over 2 years ago · 2 revisions