Mercurial > vim
comparison runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @ 13706:bfd9249f72e0 v8.0.1725
patch 8.0.1725: terminal debugger doesn't handle command arguments
commit https://github.com/vim/vim/commit/32c67ba733abcd4f2d729595fdccb2295445636a
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Apr 16 16:21:49 2018 +0200
patch 8.0.1725: terminal debugger doesn't handle command arguments
Problem: Terminal debugger doesn't handle command arguments.
Solution: Add the :TermdebugCommand command. Use a ! to execute right away.
(Christian Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 16 Apr 2018 16:30:08 +0200 |
parents | fc660a6ef37d |
children | 274c9f1fbfd2 |
comparison
equal
deleted
inserted
replaced
13705:7dd71a906267 | 13706:bfd9249f72e0 |
---|---|
23 " Uncomment this line to write logging in "debuglog". | 23 " Uncomment this line to write logging in "debuglog". |
24 " call ch_logfile('debuglog', 'w') | 24 " call ch_logfile('debuglog', 'w') |
25 | 25 |
26 " The command that starts debugging, e.g. ":Termdebug vim". | 26 " The command that starts debugging, e.g. ":Termdebug vim". |
27 " To end type "quit" in the gdb window. | 27 " To end type "quit" in the gdb window. |
28 command -nargs=* -complete=file Termdebug call s:StartDebug(<f-args>) | 28 command -nargs=* -complete=file -bang Termdebug call s:StartDebug(<bang>0, <f-args>) |
29 command -nargs=+ -complete=file -bang TermdebugCommand call s:StartDebugCommand(<bang>0, <f-args>) | |
29 | 30 |
30 " Name of the gdb command, defaults to "gdb". | 31 " Name of the gdb command, defaults to "gdb". |
31 if !exists('termdebugger') | 32 if !exists('termdebugger') |
32 let termdebugger = 'gdb' | 33 let termdebugger = 'gdb' |
33 endif | 34 endif |
41 else | 42 else |
42 hi default debugPC term=reverse ctermbg=darkblue guibg=darkblue | 43 hi default debugPC term=reverse ctermbg=darkblue guibg=darkblue |
43 endif | 44 endif |
44 hi default debugBreakpoint term=reverse ctermbg=red guibg=red | 45 hi default debugBreakpoint term=reverse ctermbg=red guibg=red |
45 | 46 |
46 func s:StartDebug(...) | 47 func s:StartDebug(bang, ...) |
48 " First argument is the command to debug, second core file or process ID. | |
49 call s:StartDebug_internal({'gdb_args': a:000, 'bang': a:bang}) | |
50 endfunc | |
51 | |
52 func s:StartDebugCommand(bang, ...) | |
53 " First argument is the command to debug, rest are run arguments. | |
54 call s:StartDebug_internal({'gdb_args': [a:1], 'proc_args': a:000[1:], 'bang': a:bang}) | |
55 endfunc | |
56 | |
57 func s:StartDebug_internal(dict) | |
47 if exists('s:gdbwin') | 58 if exists('s:gdbwin') |
48 echoerr 'Terminal debugger already running' | 59 echoerr 'Terminal debugger already running' |
49 return | 60 return |
50 endif | 61 endif |
51 | 62 |
93 endif | 104 endif |
94 let commpty = job_info(term_getjob(s:commbuf))['tty_out'] | 105 let commpty = job_info(term_getjob(s:commbuf))['tty_out'] |
95 | 106 |
96 " Open a terminal window to run the debugger. | 107 " Open a terminal window to run the debugger. |
97 " Add -quiet to avoid the intro message causing a hit-enter prompt. | 108 " Add -quiet to avoid the intro message causing a hit-enter prompt. |
98 let cmd = [g:termdebugger, '-quiet', '-tty', pty] + a:000 | 109 let gdb_args = get(a:dict, 'gdb_args', []) |
110 let proc_args = get(a:dict, 'proc_args', []) | |
111 | |
112 let cmd = [g:termdebugger, '-quiet', '-tty', pty] + gdb_args | |
99 echomsg 'executing "' . join(cmd) . '"' | 113 echomsg 'executing "' . join(cmd) . '"' |
100 let s:gdbbuf = term_start(cmd, { | 114 let s:gdbbuf = term_start(cmd, { |
101 \ 'exit_cb': function('s:EndDebug'), | 115 \ 'exit_cb': function('s:EndDebug'), |
102 \ 'term_finish': 'close', | 116 \ 'term_finish': 'close', |
103 \ }) | 117 \ }) |
106 exe 'bwipe! ' . s:ptybuf | 120 exe 'bwipe! ' . s:ptybuf |
107 exe 'bwipe! ' . s:commbuf | 121 exe 'bwipe! ' . s:commbuf |
108 return | 122 return |
109 endif | 123 endif |
110 let s:gdbwin = win_getid(winnr()) | 124 let s:gdbwin = win_getid(winnr()) |
125 | |
126 " Set arguments to be run | |
127 if len(proc_args) | |
128 call term_sendkeys(s:gdbbuf, 'set args ' . join(proc_args) . "\r") | |
129 endif | |
111 | 130 |
112 " Connect gdb to the communication pty, using the GDB/MI interface | 131 " Connect gdb to the communication pty, using the GDB/MI interface |
113 call term_sendkeys(s:gdbbuf, 'new-ui mi ' . commpty . "\r") | 132 call term_sendkeys(s:gdbbuf, 'new-ui mi ' . commpty . "\r") |
114 | 133 |
115 " Wait for the response to show up, users may not notice the error and wonder | 134 " Wait for the response to show up, users may not notice the error and wonder |
180 | 199 |
181 augroup TermDebug | 200 augroup TermDebug |
182 au BufRead * call s:BufRead() | 201 au BufRead * call s:BufRead() |
183 au BufUnload * call s:BufUnloaded() | 202 au BufUnload * call s:BufUnloaded() |
184 augroup END | 203 augroup END |
204 | |
205 " Run the command if the bang attribute was given | |
206 " and got to the window | |
207 if get(a:dict, 'bang', 0) | |
208 call s:SendCommand('-exec-run') | |
209 call win_gotoid(s:ptywin) | |
210 endif | |
211 | |
185 endfunc | 212 endfunc |
186 | 213 |
187 func s:EndDebug(job, status) | 214 func s:EndDebug(job, status) |
188 exe 'bwipe! ' . s:ptybuf | 215 exe 'bwipe! ' . s:ptybuf |
189 exe 'bwipe! ' . s:commbuf | 216 exe 'bwipe! ' . s:commbuf |