Opening a TFile crashes gdb session

When debugging an executable opening a TFile with GDB (both 10.2 and 11.1) the debug session ends with a SIGTRAP and not much useful information for understanding the problem. This is a simple reproducer:

#include "TFile.h"
int main(int argc, char** argv){
        TFile *file = TFile::Open(argv[1]);
        return 0;
}

When starting a debug session with no breakpoints I get:

$ gdb a.out      
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.                                                                                                                                                                                                                              
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) r
Starting program: /tmp/test/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[Detaching after vfork from child process 118892]

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
(gdb)

The Program terminated with signal SIGTRAP, Trace/breakpoint trap. mesage is found over many help threads on the web, but it is usually related to breakpoints, and I don’t have any in my test session.

I’m clueless so I’d need a bit of help with this. I can provide more info about my system and Root build configuration if needed.
Thanks in advance for any help


ROOT Version: 6.22.08
Platform: Archlinux, glibc 2.33
Compiler: GCC 11.1.0


Can you put a breakpoint before this line and examine argv[1] ?
@pcanal might have some ideas about it.

Hi, I put a cout and it’s correctly set. Also, executing without gdb gives no error. Should I still try to place the breakpoint as you suggested or these info makes it not so useful?
Thanks

You need:

$ gdb --args a.out MyFile.root
(gdb) run

or:

$ gdb a.out
(gdb) set args MyFile.root
(gdb) run

Yes, you are right, I forgot --args. However, I get the same gdb behavior with and without that argument, so I guess that if it’s really something inside TFile::Open that crashes gdb then it probably happens before the file name is actually used.

Edit: the same happens using the name of a file that does not exist.

Try:

$ gdb a.out
(gdb) set args MyFile.root
(gdb) break main
(gdb) run

Thans @Wile_E_Coyote for the suggestion, here’s the output:

$ gdb a.out
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) set args test.root
(gdb) break main
Breakpoint 1 at 0x1158: file main.cpp, line 6.
(gdb) run
Starting program: /tmp/test/a.out test.root
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, main (argc=2, argv=0x7fffffffda78) at main.cpp:6
6               TFile *file = TFile::Open(argv[1]);
(gdb) p argv[1]
$1 = 0x7fffffffdf78 "test.root"
(gdb) s
[Detaching after vfork from child process 121501]

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
(gdb)

What do you have in lines 1 to 5 of your “main.cpp”?
I suspect it dies in one of these lines (the “s” command does not reach the “TFile” line, it just enters the “main”).

These are just commented lines that I didn’t report in the reproducer code in my first post, sorry for the misleading practice but I didn’t figure out it could interfere with the diagnostics.

Edit: this is the outcome after removing the commented lines and making the actual source identical to that in the first post:

$ gdb --args a.out test.root 
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) break main
Breakpoint 1 at 0x1158: file main.cpp, line 3.
(gdb) r
Starting program: /tmp/test/a.out test.root
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, main (argc=2, argv=0x7fffffffda78) at main.cpp:3
3               TFile *file = TFile::Open(argv[1]);
(gdb) s
[Detaching after vfork from child process 122556]

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
(gdb)

Are you sure that under “gdb” you use the same ROOT version as the one that was used to build “a.out”?
Try: ldd a.out

I think I don’t understand clearly what you mean with “under gdb”. I start from a clean shell, set the environment, then compile the program and start gdb as follows:

$ root
bash: root: command not found
$ source ~/software/install/ROOT_6.22.08/bin/thisroot.sh
$ which root
/home/mori/software/install/ROOT_6.22.08/bin/root
$ g++ -g3 -std=c++14 -I $ROOTSYS/include/ `root-config --libs` main.cpp
$ ./a.out 
Error in <TFile::Open>: no url specified
$ ./a.out test.root 
$ gdb --args a.out test.root
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) break main
Breakpoint 1 at 0x1158: file main.cpp, line 3.
(gdb) r
Starting program: /tmp/test/a.out test.root
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, main (argc=2, argv=0x7fffffffdad8) at main.cpp:3
3               TFile *file = TFile::Open(argv[1]);
(gdb) s
[Detaching after vfork from child process 122898]

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
(gdb) 

And here’s the output of ldd:

$ ldd a.out
        linux-vdso.so.1 (0x00007ffd27354000)
        libCore.so => /home/mori/software/install/ROOT_6.22.08/lib/libCore.so (0x00007f3c0ebc9000)
        libImt.so => /home/mori/software/install/ROOT_6.22.08/lib/libImt.so (0x00007f3c0ebb7000)
        libRIO.so => /home/mori/software/install/ROOT_6.22.08/lib/libRIO.so (0x00007f3c0e7d8000)
        libNet.so => /home/mori/software/install/ROOT_6.22.08/lib/libNet.so (0x00007f3c0e6f7000)
        libHist.so => /home/mori/software/install/ROOT_6.22.08/lib/libHist.so (0x00007f3c0e2d9000)
        libGraf.so => /home/mori/software/install/ROOT_6.22.08/lib/libGraf.so (0x00007f3c0e16b000)
        libGraf3d.so => /home/mori/software/install/ROOT_6.22.08/lib/libGraf3d.so (0x00007f3c0e0b5000)
        libGpad.so => /home/mori/software/install/ROOT_6.22.08/lib/libGpad.so (0x00007f3c0dfd9000)
        libROOTVecOps.so => /home/mori/software/install/ROOT_6.22.08/lib/libROOTVecOps.so (0x00007f3c0def9000)
        libTree.so => /home/mori/software/install/ROOT_6.22.08/lib/libTree.so (0x00007f3c0dd68000)
        libTreePlayer.so => /home/mori/software/install/ROOT_6.22.08/lib/libTreePlayer.so (0x00007f3c0dbcc000)
        libRint.so => /home/mori/software/install/ROOT_6.22.08/lib/libRint.so (0x00007f3c0dba0000)
        libPostscript.so => /home/mori/software/install/ROOT_6.22.08/lib/libPostscript.so (0x00007f3c0db1f000)
        libMatrix.so => /home/mori/software/install/ROOT_6.22.08/lib/libMatrix.so (0x00007f3c0d9a0000)
        libPhysics.so => /home/mori/software/install/ROOT_6.22.08/lib/libPhysics.so (0x00007f3c0d950000)
        libMathCore.so => /home/mori/software/install/ROOT_6.22.08/lib/libMathCore.so (0x00007f3c0d728000)
        libThread.so => /home/mori/software/install/ROOT_6.22.08/lib/libThread.so (0x00007f3c0d6d2000)
        libMultiProc.so => /home/mori/software/install/ROOT_6.22.08/lib/libMultiProc.so (0x00007f3c0d6c3000)
        libROOTDataFrame.so => /home/mori/software/install/ROOT_6.22.08/lib/libROOTDataFrame.so (0x00007f3c0d5ef000)
        libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f3c0d5b3000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f3c0d39d000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f3c0d259000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f3c0d23e000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f3c0d21d000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f3c0d04f000)
        libpcre.so.1 => /usr/lib/libpcre.so.1 (0x00007f3c0cfd8000)
        liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007f3c0cfaf000)
        libxxhash.so.0 => /usr/lib/libxxhash.so.0 (0x00007f3c0cfa3000)
        liblz4.so.1 => /usr/lib/liblz4.so.1 (0x00007f3c0cf80000)
        libz.so.1 => /usr/lib/libz.so.1 (0x00007f3c0cf66000)
        libzstd.so.1 => /usr/lib/libzstd.so.1 (0x00007f3c0ce55000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f3c0f057000)
        libtbb.so.2 => /usr/lib/libtbb.so.2 (0x00007f3c0ce0f000)
        libssl.so.1.1 => /usr/lib/libssl.so.1.1 (0x00007f3c0cd7d000)
        libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1 (0x00007f3c0ca9e000)
        libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007f3c0c9d4000)
        libvdt.so => /home/mori/software/install/ROOT_6.22.08/lib/libvdt.so (0x00007f3c0c9c8000)
        libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x00007f3c0c883000)
        librt.so.1 => /usr/lib/librt.so.1 (0x00007f3c0c878000)
        libbz2.so.1.0 => /usr/lib/libbz2.so.1.0 (0x00007f3c0c863000)
        libpng16.so.16 => /usr/lib/libpng16.so.16 (0x00007f3c0c82c000)
        libharfbuzz.so.0 => /usr/lib/libharfbuzz.so.0 (0x00007f3c0c753000)
        libbrotlidec.so.1 => /usr/lib/libbrotlidec.so.1 (0x00007f3c0c745000)
        libgraphite2.so.3 => /usr/lib/libgraphite2.so.3 (0x00007f3c0c720000)
        libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f3c0c5ea000)
        libbrotlicommon.so.1 => /usr/lib/libbrotlicommon.so.1 (0x00007f3c0c5c5000)

Try to build it using:

`root-config --cxx --cflags` -g main.cpp `root-config --libs`

BTW. I don’t understand why “ldd” lists all these libraries (there should be just “libCore”, “libRIO” and “libThread”).

Same result.

Edit: about the actually linked libraries, I think my distribution builds gcc with --no-as-needed enabled by default

Well, try:

#include "TApplication.h"
#include "TFile.h"
int main(int argc, char** argv) {
  TApplication a("a", 0, 0);
  TFile *file = TFile::Open(argv[1]);
  return 0;
}

Well, this actually changes something:

$ gdb --args a.out test.root 
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) break main
Breakpoint 1 at 0x11a2: file main.cpp, line 3.
(gdb) r
Starting program: /tmp/test/a.out test.root
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, main (argc=2, argv=0x7fffffffda78) at main.cpp:3
3       int main(int argc, char** argv) {
(gdb) s
4         TApplication a("a", 0, 0);
(gdb) s
[Detaching after vfork from child process 124430]

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
(gdb)

Now the session crashes before the file being opened.

Maybe @pcanal or @Axel will have some idea.
Post the output of:
root-config --cxx --cflags
root-config --libs

BTW. You seem to use “GCC 11.1.0” with “ROOT 6.22/08”. Are you sure this setup is supported? Maybe you could try “ROOT 6.24/06”?

$ root-config --cxx --cflags
c++ -pthread -std=c++14 -m64 -I/home/mori/software/install/ROOT_6.22.08/include
$ root-config --libs
-L/home/mori/software/install/ROOT_6.22.08/lib -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -pthread -lm -ldl -rdynamic

I don’t know if gcc 11 is supported or not by 6.22.08, but apart from this issue with gdb I had no other problem with it

One more trial maybe:

`root-config --cxx --cflags` -g main.cpp -Wl,--as-needed `root-config --libs`
ldd a.out # libCore, libRIO and libThread only?
gdb a.out # try to "debug" it

I’ve already tried with only needed libraries, to no avail. Anyway, here’s the output:

$ `root-config --cxx --cflags` -g main.cpp -Wl,--as-needed `root-config --libs`
$ ldd a.out
        linux-vdso.so.1 (0x00007ffd23bb5000)
        libCore.so => /home/mori/software/install/ROOT_6.22.08/lib/libCore.so (0x00007f7f0c0ee000)
        libRIO.so => /home/mori/software/install/ROOT_6.22.08/lib/libRIO.so (0x00007f7f0bd0f000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f7f0bac4000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f7f0baa9000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f7f0b8dd000)
        libpcre.so.1 => /usr/lib/libpcre.so.1 (0x00007f7f0b866000)
        liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007f7f0b83b000)
        libxxhash.so.0 => /usr/lib/libxxhash.so.0 (0x00007f7f0b82f000)
        liblz4.so.1 => /usr/lib/liblz4.so.1 (0x00007f7f0b80c000)
        libz.so.1 => /usr/lib/libz.so.1 (0x00007f7f0b7f2000)
        libzstd.so.1 => /usr/lib/libzstd.so.1 (0x00007f7f0b6e3000)
        libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f7f0b6dc000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f7f0b6b9000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f7f0b575000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f7f0c57c000)
        libThread.so => /home/mori/software/install/ROOT_6.22.08/lib/libThread.so (0x00007f7f0b51f000)
$ gdb --args a.out test.root 
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) break main
Breakpoint 1 at 0x11a2: file main.cpp, line 3.
(gdb) r
Starting program: /tmp/test/a.out test.root
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, main (argc=2, argv=0x7fffffffdab8) at main.cpp:3
3       int main(int argc, char** argv) {
(gdb) s
4         TApplication a("a", 0, 0);
(gdb) s
[Detaching after vfork from child process 127108]

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
(gdb) 

I compiled Root in debug mode (-DCMAKE_BUILD_TYPE=Debug), to see in which code portion inside Root gdb was misbehaving. Interestingly, with the Root debug binaries gdb works fine:

$ gdb --args a.out test.root 
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) break main
Breakpoint 1 at 0x1158: file main.cpp, line 3.
(gdb) r
Starting program: /tmp/a.out test.root
warning: File "/home/mori/software/install/ROOT_6.22.08_DEBUG/lib/libCore.so-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
        add-auto-load-safe-path /home/mori/software/install/ROOT_6.22.08_DEBUG/lib/libCore.so-gdb.py
line to your configuration file "/home/mori/.gdbinit".
To completely disable this security protection add
        set auto-load safe-path /
line to your configuration file "/home/mori/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
        info "(gdb)Auto-loading safe path"
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, main (argc=2, argv=0x7fffffffdaf8) at main.cpp:3
3               TFile *file = TFile::Open(argv[1]);
(gdb) s
TFile::Open (url=0x7fffffffdfe6 "test.root", options=0x55555555607b "", ftitle=0x55555555607b "", compress=101, netopt=0) at /home/mori/software/source/root-6.22.08/io/io/src/TFile.cxx:3945
3945    {
(gdb) s
3947       TFile *f = nullptr;
(gdb) s
3948       EFileType type = kFile;
(gdb) s
3951       if (!url || strlen(url) <= 0) {
(gdb) c
Continuing.
[Detaching after vfork from child process 56959]
[Detaching after vfork from child process 56961]
[Detaching after vfork from child process 56963]
[Detaching after vfork from child process 56965]
[Detaching after vfork from child process 56969]
[Detaching after vfork from child process 56971]
[Detaching after vfork from child process 56975]
[Inferior 1 (process 56952) exited normally]
(gdb)

I don’t know if this can be of any help in tracing the source of the problem.