Skip to content

Commit 1f6056b

Browse files
committed
nvim-gdb persistent bps
1 parent fb4a6af commit 1f6056b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

gdbinit

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set print pretty on
44
# 保存gdb历史命令
55
set history save on
66

7-
87
# 开启log
98
set logging file ./gdb.log
109
set logging on
@@ -14,7 +13,8 @@ set logging on
1413
# macos 防卡住
1514
# set startup-with-shell off
1615

17-
# 退出gdb无提示
16+
# 退出gdb quit
1817
define hook-quit
1918
set confirm off
19+
save breakpoints bps.txt
2020
end

nvim/lua/user/conf/nvimgdb.lua

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- NOTE: nvimgdb 依赖 gdb with python support
22
-- 检查方式为: gdb --config
33
-- 输出类似如下:
4-
--with-python=/usr
5-
--with-python-libdir=/usr/lib
4+
--with-python=/usr
5+
--with-python-libdir=/usr/lib
66

77
-- 如果不支持python, 需要从源码编译gdb:
88
-- 1. 下载gdb源码: https://ftp.gnu.org/gnu/gdb/, 并解压
@@ -14,6 +14,7 @@
1414
vim.cmd([[
1515
let g:nvimgdb_disable_start_keymaps = 1
1616
let g:nvimgdb_use_find_executables = 0
17+
let g:nvimgdb_use_cmake_to_find_executables = 0
1718
let g:nvimgdb_config_override = {
1819
\ 'key_next': ';n',
1920
\ 'key_step': ';s',
@@ -24,6 +25,16 @@ vim.cmd([[
2425
\ }
2526
]])
2627

27-
vim.cmd([[
28-
nnoremap <silent> <expr> <leader>dd ":GdbStart gdb -q " . input("debugee file path: ") . "\<ESC>"
29-
]])
28+
-- vim.cmd([[
29+
-- nnoremap <silent> <expr> <leader>dd ":GdbStart gdb -q " . input("debugee file path: ") . "\<ESC>"
30+
-- ]])
31+
32+
_G.StartGdbSession = function()
33+
local exec_file = vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
34+
vim.api.nvim_command(":GdbStart gdb -q " .. exec_file)
35+
vim.defer_fn(function()
36+
vim.api.nvim_command(":Gdb source bps.txt")
37+
end, 300)
38+
end
39+
40+
vim.api.nvim_set_keymap("n", "<leader>dd", "<cmd>lua StartGdbSession()<cr>", {})

0 commit comments

Comments
 (0)