python-clang因分段错误而崩溃

时间:2017-08-27 04:15:15

标签: python c++ clang abstract-syntax-tree bitcoin

我有以下简单的python代码,它使用libclang python绑定遍历AST,不幸的是它崩溃了分段错误。 我使用python2.7并尝试了以下所有clang版本3.8,3.9,4.0,5.0,6.0(当然也为每个版本使用了正确的python clang绑定)

import clang.cindex

def traverse(node):
    print("%-42s %-20s %-10s %-6s %s" % (node.kind, node.spelling, node.type.spelling, node.location.line, node.mangled_name))
    for child in node.get_children():
        traverse(child)

clang.cindex.Config.set_library_file('/usr/lib/llvm-3.8/lib/libclang.so')
index = clang.cindex.Index.create()
tu = index.parse(sys.argv[1], args=['-Werror'])
traverse(tu.cursor)

回溯:

#0  clang::TagType::getDecl (this=0x0) at /build/llvm-toolchain-3.8-_PD09B/llvm-toolchain-3.8-3.8/tools/clang/lib/AST/Type.cpp:2962
#1  0x00007f9ecbe65caf in clang::RecordType::getDecl (this=<optimized out>) at /build/llvm-toolchain-3.8-_PD09B/llvm-toolchain-3.8-3.8/tools/clang/include/clang/AST/Type.h:3554
#2  (anonymous namespace)::CXXNameMangler::mangleUnqualifiedName (this=this@entry=0x7ffe35f45470, ND=ND@entry=0x7f9ec0092cc8, Name=..., 
    AdditionalAbiTags=AdditionalAbiTags@entry=0x7ffe35f453c0, KnownArity=4294967295)
    at /build/llvm-toolchain-3.8-_PD09B/llvm-toolchain-3.8-3.8/tools/clang/lib/AST/ItaniumMangle.cpp:1184
#3  0x00007f9ecbe60250 in (anonymous namespace)::CXXNameMangler::mangleUnqualifiedName (AdditionalAbiTags=0x7ffe35f453c0, ND=<optimized out>, this=0x7ffe35f45470)
    at /build/llvm-toolchain-3.8-_PD09B/llvm-toolchain-3.8-3.8/tools/clang/lib/AST/ItaniumMangle.cpp:481
#4  (anonymous namespace)::CXXNameMangler::mangleLocalName (this=this@entry=0x7ffe35f45470, D=D@entry=0x7f9ec0092cc8, AdditionalAbiTags=AdditionalAbiTags@entry=0x7ffe35f453c0, 
    ExcludeUnqualifiedName=ExcludeUnqualifiedName@entry=false) at /build/llvm-toolchain-3.8-_PD09B/llvm-toolchain-3.8-3.8/tools/clang/lib/AST/ItaniumMangle.cpp:1471
#5  0x00007f9ecbe607b7 in (anonymous namespace)::CXXNameMangler::mangleNameWithAbiTags (this=this@entry=0x7ffe35f45470, ND=ND@entry=0x7f9ec0092cc8, 
    AdditionalAbiTags=AdditionalAbiTags@entry=0x7ffe35f453c0, ExcludeUnqualifiedName=ExcludeUnqualifiedName@entry=false)
    at /build/llvm-toolchain-3.8-_PD09B/llvm-toolchain-3.8-3.8/tools/clang/lib/AST/ItaniumMangle.cpp:801
#6  0x00007f9ecbe61621 in (anonymous namespace)::CXXNameMangler::mangleName (this=0x7ffe35f45470, ND=0x7f9ec0092cc8, ExcludeUnqualifiedName=<optimized out>)
    at /build/llvm-toolchain-3.8-_PD09B/llvm-toolchain-3.8-3.8/tools/clang/lib/AST/ItaniumMangle.cpp:776
#7  0x00007f9ecbe62822 in (anonymous namespace)::ItaniumMangleContextImpl::mangleCXXName (this=<optimized out>, D=0x7f9ec0092cc8, Out=...)
    at /build/llvm-toolchain-3.8-_PD09B/llvm-toolchain-3.8-3.8/tools/clang/lib/AST/ItaniumMangle.cpp:4422
#8  0x00007f9ecbd4df6b in clang_Cursor_getMangling (C=...) at /build/llvm-toolchain-3.8-_PD09B/llvm-toolchain-3.8-3.8/tools/clang/tools/libclang/CIndex.cpp:3996
#9  0x00007f9eccbd2e40 in ffi_call_unix64 () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#10 0x00007f9eccbd28ab in ffi_call () from /usr/lib/x86_64-linux-gnu/libffi.so.6

我在github上运行比特币源码的python代码,这个回溯是针对文件 src / bitcoin-cli.cpp

知道崩溃的原因吗? 谢谢,Sagi

2 个答案:

答案 0 :(得分:1)

这看起来像一个错误,正在跟踪:https://bugs.llvm.org/show_bug.cgi?id=34484

答案 1 :(得分:0)

我发现node.mangled_name导致崩溃。