Project

General

Profile

Debugging » History » Revision 2

Revision 1 (Ole Hansen, 08/26/2022 12:24 PM) → Revision 2/4 (Ole Hansen, 08/27/2022 12:12 PM)

h1. Debugging 

 Advanced users may be interested in creating a debug build. To do so, build the analyzer with the CMake build type "Debug": 
 <pre> 
 cmake -B build-debug -S . -DCMAKE_BUILD_TYPE=Debug 
 cmake --build build-debug -j 
 </pre> 
 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":https://root.cern/building-root, again using <code>CMAKE_BUILD_TYPE=Debug</code>, 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 <code>gdb</code> on Linux and <code>lldb</code> 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: 
 <pre> 
 alias lldb='/Library/Developer/CommandLineTools/usr/bin/lldb' 
 </pre> 
 The analyzer may be run directly from the build location under the debugger of your choice: 
 <pre> 
 % ./build-debug/apps/analyzer 
 </pre> 
 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 <code>gdb</code>: 
 <pre> 
 % 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. 
 </pre> 
 This sets a breakpoint for all versions of the <code>THaRun</code> constructor. The <code>continue</code> command (shorthand <code>c</code>) resumes execution of the program. 

 Go back to the analyzer prompt and create a <code>THaRun</code> object. The process will stop and print information (in the debugger window), allowing you to inspect data, single step through the code, etc.: 
 <pre> 
 analyzer [0] r = new THaRun("/data/raw/run_7211.evio.0") 
 </pre> 
 In the debugger window, you'll see 
 <pre> 
 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) 
 </pre> 
 Here, we printed (shorthand <code>p</code>) the contents of the variable <code>fname</code>. To end the session, type <code>q</code> in the debugger window. 

 The process is very similar under macOS with <code>lldb</code>, although the syntax of some <code>lldb</code> commands differes from that of <code>gdb</code>. 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 <code>gdb</code> or <code>lldb</code>, there are plenty of tutorials available online that should get you started quickly.