Debugging root macro with gdb

Hi experts,
I wanted to debug my buggy and lengthy root macro latest_automatic.C (attached).
Therefore I use following comands:
gdb /scratch8/ge37liw/workingspace/FairSoft/build/bin/root.exe
then
(gdb) run -l -b
and finally:
.x latest_automatic.C("0089_0004") (the macro takes the name snippet of the data file as input argument)

The macro runs then through the data but I cannot find a way to analyze the variables in the macro and debug.
E.g. I press Control-C
and then type next I get as output:
TBufferFile::ApplySequenceVecPtr (this=0x7dbf590, sequence=..., start_collection=0x7dccb90, end_collection=0x7dccb90) at /scratch8/ge37liw/workingspace/FairSoft/tools/root/io/io/src/TBufferFile.cxx:3593 3593 (*iter)(*this,start_collection,end_collection);
or
3590 for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();

so I am somewhere outside the macro.
How can I step into the macro and analyze/debug it?

Thanks in advance
Tobias latest_automatic.C (129.3 KB)

Hi Tobias,

Wow, you already figured out how to debug ROOT - good! The code you have is just-in-time compiled, and we never found the cycles to enable debug info for that. It’s now on our plan for this year.

Until that’s done please run .x latest_automatic.C+g("0089_0004"). The + builds a shared library from your code instead of just-in-time compiling it; the g adds debug info. That will allow you to put breakpoints, see variables, etc.

Cheers, Axel.

Hi Axel,
thanks for the quick response.
I tried to run it as you said with
.x latest_automatic.C+g("0089_0004")
But it gets stuck as it doesn’t seem to find ROOT libraries anymore. As output I get:

root [0] .x latest_automatic.C+g("0089_0004")
Info in <TUnixSystem::ACLiC>: creating shared library /home/ge37liw/farm_exer/a_q_z_jobs/mw3_no_off/./latest_automatic_C.so
Detaching after fork from child process 7373.
Detaching after fork from child process 7374.
Detaching after fork from child process 7376.
Detaching after fork from child process 7377.
Detaching after fork from child process 7378.
In file included from input_line_12:9:
././latest_automatic.C:158:1: error: unknown type name 'TH1F'
TH1F* h1_z_all_iso;
^
././latest_automatic.C:159:1: error: unknown type name 'TH1F'
TH1F* h1_a_q_z5;
^
././latest_automatic.C:160:1: error: unknown type name 'TH1F'
TH1F* h1_a_q_z6;
^
././latest_automatic.C:162:1: error: unknown type name 'TH2F'
TH2F* h2_theta_out_vs_mw3_10b;


fatal error: too many errors emitted, stopping now [-ferror-limit=]
Error in <ACLiC>: Dictionary generation failed!

Do you have an idea how I can fix this issue (so that it recognizes the ROOT libraries /environment variables again)?

Best Regards
Tobias

Now that ROOT is compiling it (that’s what the + does), the macrot is probably just missing a few includes, e.g. #include <TH2F.h>.

(alternative method: compile your code as a standard C++ program with g++ -g -O main main.cpp $(root-config --libs --cflags) and debug it as normal)

Cheers,
Enrico

Hi Enrico,
that makes sense. I just have a problem when compiling it: I use own libraries. At runtime they can be found (as I have set environment variables) but not when compiling with " g++ -g -O main main.cpp $(root-config --libs --cflags)" . How can I add these libraries when compiling?

Thanks in advance
Tobias

P.S.: I know this is not a ROOT specific question, nevertheless it would really help me…

That’s standard C/C++: you need to compile your own libraries in their binary object (a ".o file") and link that file when you compile the full application:

g++ -o yourlib.o yourlib.cpp $(root-config --libs --cflags)
g++ -o main main.cpp yourlib.o $(root-config --libs --cflags)

If main.cpp has something like a #include "yourlib.h" and yourlib.h is not in the same directory as main.cpp, you also have to tell g++ where to look for included headers, so you also have to pass -Ipath/to/dir/with/headers.

Cheers,
Enrico

Thanks for the detailed explanation. In my case it’s not just a few libraries, but a whole package. In that case it’s probably more convenient to write a Makefile…

Regards
Tobias

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.