comparison runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @ 18130:1e5672da6a69

Updte runtime files Commit: https://github.com/vim/vim/commit/589edb340454e7f1b19358f129287a636d53d0e1 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 20 14:38:13 2019 +0200 Updte runtime files
author Bram Moolenaar <Bram@vim.org>
date Fri, 20 Sep 2019 14:45:05 +0200
parents 58bebe21f0ef
children 40344f717010
comparison
equal deleted inserted replaced
18129:52078b0635f7 18130:1e5672da6a69
154 endfunc 154 endfunc
155 155
156 func s:StartDebug_term(dict) 156 func s:StartDebug_term(dict)
157 " Open a terminal window without a job, to run the debugged program in. 157 " Open a terminal window without a job, to run the debugged program in.
158 let s:ptybuf = term_start('NONE', { 158 let s:ptybuf = term_start('NONE', {
159 \ 'term_name': 'debugged program', 159 \ 'term_name': 'debugged program',
160 \ 'vertical': s:vertical, 160 \ 'vertical': s:vertical,
161 \ }) 161 \ })
162 if s:ptybuf == 0 162 if s:ptybuf == 0
163 echoerr 'Failed to open the program terminal window' 163 echoerr 'Failed to open the program terminal window'
164 return 164 return
165 endif 165 endif
166 let pty = job_info(term_getjob(s:ptybuf))['tty_out'] 166 let pty = job_info(term_getjob(s:ptybuf))['tty_out']
175 endif 175 endif
176 endif 176 endif
177 177
178 " Create a hidden terminal window to communicate with gdb 178 " Create a hidden terminal window to communicate with gdb
179 let s:commbuf = term_start('NONE', { 179 let s:commbuf = term_start('NONE', {
180 \ 'term_name': 'gdb communication', 180 \ 'term_name': 'gdb communication',
181 \ 'out_cb': function('s:CommOutput'), 181 \ 'out_cb': function('s:CommOutput'),
182 \ 'hidden': 1, 182 \ 'hidden': 1,
183 \ }) 183 \ })
184 if s:commbuf == 0 184 if s:commbuf == 0
185 echoerr 'Failed to open the communication terminal window' 185 echoerr 'Failed to open the communication terminal window'
186 exe 'bwipe! ' . s:ptybuf 186 exe 'bwipe! ' . s:ptybuf
187 return 187 return
188 endif 188 endif
194 let proc_args = get(a:dict, 'proc_args', []) 194 let proc_args = get(a:dict, 'proc_args', [])
195 195
196 let cmd = [g:termdebugger, '-quiet', '-tty', pty] + gdb_args 196 let cmd = [g:termdebugger, '-quiet', '-tty', pty] + gdb_args
197 call ch_log('executing "' . join(cmd) . '"') 197 call ch_log('executing "' . join(cmd) . '"')
198 let s:gdbbuf = term_start(cmd, { 198 let s:gdbbuf = term_start(cmd, {
199 \ 'term_finish': 'close', 199 \ 'term_finish': 'close',
200 \ }) 200 \ })
201 if s:gdbbuf == 0 201 if s:gdbbuf == 0
202 echoerr 'Failed to open the gdb terminal window' 202 echoerr 'Failed to open the gdb terminal window'
203 call s:CloseBuffers() 203 call s:CloseBuffers()
204 return 204 return
205 endif 205 endif
227 let response = '' 227 let response = ''
228 for lnum in range(1, 200) 228 for lnum in range(1, 200)
229 let line1 = term_getline(s:gdbbuf, lnum) 229 let line1 = term_getline(s:gdbbuf, lnum)
230 let line2 = term_getline(s:gdbbuf, lnum + 1) 230 let line2 = term_getline(s:gdbbuf, lnum + 1)
231 if line1 =~ 'new-ui mi ' 231 if line1 =~ 'new-ui mi '
232 " response can be in the same line or the next line 232 " response can be in the same line or the next line
233 let response = line1 . line2 233 let response = line1 . line2
234 if response =~ 'Undefined command' 234 if response =~ 'Undefined command'
235 echoerr 'Sorry, your gdb is too old, gdb 7.12 is required' 235 echoerr 'Sorry, your gdb is too old, gdb 7.12 is required'
236 call s:CloseBuffers() 236 call s:CloseBuffers()
237 return 237 return
238 endif 238 endif
239 if response =~ 'New UI allocated' 239 if response =~ 'New UI allocated'
240 " Success! 240 " Success!
241 break 241 break
242 endif 242 endif
243 elseif line1 =~ 'Reading symbols from' && line2 !~ 'new-ui mi ' 243 elseif line1 =~ 'Reading symbols from' && line2 !~ 'new-ui mi '
244 " Reading symbols might take a while, try more times 244 " Reading symbols might take a while, try more times
245 let try_count -= 1 245 let try_count -= 1
246 endif 246 endif
247 endfor 247 endfor
298 298
299 let cmd = [g:termdebugger, '-quiet', '--interpreter=mi2'] + gdb_args 299 let cmd = [g:termdebugger, '-quiet', '--interpreter=mi2'] + gdb_args
300 call ch_log('executing "' . join(cmd) . '"') 300 call ch_log('executing "' . join(cmd) . '"')
301 301
302 let s:gdbjob = job_start(cmd, { 302 let s:gdbjob = job_start(cmd, {
303 \ 'exit_cb': function('s:EndPromptDebug'), 303 \ 'exit_cb': function('s:EndPromptDebug'),
304 \ 'out_cb': function('s:GdbOutCallback'), 304 \ 'out_cb': function('s:GdbOutCallback'),
305 \ }) 305 \ })
306 if job_status(s:gdbjob) != "run" 306 if job_status(s:gdbjob) != "run"
307 echoerr 'Failed to start gdb' 307 echoerr 'Failed to start gdb'
308 exe 'bwipe! ' . s:promptbuf 308 exe 'bwipe! ' . s:promptbuf
309 return 309 return
310 endif 310 endif
325 call s:SendCommand('set new-console on') 325 call s:SendCommand('set new-console on')
326 elseif has('terminal') 326 elseif has('terminal')
327 " Unix: Run the debugged program in a terminal window. Open it below the 327 " Unix: Run the debugged program in a terminal window. Open it below the
328 " gdb window. 328 " gdb window.
329 belowright let s:ptybuf = term_start('NONE', { 329 belowright let s:ptybuf = term_start('NONE', {
330 \ 'term_name': 'debugged program', 330 \ 'term_name': 'debugged program',
331 \ }) 331 \ })
332 if s:ptybuf == 0 332 if s:ptybuf == 0
333 echoerr 'Failed to open the program terminal window' 333 echoerr 'Failed to open the program terminal window'
334 call job_stop(s:gdbjob) 334 call job_stop(s:gdbjob)
335 return 335 return
336 endif 336 endif
506 let i = 1 506 let i = 1
507 while a:quotedText[i] != '"' && i < len(a:quotedText) 507 while a:quotedText[i] != '"' && i < len(a:quotedText)
508 if a:quotedText[i] == '\' 508 if a:quotedText[i] == '\'
509 let i += 1 509 let i += 1
510 if a:quotedText[i] == 'n' 510 if a:quotedText[i] == 'n'
511 " drop \n 511 " drop \n
512 let i += 1 512 let i += 1
513 continue 513 continue
514 elseif a:quotedText[i] == 't'
515 " append \t
516 let i += 1
517 let result .= "\t"
518 continue
514 endif 519 endif
515 endif 520 endif
516 let result .= a:quotedText[i] 521 let result .= a:quotedText[i]
517 let i += 1 522 let i += 1
518 endwhile 523 endwhile
592 if msg[0] == "\n" 597 if msg[0] == "\n"
593 let msg = msg[1:] 598 let msg = msg[1:]
594 endif 599 endif
595 if msg != '' 600 if msg != ''
596 if msg =~ '^\(\*stopped\|\*running\|=thread-selected\)' 601 if msg =~ '^\(\*stopped\|\*running\|=thread-selected\)'
597 call s:HandleCursor(msg) 602 call s:HandleCursor(msg)
598 elseif msg =~ '^\^done,bkpt=' || msg =~ '^=breakpoint-created,' 603 elseif msg =~ '^\^done,bkpt=' || msg =~ '^=breakpoint-created,'
599 call s:HandleNewBreakpoint(msg) 604 call s:HandleNewBreakpoint(msg)
600 elseif msg =~ '^=breakpoint-deleted,' 605 elseif msg =~ '^=breakpoint-deleted,'
601 call s:HandleBreakpointDelete(msg) 606 call s:HandleBreakpointDelete(msg)
602 elseif msg =~ '^=thread-group-started' 607 elseif msg =~ '^=thread-group-started'
603 call s:HandleProgramRun(msg) 608 call s:HandleProgramRun(msg)
604 elseif msg =~ '^\^done,value=' 609 elseif msg =~ '^\^done,value='
605 call s:HandleEvaluate(msg) 610 call s:HandleEvaluate(msg)
606 elseif msg =~ '^\^error,msg=' 611 elseif msg =~ '^\^error,msg='
607 call s:HandleError(msg) 612 call s:HandleError(msg)
608 endif 613 endif
609 endif 614 endif
610 endfor 615 endfor
616 endfunc
617
618 func s:GotoProgram()
619 if has('win32')
620 if executable('powershell')
621 call system(printf('powershell -Command "add-type -AssemblyName microsoft.VisualBasic;[Microsoft.VisualBasic.Interaction]::AppActivate(%d);"', s:pid))
622 endif
623 else
624 win_gotoid(s:ptywin)
625 endif
611 endfunc 626 endfunc
612 627
613 " Install commands in the current window to control the debugger. 628 " Install commands in the current window to control the debugger.
614 func s:InstallCommands() 629 func s:InstallCommands()
615 let save_cpo = &cpo 630 let save_cpo = &cpo
616 set cpo&vim 631 set cpo&vim
617 632
618 command Break call s:SetBreakpoint() 633 command -nargs=? Break call s:SetBreakpoint(<q-args>)
619 command Clear call s:ClearBreakpoint() 634 command Clear call s:ClearBreakpoint()
620 command Step call s:SendCommand('-exec-step') 635 command Step call s:SendCommand('-exec-step')
621 command Over call s:SendCommand('-exec-next') 636 command Over call s:SendCommand('-exec-next')
622 command Finish call s:SendCommand('-exec-finish') 637 command Finish call s:SendCommand('-exec-finish')
623 command -nargs=* Run call s:Run(<q-args>) 638 command -nargs=* Run call s:Run(<q-args>)
631 command Continue call term_sendkeys(s:gdbbuf, "continue\r") 646 command Continue call term_sendkeys(s:gdbbuf, "continue\r")
632 endif 647 endif
633 648
634 command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>) 649 command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>)
635 command Gdb call win_gotoid(s:gdbwin) 650 command Gdb call win_gotoid(s:gdbwin)
636 command Program call win_gotoid(s:ptywin) 651 command Program call s:GotoProgram()
637 command Source call s:GotoSourcewinOrCreateIt() 652 command Source call s:GotoSourcewinOrCreateIt()
638 command Winbar call s:InstallWinbar() 653 command Winbar call s:InstallWinbar()
639 654
640 " TODO: can the K mapping be restored? 655 " TODO: can the K mapping be restored?
641 nnoremap K :Evaluate<CR> 656 nnoremap K :Evaluate<CR>
693 if has('menu') 708 if has('menu')
694 " Remove the WinBar entries from all windows where it was added. 709 " Remove the WinBar entries from all windows where it was added.
695 let curwinid = win_getid(winnr()) 710 let curwinid = win_getid(winnr())
696 for winid in s:winbar_winids 711 for winid in s:winbar_winids
697 if win_gotoid(winid) 712 if win_gotoid(winid)
698 aunmenu WinBar.Step 713 aunmenu WinBar.Step
699 aunmenu WinBar.Next 714 aunmenu WinBar.Next
700 aunmenu WinBar.Finish 715 aunmenu WinBar.Finish
701 aunmenu WinBar.Cont 716 aunmenu WinBar.Cont
702 aunmenu WinBar.Stop 717 aunmenu WinBar.Stop
703 aunmenu WinBar.Eval 718 aunmenu WinBar.Eval
704 endif 719 endif
705 endfor 720 endfor
706 call win_gotoid(curwinid) 721 call win_gotoid(curwinid)
707 let s:winbar_winids = [] 722 let s:winbar_winids = []
708 723
731 endfor 746 endfor
732 let s:BreakpointSigns = [] 747 let s:BreakpointSigns = []
733 endfunc 748 endfunc
734 749
735 " :Break - Set a breakpoint at the cursor position. 750 " :Break - Set a breakpoint at the cursor position.
736 func s:SetBreakpoint() 751 func s:SetBreakpoint(at)
737 " Setting a breakpoint may not work while the program is running. 752 " Setting a breakpoint may not work while the program is running.
738 " Interrupt to make it work. 753 " Interrupt to make it work.
739 let do_continue = 0 754 let do_continue = 0
740 if !s:stopped 755 if !s:stopped
741 let do_continue = 1 756 let do_continue = 1
744 else 759 else
745 call s:SendCommand('-exec-interrupt') 760 call s:SendCommand('-exec-interrupt')
746 endif 761 endif
747 sleep 10m 762 sleep 10m
748 endif 763 endif
764
749 " Use the fname:lnum format, older gdb can't handle --source. 765 " Use the fname:lnum format, older gdb can't handle --source.
750 call s:SendCommand('-break-insert ' 766 let at = empty(a:at) ?
751 \ . fnameescape(expand('%:p')) . ':' . line('.')) 767 \ fnameescape(expand('%:p')) . ':' . line('.') : a:at
768 call s:SendCommand('-break-insert ' . at)
752 if do_continue 769 if do_continue
753 call s:SendCommand('-exec-continue') 770 call s:SendCommand('-exec-continue')
754 endif 771 endif
755 endfunc 772 endfunc
756 773
761 let bploc = printf('%s:%d', fname, lnum) 778 let bploc = printf('%s:%d', fname, lnum)
762 if has_key(s:breakpoint_locations, bploc) 779 if has_key(s:breakpoint_locations, bploc)
763 let idx = 0 780 let idx = 0
764 for id in s:breakpoint_locations[bploc] 781 for id in s:breakpoint_locations[bploc]
765 if has_key(s:breakpoints, id) 782 if has_key(s:breakpoints, id)
766 " Assume this always works, the reply is simply "^done". 783 " Assume this always works, the reply is simply "^done".
767 call s:SendCommand('-break-delete ' . id) 784 call s:SendCommand('-break-delete ' . id)
768 for subid in keys(s:breakpoints[id]) 785 for subid in keys(s:breakpoints[id])
769 exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid) 786 exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid)
770 endfor 787 endfor
771 unlet s:breakpoints[id] 788 unlet s:breakpoints[id]
772 unlet s:breakpoint_locations[bploc][idx] 789 unlet s:breakpoint_locations[bploc][idx]
773 break 790 break
774 else 791 else
775 let idx += 1 792 let idx += 1
776 endif 793 endif
777 endfor 794 endfor
778 if empty(s:breakpoint_locations[bploc]) 795 if empty(s:breakpoint_locations[bploc])
897 if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname) 914 if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname)
898 let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '') 915 let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '')
899 if lnum =~ '^[0-9]*$' 916 if lnum =~ '^[0-9]*$'
900 call s:GotoSourcewinOrCreateIt() 917 call s:GotoSourcewinOrCreateIt()
901 if expand('%:p') != fnamemodify(fname, ':p') 918 if expand('%:p') != fnamemodify(fname, ':p')
902 if &modified 919 if &modified
903 " TODO: find existing window 920 " TODO: find existing window
904 exe 'split ' . fnameescape(fname) 921 exe 'split ' . fnameescape(fname)
905 let s:sourcewin = win_getid(winnr()) 922 let s:sourcewin = win_getid(winnr())
906 call s:InstallWinbar() 923 call s:InstallWinbar()
907 else 924 else
908 exe 'edit ' . fnameescape(fname) 925 exe 'edit ' . fnameescape(fname)
909 endif 926 endif
910 endif 927 endif
911 exe lnum 928 exe lnum
912 exe 'sign unplace ' . s:pc_id 929 exe 'sign unplace ' . s:pc_id
913 exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fname 930 exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fname
914 setlocal signcolumn=yes 931 setlocal signcolumn=yes
999 return 1016 return
1000 endif 1017 endif
1001 if has_key(s:breakpoints, id) 1018 if has_key(s:breakpoints, id)
1002 for [subid, entry] in items(s:breakpoints[id]) 1019 for [subid, entry] in items(s:breakpoints[id])
1003 if has_key(entry, 'placed') 1020 if has_key(entry, 'placed')
1004 exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid) 1021 exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid)
1005 unlet entry['placed'] 1022 unlet entry['placed']
1006 endif 1023 endif
1007 endfor 1024 endfor
1008 unlet s:breakpoints[id] 1025 unlet s:breakpoints[id]
1009 endif 1026 endif
1010 endfunc 1027 endfunc
1024 func s:BufRead() 1041 func s:BufRead()
1025 let fname = expand('<afile>:p') 1042 let fname = expand('<afile>:p')
1026 for [id, entries] in items(s:breakpoints) 1043 for [id, entries] in items(s:breakpoints)
1027 for [subid, entry] in items(entries) 1044 for [subid, entry] in items(entries)
1028 if entry['fname'] == fname 1045 if entry['fname'] == fname
1029 call s:PlaceSign(id, subid, entry) 1046 call s:PlaceSign(id, subid, entry)
1030 endif 1047 endif
1031 endfor 1048 endfor
1032 endfor 1049 endfor
1033 endfunc 1050 endfunc
1034 1051
1036 func s:BufUnloaded() 1053 func s:BufUnloaded()
1037 let fname = expand('<afile>:p') 1054 let fname = expand('<afile>:p')
1038 for [id, entries] in items(s:breakpoints) 1055 for [id, entries] in items(s:breakpoints)
1039 for [subid, entry] in items(entries) 1056 for [subid, entry] in items(entries)
1040 if entry['fname'] == fname 1057 if entry['fname'] == fname
1041 let entry['placed'] = 0 1058 let entry['placed'] = 0
1042 endif 1059 endif
1043 endfor 1060 endfor
1044 endfor 1061 endfor
1045 endfunc 1062 endfunc
1046 1063