annotate runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @ 12756:3b26420fc639

Long overdue runtime update. commit https://github.com/vim/vim/commit/01164a6546b4c635daf96a1f17d1cb2d07f32a66 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 2 22:58:42 2017 +0100 Long overdue runtime update.
author Christian Brabandt <cb@256bit.org>
date Thu, 02 Nov 2017 23:00:08 +0100
parents 34c8ec888122
children d9067dad4ac6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
1 " Debugger plugin using gdb.
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 "
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " WORK IN PROGRESS - much doesn't work yet
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 "
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
5 " Open two visible terminal windows:
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 " 1. run a pty, as with ":term NONE"
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 " 2. run gdb, passing the pty
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
8 " The current window is used to view source code and follows gdb.
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
9 "
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
10 " A third terminal window is hidden, it is used for communication with gdb.
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
11 "
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
12 " The communication with gdb uses GDB/MI. See:
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
13 " https://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI.html
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 "
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 " Author: Bram Moolenaar
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
16 " Copyright: Vim license applies, see ":help license"
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12487
diff changeset
18 " In case this gets loaded twice.
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12487
diff changeset
19 if exists(':Termdebug')
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12487
diff changeset
20 finish
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12487
diff changeset
21 endif
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 12487
diff changeset
22
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
23 " The command that starts debugging, e.g. ":Termdebug vim".
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
24 " To end type "quit" in the gdb window.
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 command -nargs=* -complete=file Termdebug call s:StartDebug(<q-args>)
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
27 " Name of the gdb command, defaults to "gdb".
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
28 if !exists('termdebugger')
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
29 let termdebugger = 'gdb'
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 endif
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
32 let s:pc_id = 12
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
33 let s:break_id = 13
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
34
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
35 if &background == 'light'
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
36 hi default debugPC term=reverse ctermbg=lightblue guibg=lightblue
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
37 else
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
38 hi default debugPC term=reverse ctermbg=darkblue guibg=darkblue
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
39 endif
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
40 hi default debugBreakpoint term=reverse ctermbg=red guibg=red
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
41
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 func s:StartDebug(cmd)
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
43 let s:startwin = win_getid(winnr())
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
44 let s:startsigncolumn = &signcolumn
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
45
12559
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
46 let s:save_columns = 0
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
47 if exists('g:termdebug_wide')
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
48 if &columns < g:termdebug_wide
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
49 let s:save_columns = &columns
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
50 let &columns = g:termdebug_wide
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
51 endif
12455
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
52 let vertical = 1
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
53 else
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
54 let vertical = 0
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
55 endif
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
56
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 " Open a terminal window without a job, to run the debugged program
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
58 let s:ptybuf = term_start('NONE', {
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
59 \ 'term_name': 'gdb program',
12455
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
60 \ 'vertical': vertical,
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
61 \ })
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
62 if s:ptybuf == 0
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
63 echoerr 'Failed to open the program terminal window'
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
64 return
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
65 endif
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
66 let pty = job_info(term_getjob(s:ptybuf))['tty_out']
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
67 let s:ptywin = win_getid(winnr())
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
68
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
69 " Create a hidden terminal window to communicate with gdb
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
70 let s:commbuf = term_start('NONE', {
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
71 \ 'term_name': 'gdb communication',
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
72 \ 'out_cb': function('s:CommOutput'),
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
73 \ 'hidden': 1,
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
74 \ })
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
75 if s:commbuf == 0
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
76 echoerr 'Failed to open the communication terminal window'
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
77 exe 'bwipe! ' . s:ptybuf
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
78 return
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
79 endif
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
80 let commpty = job_info(term_getjob(s:commbuf))['tty_out']
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 " Open a terminal window to run the debugger.
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
83 let cmd = [g:termdebugger, '-tty', pty, a:cmd]
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 echomsg 'executing "' . join(cmd) . '"'
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 let gdbbuf = term_start(cmd, {
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 \ 'exit_cb': function('s:EndDebug'),
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
87 \ 'term_finish': 'close',
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 \ })
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
89 if gdbbuf == 0
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
90 echoerr 'Failed to open the gdb terminal window'
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
91 exe 'bwipe! ' . s:ptybuf
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
92 exe 'bwipe! ' . s:commbuf
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
93 return
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
94 endif
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
95 let s:gdbwin = win_getid(winnr())
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
96
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
97 " Connect gdb to the communication pty, using the GDB/MI interface
12756
3b26420fc639 Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents: 12559
diff changeset
98 " If you get an error "undefined command" your GDB is too old.
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
99 call term_sendkeys(gdbbuf, 'new-ui mi ' . commpty . "\r")
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
100
12455
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
101 " Sign used to highlight the line where the program has stopped.
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
102 " There can be only one.
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
103 sign define debugPC linehl=debugPC
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
104
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
105 " Sign used to indicate a breakpoint.
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
106 " Can be used multiple times.
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
107 sign define debugBreakpoint text=>> texthl=debugBreakpoint
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
108
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
109 " Install debugger commands in the text window.
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
110 call win_gotoid(s:startwin)
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
111 call s:InstallCommands()
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
112 call win_gotoid(s:gdbwin)
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
113
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
114 let s:breakpoints = {}
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
115
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
116 augroup TermDebug
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
117 au BufRead * call s:BufRead()
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
118 au BufUnload * call s:BufUnloaded()
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
119 augroup END
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120 endfunc
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 func s:EndDebug(job, status)
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
123 exe 'bwipe! ' . s:ptybuf
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
124 exe 'bwipe! ' . s:commbuf
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
125
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
126 let curwinid = win_getid(winnr())
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
127
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
128 call win_gotoid(s:startwin)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
129 let &signcolumn = s:startsigncolumn
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
130 call s:DeleteCommands()
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
131
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
132 call win_gotoid(curwinid)
12455
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
133 if s:save_columns > 0
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
134 let &columns = s:save_columns
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
135 endif
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
136
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
137 au! TermDebug
12254
8d76a56861ec Update runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 endfunc
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
139
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
140 " Handle a message received from gdb on the GDB/MI interface.
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
141 func s:CommOutput(chan, msg)
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
142 let msgs = split(a:msg, "\r")
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
143
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
144 for msg in msgs
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
145 " remove prefixed NL
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
146 if msg[0] == "\n"
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
147 let msg = msg[1:]
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
148 endif
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
149 if msg != ''
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
150 if msg =~ '^\(\*stopped\|\*running\|=thread-selected\)'
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
151 call s:HandleCursor(msg)
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
152 elseif msg =~ '^\^done,bkpt=' || msg =~ '^=breakpoint-created,'
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
153 call s:HandleNewBreakpoint(msg)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
154 elseif msg =~ '^=breakpoint-deleted,'
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
155 call s:HandleBreakpointDelete(msg)
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
156 elseif msg =~ '^\^done,value='
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
157 call s:HandleEvaluate(msg)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
158 elseif msg =~ '^\^error,msg='
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
159 call s:HandleError(msg)
12395
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
160 endif
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
161 endif
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
162 endfor
39e1087e7094 patch 8.0.1077: no debugger making use of the terminal window
Christian Brabandt <cb@256bit.org>
parents: 12254
diff changeset
163 endfunc
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
164
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
165 " Install commands in the current window to control the debugger.
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
166 func s:InstallCommands()
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
167 command Break call s:SetBreakpoint()
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
168 command Delete call s:DeleteBreakpoint()
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
169 command Step call s:SendCommand('-exec-step')
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
170 command Over call s:SendCommand('-exec-next')
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
171 command Finish call s:SendCommand('-exec-finish')
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
172 command Continue call s:SendCommand('-exec-continue')
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
173 command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
174 command Gdb call win_gotoid(s:gdbwin)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
175 command Program call win_gotoid(s:ptywin)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
176
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
177 " TODO: can the K mapping be restored?
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
178 nnoremap K :Evaluate<CR>
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
179
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
180 if has('menu')
12559
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
181 nnoremenu WinBar.Step :Step<CR>
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
182 nnoremenu WinBar.Next :Over<CR>
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
183 nnoremenu WinBar.Finish :Finish<CR>
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
184 nnoremenu WinBar.Cont :Continue<CR>
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
185 nnoremenu WinBar.Eval :Evaluate<CR>
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
186 endif
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
187 endfunc
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
188
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
189 " Delete installed debugger commands in the current window.
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
190 func s:DeleteCommands()
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
191 delcommand Break
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
192 delcommand Delete
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
193 delcommand Step
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
194 delcommand Over
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
195 delcommand Finish
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
196 delcommand Continue
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
197 delcommand Evaluate
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
198 delcommand Gdb
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
199 delcommand Program
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
200
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
201 nunmap K
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
202
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
203 if has('menu')
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
204 aunmenu WinBar.Step
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
205 aunmenu WinBar.Next
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
206 aunmenu WinBar.Finish
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
207 aunmenu WinBar.Cont
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
208 aunmenu WinBar.Eval
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
209 endif
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
210
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
211 exe 'sign unplace ' . s:pc_id
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
212 for key in keys(s:breakpoints)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
213 exe 'sign unplace ' . (s:break_id + key)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
214 endfor
12455
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
215 sign undefine debugPC
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
216 sign undefine debugBreakpoint
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
217 unlet s:breakpoints
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
218 endfunc
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
219
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
220 " :Break - Set a breakpoint at the cursor position.
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
221 func s:SetBreakpoint()
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
222 call term_sendkeys(s:commbuf, '-break-insert --source '
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
223 \ . fnameescape(expand('%:p')) . ' --line ' . line('.') . "\r")
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
224 endfunc
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
225
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
226 " :Delete - Delete a breakpoint at the cursor position.
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
227 func s:DeleteBreakpoint()
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
228 let fname = fnameescape(expand('%:p'))
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
229 let lnum = line('.')
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
230 for [key, val] in items(s:breakpoints)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
231 if val['fname'] == fname && val['lnum'] == lnum
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
232 call term_sendkeys(s:commbuf, '-break-delete ' . key . "\r")
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
233 " Assume this always wors, the reply is simply "^done".
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
234 exe 'sign unplace ' . (s:break_id + key)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
235 unlet s:breakpoints[key]
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
236 break
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
237 endif
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
238 endfor
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
239 endfunc
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
240
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
241 " :Next, :Continue, etc - send a command to gdb
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
242 func s:SendCommand(cmd)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
243 call term_sendkeys(s:commbuf, a:cmd . "\r")
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
244 endfunc
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
245
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
246 " :Evaluate - evaluate what is under the cursor
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
247 func s:Evaluate(range, arg)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
248 if a:arg != ''
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
249 let expr = a:arg
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
250 elseif a:range == 2
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
251 let pos = getcurpos()
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
252 let reg = getreg('v', 1, 1)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
253 let regt = getregtype('v')
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
254 normal! gv"vy
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
255 let expr = @v
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
256 call setpos('.', pos)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
257 call setreg('v', reg, regt)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
258 else
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
259 let expr = expand('<cexpr>')
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
260 endif
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
261 call term_sendkeys(s:commbuf, '-data-evaluate-expression "' . expr . "\"\r")
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
262 let s:evalexpr = expr
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
263 endfunc
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
264
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
265 " Handle the result of data-evaluate-expression
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
266 func s:HandleEvaluate(msg)
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
267 let value = substitute(a:msg, '.*value="\(.*\)"', '\1', '')
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
268 let value = substitute(value, '\\"', '"', 'g')
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
269 echomsg '"' . s:evalexpr . '": ' . value
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
270
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
271 if s:evalexpr[0] != '*' && value =~ '^0x' && value !~ '"$'
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
272 " Looks like a pointer, also display what it points to.
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
273 let s:evalexpr = '*' . s:evalexpr
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
274 call term_sendkeys(s:commbuf, '-data-evaluate-expression "' . s:evalexpr . "\"\r")
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
275 endif
12425
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
276 endfunc
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
277
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
278 " Handle an error.
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
279 func s:HandleError(msg)
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
280 echoerr substitute(a:msg, '.*msg="\(.*\)"', '\1', '')
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
281 endfunc
29d21591ad6b patch 8.0.1092: terminal debugger can't evaluate expressions
Christian Brabandt <cb@256bit.org>
parents: 12411
diff changeset
282
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
283 " Handle stopping and running message from gdb.
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
284 " Will update the sign that shows the current position.
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
285 func s:HandleCursor(msg)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
286 let wid = win_getid(winnr())
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
287
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
288 if win_gotoid(s:startwin)
12455
85ddf8e00595 patch 8.0.1107: terminal debugger jumps to non-existing file
Christian Brabandt <cb@256bit.org>
parents: 12425
diff changeset
289 let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
290 if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname)
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
291 let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '')
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
292 if lnum =~ '^[0-9]*$'
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
293 if expand('%:p') != fnamemodify(fname, ':p')
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
294 if &modified
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
295 " TODO: find existing window
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
296 exe 'split ' . fnameescape(fname)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
297 let s:startwin = win_getid(winnr())
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
298 else
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
299 exe 'edit ' . fnameescape(fname)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
300 endif
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
301 endif
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
302 exe lnum
12756
3b26420fc639 Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents: 12559
diff changeset
303 exe 'sign unplace ' . s:pc_id
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
304 exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fname
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
305 setlocal signcolumn=yes
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
306 endif
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
307 else
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
308 exe 'sign unplace ' . s:pc_id
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
309 endif
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
310
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
311 call win_gotoid(wid)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
312 endif
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
313 endfunc
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
314
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
315 " Handle setting a breakpoint
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
316 " Will update the sign that shows the breakpoint
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
317 func s:HandleNewBreakpoint(msg)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
318 let nr = substitute(a:msg, '.*number="\([0-9]\)*\".*', '\1', '') + 0
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
319 if nr == 0
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
320 return
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
321 endif
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
322
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
323 if has_key(s:breakpoints, nr)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
324 let entry = s:breakpoints[nr]
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
325 else
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
326 let entry = {}
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
327 let s:breakpoints[nr] = entry
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
328 endif
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
329
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
330 let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
331 let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '')
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
332 let entry['fname'] = fname
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
333 let entry['lnum'] = lnum
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
334
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
335 if bufloaded(fname)
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
336 call s:PlaceSign(nr, entry)
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
337 endif
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
338 endfunc
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
339
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
340 func s:PlaceSign(nr, entry)
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
341 exe 'sign place ' . (s:break_id + a:nr) . ' line=' . a:entry['lnum'] . ' name=debugBreakpoint file=' . a:entry['fname']
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
342 let a:entry['placed'] = 1
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
343 endfunc
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
344
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
345 " Handle deleting a breakpoint
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
346 " Will remove the sign that shows the breakpoint
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
347 func s:HandleBreakpointDelete(msg)
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
348 let nr = substitute(a:msg, '.*id="\([0-9]*\)\".*', '\1', '') + 0
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
349 if nr == 0
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
350 return
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
351 endif
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
352 if has_key(s:breakpoints, nr)
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
353 let entry = s:breakpoints[nr]
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
354 if has_key(entry, 'placed')
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
355 exe 'sign unplace ' . (s:break_id + nr)
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
356 unlet entry['placed']
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
357 endif
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
358 unlet s:breakpoints[nr]
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
359 endif
12411
5d4d744151c2 patch 8.0.1085: terminal debugger can't set breakpoints
Christian Brabandt <cb@256bit.org>
parents: 12395
diff changeset
360 endfunc
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
361
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
362 " Handle a BufRead autocommand event: place any signs.
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
363 func s:BufRead()
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
364 let fname = expand('<afile>:p')
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
365 for [nr, entry] in items(s:breakpoints)
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
366 if entry['fname'] == fname
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
367 call s:PlaceSign(nr, entry)
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
368 endif
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
369 endfor
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
370 endfunc
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
371
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
372 " Handle a BufUnloaded autocommand event: unplace any signs.
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
373 func s:BufUnloaded()
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
374 let fname = expand('<afile>:p')
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
375 for [nr, entry] in items(s:breakpoints)
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
376 if entry['fname'] == fname
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
377 let entry['placed'] = 0
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
378 endif
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
379 endfor
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
380 endfunc
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12455
diff changeset
381