Skip to content

Instantly share code, notes, and snippets.

@lewis6991
Last active January 10, 2022 11:03
Show Gist options
  • Save lewis6991/043ad5d0cd9b7991b1c37a2c4a5df010 to your computer and use it in GitHub Desktop.
Save lewis6991/043ad5d0cd9b7991b1c37a2c4a5df010 to your computer and use it in GitHub Desktop.
Neovim dev notes

Clang sanitizers (ASAN and UBSAN)

ASAN/UBSAN can be used to detect memory errors and other common forms of undefined behavior at runtime in debug builds.

  • To build Neovim with sanitizers enabled, use
    rm -rf build && CMAKE_EXTRA_FLAGS="-DCMAKE_C_COMPILER=clang -DCLANG_ASAN_UBSAN=1" make
  • When running Neovim, use
    UBSAN_OPTIONS='print_stacktrace=1' nvim args...
    or
    UBSAN_OPTIONS='print_stacktrace=1' ASAN_OPTIONS=log_path=/tmp/nvim_asan nvim args...
  • To run a test:
     UBSAN_OPTIONS='print_stacktrace=1' make functionaltest TEST_FILE=...
local nvim_clint = {
method = null_ls.methods.DIAGNOSTICS,
filetypes = { "c" },
generator = null_ls.generator {
command = "./src/clint.py",
runtime_condition = required_files{'build/errors', 'src/nvim'},
args = function(params)
local ok, _, root, base = params.bufname:find('(.*)/src/nvim/(.*)')
if ok then
local suppress_file = root..'/build/errors/'..base:gsub('[/.]', '%-')..'.json'
local check_file = 'src/nvim/'..base
return {
'--suppress-errors='..suppress_file,
'--stdin-filename='..check_file,
'-'
}
end
return {
'--stdin-filename='..params.bufname,
'-'
}
end,
to_stdin = true,
check_exit_code = function(code)
return code <= 1
end,
on_output = function(params, done)
local diags = {}
for _, line in ipairs(vim.split(params.output or '', "\n")) do
local ok, _, row, msg = line:find('^[^:]*:(%d+): (.*)')
if ok then
diags[#diags+1] = {
row = row,
message = msg,
severity = 1,
source = "clint",
}
end
end
return done(diags)
end,
}
}
null_ls.setup {
sources = {
nvim_clint
}
}
local function run_nvim_test()
local name = vim.api.nvim_buf_get_name(0)
if not name:match('^.*/test/functional/.*$') then
print('Buffer is not an nvim functional test file')
return
end
local lnum = vim.fn.line('.')
local test
for i = lnum, 1, -1 do
test = vim.fn.getline(i):match("^%s*it%(['\"](.*)['\"'],")
if test then
break
end
end
if test then
vim.cmd(string.format(
'! make functionaltest TEST_FILE=%s TEST_FILTER="%s"', name, test))
else
print('Could not find test')
end
end
vim.api.nvim_add_user_command('Run_test', run_nvim_test, {
force=true,
nargs='*' -- shouldn't need this. Must be a bug.
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment