简体   繁体   English

ROOT:分段违规

[英]ROOT: Segmentation violation

I am running Cern ROOT 6.22/00 on Ubuntu 18.04.我在 Ubuntu 18.04 上运行 Cern ROOT 6.22/00。 I am running a very simple code that reads data and plots a graph.我正在运行一个非常简单的代码来读取数据并绘制图形。

// filename.C Example of graph with SetPoint

{
    g = new TGraph();
    
    for(i=0; i<10; i++) {
        g->SetPoint(i, i, i*i - 4*i + 7);
    }
    
    g->SetMarkerStyle(22);
    g->Draw("ALP");
}

When I go ahead and execute the code with .x filename.C , the code works as intended.当我继续使用.x filename.C执行代码时,代码按预期工作。 However, when I run the same command again, I get the segmentation error:但是,当我再次运行相同的命令时,出现分段错误:

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f7c2e7166e7 in waitpid () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007f7c2e681107 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007f7c2f2b8ed3 in TUnixSystem::StackTrace() () from /home/nick/root/lib/libCore.so.6.22
#3  0x00007f7c2f2bb9c5 in TUnixSystem::DispatchSignals(ESignals) () from /home/nick/root/lib/libCore.so.6.22
#4  <signal handler called>
#5  0x00007f7c29f24393 in (anonymous namespace)::ScalarExprEmitter::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation, bool) () from /home/nick/root/lib/libCling.so
#6  0x00007f7c29f25e84 in clang::CodeGen::CodeGenFunction::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation) () from /home/nick/root/lib/libCling.so
#7  0x00007f7c29eed6e0 in clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) () from /home/nick/root/lib/libCling.so
#8  0x00007f7c29d70dc3 in clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) () from /home/nick/root/lib/libCling.so
#9  0x00007f7c29d6f305 in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) () from /home/nick/root/lib/libCling.so
#10 0x00007f7c29d6f42f in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /home/nick/root/lib/libCling.so
#11 0x00007f7c29daab12 in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) () from /home/nick/root/lib/libCling.so
#12 0x00007f7c29dc8098 in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/nick/root/lib/libCling.so
#13 0x00007f7c29dea828 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/nick/root/lib/libCling.so
#14 0x00007f7c29debb05 in clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) () from /home/nick/root/lib/libCling.so
#15 0x00007f7c29dec46f in clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) () from /home/nick/root/lib/libCling.so
#16 0x00007f7c29d2edfd in clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#17 0x00007f7c2a07aba0 in clang::MultiplexConsumer::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#18 0x00007f7c29ca5aea in cling::DeclCollector::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#19 0x00007f7c29c72bec in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /home/nick/root/lib/libCling.so
#20 0x00007f7c29c7540c in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /home/nick/root/lib/libCling.so
#21 0x00007f7c29bf36ad in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/nick/root/lib/libCling.so
#22 0x00007f7c29bf3aaa in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /home/nick/root/lib/libCling.so
#23 0x00007f7c29cb50df in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, unsigned long, bool) () from /home/nick/root/lib/libCling.so
#24 0x00007f7c29b6e004 in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/nick/root/lib/libCling.so
#25 0x00007f7c29b6eaa2 in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /home/nick/root/lib/libCling.so
#26 0x00007f7c2f15cba8 in TApplication::ExecuteFile(char const*, int*, bool) () from /home/nick/root/lib/libCore.so.6.22
#27 0x00007f7c2f15c3d0 in TApplication::ProcessLine(char const*, bool, int*) () from /home/nick/root/lib/libCore.so.6.22
#28 0x00007f7c2f6d9002 in TRint::ProcessLineNr(char const*, char const*, int*) () from /home/nick/root/lib/libRint.so.6.22
#29 0x00007f7c2f6d93f4 in TRint::HandleTermInput() () from /home/nick/root/lib/libRint.so.6.22
#30 0x00007f7c2f2bacb0 in TUnixSystem::CheckDescriptors() () from /home/nick/root/lib/libCore.so.6.22
#31 0x00007f7c2f2bc668 in TUnixSystem::DispatchOneEvent(bool) () from /home/nick/root/lib/libCore.so.6.22
#32 0x00007f7c2f1c7751 in TSystem::Run() () from /home/nick/root/lib/libCore.so.6.22
#33 0x00007f7c2f159e7f in TApplication::Run(bool) () from /home/nick/root/lib/libCore.so.6.22
#34 0x00007f7c2f6da9f1 in TRint::Run(bool) () from /home/nick/root/lib/libRint.so.6.22
#35 0x000055f5d5017a3c in main ()
===========================================================


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.
===========================================================
#5  0x00007f7c29f24393 in (anonymous namespace)::ScalarExprEmitter::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation, bool) () from /home/nick/root/lib/libCling.so
#6  0x00007f7c29f25e84 in clang::CodeGen::CodeGenFunction::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation) () from /home/nick/root/lib/libCling.so
#7  0x00007f7c29eed6e0 in clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) () from /home/nick/root/lib/libCling.so
#8  0x00007f7c29d70dc3 in clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) () from /home/nick/root/lib/libCling.so
#9  0x00007f7c29d6f305 in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) () from /home/nick/root/lib/libCling.so
#10 0x00007f7c29d6f42f in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /home/nick/root/lib/libCling.so
#11 0x00007f7c29daab12 in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) () from /home/nick/root/lib/libCling.so
#12 0x00007f7c29dc8098 in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/nick/root/lib/libCling.so
#13 0x00007f7c29dea828 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/nick/root/lib/libCling.so
#14 0x00007f7c29debb05 in clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) () from /home/nick/root/lib/libCling.so
#15 0x00007f7c29dec46f in clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) () from /home/nick/root/lib/libCling.so
#16 0x00007f7c29d2edfd in clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#17 0x00007f7c2a07aba0 in clang::MultiplexConsumer::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#18 0x00007f7c29ca5aea in cling::DeclCollector::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/nick/root/lib/libCling.so
#19 0x00007f7c29c72bec in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /home/nick/root/lib/libCling.so
#20 0x00007f7c29c7540c in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /home/nick/root/lib/libCling.so
#21 0x00007f7c29bf36ad in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/nick/root/lib/libCling.so
#22 0x00007f7c29bf3aaa in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /home/nick/root/lib/libCling.so
#23 0x00007f7c29cb50df in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, unsigned long, bool) () from /home/nick/root/lib/libCling.so
===========================================================

I am sure it has nothing to do with my code itself, but ideas to resolve this?我确定这与我的代码本身无关,但是解决这个问题的想法?

I tried your code on ROOT 6.20/06 and it indeed crashed with the same segmentation errors you posted, but I am able to run your code simply by declaring the types of variables g and i:我在 ROOT 6.20/06 上尝试了您的代码,它确实因您发布的相同分段错误而崩溃,但我只需声明变量 g 和 i 的类型即可运行您的代码:

{
  TGraph* g = new TGraph();
  for(int i=0; i<10; i++) {
    g->SetPoint(i, i, i*i - 4*i + 7);
  }
  g->SetMarkerStyle(22);
  g->Draw("ALP");
}

TGraph::SetPoint method can itself handle the memory allocation issue, so the code has no problem in principle, just need to be careful when declaring variables in C/C++. TGraph::SetPoint 方法本身可以处理内存分配问题,所以代码原则上没有问题,只是需要在C/C++中声明变量时小心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM