Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.
Fangrui Song edited this page Jan 9, 2018 · 43 revisions

For more build instructions. And how to build on Windows, FreeBSD, OpenIndiana!

To tell cquery how to find the source tree in your project, you may create either .cquery or compile_commands.json in your project root. .cquery is easy and useful for simple projects. compile_commands.json allows for explicit specification of compilation command line for each source file.

You need to set up a language client for your editor to use definition/reference/hover/... and for some advanced cquery features some extension is needed.

Comments

Pass command line option --init='{"enableComments": true}' to cquery (VSCode:cquery.launch.args, Emacs:cquery-additional-arguments). cquery will index comments associated with functions/types/variables (macros are not handled due to clang_Cursor_getRawCommentText's peculiarity).

Certain comment markers /** /// //! are processed by default. If you want to index /* //, parse -fparse-all-comments to the clang command line.

Visual Studio Code: good Emacs: lsp-ui-doc https://github.com/emacs-lsp/lsp-ui LanguageClient-neovim: 😢 https://github.com/autozimu/LanguageClient-neovim/issues/224

Diagnostics

Dump JSON requests and responses:

sudo sysdig -As999 --unbuffered -p '%evt.type %evt.buffer' "proc.pid=$(pgrep -fn build/app) and fd.type=pipe" | egrep -v '^Content|^$'

Passing the option --log-stdin-stdout-to-stderr.

Insert volatile static int z=0;while(!z); for a poor man's breakpoint and run gdb -p $(pgrep -fn cquery) to attach to the cquery process. p z=1 for continuing.

Some issues introduce diagnostic methods:

On Linux, if --log-file reports indexer.cc:1892 WARN| Indexing /tmp/json/test/src/unit-iterators2.cpp failed with errno=1\nlibclang: crash detected during indexing TU, consider patching your libclang.so.5.0 or libclang.so.4.0 with the following commands:

% printf '\x4d' | dd of=build/release/lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5.0 obs=1 seek=$[0x47aece] conv=notrunc
% printf '\x4d' | dd of=build/release/lib/clang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.4.0 obs=1 seek=$[0x4172b5] conv=notrunc