1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
local workspace_folder = vim.fn.getcwd()
local function safe_require(module)
local ok, mod = pcall(require, module)
if not ok then return nil end
return mod
end
-- C++
local default_clangd_config = vim.deepcopy(vim.lsp.config["clangd"]) or {}
default_clangd_config.cmd = {
"clangd",
"--background-index",
"--clang-tidy",
"--header-insertion=iwyu",
"--completion-style=detailed",
string.format("--compile-commands-dir=%s/build", workspace_folder),
"--query-driver=**/x86_64-pc-elf-g++"
}
vim.lsp.config("clangd", default_clangd_config)
vim.filetype.add({
pattern = {
[".*/kstd/include/kstd/.*"] = "cpp",
}
})
-- Debugging
local dap = require("dap")
local qemu_job = nil
dap.adapters.teachos_qemu_mi = function(callback, config)
if qemu_job then
qemu_job:kill(9)
end
local artifact_path = config.program
if not artifact_path then
vim.notify("Fatal: No artifact path resolved by CMake", vim.log.levels.ERROR)
return
end
local elf_path = string.gsub(artifact_path, "%.sym$", ".elf")
qemu_job = vim.system({
"qemu-system-x86_64",
"-kernel", elf_path,
"-s", "-S",
"-nographic"
}, { text = true })
vim.defer_fn(function()
callback({
type = "executable",
command = vim.fn.stdpath("data") .. "/mason/bin/OpenDebugAD7",
})
end, 500)
end
dap.listeners.after.event_terminated["teachos_qemu_teardown"] = function()
if qemu_job then
qemu_job:kill(9)
qemu_job = nil
end
end
require("cmake-tools").setup({
cmake_dap_configuration = {
name = "(gdb) QEMU MI Attach",
type = "teachos_qemu_mi",
request = "launch",
miDebuggerServerAddress = "localhost:1234",
miDebuggerPath = "x86_64-pc-elf-gdb",
stopAtEntry = true,
}
})
|