jacobdufault / cquery

C/C++ language server supporting multi-million line code base, powered by libclang. Emacs, Vim, VSCode, and others with language server protocol support. Cross references, completion, diagnostics, semantic highlighting and more
MIT License
2.35k stars 163 forks source link

Completion suggestions only works when typing <C-p> #763

Open skopaas opened 6 years ago

skopaas commented 6 years ago

Hi, I would like to have some help with cquery. I can only get completions on my c++ code if I type Ctrl+p after having written some letters. Is there a possibility to have auto completion enabled without having to type Ctrl+p? I am also not sure if I did everything accordingly to make my installation work. Any help would be greatly appreciated! Thank you.

Here are my specs: I have cquery's folder on my usb stick alongside clang in the build folder as described in the wiki. git rev-parse --short HEAD a8971e8 OS: Ubuntu 16.04.2 LTS cquery is on my usb strick: $ /media/mat/home/cquery/build/cquery --check ~/0pr/traverse.cpp

(   0.000s) [main thread  ]   command_line.cc:438   | Running --check
(   0.000s) [main thread  ]          utils.cc:298   | Reading /home/mat/0pr/traverse.cpp
(   0.001s) [main thread  ]   command_line.cc:451   | Using path /home/mat/0pr/traverse.cpp
(   0.001s) [main thread  ]        project.cc:606   | Trying to load /home/mat/0pr/build/compile_commands.json
(   0.001s) [main thread  ]        project.cc:613   | Trying to load /home/mat/0pr/compile_commands.json
(   0.001s) [main thread  ]clang_system_include_extractor.cc:76    | Using compiler drivers /usr/bin/c++, /media/ubuntu-gnome/_home/home2/cquery/build/cquery-clang, clang++, g++
(   0.006s) [main thread  ]       platform.cc:146   | Executed "/usr/bin/c++ --version"
(   0.006s) [main thread  ]clang_system_include_extractor.cc:88    | Running /usr/bin/c++ -E -x c++ - -v
(   0.018s) [main thread  ]       platform.cc:146   | Executed "/usr/bin/c++ -E -x c++ - -v"
(   0.018s) [main thread  ]clang_system_include_extractor.cc:93    | Output:
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "<stdin>"
Using built-in specs.
COLLECT_GCC=/usr/bin/c++
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-21ubuntu1~16.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-21ubuntu1~16.04) 
COLLECT_GCC_OPTIONS='-E' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/7/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE - -mtune=generic -march=x86-64 -fstack-protector-strong -Wformat -Wformat-security
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/7"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/7
 /usr/include/x86_64-linux-gnu/c++/7
 /usr/include/c++/7/backward
 /usr/lib/gcc/x86_64-linux-gnu/7/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-E' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
(   0.019s) [main thread  ]        project.cc:166   | Using system include directory flags
  -isystem/usr/include/c++/7
  -isystem/usr/include/x86_64-linux-gnu/c++/7
  -isystem/usr/include/c++/7/backward
  -isystem/usr/lib/gcc/x86_64-linux-gnu/7/include
  -isystem/usr/local/include
  -isystem/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
  -isystem/usr/include/x86_64-linux-gnu
  -isystem/usr/include
(   0.019s) [main thread  ]        project.cc:170   | To disable this set the discoverSystemIncludes config option to false.
(   0.019s) [main thread  ]          timer.cc:41    | compile_commands.json clang time took 0.76ms
(   0.019s) [main thread  ]          timer.cc:41    | compile_commands.json our time took 17.17564ms
(   0.019s) [main thread  ]   command_line.cc:461   | Using arguments /usr/bin/c++ -working-directory=/home/mat/0pr -std=gnu++14 /home/mat/0pr/traverse.cpp -Wno-unknown-warning-option -fparse-all-comments -isystem/usr/include/c++/7 -isystem/usr/include/x86_64-linux-gnu/c++/7 -isystem/usr/include/c++/7/backward -isystem/usr/lib/gcc/x86_64-linux-gnu/7/include -isystem/usr/local/include -isystem/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed -isystem/usr/include/x86_64-linux-gnu -isystem/usr/include
(   0.626s) [main thread  ]  clang_indexer.cc:2401  | Got 0 diagnostics
(   0.629s) [main thread  ]        loguru.hpp:1767  | atexit

in my project's root dir: /home/mat/0pr/settings.json

{
  "initializationOptions": {
    "cacheDirectory": "/home/mat/0pr/cache_ini"
  }
}

/home/mat/0pr/start_cquery.sh:

#!/usr/bin/env sh
/media/mat/home/cquery/build/cquery --log-file /tmp/cquery_log.txt --init='{
  "cacheDirectory": "/home/mat/0pr/cache_ini",
  "progressReportFrequencyMs": -1
}'

/home/mat/0pr/CMakeLists.txt:

cmake_minimum_required(VERSION 3.04)
project(traverse)

file(GLOB SOURCE
    traverse.cpp)

set(CMAKE_CXX_STANDARD 14)

add_executable(traverse ${SOURCE})

I did these commands in my project root: (/home/mat/0pr) (clang ++ is also on my usb stick) $/media/mat/home/cquery/build/clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-16.04/bin/clang++ -MJ traverse.o.json -Wall -std=c++14 -o traverse.o -c traverse.cpp $sed -e '1s/^/[\n/' -e '$s/,$/\n]/' *.o.json > compile_commands.json $mkdir build $cd build; cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES .. $ln -s build/compile_commands.json

compile_commands.json:

[
{
  "directory": "/home/mat/0pr",
  "command": "/usr/bin/c++       -std=gnu++14 -o CMakeFiles/traverse.dir/traverse.cpp.o -c /home/mat/0pr/traverse.cpp",
  "file": "/home/mat/0pr/traverse.cpp"
}
]

my .vimrc:

set nocompatible
call plug#begin('~/.vim/plugged')
Plug 'autozimu/LanguageClient-neovim', { 'branch': 'next', 'do':'install.sh', }
call plug#end()

let $RUST_BACKTRACE = 'full'
autocmd FileType cpp LanguageClientStart
let g:LanguageClient_loadSettings = 1 
let g:LanguageClient_settingsPath = '/home/mat/0pr/settings.json'

set completefunc=LanguageClient#complete

let g:LanguageClient_serverCommands = {
    \ 'cpp': ['/media/mat/home/cquery/build/cquery', '--log-file=/tmp/cq.log'],
    \ }
let g:LanguageClient_loggingFile = '/tmp/LanguageClient.log'
let g:LanguageClient_loggingLevel = 'INFO'
let g:LanguageClient_serverStderr = '/tmp/LanguageServer.log'

nn <silent> <M-.> :call LanguageClient_textDocument_definition()<cr>
nn <silent> <M-,> :call LanguageClient_textDocument_references()<cr>
nn <f2> :call LanguageClient_textDocument_rename()<cr>
nn <leader>ji :Denite documentSymbol<cr>
nn <leader>jI :Denite workspaceSymbol<cr>
nn ,la :call LanguageClient_workspace_symbol({'query':input('workspace/symbol ')})<cr>

nnoremap <silent> gh :call LanguageClient_textDocument_hover()<CR>
nnoremap <silent> gs :call LanguageClient_textDocument_documentSymbol()<CR>

augroup LanguageClient_config
  au!
  au BufEnter * let b:Plugin_LanguageClient_started = 0
  au User LanguageClientStarted setl signcolumn=yes
  au User LanguageClientStarted let b:Plugin_LanguageClient_started = 1
  au User LanguageClientStopped setl signcolumn=auto
  au User LanguageClientStopped let b:Plugin_LanguageClient_stopped = 0
  au CursorMoved * if b:Plugin_LanguageClient_started | call LanguageClient_textDocument_hover() | endif
augroup END

set signcolumn=yes 
set laststatus=2
set wildmenu
set t_Co=256
let base16colorspace=256
syntax on
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab

vim --version

VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug  7 2018 16:14:44)
Included patches: 1-252
Compiled by ubuntu-gnome@ubuntu-gnome
Huge version without GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static
+arabic            +farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    -tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
-balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
-browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +timers
+byte_offset       -hangul_input      +num64             +title
+channel           +iconv             +packages          -toolbar
+cindent           +insert_expand     +path_extra        +user_commands
-clientserver      +job               -perl              +vartabs
-clipboard         +jumplist          +persistent_undo   +vertsplit
+cmdline_compl     +keymap            +postscript        +virtualedit
+cmdline_hist      +lambda            +printer           +visual
+cmdline_info      +langmap           +profile           +visualextra
+comments          +libcall           +python/dyn        +viminfo
+conceal           +linebreak         +python3/dyn       +vreplace
+cryptv            +lispindent        +quickfix          +wildignore
+cscope            +listcmds          +reltime           +wildmenu
+cursorbind        +localmap          +rightleft         +windows
+cursorshape       -lua               -ruby              +writebackup
+dialog_con        +menu              +scrollbind        -X11
+diff              +mksession         +signs             -xfontset
+digraphs          +modify_fname      +smartindent       -xim
-dnd               +mouse             +startuptime       -xpm
-ebcdic            -mouseshape        +statusline        -xsmp
+emacs_tags        +mouse_dec         -sun_workshop      -xterm_clipboard
+eval              -mouse_gpm         +syntax            -xterm_save
+ex_extra          -mouse_jsbterm     +tag_binary        
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lnsl    -ldl         

~/.vim/plugged/LanguageClient-neovim/bin/languageclient --version is languageclient 0.1.106

and my log files:

cquery_log.txt

File verbosity level: 9
date       time         ( uptime  ) [ thread name/id]              file:line     v|
2018-08-08 14:06:05.327 (   0.030s) [     75E2F740]        loguru.hpp:2049     0| Logging to '/tmp/cquery_log.txt', mode: 'w', verbosity: 9
(   0.030s) [main thread  ]        loguru.hpp:1887  | arguments: /media/mat/home/cquery/build/cquery --log-file /tmp/cquery_log.txt --init={\n\ \ \"cacheDirectory\":\ \"/home/mat/0pr/cache_ini\",\n\ \ \"progressReportFrequencyMs\":\ -1\n}
(   0.030s) [main thread  ]        loguru.hpp:1890  | Current dir: /home/mat/0pr
(   0.030s) [main thread  ]        loguru.hpp:1892  | stderr verbosity: -1
(   0.030s) [main thread  ]        loguru.hpp:1893  | -----------------------------------

/tmp/LanguageServer.log:

Loguru caught a signal: SIGTERM
Stack trace:
9             0x470d59 _start + 41
8       0x7fb663c0d830 __libc_start_main + 240
7             0x465592 main + 3714
6             0x4e132f LanguageServerMain(std::string const&) + 111
5             0x4e0a0b RunQueryDbThread(std::string const&) + 2043
4       0x7fb6647ab79c std::condition_variable::wait(std::unique_lock<std::mutex>&) + 12
3       0x7fb663fc3360 pthread_cond_wait + 192
2       0x7fb663fc7390 /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390) [0x7fb663fc7390]
1       0x7fb66651bb19 /media/mat/home/cquery/build/clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/libclang.so.6(+0x1897b19) [0x7fb66651bb19]
0       0x7fb663fc7269 raise + 41
(  85.564s) [querydb      ]                  :0     | Signal: SIGTERM
2018-08-08 10:18:38.108 (   0.000s) [     5FEDA740]        loguru.hpp:2049     0| Logging to '/tmp/cq.log', mode: 'w', verbosity: 9

Loguru caught a signal: SIGTERM
Stack trace:
9             0x470d59 _start + 41
8       0x7fdf5ae1d830 __libc_start_main + 240
7             0x465592 main + 3714
6             0x4e132f LanguageServerMain(std::string const&) + 111
5             0x4e0a0b RunQueryDbThread(std::string const&) + 2043
4       0x7fdf5b9bb79c std::condition_variable::wait(std::unique_lock<std::mutex>&) + 12
3       0x7fdf5b1d3360 pthread_cond_wait + 192
2       0x7fdf5b1d7390 /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390) [0x7fdf5b1d7390]
1       0x7fdf5d72bb19 /media/mat/home/cquery/build/clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/libclang.so.6(+0x1897b19) [0x7fdf5d72bb19]
0       0x7fdf5b1d7269 raise + 41
( 655.112s) [querydb      ]                  :0     | Signal: SIGTERM
2018-08-08 10:29:34.199 (   0.000s) [     93FC0740]        loguru.hpp:2049     0| Logging to '/tmp/cq.log', mode: 'w', verbosity: 9
(   2.647s) [scan_includes]          utils.cc:192   | Unable to read file compile_commands.json when reading directory /home/mat/0pr/

Thank you

dimbleby commented 6 years ago

@ganimaedes this sounds like a question about your client setup. Seems like you're wanting help with Vim, or with the language-client plugin - and not with cquery. Right?

Suggest trying /r/vim, or the language-client repository.

skopaas commented 6 years ago

LanguageClient works very well and I have no issue with vim. My issue has more to do with cquery not being able to autocomplete.

jacobdufault commented 6 years ago

From the log file, cquery is crashing very soon after startup. Likely you'll need to open a debugger on cquery and try to determine why. I'd recommend compiling with the -DASSERTS=on -DASAN=on cmake config option.

skopaas commented 6 years ago

@jacobdufault I had to change to these to make it work for -DASSERTS and DASAN

git clone https://github.com/cquery-project/cquery.git --recursive
cd cquery
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=release \
-DASSERTS=on -DASAN=on -DCMAKE_EXPORT_COMPILE_COMMANDS=YES \
 -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=gold -DCMAKE_BUILD_TYPE=Debug
cmake --build .
cmake --build . --target install

note : i used LanguageClient-neovim v 0.1.113 start_cquery.sh file:

#!/usr/bin/env sh

$HOME/cquery/build/cquery --log-file /tmp/cquery_log.txt --log-all-to-stderr --init='{
  "cacheDirectory": "/tmp/cquery",
  "progressReportFrequencyMs": -1
}'

when I stop ./start_cquery.sh by pressing <C-d>

./start_cquery.sh 
2018-08-21 14:33:47.757 (   0.003s) [     F47867C0]        loguru.hpp:2049     0| Logging to '/tmp/cquery_log.txt', mode: 'w', verbosity: 9
( uptime  ) [ thread name/id]              file:line  | 
(   0.003s) [main thread  ]        loguru.hpp:1887  | arguments: /home/mat/cquery/build/cquery --log-file /tmp/cquery_log.txt --log-all-to-stderr --init={\n\ \ \"cacheDirectory\":\ \"/tmp/cquery\",\n\ \ \"progressReportFrequencyMs\":\ -1\n}
(   0.003s) [main thread  ]        loguru.hpp:1890  | Current dir: /home/mat/project
(   0.003s) [main thread  ]        loguru.hpp:1892  | stderr verbosity: 0
(   0.003s) [main thread  ]        loguru.hpp:1893  | -----------------------------------
Content-Length: 152

{"jsonrpc":"2.0","method":"$cquery/progress","params":{"indexRequestCount":0,"doIdMapCount":0,"onIdMappedCount":0,"onIndexedCount":0,"activeThreads":0}}(4112.207s) [stdin        ]            lsp.cc:82    | No more input when reading header
(4112.245s) [stdin        ]            lsp.cc:188   | Failed to read JsonRpc input; exiting
(4112.245s) [stdin        ]        loguru.hpp:1767  | atexit

=================================================================
==23052==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 12 byte(s) in 1 object(s) allocated from:
    #0 0x7f1ef367734f in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x6234f)
    #1 0xe82b1f in loguru::set_thread_name(char const*) /home/mat/cquery/third_party/loguru/loguru.hpp:2141
    #2 0xe804e5 in loguru::init(int&, char**, char const*) /home/mat/cquery/third_party/loguru/loguru.hpp:1857
    #3 0xa4216b in main /home/mat/cquery/src/command_line.cc:420
    #4 0x7f1eeda3a82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f1ef36ae592 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99592)
    #1 0xedbf7b in WorkThread::StartThread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) /home/mat/cquery/src/work_thread.cc:11
    #2 0x94dcec in ClangCompleteManager::ClangCompleteManager(Project*, WorkingFiles*, std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<lsDiagnostic, std::allocator<lsDiagnostic> >)>, std::function<void (lsRequestId)>) /home/mat/cquery/src/clang_complete.cc:717
    #3 0xa3ea36 in RunQueryDbThread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/mat/cquery/src/command_line.cc:228
    #4 0xa413d8 in LanguageServerMain(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/mat/cquery/src/command_line.cc:379
    #5 0xa43ae7 in main /home/mat/cquery/src/command_line.cc:506
    #6 0x7f1eeda3a82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f1ef36ae592 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99592)
    #1 0xedbf7b in WorkThread::StartThread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) /home/mat/cquery/src/work_thread.cc:11
    #2 0xa411f4 in LaunchStdoutThread(std::unordered_map<char const*, Timer, std::hash<char const*>, std::equal_to<char const*>, std::allocator<std::pair<char const* const, Timer> > >*) /home/mat/cquery/src/command_line.cc:365
    #3 0xa413a0 in LanguageServerMain(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/mat/cquery/src/command_line.cc:375
    #4 0xa43ae7 in main /home/mat/cquery/src/command_line.cc:506
    #5 0x7f1eeda3a82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f1ef36ae592 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99592)
    #1 0xedbf7b in WorkThread::StartThread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) /home/mat/cquery/src/work_thread.cc:11
    #2 0xa40bfd in LaunchStdinLoop(std::unordered_map<char const*, Timer, std::hash<char const*>, std::equal_to<char const*>, std::allocator<std::pair<char const* const, Timer> > >*) /home/mat/cquery/src/command_line.cc:345
    #3 0xa41394 in LanguageServerMain(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/mat/cquery/src/command_line.cc:371
    #4 0xa43ae7 in main /home/mat/cquery/src/command_line.cc:506
    #5 0x7f1eeda3a82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f1ef36ae592 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99592)
    #1 0xedbf7b in WorkThread::StartThread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) /home/mat/cquery/src/work_thread.cc:11
    #2 0x94ddac in ClangCompleteManager::ClangCompleteManager(Project*, WorkingFiles*, std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<lsDiagnostic, std::allocator<lsDiagnostic> >)>, std::function<void (lsRequestId)>) /home/mat/cquery/src/clang_complete.cc:719
    #3 0xa3ea36 in RunQueryDbThread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/mat/cquery/src/command_line.cc:228
    #4 0xa413d8 in LanguageServerMain(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/mat/cquery/src/command_line.cc:379
    #5 0xa43ae7 in main /home/mat/cquery/src/command_line.cc:506
    #6 0x7f1eeda3a82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f1ef36ae592 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99592)
    #1 0xedbf7b in WorkThread::StartThread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) /home/mat/cquery/src/work_thread.cc:11
    #2 0x94de66 in ClangCompleteManager::ClangCompleteManager(Project*, WorkingFiles*, std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<lsDiagnostic, std::allocator<lsDiagnostic> >)>, std::function<void (lsRequestId)>) /home/mat/cquery/src/clang_complete.cc:720
    #3 0xa3ea36 in RunQueryDbThread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/mat/cquery/src/command_line.cc:228
    #4 0xa413d8 in LanguageServerMain(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/mat/cquery/src/command_line.cc:379
    #5 0xa43ae7 in main /home/mat/cquery/src/command_line.cc:506
    #6 0x7f1eeda3a82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: 52 byte(s) leaked in 6 allocation(s).

and here's the LanguageServer.log file:

2018-08-21 19:27:31.528 (   0.001s) [     A0C107C0]        loguru.hpp:2049     0| Logging to '/tmp/cq.log', mode: 'w', verbosity: 9
=================================================================
==24229==ERROR: AddressSanitizer: heap-use-after-free on address 0x60700000cb50 at pc 0x000000e862e2 bp 0x7f81943dd9f0 sp 0x7f81943dd9e0
READ of size 4 at 0x60700000cb50 thread T7 (indexer1)

Loguru caught a signal: SIGTERM
    #0 0xe862e1 in log_message /home/mat/cquery/third_party/loguru/loguru.hpp:2499
    #1 0xe869f2 in loguru::log_to_everywhere(int, int, char const*, unsigned int, char const*, char const*) /home/mat/cquery/third_party/loguru/loguru.hpp:2549
    #2 0xe86bf7 in loguru::log(int, char const*, unsigned int, char const*, ...) /home/mat/cquery/third_party/loguru/loguru.hpp:2572
    #3 0xe8897f in loguru::StreamLogger::~StreamLogger() /home/mat/cquery/third_party/loguru/loguru.hpp:2688
    #4 0xac81b7 in ComputeChangeStatus /home/mat/cquery/src/import_pipeline.cc:163
    #5 0xac8d9b in TryLoadFromCache /home/mat/cquery/src/import_pipeline.cc:199
    #6 0xaca370 in ParseFile /home/mat/cquery/src/import_pipeline.cc:305
    #7 0xacc7ef in IndexMain_DoParse /home/mat/cquery/src/import_pipeline.cc:422
    #8 0xacddea in Indexer_Main(DiagnosticsEngine*, FileConsumerSharedState*, TimestampManager*, ImportManager*, ImportPipelineStatus*, Project*, WorkingFiles*) /home/mat/cquery/src/import_pipeline.cc:528
    #9 0xf61d41 in (anonymous namespace)::Handler_Initialize::Run((anonymous namespace)::In_InitializeRequest*)::{lambda()#1}::operator()() const (/home/mat/cquery/build/cquery+0xf61d41)
    #10 0xf6782e in _M_invoke /usr/include/c++/5/functional:1871
    #11 0xa3bcd3 in std::function<void ()>::operator()() const /usr/include/c++/5/functional:2267
    #12 0xedbd9e in WorkThread::StartThread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>)::{lambda()#1}::operator()() const (/home/mat/cquery/build/cquery+0xedbd9e)
    #13 0xedf7d4 in _M_invoke<> /usr/include/c++/5/functional:1531
    #14 0xedf49d in operator() /usr/include/c++/5/functional:1520
    #15 0xedf3b8 in _M_run /usr/include/c++/5/thread:115
    #16 0x7f819b78b8ef  (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xbd8ef)
    #17 0x7f819a2756b9 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x76b9)
    #18 0x7f8199fab41c in clone (/lib/x86_64-linux-gnu/libc.so.6+0x10741c)

0x60700000cb50 is located 48 bytes inside of 80-byte region [0x60700000cb20,0x60700000cb70)
freed by thread T0 (querydb) here:
    #0 0x7f819fb38b8a in operator delete(void*) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99b8a)
    #1 0xeb2a03 in __gnu_cxx::new_allocator<loguru::Callback>::deallocate(loguru::Callback*, unsigned long) /usr/include/c++/5/ext/new_allocator.h:110
    #2 0xeb053b in std::allocator_traits<std::allocator<loguru::Callback> >::deallocate(std::allocator<loguru::Callback>&, loguru::Callback*, unsigned long) /usr/include/c++/5/bits/alloc_traits.h:517
    #3 0xeabe7c in std::_Vector_base<loguru::Callback, std::allocator<loguru::Callback> >::_M_deallocate(loguru::Callback*, unsigned long) /usr/include/c++/5/bits/stl_vector.h:178
    #4 0xea32cc in std::_Vector_base<loguru::Callback, std::allocator<loguru::Callback> >::~_Vector_base() /usr/include/c++/5/bits/stl_vector.h:160
    #5 0xeb6ad6 in std::vector<loguru::Callback, std::allocator<loguru::Callback> >::~vector() /usr/include/c++/5/bits/stl_vector.h:425
    #6 0x7f8199eddff7  (/lib/x86_64-linux-gnu/libc.so.6+0x39ff7)

previously allocated by thread T0 (querydb) here:
    #0 0x7f819fb38592 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99592)
    #1 0xeb41a0 in __gnu_cxx::new_allocator<loguru::Callback>::allocate(unsigned long, void const*) /usr/include/c++/5/ext/new_allocator.h:104
    #2 0xeb2aa8 in std::allocator_traits<std::allocator<loguru::Callback> >::allocate(std::allocator<loguru::Callback>&, unsigned long) /usr/include/c++/5/bits/alloc_traits.h:491
    #3 0xeb0d08 in std::_Vector_base<loguru::Callback, std::allocator<loguru::Callback> >::_M_allocate(unsigned long) /usr/include/c++/5/bits/stl_vector.h:170
    #4 0xeabfa4 in void std::vector<loguru::Callback, std::allocator<loguru::Callback> >::_M_emplace_back_aux<loguru::Callback>(loguru::Callback&&) /usr/include/c++/5/bits/vector.tcc:412
    #5 0xea3715 in void std::vector<loguru::Callback, std::allocator<loguru::Callback> >::emplace_back<loguru::Callback>(loguru::Callback&&) /usr/include/c++/5/bits/vector.tcc:101
    #6 0xe9a1da in std::vector<loguru::Callback, std::allocator<loguru::Callback> >::push_back(loguru::Callback&&) /usr/include/c++/5/bits/stl_vector.h:932
    #7 0xe8224e in loguru::add_callback(char const*, void (*)(void*, loguru::Message const&), void*, int, void (*)(void*), void (*)(void*)) /home/mat/cquery/third_party/loguru/loguru.hpp:2091
    #8 0xe81a83 in loguru::add_file(char const*, loguru::FileMode, int) /home/mat/cquery/third_party/loguru/loguru.hpp:2029
    #9 0xa41b7f in main /home/mat/cquery/src/command_line.cc:399
    #10 0x7f8199ec482f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Thread T7 (indexer1) created by T0 (querydb) here:
    #0 0x7f819fad51e3 in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x361e3)
    #1 0x7f819b78ba03 in std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)()) (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xbda03)

SUMMARY: AddressSanitizer: heap-use-after-free /home/mat/cquery/third_party/loguru/loguru.hpp:2499 log_message
Shadow bytes around the buggy address:
  0x0c0e7fff9910: 00 00 00 00 00 00 00 00 00 00 fa fa fa fa 00 00
  0x0c0e7fff9920: 00 00 00 00 00 00 00 00 fa fa fa fa 00 00 00 00
  0x0c0e7fff9930: 00 00 00 00 00 00 fa fa fa fa 00 00 00 00 00 00
  0x0c0e7fff9940: 00 00 00 00 fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c0e7fff9950: 00 00 fa fa fa fa 00 00 00 00 00 00 00 00 00 00
=>0x0c0e7fff9960: fa fa fa fa fd fd fd fd fd fd[fd]fd fd fd fa fa
  0x0c0e7fff9970: fa fa 00 00 00 00 00 00 00 00 00 00 fa fa fa fa
  0x0c0e7fff9980: 00 00 00 00 00 00 00 00 00 00 fa fa fa fa 00 00
  0x0c0e7fff9990: 00 00 00 00 00 00 00 00 fa fa fa fa 00 00 00 00
  0x0c0e7fff99a0: 00 00 00 00 00 00 fa fa fa fa 00 00 00 00 00 00
  0x0c0e7fff99b0: 00 00 00 00 fa fa fa fa 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
==24229==ABORTING

Thank you

jacobdufault commented 6 years ago

Does cquery/asan show any errors when you run using vim? Pressing ctrl+d when running cquery directly will cause cquery to exit; it probably shouldn't do so via a crash, but I don't think that this is the cause of the completion problem.

skopaas commented 6 years ago

@jacobdufault cquery/asan do not show any errors when running vim. I think i've found an error: i have executed this command echo "export PATH=$PATH:~/cquery/build/cquery" >> ~/.bashrc when it should have been echo "export PATH=$PATH:~/cquery/build/" >> ~/.bashrc but i'm not sure if the latter is the correct one?? This however, still doesn't solve the completion.