pipsqueaker117
pipsqueaker117

Reputation: 2366

Debugging C++ language server errors: Invalid AST

I've got a C++ project in which I can open up any .cpp or .h, and the LSP will crash/fail (I'm using emacs with lsp-mode).

For instance if I try to open a file called IDictionary.h, clangd will fail with the following errors in the clangd::stderr buffer

I[17:33:37.200] BeginSourceFile() failed when building AST for /home/anlsh/work/horizon-runtime/src/prod/data/IDictionary.h
I[17:33:37.246] <-- textDocument/documentHighlight(103)
I[17:33:37.246] --> reply:textDocument/documentHighlight(103) 0 ms, error: invalid AST

ccls also fails (exits with signal), though its error messages aren't helpful either

17:36:44 indexer6          indexer.cc:1302 E failed to index /home/anlsh/work/horizon-runtime/src/prod/data/IDictionary.h
/snap/ccls/48/bin/../usr/lib/x86_64-linux-gnu/libLLVM-7.so.1(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x2a)[0x7f2301010e8a]
/snap/ccls/48/bin/../usr/lib/x86_64-linux-gnu/libLLVM-7.so.1(_ZN4llvm3sys17RunSignalHandlersEv+0x34)[0x7f230100f544]
/snap/ccls/48/bin/../usr/lib/x86_64-linux-gnu/libLLVM-7.so.1(+0x907682)[0x7f230100f682]
/snap/core18/current/lib/x86_64-linux-gnu/libpthread.so.0(+0x128a0)[0x7f22fff5a8a0]
/snap/ccls/48/bin/ccls(+0x24ae87)[0x5564df56ee87]
/snap/core18/current/lib/x86_64-linux-gnu/libpthread.so.0(+0x76db)[0x7f22fff4f6db]
/snap/core18/current/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7f22ffc78a3f]

Anyways, this happens for every single file in the project, even ones as simple as

#include "stdafx.h"
using namespace Api;

My assumption was that some file being pulled in by the build/compile_commands.json is screwing everything up, but I can't be sure. VSCode (which I assume is using an LSP, though I know it has its own tricks) doesn't have any issues on my project at all.

Anyways, I was hoping that someone could point me towards some more detailed clangd or ccls logs, and maybe some commands which could get me some more informative error messages or validate files in my project

Upvotes: 3

Views: 3292

Answers (1)

pipsqueaker117
pipsqueaker117

Reputation: 2366

The issue appears to be fixed on the latest versions of clangd (11.0) and ccls (0.20190823.6-26-g141aea8a)

Sam McCall over on the LLVM discord also had this to say

You can get a bit more info by adding -log=verbose to the clangd args, and providing more of the log (things that might be relevant include version, path, preamble build, ...). I don't know much about windows stdafx, but I understand it pulls in a lot of stuff, some of which may have tickled a bug in that version.

Upvotes: 3

Related Questions