Merge pull request #18738 from zeertzjq/vim-8.2.5010

vim-patch:8.2.5010: the terminal debugger uses various global variables
This commit is contained in:
zeertzjq 2022-05-26 08:08:35 +08:00 committed by GitHub
commit f246a929e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 127 additions and 52 deletions

View File

@ -304,7 +304,7 @@ breakpoint, or use the "Clear breakpoint" right-click menu entry.
Inspecting variables ~ Inspecting variables ~
*termdebug-variables* *:Evaluate* *termdebug-variables* *:Evaluate*
`:Evaluate` evaluate the expression under the cursor `:Evaluate` evaluate the expression under the cursor
`K` same `K` same (see |termdebug_map_K| to disable)
`:Evaluate` {expr} evaluate {expr} `:Evaluate` {expr} evaluate {expr}
`:'<,'>Evaluate` evaluate the Visually selected text `:'<,'>Evaluate` evaluate the Visually selected text
@ -333,7 +333,7 @@ Four autocommands can be used: >
*TermdebugStartPre* *TermdebugStartPre*
TermdebugStartPre Before starting debugging. TermdebugStartPre Before starting debugging.
Not triggered if the debugger is already Not triggered if the debugger is already
running or |g:termdebugger| cannot be running or the debugger command cannot be
executed. executed.
*TermdebugStartPost* *TermdebugStartPost*
TermdebugStartPost After debugging has initialized. TermdebugStartPost After debugging has initialized.
@ -362,14 +362,24 @@ This works slightly differently:
*termdebug_use_prompt* *termdebug_use_prompt*
Prompt mode can be used with: > Prompt mode can be used with: >
let g:termdebug_config['use_prompt'] = 1
Or if there is no g:termdebug_config: >
let g:termdebug_use_prompt = 1 let g:termdebug_use_prompt = 1
<
*termdebug_map_K*
The K key is normally mapped to :Evaluate. If you do not want this use: >
let g:termdebug_config['map_K'] = 0
Or if there is no g:termdebug_config: >
let g:termdebug_map_K = 0
< <
*termdebug_disasm_window* *termdebug_disasm_window*
If you want the Asm window shown by default, set this to 1. Setting to If you want the Asm window shown by default, set the flag to 1.
any value greater than 1 will set the Asm window height to that value: > the "disasm_window_height" entry can be used to set the window height: >
let g:termdebug_config['disasm_window'] = 1
let g:termdebug_config['disasm_window_height'] = 15
or, if there is no g:termdebug_config: >
let g:termdebug_disasm_window = 15 let g:termdebug_disasm_window = 15
< Any value greater than 1 will set the Asm window height to that value: >
Communication ~ Communication ~
*termdebug-communication* *termdebug-communication*
@ -386,13 +396,24 @@ communication channel.
Customizing ~ Customizing ~
*termdebug-customizing* *g:termdebug_config*
In the past several global variables were used for configuration. These are
deprecated, using the g:termdebug_config dictionary is preferred. When
g:termdebug_config exists the other global variables will not be used.
GDB command *termdebug-customizing*
To change the name of the gdb command, set the "termdebugger" variable before GDB command ~
invoking `:Termdebug`: > *g:termdebugger*
let termdebugger = "mygdb" To change the name of the gdb command, set "debugger" entry in
g:termdebug_config or the "g:termdebugger" variable before invoking
`:Termdebug`: >
let g:termdebug_config['command'] = "mygdb"
Or if there is no g:termdebug_config: >
let g:termdebugger = "mygdb"
If the command needs an argument use a List: > If the command needs an argument use a List: >
let g:termdebug_config['command'] = ['rr', 'replay', '--']
Or if there is no g:termdebug_config: >
let g:termdebugger = ['rr', 'replay', '--'] let g:termdebugger = ['rr', 'replay', '--']
To not use neovim floating windows for previewing variable evaluation, set the To not use neovim floating windows for previewing variable evaluation, set the
@ -406,7 +427,17 @@ cursor: >
or set/unset a breakpoint: > or set/unset a breakpoint: >
nnoremap <RightMouse> :Break<CR> nnoremap <RightMouse> :Break<CR>
< *gdb-version*
Several arguments will be added to make gdb work well for the debugger.
If you want to modify them, add a function to filter the argument list: >
let g:termdebug_config['command_filter'] = MyDebugFilter
If you do not want the arguments to be added, but you do need to set the
"pty", use a function to add the necessary arguments: >
let g:termdebug_config['command_add_args'] = MyAddArguments
The function will be called with the list of arguments so far, and a second
argument that is the name of the pty.
*gdb-version*
Only debuggers fully compatible with gdb will work. Vim uses the GDB/MI Only debuggers fully compatible with gdb will work. Vim uses the GDB/MI
interface. The "new-ui" command requires gdb version 7.12 or later. if you interface. The "new-ui" command requires gdb version 7.12 or later. if you
get this error: get this error:
@ -414,8 +445,8 @@ get this error:
Then your gdb is too old. Then your gdb is too old.
Colors *hl-debugPC* *hl-debugBreakpoint* Colors~
*hl-debugPC* *hl-debugBreakpoint*
The color of the signs can be adjusted with these highlight groups: The color of the signs can be adjusted with these highlight groups:
- debugPC the current position - debugPC the current position
- debugBreakpoint a breakpoint - debugBreakpoint a breakpoint
@ -439,16 +470,20 @@ The argument is the gdb command.
Vim window width *termdebug_wide* Vim window width *termdebug_wide*
To change the width of the Vim window when debugging starts, and use a To change the width of the Vim window when debugging starts and use a vertical
vertical split: > split: >
let g:termdebug_wide = 163 let g:termdebug_config['wide'] = 163
This will set &columns to 163 when `:Termdebug` is used. The value is restored Or if there is no g:termdebug_config: >
when quitting the debugger. let g:termdebug_wide = 163
If g:termdebug_wide is set and &columns is already larger than
g:termdebug_wide then a vertical split will be used without changing &columns.
Set it to 1 to get a vertical split without every changing &columns (useful
for when the terminal can't be resized by Vim).
This will set 'columns' to 163 when `:Termdebug` is used. The value is
restored when quitting the debugger.
If the wide value is set and 'columns' is already a greater value, then a
vertical split will be used without modifying 'columns'.
Set the wide value to 1 to use a vertical split without ever changing
'columns'. This is useful when the terminal can't be resized by Vim.
vim:tw=78:ts=8:noet:ft=help:norl: vim:tw=78:ts=8:noet:ft=help:norl:

View File

@ -2,7 +2,7 @@
" "
" Author: Bram Moolenaar " Author: Bram Moolenaar
" Copyright: Vim license applies, see ":help license" " 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 " WORK IN PROGRESS - The basics works stable, more to come
" Note: In general you need at least GDB 7.12 because this provides the " Note: In general you need at least GDB 7.12 because this provides the
@ -71,11 +71,6 @@ set cpo&vim
command -nargs=* -complete=file -bang Termdebug call s:StartDebug(<bang>0, <f-args>) command -nargs=* -complete=file -bang Termdebug call s:StartDebug(<bang>0, <f-args>)
command -nargs=+ -complete=file -bang TermdebugCommand call s:StartDebugCommand(<bang>0, <f-args>) command -nargs=+ -complete=file -bang TermdebugCommand call s:StartDebugCommand(<bang>0, <f-args>)
" Name of the gdb command, defaults to "gdb".
if !exists('g:termdebugger')
let g:termdebugger = 'gdb'
endif
let s:pc_id = 12 let s:pc_id = 12
let s:asm_id = 13 let s:asm_id = 13
let s:break_id = 14 " breakpoint number is added to this let s:break_id = 14 " breakpoint number is added to this
@ -105,8 +100,17 @@ call s:Highlight(1, '', &background)
hi default debugBreakpoint term=reverse ctermbg=red guibg=red hi default debugBreakpoint term=reverse ctermbg=red guibg=red
hi default debugBreakpointDisabled term=reverse ctermbg=gray guibg=gray 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() 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 endfunc
func s:StartDebug(bang, ...) func s:StartDebug(bang, ...)
@ -177,12 +181,10 @@ func s:StartDebug_internal(dict)
call s:StartDebug_term(a:dict) call s:StartDebug_term(a:dict)
endif endif
if exists('g:termdebug_disasm_window') if s:GetDisasmWindow()
if g:termdebug_disasm_window let curwinid = win_getid(winnr())
let curwinid = win_getid(winnr()) call s:GotoAsmwinOrCreateIt()
call s:GotoAsmwinOrCreateIt() call win_gotoid(curwinid)
call win_gotoid(curwinid)
endif
endif endif
if exists('#User#TermdebugStartPost') if exists('#User#TermdebugStartPost')
@ -252,18 +254,28 @@ func s:StartDebug_term(dict)
let proc_args = get(a:dict, 'proc_args', []) let proc_args = get(a:dict, 'proc_args', [])
let gdb_cmd = s:GetCommand() let gdb_cmd = s:GetCommand()
" Add -quiet to avoid the intro message causing a hit-enter prompt.
let gdb_cmd += ['-quiet'] if exists('g:termdebug_config') && has_key(g:termdebug_config, 'command_add_args')
" Disable pagination, it causes everything to stop at the gdb let gdb_cmd = g:termdebug_config.command_add_args(gdb_cmd, pty)
let gdb_cmd += ['-iex', 'set pagination off'] else
" Interpret commands while the target is running. This should usually only " Add -quiet to avoid the intro message causing a hit-enter prompt.
" be exec-interrupt, since many commands don't work properly while the let gdb_cmd += ['-quiet']
" target is running (so execute during startup). " Disable pagination, it causes everything to stop at the gdb
let gdb_cmd += ['-iex', 'set mi-async on'] let gdb_cmd += ['-iex', 'set pagination off']
" Open a terminal window to run the debugger. " Interpret commands while the target is running. This should usually only
let gdb_cmd += ['-tty', pty] " be exec-interrupt, since many commands don't work properly while the
" Command executed _after_ startup is done, provides us with the necessary feedback " target is running (so execute during startup).
let gdb_cmd += ['-ex', 'echo startupdone\n'] 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 " Adding arguments requested by the user
let gdb_cmd += gdb_args let gdb_cmd += gdb_args
@ -871,7 +883,13 @@ func s:InstallCommands()
command Asm call s:GotoAsmwinOrCreateIt() command Asm call s:GotoAsmwinOrCreateIt()
command Winbar call s:InstallWinbar() 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) " let s:k_map_saved = maparg('K', 'n', 0, 1)
let s:k_map_saved = {} let s:k_map_saved = {}
for map in nvim_get_keymap('n') for map in nvim_get_keymap('n')
@ -1280,6 +1298,26 @@ func s:GotoSourcewinOrCreateIt()
endif endif
endfunc 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() func s:GotoAsmwinOrCreateIt()
if !win_gotoid(s:asmwin) if !win_gotoid(s:asmwin)
if win_gotoid(s:sourcewin) if win_gotoid(s:sourcewin)
@ -1303,10 +1341,8 @@ func s:GotoAsmwinOrCreateIt()
exe 'file Termdebug-asm-listing' exe 'file Termdebug-asm-listing'
endif endif
if exists('g:termdebug_disasm_window') if s:GetDisasmWindowHeight() > 0
if g:termdebug_disasm_window > 1 exe 'resize ' .. s:GetDisasmWindowHeight()
exe 'resize ' . g:termdebug_disasm_window
endif
endif endif
endif endif

View File

@ -243,6 +243,10 @@ preprocess_patch() {
LC_ALL=C sed -e 's/\( [ab]\/src\/nvim\)\/keymap\.h/\1\/keycodes.h/g' \ LC_ALL=C sed -e 's/\( [ab]\/src\/nvim\)\/keymap\.h/\1\/keycodes.h/g' \
"$file" > "$file".tmp && mv "$file".tmp "$file" "$file" > "$file".tmp && mv "$file".tmp "$file"
# Rename terminal.txt to nvim_terminal_emulator.txt
LC_ALL=C sed -e 's/\( [ab]\/runtime\/doc\)\/terminal\.txt/\1\/nvim_terminal_emulator.txt/g' \
"$file" > "$file".tmp && mv "$file".tmp "$file"
# Rename test_urls.vim to check_urls.vim # Rename test_urls.vim to check_urls.vim
LC_ALL=C sed -e 's@\( [ab]\)/runtime/doc/test\(_urls\.vim\)@\1/scripts/check\2@g' \ LC_ALL=C sed -e 's@\( [ab]\)/runtime/doc/test\(_urls\.vim\)@\1/scripts/check\2@g' \
"$file" > "$file".tmp && mv "$file".tmp "$file" "$file" > "$file".tmp && mv "$file".tmp "$file"