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:
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
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
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.
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)
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)
$ 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.
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.