***Break**** Segmentation violation for a compiled program

Hello!

I am trying to compile a program based on macro.C (attached to this message); what I am trying to do is to write the classes into separate files, not in the main program like macro.C and get an executable. The program compiles without a problem but when I try to open it (./task1) I get ***Break**** Segmentation violation. The main body of the program is task1.C.

For the compilation, I am using this commands:

‘root-config --cxx --cflags’ -fPIC -c clase.cxx
rootcint -f clase_Dict.cxx -c -p clase.hxx clase_LinkDef.h
‘root-config --cxx --cflags’ -fPIC -c clase_Dict.cxx
‘root-config --cxx --cflags’ -fPIC -shared -o libclase.so clase.o clase_Dict.o
g++ -o task1 task1.C clase.cxx clase_Dict.o clase.o root-config --cflags --libs

Is there something else I need to do?

Thanks!

task1.C (1.2 KB) macro.C (1.3 KB) clase_LinkDef.h (87 Bytes) clase.hxx (305 Bytes) clase.cxx (38 Bytes)


ROOT Version: 6.22/02
Platform: Xubuntu 20.04 LTS
Compiler: g++ 9.3.0


Hello boboc,

I was not able to reproduce this in my environment with gcc-4.8.5 (CentOS 7) and ROOT v6-22-02.

What I can suggest is to add the -g compiler option to your command line, and running your program under gdb so that you are able to get a backtrace when the program SIGSEGV’s. Please, attach the generated backtrace so that we can diagnose the problem.

Cheers,
J.

Hello, @jalopezg!

Here is the updated code:task1.C (1.2 KB) macro.C (1.3 KB) clase_LinkDef.h (89 Bytes) clase.hxx (351 Bytes) clase.cxx (58 Bytes)

When I comment lines 58 to 62 from task1.C the program works well and I can visualize the data with TBrowser. But when I uncomment those lines, tree -> StartViewer() gives me a segmentation fault. Here is the error:

>*** Break *** segmentation violation
>
>
>
>===========================================================
>There was a crash.
>This is the entire stack trace of all threads:
>===========================================================
>#0  0x00007f100c8f6dba in __GI___wait4 (pid=10206, stat_loc=stat_loc
>entry=0x7ffe5be9d8e8, options=options
>entry=0, usage=usage
>entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
>#1  0x00007f100c8f6d7b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
>entry=0x7ffe5be9d8e8, options=options
>entry=0) at waitpid.c:38
>#2  0x00007f100c8660e7 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:172
>#3  0x00007f100d90f49e in TUnixSystem::StackTrace() () from /home/petre/ROOT/lib/libCore.so.6.22
>#4  0x00007f100d90c325 in TUnixSystem::DispatchSignals(ESignals) () from /home/petre/ROOT/lib/libCore.so.6.22
>#5  <signal handler called>
>#6  0x0000561a1690bb57 in main () at task1.C:58
>===========================================================
>
>
>The lines below might hint at the cause of the crash.
>You may get help by asking at the ROOT forum http://root.cern.ch/forum
>Only if you are really convinced it is a bug in ROOT then please submit a
>report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
>from above as an attachment in addition to anything else
>that might help us fixing this issue.
>===========================================================
>#6  0x0000561a1690bb57 in main () at task1.C:58
>===========================================================

Thank you,
Petre Boboc

Hello @boboc,

Lacking a ROOT debug build where I can inspect the complete backtrace, I will invite @jblomer and @eguiraud. Maybe they can help diagnosing this issue.

Cheers,
J.

In task1.C, shouldn’t it be canv->cd(0) (or simply canv->cd()) since no sub pads were defined?

Hello @jblomer,

I just tried with both canv->cd(0) and canv->cd(); I still have the same problem.

I ran you macro on Mac with ROOT 6.23.
It does not crash.

The macro works well. The problem appears when I compile the program and I run it (when I run ./task1). I don’t understand why this happens since the macro works without issues.

You could try adding:

int main(int argc, char **argv) {
   TApplication app(argc, argv);

Hi,
the stacktrace mentions task1.C:58 as the offending line.
At that line there is

tree->StartViewer();

but right before you close the file that contains tree, outputFile->Close: as a consequence, the TTree object tree points to is destroyed. Classic ROOT ownership shenanigans.

Moving outputFile->Close(); to the end of main should fix the issue.

Cheers,
Enrico

Hello, @eguiraud!

I still get “Segmentation fault” when I move outputFile->Close(); to the end of main.

Best regards,
Petre Boboc

Argh, yes, different crash – now at line 62.
I can reproduce it, the best stacktrace I could get so far is

#8  0x00007f322e1ebb44 in TGCompositeFrame::TGCompositeFrame (this=0x3e378c0, p=0x0, w=10, h=10, options=3, back=0) at /workspace/build/projects/ROOT-v6.22.00/src/ROOT/v6.22.00/gui/gui/src/TGFrame.cxx:852
#9  0x00007f322e1ed6f2 in TGMainFrame::TGMainFrame (this=0x3e378c0, p=0x0, w=10, h=10, options=2) at /workspace/build/projects/ROOT-v6.22.00/src/ROOT/v6.22.00/gui/gui/src/TGFrame.cxx:1429
#10 0x00007f322e6224ce in TTreeViewer::TTreeViewer (this=0x3e378c0, tree=0x33531e0) at /workspace/build/projects/ROOT-v6.22.00/src/ROOT/v6.22.00/tree/treeviewer/src/TTreeViewer.cxx:346
#11 0x00007f3246283059 in ?? ()
#12 0x00000000017e45a0 in ?? ()
#13 0x00000000017e45a0 in ?? ()
#14 0x0000000003e378c0 in ?? ()
#15 0x0000000003e378c0 in ?? ()
#16 0x00007ffffd3f54e0 in ?? ()
#17 0x00007ffffd3f5688 in ?? ()
#18 0x00007ffffd3f5f50 in ?? ()
#19 0x00007ffffd3f56a8 in ?? ()
#20 0x00000001fd3f5690 in ?? ()
#21 0x0000000000000000 in ?? ()

Work in progress :smiley:

Alright: to fix the TGCompositeFrame crash, you need to have a TApplication running, as mentioned above in the thread (it’s always needed to have ROOT graphics properly working in compiled ROOT programs).

You need to:

  • #include "TApplication.h"
  • add TApplication app("app", nullptr, nullptr); at the beginning of main
  • add app.Run() at the end of main, before outputfile->Close()

The attached version of task1.C compiles and runs fine for me.

task1.C (1.3 KB)

Cheers,
Enrico

1 Like

See also Creating a user application with ROOT

1 Like

It works!

Thank you very much!