Mercurial > vim
comparison src/testdir/test_termdebug.vim @ 33944:4cacac1abdb8
runtime(termdebug): add Tbreak command
Commit: https://github.com/vim/vim/commit/323dda1484d95ee5c8a1b2205f8c495446df75ee
Author: iam28th <artyom28th@gmail.com>
Date: Thu Dec 14 20:30:26 2023 +0100
runtime(termdebug): add Tbreak command
closes: https://github.com/vim/vim/issues/13656
Signed-off-by: iam28th <artyom28th@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 14 Dec 2023 20:45:03 +0100 |
parents | ffe9ffcb57e7 |
children | a05d0836b0a0 |
comparison
equal
deleted
inserted
replaced
33943:2b5dfa987093 | 33944:4cacac1abdb8 |
---|---|
16 let g:GCC = exepath('gcc') | 16 let g:GCC = exepath('gcc') |
17 if g:GCC->empty() | 17 if g:GCC->empty() |
18 throw 'Skipped: gcc is not found in $PATH' | 18 throw 'Skipped: gcc is not found in $PATH' |
19 endif | 19 endif |
20 | 20 |
21 packadd termdebug | 21 function s:generate_files(bin_name) |
22 | 22 let src_name = a:bin_name .. '.c' |
23 func Test_termdebug_basic() | |
24 let lines =<< trim END | 23 let lines =<< trim END |
25 #include <stdio.h> | 24 #include <stdio.h> |
26 #include <stdlib.h> | 25 #include <stdlib.h> |
27 | 26 |
28 int isprime(int n) | 27 int isprime(int n) |
44 printf("%d is %s prime\n", n, isprime(n) ? "a" : "not a"); | 43 printf("%d is %s prime\n", n, isprime(n) ? "a" : "not a"); |
45 | 44 |
46 return 0; | 45 return 0; |
47 } | 46 } |
48 END | 47 END |
49 call writefile(lines, 'XTD_basic.c', 'D') | 48 call writefile(lines, src_name) |
50 call system($'{g:GCC} -g -o XTD_basic XTD_basic.c') | 49 call system($'{g:GCC} -g -o {a:bin_name} {src_name}') |
50 endfunction | |
51 | |
52 function s:cleanup_files(bin_name) | |
53 call delete(a:bin_name) | |
54 call delete(a:bin_name .. '.c') | |
55 endfunction | |
56 | |
57 packadd termdebug | |
58 | |
59 func Test_termdebug_basic() | |
60 let bin_name = 'XTD_basic' | |
61 let src_name = bin_name .. '.c' | |
62 call s:generate_files(bin_name) | |
51 | 63 |
52 edit XTD_basic.c | 64 edit XTD_basic.c |
53 Termdebug ./XTD_basic | 65 Termdebug ./XTD_basic |
54 call WaitForAssert({-> assert_equal(3, winnr('$'))}) | 66 call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
55 let gdb_buf = winbufnr(1) | 67 let gdb_buf = winbufnr(1) |
146 quit! | 158 quit! |
147 redraw! | 159 redraw! |
148 call WaitForAssert({-> assert_equal(1, winnr('$'))}) | 160 call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
149 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs) | 161 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
150 | 162 |
151 call delete('XTD_basic') | 163 call s:cleanup_files(bin_name) |
164 %bw! | |
165 endfunc | |
166 | |
167 func Test_termdebug_tbreak() | |
168 let g:test_is_flaky = 1 | |
169 let bin_name = 'XTD_tbreak' | |
170 let src_name = bin_name .. '.c' | |
171 | |
172 eval s:generate_files(bin_name) | |
173 | |
174 execute 'edit ' .. src_name | |
175 execute 'Termdebug ./' .. bin_name | |
176 | |
177 call WaitForAssert({-> assert_equal(3, winnr('$'))}) | |
178 let gdb_buf = winbufnr(1) | |
179 wincmd b | |
180 | |
181 let bp_line = 22 " 'return' statement in main | |
182 let temp_bp_line = 10 " 'if' statement in 'for' loop body | |
183 execute "Tbreak " .. temp_bp_line | |
184 execute "Break " .. bp_line | |
185 | |
186 call term_wait(gdb_buf) | |
187 redraw! | |
188 " both temporary and normal breakpoint signs were displayed... | |
189 call assert_equal([ | |
190 \ {'lnum': temp_bp_line, 'id': 1014, 'name': 'debugBreakpoint1.0', | |
191 \ 'priority': 110, 'group': 'TermDebug'}, | |
192 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0', | |
193 \ 'priority': 110, 'group': 'TermDebug'}], | |
194 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs) | |
195 | |
196 Run | |
197 call term_wait(gdb_buf, 400) | |
198 redraw! | |
199 " debugPC sign is on the line where the temp. bp was set; | |
200 " temp. bp sign was removed after hit; | |
201 " normal bp sign is still present | |
202 call WaitForAssert({-> assert_equal([ | |
203 \ {'lnum': temp_bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110, | |
204 \ 'group': 'TermDebug'}, | |
205 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0', | |
206 \ 'priority': 110, 'group': 'TermDebug'}], | |
207 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) | |
208 | |
209 Continue | |
210 call term_wait(gdb_buf) | |
211 redraw! | |
212 " debugPC is on the normal breakpoint, | |
213 " temp. bp on line 10 was only hit once | |
214 call WaitForAssert({-> assert_equal([ | |
215 \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110, | |
216 \ 'group': 'TermDebug'}, | |
217 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0', | |
218 \ 'priority': 110, 'group': 'TermDebug'}], | |
219 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) | |
220 | |
221 wincmd t | |
222 quit! | |
223 redraw! | |
224 call WaitForAssert({-> assert_equal(1, winnr('$'))}) | |
225 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs) | |
226 | |
227 eval s:cleanup_files(bin_name) | |
152 %bw! | 228 %bw! |
153 endfunc | 229 endfunc |
154 | 230 |
155 func Test_termdebug_mapping() | 231 func Test_termdebug_mapping() |
156 %bw! | 232 %bw! |