JCWasmx86 / mesonlsp

An unofficial, unendorsed language server for meson written in C++
GNU General Public License v3.0
59 stars 8 forks source link

segfault at startup #135

Closed qtyra closed 3 weeks ago

qtyra commented 3 weeks ago

Describe the bug

mesonlsp segfaults at startup when a meson.build file lacks a project call at the top and there is some other statement.

Steps To Reproduce

  1. Run mkdir /tmp/testlsp && cd /tmp/testlsp and copy this on minimal_init.lua:
    
    vim.env.LAZY_STDPATH = ".repro"
    load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({ spec = { { "williamboman/mason-lspconfig.nvim", dependencies = { "williamboman/mason.nvim", opts = {} }, opts = { ensure_installed = { "mesonlsp" }, handlers = { mesonlsp = function() require("lspconfig")["mesonlsp"].setup({ capabilities = vim.lsp.protocol.make_client_capabilities(), }) end, }, }, }, { "neovim/nvim-lspconfig", config = function() vim.lsp.set_log_level("trace") require("vim.lsp.log").set_format_func(vim.inspect) end, }, }, })


2. Copy this in `meson.build`:

gtkdep = dependency('gtk+-3.0')


3. Run `nvim --clean -u minimal_init.lua meson.build`, wait a few seconds until mesonlsp is installed (a message will appear at the bottom).
4. Load the file with `:e` and get the error: `Client mesonlsp quit with exit code 0 and signal 11. Check log for errors: ...`

**Expected behavior**

Get `Missing project() call at the top of file` as normal.

**System info**
 - OS: Arch linux
 - Editor: Neovim
 - Version: NVIM v0.10.1

**Additional context**

last two messages of lsp log (github doesn't allow me to send the full message):

[ INFO ] analyze::mesontree - ../src/libanalyze/mesontree.cpp:121: Using custom parser for /tmp/testlsp/meson.build \n" [INFO][2024-08-30 08:47:22] .../lua/vim/lsp.lua:799 "exit_handler" {}


gdb stacktrace:

0 0x00000000004f71cf in std::__shared_ptr<Node, (__gnu_cxx::_Lock_policy)2>::get (this=) at /usr/include/c++/13.2.1/bits/shared_ptr_base.h:1666

1 FunctionExpression::functionName[abi:cxx11]() const (this=) at ../src/libast/node.hpp:445

2 getSubprojectBaseDir (tree=: ) at ../src/libanalyze/subprojects/subprojectstate.cpp:40

3 SubprojectState::findSubprojects (this=0x7d79962c4118, downloadSubprojects=0x1, tree=) at ../src/libanalyze/subprojects/subprojectstate.cpp:67

4 0x00000000004e3692 in SubprojectState::fullSetup (tree=0x7d79962c4010, useCustomParser=0x1, downloadSubprojects=, ns=..., parentIdentifier=..., depth=0x1, options=..., this=0x7d79962c4118) at ../src/libanalyze/subprojects/subprojectstate.hpp:57

5 MesonTree::fullParse (this=0x7d79962c4010, analysisOptions=..., downloadSubprojects=) at ../src/libanalyze/mesontree.hpp:50

6 0x00000000006c6187 in Workspace::parse[abi:cxx11](TypeNamespace const&) (this=0x7d79962b8010, ns=...) at ../src/liblangserver/workspace.cpp:496

7 0x00000000006ad3f7 in LanguageServer::initialize (this=0x7d7996a2a510, params=...) at ../src/liblangserver/langserver.cpp:236

8 0x000000000071045d in AbstractLanguageServer::handleRequest (this=0x7d7996a2a510, method=..., callId=..., params=...) at ../src/libls/ls.cpp:83

9 0x0000000000695ff9 in std::invoke_impl<void, void (jsonrpc::JsonRpcHandler::*)(std::__cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >), std::shared_ptr, std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > > > (f=, t=...) at /usr/include/c++/13.2.1/bits/invoke.h:74

10 std::invoke<void (jsonrpc::JsonRpcHandler::*)(std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >), std::shared_ptr, std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > > > (fn=) at /usr/include/c++/13.2.1/bits/invoke.h:96

11 std::thread::_Invoker<std::tuple<void (jsonrpc::JsonRpcHandler::*)(std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >), std::shared_ptr, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > > > >::_M_invoke<0ul, 1ul, 2ul, 3ul, 4ul> (this=) at /usr/include/c++/13.2.1/bits/std_thread.h:292

12 std::thread::_Invoker<std::tuple<void (jsonrpc::JsonRpcHandler::*)(std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >), std::shared_ptr, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > > > >::operator() (this=) at /usr/include/c++/13.2.1/bits/std_thread.h:299

13 std::future_base::_Task_setter<std::unique_ptr<std::future_base::_Result, std::future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<void (jsonrpc::JsonRpcHandler::*)(std::__cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >), std::shared_ptr, std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > > > >, void>::operator() (this=) at /usr/include/c++/13.2.1/future:1432

14 std::invoke_impl<std::unique_ptr<std::future_base::_Result, std::future_base::_Result_base::_Deleter>, std::future_base::_Task_setter<std::unique_ptr<std::future_base::_Result, std::future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<void (jsonrpc::JsonRpcHandler::*)(std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >), std::shared_ptr, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > > > >, void>&> (__f=...) at /usr/include/c++/13.2.1/bits/invoke.h:61

15 std::invoke_r<std::unique_ptr<std::future_base::_Result_base, std::future_base::_Result_base::_Deleter>, std::future_base::_Task_setter<std::unique_ptr<std::future_base::_Result, std::future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<void (jsonrpc::JsonRpcHandler::*)(std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >), std::shared_ptr, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > > > >, void>&> (__fn=...) at /usr/include/c++/13.2.1/bits/invoke.h:116

16 std::_Function_handler<std::unique_ptr<std::future_base::_Result_base, std::future_base::_Result_base::_Deleter>(), std::future_base::_Task_setter<std::unique_ptr<std::future_base::_Result, std::future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<void (jsonrpc::JsonRpcHandler::*)(std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >), std::shared_ptr, std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > > > >, void> >::_M_invoke (functor=...) at /usr/include/c++/13.2.1/bits/std_function.h:291

17 0x000000000068b325 in std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()>::operator() (this=) at /usr/include/c++/13.2.1/bits/std_function.h:591

18 std::future_base::_State_baseV2::_M_do_set (this=0x7d7996b57f90, f=, __did_set=0x7d7996e3ef57) at /usr/include/c++/13.2.1/future:589

19 0x0000000000d0391e in pthread_once_full (init=0xc900a0 <once_proxy>, control=0x7d7996b57fa8) at src/thread/pthread_once.c:22

20 pthread_once_full (control=0x7d7996b57fa8, init=0xc900a0 <once_proxy>) at src/thread/pthread_once.c:11

21 0x00000000006949a7 in __gthread_once (func=, once=) at /usr/include/c++/13.2.1/x86_64-alpine-linux-musl/bits/gthr-default.h:700

22 std::call_once<void (std::future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::future_base::_Result_base, std::future_base::_Result_base::_Deleter>()>, bool), std::future_base::_State_baseV2, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()>, bool> (f=@0x7d7996e3ef70: (void (std::future_base::_State_baseV2::)(std::future_base::_State_baseV2 * const, std::function<std::unique_ptr<std::future_base::_Result_base, std::future_base::_Result_base::_Deleter>()> , bool )) 0x68b2f0 <std::future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::future_base::_Result_base::_Deleter> ()>, bool)>, once=...) at /usr/include/c++/13.2.1/mutex:907

23 std::future_base::_State_baseV2::_M_set_result (ignore_failure=0x0, __res=..., this=) at /usr/include/c++/13.2.1/future:428

24 std::future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<void (jsonrpc::JsonRpcHandler::*)(std::__cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >), std::shared_ptr, std::cxx11::basic_string<char, std::char_traits, std::allocator >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator > > > >, void>::_M_run (this=0x7d7996b57f90) at /usr/include/c++/13.2.1/future:1774

25 0x0000000000ca4f6f in execute_native_thread_routine ()

26 0x0000000000d02838 in start (p=0x7d7996e3f048) at src/thread/pthread_create.c:207

27 0x0000000000d03d53 in __clone () at src/thread/x86_64/clone.s:22

Backtrace stopped: frame did not save the PC quit

JCWasmx86 commented 3 weeks ago

Thanks, I'm currently away from my laptop, but I will fix it tomorrow

JCWasmx86 commented 3 weeks ago

It will be fixed in the next release (BTW thanks for this great issue description with nice reproduceable example and a backtrace)