C ++找到调用函数的位置以查找向量范围检查错误

时间:2016-03-30 16:43:42

标签: c++ vector debug-information

我遇到了一个向导的范围检查错误,我遇到针脚问题。我正在一个非常大的c ++框架中工作,这个框架设计得不是很好。 Python被用作一个UI,然后调用c ++函数/类来完成所有繁重的工作。所以我运行的实际命令是'python thing.py --option1 etc ......'。有一个函数返回它通过向量中的索引找到的对象。它可以根据设置的bool使用两个向量。更具体地说,我有类似的东西:

object getObject(int i, bool trig=false){
    if(trig) return vector1.at(i);
    return vector2.at(i);
}

问题在于向量的长度不同,所以如果你给它指错了,或者你忘了设置'trig'bool,那么你很有可能超出范围。这个函数或类似的东西在许多不同的文件中被调用了数千次,所以我很难找到这个范围检查错误实际来自哪里。目前我一直在评论代码块,或者在打印出来之前试图找到代码在崩溃之前的位置,但考虑到我必须这样做的地方数量,这是非常困难的。

当我得到范围检查错误时,是否有一种简单的方法可以打印出调用此函数的位置?堆栈跟踪或类似的东西?我对这类事情并不熟悉。

更新 我尝试过使用GDB命令,如:

gdb -ex  r --args python fakes.py --datasets data --dir outdir

我看到同样的错误,我总是得到这样的错误:

Traceback (most recent call last):
File "fakes.py", line 299, in <module>
main(options,args)
File "fakes.py", line 240, in main
driver.submit(job, submitDir)
Exception: void EL::Driver::submit(const EL::Job& job,
const string& location) =>
DataVector::at range check (C++ exception)

然后它让我进入GDB命令行。如果我输入bt(这似乎是获得堆栈跟踪的正确命令),我会收到消息“No stack。”

我也试过用这个命令运行Valgrind,但我没有看到任何有用的东西。因为我是valgrind的新手,所以我可能会错过一些东西。以下是出现错误的valgrind输出:

==344722== Conditional jump or move depends on uninitialised value(s)
==344722==    at 0xE80FEC5: TObject::~TObject() (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCore.so)
==344722==    by 0x25437C52: EL::Driver::submitOnly(EL::Job const&, std::string const&) const (Driver.cxx:103)
==344722==    by 0x25437F88: EL::Driver::submit(EL::Job const&, std::string const&) const (Driver.cxx:84)
==344722==    by 0x1CA83031: ???
==344722==    by 0xFFE6F7E: TClingCallFunc::exec(void*, void*) const (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0xD1AA1AE: PyROOT::TVoidExecutor::Execute(long, void*, PyROOT::TCallContext*) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libPyROOT.so)
==344722==    by 0xD1CB0CB: PyROOT::TMethodHolder::CallSafe(void*, long, PyROOT::TCallContext*) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libPyROOT.so)
==344722==    by 0xD1C9DB9: PyROOT::TMethodHolder::Execute(void*, long, PyROOT::TCallContext*) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libPyROOT.so)
==344722==    by 0xD1C8A24: PyROOT::TMethodHolder::Call(PyROOT::ObjectProxy*, _object*, _object*, PyROOT::TCallContext*) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libPyROOT.so)
==344722==    by 0xD1E35A4: PyROOT::(anonymous namespace)::mp_call(PyROOT::MethodProxy*, _object*, _object*) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libPyROOT.so)
==344722==    by 0x4C61B62: PyObject_Call (abstract.c:2529)
==344722==    by 0x4D161AD: PyEval_EvalFrameEx (ceval.c:4251)
==344722==
Traceback (most recent call last):
  File "fakes.py", line 299, in <module>
    main(options,args)
  File "fakes.py", line 240, in main
    driver.submit(job, submitDir)
Exception: void EL::Driver::submit(const EL::Job& job, const string& location) =>
    DataVector::at range check (C++ exception)
==344722== Invalid read of size 4
==344722==    at 0x4CB08F3: PyObject_Free (obmalloc.c:994)
==344722==    by 0x4D55452: collect (gcmodule.c:821)
==344722==    by 0x4D55D27: PyGC_Collect (gcmodule.c:1440)
==344722==    by 0x4D3E018: Py_Finalize (pythonrun.c:449)
==344722==    by 0x4D53F8E: Py_Main (main.c:665)
==344722==    by 0x3038C1ED5C: (below main) (in /lib64/libc-2.12.so)
==344722==  Address 0x682d020 is 16 bytes before a block of size 48 alloc'd
==344722==    at 0x4A085FC: operator new(unsigned long) (vg_replace_malloc.c:298)
==344722==    by 0x10B7DD41: clang::ASTReader::ReadDeclContextStorage(clang::serialization::ModuleFile&, llvm::BitstreamCursor&, std::pair<unsigned long, unsigned long> const&, clang::serialization::DeclContextInfo&) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x10BD8CCC: clang::ASTReader::ReadDeclRecord(unsigned int) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x10B82DCC: clang::ASTReader::GetDecl(unsigned int) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x11036DED: clang::MultiplexExternalSemaSource::GetExternalDecl(unsigned int) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x1114F052: clang::ClassTemplateDecl::LoadLazySpecializations() const (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x1114F078: clang::ClassTemplateDecl::getSpecializations() const (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x11151209: clang::ClassTemplateDecl::findSpecialization(llvm::ArrayRef<clang::TemplateArgument>, void*&) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x10F55800: clang::Sema::CheckTemplateIdType(clang::TemplateName, clang::SourceLocation, clang::TemplateArgumentListInfo&) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x10FCC354: clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTemplateSpecializationType(clang::TypeLocBuilder&, clang::TemplateSpecializationTypeLoc, clang::TemplateName) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x10FB8805: clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)
==344722==    by 0x10FB8DFC: clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.04.12-x86_64-slc6-gcc49-opt/lib/libCling.so)

0 个答案:

没有答案