Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

AssertionError with libclang, compilation database, and Objective-C header files. #299

Closed
alloy opened this Issue · 9 comments

2 participants

@alloy

I’ve just installed clang_complete for which I generate compile_commands.json files, which works great for all Objective-C implementation files. Thanks so much for that!

However, every header file I open results in the exception below. I’m a terrible vim and python noob, so please instruct me how I can help you further in debugging this :)

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 552, in __boots
trap_inner
    self.run()
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/libclang.py", line 433, in run
    self.timer)
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/libclang.py", line 164, in getCurrentTranslationUnit
    tu = index.parse(fileName, args, [currentFile], flags)
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/clang/cindex.py", line 1907, in parse
    self)
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/clang/cindex.py", line 2021, in from_source
    return cls(ptr, index=index)
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/clang/cindex.py", line 2053, in __init__
    ClangObject.__init__(self, ptr)
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/clang/cindex.py", line 1637, in __init__
    assert isinstance(obj, c_object_p) and obj
AssertionError
Exception ctypes.ArgumentError: "argument 1: <type 'exceptions.AttributeError'>: 'TranslationUnit' object has no a
ttribute '_as_parameter_'" in <bound method TranslationUnit.__del__ of <clang.cindex.TranslationUnit object at 0x1
02aece50>> ignored

This is with Xcode’s libclang:

$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix
let g:clang_exec="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
let g:clang_library_path="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib"

Possibly related:

@alloy

I should add that after this initial exception completion does work, but many messages like the following are printed:

line    7:
E121: Undefined variable: base
Error detected while processing function 183..185..233..155:  
@alloy

Oops, please ignore the comment, it was totally unrelated (in another plugin). I have no idea why this started to show up at the same time, but I’ve removed the other plugin and now those error messages are gone.

@Rip-Rip Rip-Rip referenced this issue from a commit
@Rip-Rip Let's try to fix #299
None is not NULL.
37c5b10
@Rip-Rip
Owner

Thanks for the report. First, g:clang_exec is now useless you can remove it, although that won't solve your problem.

Secondly, I've pushed a small change to the branch issue299. Can you try it?

@Rip-Rip Rip-Rip referenced this issue from a commit
@Rip-Rip Do not assert on 2 things at the same time.
It makes debugging and understanding what could happen in #299 harder.
34c6657
@alloy

Thanks for the quick reply. With the changes in the issue299 branch I now get the following trace:

Exception in thread Thread-5:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 552, in __boots
trap_inner
    self.run()
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/libclang.py", line 433, in run
    self.timer)
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/libclang.py", line 164, in getCurrentTranslationUnit
    tu = index.parse(fileName, args, [currentFile], flags)
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/clang/cindex.py", line 1909, in parse
    self)
  File "/Users/eloy/.vim/bundle/clang_complete/plugin/clang/cindex.py", line 2021, in from_source
    raise TranslationUnitLoadError("Error parsing translation unit.")
TranslationUnitLoadError: Error parsing translation unit.   

HTH :)

@Rip-Rip
Owner

Yet it helps :). Can you try the new code I've just pushed to the branch issue299? You won't be able to complete, but at least you won't get that backtrace. You'll got something that looks like:

Cannot parse this source file. The following arguments are used for clang ...

If you could copy/paste the message, that would be even more helpful.

@alloy

Cool, I indeed no longer get the backtrace, thanks :)

However, I’m not seeing that message and completion seems to work. Is that a good thing?

fwiw, after using completion in an implementation file first, I can complete an interface file which uses the following command:

"~/Code/ATV/UitzendingGemist/UitzendingGemist/Gemist/App/Controllers/UZGAssetsListController.h" 31L, 1043C

libclang code completion
========================
Command: clang -x objective-c -arch armv7 -fmessage-length=0 -std=gnu99 -fobjc-arc -Wno-trigraphs -fpascal-string
s -O0 -Wno-missing-field-initializers -Wmissing-prototypes -Wreturn-type -Wno-implicit-atomic-properties -Wno-rec
eiver-is-weak -Wduplicate-method-match -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -
Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown
-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-e
num-conversion -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wn
o-undeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -DBITHOCKEY_VERSION=@"3.0.0" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -fstrict-aliasing -Wp
rotocol -Wdeprecated-declarations -g -Wno-sign-conversion -miphoneos-version-min=5.1 -I/Users/eloy/Code/ATV/Uitze
ndingGemist/UitzendingGemist/DerivedData/UitzendingGemist/Build/Intermediates/UitzendingGemist.build/Debug-iphone
os/Gemist.build/Gemist.hmap -I/Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/DerivedData/UitzendingGemist
/Build/Products/Debug-iphoneos/include -IBackRow/Device/include -IBackRow/Device/include/BackRow -I/Users/eloy/Co
de/ATV/UitzendingGemist/UitzendingGemist/BackRow/Shared/include -I/Users/eloy/Code/ATV/UitzendingGemist/Uitzendin
gGemist/Pods/Headers -I/Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/Pods/Headers/AFHTTPRequestOperation
Logger -I/Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/Pods/Headers/AFNetworking -I/Users/eloy/Code/ATV/
UitzendingGemist/UitzendingGemist/Pods/Headers/HockeySDK -I/Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist
/Pods/Headers/Objective-C-HMTL-Parser -I/Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/Pods/Headers/TMCor
eData -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr
/include/libxml2 -I/Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/DerivedData/UitzendingGemist/Build/Inte
rmediates/UitzendingGemist.build/Debug-iphoneos/Gemist.build/DerivedSources/armv7 -I/Users/eloy/Code/ATV/Uitzendi
ngGemist/UitzendingGemist/DerivedData/UitzendingGemist/Build/Intermediates/UitzendingGemist.build/Debug-iphoneos/
Gemist.build/DerivedSources -F/Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/DerivedData/UitzendingGemist
/Build/Products/Debug-iphoneos -F/Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/Pods/HockeySDK/Vendor -F/
Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Libra
ry/PrivateFrameworks -include /Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/DerivedData/UitzendingGemist
/Build/Intermediates/PrecompiledHeaders/Gemist-Prefix-chifwbnqqlknhlgompgprfkwxvyt/Gemist-Prefix.pch -MMD -MT dep
endencies -MF /Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/DerivedData/UitzendingGemist/Build/Intermedi
ates/UitzendingGemist.build/Debug-iphoneos/Gemist.build/Objects-normal/armv7/UZGAppliance.d --serialize-diagnosti
cs /Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/DerivedData/UitzendingGemist/Build/Intermediates/Uitzen
dingGemist.build/Debug-iphoneos/Gemist.build/Objects-normal/armv7/UZGAppliance.dia -I/usr/include -x objective-c-
header -fsyntax-only  -Xclang -code-completion-at=/Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/Gemist/A
pp/Controllers/UZGAssetsListController.h:33:15 /Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/Gemist/App/
Controllers/UZGAssetsListController.h
cwd: /Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist
File: /Users/eloy/Code/ATV/UitzendingGemist/UitzendingGemist/Gemist/App/Controllers/UZGAssetsListController.h
Line: 33, Column: 15

[BRController

libclang code completion -                    Get TU: 0.000s (  2.5%)
libclang code completion -             Code Complete: 0.010s ( 68.4%)
libclang code completion -      Count # Results (30): 0.001s (  7.1%)
libclang code completion -                    Filter: 0.000s (  0.0%)
libclang code completion -                      Sort: 0.000s (  1.3%)
libclang code completion -                    Format: 0.002s ( 15.8%)
libclang code completion -       Load into vimscript: 0.001s (  4.9%)

Overall: 0.015 s
========================

clang_complete: completion time 0.016273
@Rip-Rip
Owner

And if you directly open an header file, do you see the error message? When opening an header after an implementation file, the command line used for the implementation file is re-used, so I'm expecting it to work :)

@alloy

Sorry, that’s what I had meant to say; I don’t get any error message anymore when opening a header file, but completion only works after opening a implementation file first (for which I understand the reason).

@Rip-Rip Rip-Rip referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@Rip-Rip Rip-Rip closed this in fbbab60
@alloy

Nice. Thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.