Skip to content

Commit d5d08a9

Browse files
committed
debug: support path substitutions
Add g:go_debug_subtitutions and hook up their use to the debugger so that binaries that are compiled at a different location than where the local source exists can be debugged. Closes #3245
1 parent 81f8cd0 commit d5d08a9

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

autoload/go/config.vim

+4
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ function! go#config#DebugWindows() abort
211211

212212
endfunction
213213

214+
function! go#config#DebugSubstitutePaths() abort
215+
return get(g:, 'go_debug_substitute_paths', [])
216+
endfunction
217+
214218
function! go#config#DebugPreserveLayout() abort
215219
return get(g:, 'go_debug_preserve_layout', 0)
216220
endfunction

autoload/go/debug.vim

+21-3
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function! s:update_breakpoint(res) abort
158158
endif
159159

160160
exe bufs[0][0] 'wincmd w'
161-
let filename = state.currentThread.file
161+
let filename = s:substituteRemotePath(state.currentThread.file)
162162
let linenr = state.currentThread.line
163163
let oldfile = fnamemodify(expand('%'), ':p:gs!\\!/!')
164164
if oldfile != filename
@@ -357,7 +357,7 @@ function! s:goto_file() abort
357357
return
358358
endif
359359
exe bufs[0][0] 'wincmd w'
360-
let filename = m[1]
360+
let filename = s:substituteRemotePath(m[1])
361361
let linenr = m[2]
362362
let oldfile = fnamemodify(expand('%'), ':p:gs!\\!/!')
363363
if oldfile != filename
@@ -1418,7 +1418,7 @@ endfunction
14181418

14191419
" Toggle breakpoint. Returns 0 on success and 1 on failure.
14201420
function! go#debug#Breakpoint(...) abort
1421-
let l:filename = fnamemodify(expand('%'), ':p:gs!\\!/!')
1421+
let l:filename = s:substituteLocalPath(fnamemodify(expand('%'), ':p:gs!\\!/!'))
14221422
let l:linenr = line('.')
14231423

14241424
" Get line number from argument.
@@ -1737,6 +1737,24 @@ function! s:restore_mapping(maparg)
17371737
return
17381738
endfunction
17391739

1740+
function! s:substituteRemotePath(path) abort
1741+
return s:substitutePath(a:path, go#config#DebugSubstitutePaths())
1742+
endfunction
1743+
1744+
function! s:substituteLocalPath(path) abort
1745+
return s:substitutePath(a:path, map(deepcopy(go#config#DebugSubstitutePaths()), '[v:val[1], v:val[0]]'))
1746+
endfunction
1747+
1748+
function! s:substitutePath(path, substitutions) abort
1749+
for [l:from, l:to] in a:substitutions
1750+
if l:from[0:len(a:path)-1] != l:from
1751+
continue
1752+
endif
1753+
return printf('%s%s', l:to, a:path[len(l:from)])
1754+
endfor
1755+
return a:path
1756+
endfunction
1757+
17401758
" restore Vi compatibility settings
17411759
let &cpo = s:cpo_save
17421760
unlet s:cpo_save

doc/vim-go.txt

+11
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,17 @@ Preserve window layout in debugging mode. This setting is considered only when
25172517
|'g:go_debug_windows'| is not empty.
25182518
>
25192519
let g:go_debug_preserve_layout = 0
2520+
<
2521+
*'g:go_debug_substitute_paths'*
2522+
2523+
Substitute paths in the debugger. This is a list of lists, where each element
2524+
is a list where the remote path (the from side) is the first element and the
2525+
local path (the to side) is the second element. These are necessary when the
2526+
binary being debugged was not built from the same location that its source
2527+
resides locally. By default it is empty.
2528+
2529+
>
2530+
let g:go_debug_substitute_paths = [['/compiled/from', '/cloned/to']]
25202531
<
25212532
*'g:go_debug_mappings'*
25222533

0 commit comments

Comments
 (0)