From c9a431c7638ecebb6f2cb3eabd0e1b2b5e269c1e Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Mon, 23 May 2022 21:49:41 +0100 Subject: patch 8.2.5010: the terminal debugger uses various global variables Problem: The terminal debugger uses various global variables. Solution: Add a dictionary to hold the terminal debugger preferences. --- .../pack/dist/opt/termdebug/plugin/termdebug.vim | 123 +++++++++++++++------ 1 file changed, 88 insertions(+), 35 deletions(-) (limited to 'runtime/pack') diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim index a5aa5a7ad9..a9acbb2717 100644 --- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim +++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @@ -2,7 +2,7 @@ " " Author: Bram Moolenaar " Copyright: Vim license applies, see ":help license" -" Last Change: 2022 May 09 +" Last Change: 2022 May 23 " " WORK IN PROGRESS - The basics works stable, more to come " Note: In general you need at least GDB 7.12 because this provides the @@ -65,11 +65,6 @@ set cpo&vim command -nargs=* -complete=file -bang Termdebug call s:StartDebug(0, ) command -nargs=+ -complete=file -bang TermdebugCommand call s:StartDebugCommand(0, ) -" Name of the gdb command, defaults to "gdb". -if !exists('g:termdebugger') - let g:termdebugger = 'gdb' -endif - let s:pc_id = 12 let s:asm_id = 13 let s:break_id = 14 " breakpoint number is added to this @@ -99,8 +94,17 @@ call s:Highlight(1, '', &background) hi default debugBreakpoint term=reverse ctermbg=red guibg=red hi default debugBreakpointDisabled term=reverse ctermbg=gray guibg=gray +" Get the command to execute the debugger as a list, defaults to ["gdb"]. func s:GetCommand() - return type(g:termdebugger) == v:t_list ? copy(g:termdebugger) : [g:termdebugger] + if exists('g:termdebug_config') + let cmd = get(g:termdebug_config, 'command', 'gdb') + elseif exists('g:termdebugger') + let cmd = g:termdebugger + else + let cmd = 'gdb' + endif + + return type(cmd) == v:t_list ? copy(cmd) : [cmd] endfunc func s:StartDebug(bang, ...) @@ -144,10 +148,16 @@ func s:StartDebug_internal(dict) let s:save_columns = 0 let s:allleft = 0 - if exists('g:termdebug_wide') - if &columns < g:termdebug_wide + let wide = 0 + if exists('g:termdebug_config') + let wide = get(g:termdebug_config, 'wide', 0) + elseif exists('g:termdebug_wide') + let wide = g:termdebug_wide + endif + if wide > 0 + if &columns < wide let s:save_columns = &columns - let &columns = g:termdebug_wide + let &columns = wide " If we make the Vim window wider, use the whole left half for the debug " windows. let s:allleft = 1 @@ -158,7 +168,12 @@ func s:StartDebug_internal(dict) endif " Override using a terminal window by setting g:termdebug_use_prompt to 1. - let use_prompt = exists('g:termdebug_use_prompt') && g:termdebug_use_prompt + let use_prompt = 0 + if exists('g:termdebug_config') + let use_prompt = get(g:termdebug_config, 'use_prompt', 0) + elseif exists('g:termdebug_use_prompt') + let use_prompt = g:termdebug_use_prompt + endif if has('terminal') && !has('win32') && !use_prompt let s:way = 'terminal' else @@ -171,12 +186,10 @@ func s:StartDebug_internal(dict) call s:StartDebug_term(a:dict) endif - if exists('g:termdebug_disasm_window') - if g:termdebug_disasm_window - let curwinid = win_getid(winnr()) - call s:GotoAsmwinOrCreateIt() - call win_gotoid(curwinid) - endif + if s:GetDisasmWindow() + let curwinid = win_getid(winnr()) + call s:GotoAsmwinOrCreateIt() + call win_gotoid(curwinid) endif if exists('#User#TermdebugStartPost') @@ -240,18 +253,28 @@ func s:StartDebug_term(dict) let proc_args = get(a:dict, 'proc_args', []) let gdb_cmd = s:GetCommand() - " Add -quiet to avoid the intro message causing a hit-enter prompt. - let gdb_cmd += ['-quiet'] - " Disable pagination, it causes everything to stop at the gdb - let gdb_cmd += ['-iex', 'set pagination off'] - " Interpret commands while the target is running. This should usually only - " be exec-interrupt, since many commands don't work properly while the - " target is running (so execute during startup). - let gdb_cmd += ['-iex', 'set mi-async on'] - " Open a terminal window to run the debugger. - let gdb_cmd += ['-tty', pty] - " Command executed _after_ startup is done, provides us with the necessary feedback - let gdb_cmd += ['-ex', 'echo startupdone\n'] + + if exists('g:termdebug_config') && has_key(g:termdebug_config, 'command_add_args') + let gdb_cmd = g:termdebug_config.command_add_args(gdb_cmd, pty) + else + " Add -quiet to avoid the intro message causing a hit-enter prompt. + let gdb_cmd += ['-quiet'] + " Disable pagination, it causes everything to stop at the gdb + let gdb_cmd += ['-iex', 'set pagination off'] + " Interpret commands while the target is running. This should usually only + " be exec-interrupt, since many commands don't work properly while the + " target is running (so execute during startup). + let gdb_cmd += ['-iex', 'set mi-async on'] + " Open a terminal window to run the debugger. + let gdb_cmd += ['-tty', pty] + " Command executed _after_ startup is done, provides us with the necessary + " feedback + let gdb_cmd += ['-ex', 'echo startupdone\n'] + endif + + if exists('g:termdebug_config') && has_key(g:termdebug_config, 'command_filter') + let gdb_cmd = g:termdebug_config.command_filter(gdb_cmd) + endif " Adding arguments requested by the user let gdb_cmd += gdb_args @@ -855,7 +878,13 @@ func s:InstallCommands() command Asm call s:GotoAsmwinOrCreateIt() command Winbar call s:InstallWinbar() - if !exists('g:termdebug_map_K') || g:termdebug_map_K + let map = 1 + if exists('g:termdebug_config') + let map = get(g:termdebug_config, 'map_K', 1) + elseif exists('g:termdebug_map_K') + let map = g:termdebug_map_K + endif + if map let s:k_map_saved = maparg('K', 'n', 0, 1) nnoremap K :Evaluate endif @@ -863,7 +892,13 @@ func s:InstallCommands() if has('menu') && &mouse != '' call s:InstallWinbar() - if !exists('g:termdebug_popup') || g:termdebug_popup != 0 + let popup = 1 + if exists('g:termdebug_config') + let popup = get(g:termdebug_config, 'popup', 1) + elseif exists('g:termdebug_popup') + let popup = g:termdebug_popup + endif + if popup let s:saved_mousemodel = &mousemodel let &mousemodel = 'popup_setpos' an 1.200 PopUp.-SEP3- @@ -1183,6 +1218,26 @@ func s:GotoSourcewinOrCreateIt() endif endfunc +func s:GetDisasmWindow() + if exists('g:termdebug_config') + return get(g:termdebug_config, 'disasm_window', 0) + endif + if exists('g:termdebug_disasm_window') + return g:termdebug_disasm_window + endif + return 0 +endfunc + +func s:GetDisasmWindowHeight() + if exists('g:termdebug_config') + return get(g:termdebug_config, 'disasm_window_height', 0) + endif + if exists('g:termdebug_disasm_window') && g:termdebug_disasm_window > 1 + return g:termdebug_disasm_window + endif + return 0 +endfunc + func s:GotoAsmwinOrCreateIt() if !win_gotoid(s:asmwin) if win_gotoid(s:sourcewin) @@ -1206,10 +1261,8 @@ func s:GotoAsmwinOrCreateIt() exe 'file Termdebug-asm-listing' endif - if exists('g:termdebug_disasm_window') - if g:termdebug_disasm_window > 1 - exe 'resize ' . g:termdebug_disasm_window - endif + if s:GetDisasmWindowHeight() > 0 + exe 'resize ' .. s:GetDisasmWindowHeight() endif endif -- cgit v1.2.3