@@ -13,6 +13,7 @@ if !exists('s:state')
13
13
\ ' functionArgs' : {},
14
14
\ ' message' : [],
15
15
\ ' resultHandlers' : {},
16
+ \ ' kill_on_detach' : v: true ,
16
17
\ }
17
18
18
19
if go#util#HasDebug (' debugger-state' )
@@ -252,7 +253,7 @@ function! s:clearState() abort
252
253
endfunction
253
254
254
255
function ! s: stop () abort
255
- call s: call_jsonrpc (function (' s:noop' ), ' RPCServer.Detach' , {' kill' : v: true })
256
+ call s: call_jsonrpc (function (' s:noop' ), ' RPCServer.Detach' , {' kill' : s: state [ ' kill_on_detach ' ] })
256
257
257
258
if has_key (s: state , ' job' )
258
259
call go#job#Wait (s: state [' job' ])
@@ -279,8 +280,9 @@ function! go#debug#Stop() abort
279
280
for k in map (split (execute (' command GoDebug' ), " \n " )[1 :], ' matchstr(v:val, "^\\s*\\zs\\S\\+")' )
280
281
exe ' delcommand' k
281
282
endfor
282
- command ! -nargs =* -complete =customlist ,go #package#Complete GoDebugStart call go#debug#Start (0 , <f-args> )
283
- command ! -nargs =* -complete =customlist ,go #package#Complete GoDebugTest call go#debug#Start (1 , <f-args> )
283
+ command ! -nargs =* -complete =customlist ,go #package#Complete GoDebugStart call go#debug#Start (' debug' , <f-args> )
284
+ command ! -nargs =* -complete =customlist ,go #package#Complete GoDebugTest call go#debug#Start (' test' , <f-args> )
285
+ command ! -nargs =1 GoDebugAttach call go#debug#Start (' attach' , <f-args> )
284
286
command ! -nargs =? GoDebugBreakpoint call go#debug#Breakpoint (<f-args> )
285
287
286
288
" Remove all mappings.
@@ -478,6 +480,7 @@ function! s:start_cb() abort
478
480
479
481
silent ! delcommand GoDebugStart
480
482
silent ! delcommand GoDebugTest
483
+ silent ! delcommand GoDebugAttach
481
484
482
485
command ! -nargs =0 GoDebugContinue call go#debug#Stack (' continue' )
483
486
command ! -nargs =0 GoDebugStop call go#debug#Stop ()
@@ -686,10 +689,9 @@ function! s:handleRPCResult(resp) abort
686
689
endtry
687
690
endfunction
688
691
689
-
690
692
" Start the debug mode. The first argument is the package name to compile and
691
693
" debug, anything else will be passed to the running program.
692
- function ! go#debug#Start (is_test , ... ) abort
694
+ function ! go#debug#Start (mode , ... ) abort
693
695
call go#cmd#autowrite ()
694
696
695
697
if ! go#util#has_job ()
@@ -702,7 +704,7 @@ function! go#debug#Start(is_test, ...) abort
702
704
return s: state [' job' ]
703
705
endif
704
706
705
- let s: start_args = [a: is_test ] + a: 000
707
+ let s: start_args = [a: mode ] + a: 000
706
708
707
709
if go#util#HasDebug (' debugger-state' )
708
710
call go#config#SetDebugDiag (s: state )
@@ -714,33 +716,17 @@ function! go#debug#Start(is_test, ...) abort
714
716
endif
715
717
716
718
try
717
- let l: cmd = [
718
- \ dlv,
719
- \ (a: is_test ? ' test' : ' debug' ),
720
- \]
721
-
722
- " append the package when it's given.
723
- if len (a: 000 ) > 0
724
- let l: pkgname = a: 1
725
- if l: pkgname [0 ] == ' .'
726
- let l: pkgabspath = fnamemodify (l: pkgname , ' :p' )
727
-
728
- let l: cd = exists (' *haslocaldir' ) && haslocaldir () ? ' lcd' : ' cd'
729
- let l: dir = getcwd ()
730
- execute l: cd fnameescape (expand (' %:p:h' ))
731
-
732
- try
733
- let l: pkgname = go#package#FromPath (l: pkgabspath )
734
- if type (l: pkgname ) == type (0 )
735
- call go#util#EchoError (' could not determine package name' )
736
- return
737
- endif
738
- finally
739
- execute l: cd fnameescape (l: dir )
740
- endtry
741
- endif
742
719
743
- let l: cmd += [l: pkgname ]
720
+ let l: cmd = [dlv, a: mode ]
721
+
722
+ let s: state [' kill_on_detach' ] = v: true
723
+ if a: mode is ' debug' || a: mode is ' test'
724
+ let l: cmd = extend (l: cmd , s: package (a: 000 ))
725
+ elseif a: mode is ' attach'
726
+ let l: cmd = add (l: cmd , a: 1 )
727
+ let s: state [' kill_on_detach' ] = v: false
728
+ else
729
+ call go#util#EchoError (' Unknown dlv command' )
744
730
endif
745
731
746
732
let l: cmd += [
@@ -782,7 +768,40 @@ function! go#debug#Start(is_test, ...) abort
782
768
return s: state [' job' ]
783
769
endfunction
784
770
785
- " Translate a reflect kind constant to a human string.
771
+ " s:package returns the import path of package name of a :GoDebug(Start|Test)
772
+ " call as a list so that the package can be appended to a command list using
773
+ " extend(). args is expected to be a (potentially empty_ list. The first
774
+ " element in args (if there are any) is expected to be a package path. An
775
+ " emnpty list is returned when either args is an empty list or the import path
776
+ " cannot be determined.
777
+ function ! s: package (args )
778
+ if len (a: args ) == 0
779
+ return []
780
+ endif
781
+
782
+ " append the package when it's given.
783
+ let l: pkgname = a: args [0 ]
784
+ if l: pkgname [0 ] == ' .'
785
+ let l: pkgabspath = fnamemodify (l: pkgname , ' :p' )
786
+
787
+ let l: cd = exists (' *haslocaldir' ) && haslocaldir () ? ' lcd' : ' cd'
788
+ let l: dir = getcwd ()
789
+ let l: dir = go#util#Chdir (expand (' %:p:h' ))
790
+ try
791
+ let l: pkgname = go#package#FromPath (l: pkgabspath )
792
+ if type (l: pkgname ) == type (0 )
793
+ call go#util#EchoError (' could not determine package name' )
794
+ return []
795
+ endif
796
+ finally
797
+ call go#util#Chdir (l: dir )
798
+ endtry
799
+ endif
800
+
801
+ return [l: pkgname ]
802
+ endfunction
803
+
804
+ " Translate a reflect kind constant to a human string.
786
805
function ! s: reflect_kind (k )
787
806
" Kind constants from Go's reflect package.
788
807
return [
@@ -1210,6 +1229,7 @@ function! go#debug#Restart() abort
1210
1229
\ ' functionArgs' : {},
1211
1230
\ ' message' : [],
1212
1231
\ ' resultHandlers' : {},
1232
+ \ ' kill_on_detach' : s: state [' kill_on_detach' ],
1213
1233
\ }
1214
1234
1215
1235
call call (' go#debug#Start' , s: start_args )
0 commit comments