-
Notifications
You must be signed in to change notification settings - Fork 2
/
vgdb.vim
778 lines (690 loc) · 19.8 KB
/
vgdb.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vgdb - Vim plugin for interface to gdb from cterm
" Maintainer: Liang, Jian ([email protected])
" Thanks to gdbvim and vimgdb.
"
" Feedback welcome.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Prevent multiple loading unless: let force_load=1
if exists("loaded_vgdb") && !exists("force_load")
finish
endif
let s:ismswin=has('win32')
" ====== config {{{
let loaded_vgdb = 1
let s:vgdb_winheight = 10
let s:vgdb_bufname = "__VGDB__"
let s:vgdb_prompt = '(gdb) '
let s:dbg = 'gdb'
let s:perldbPromptRE = '^\s*DB<\+\d\+>\+\s*'
" used by system-call style
let s:vgdb_client = "vgdb -c" " on MSWin, actually the vgdb.bat is called in the search path
" used by libcall style
let s:vgdb_lib = s:ismswin ? 'vgdbc.dll' : 'libvgdbc.so'
"}}}
" ====== global {{{
let s:bplist = {} " id => {file, line, disabled} that returned by gdb
let s:vgdb_running = 0
let s:debugging = 0
" for pathfix
let s:unresolved_bplist = {} " elem: file_basename => %bplist
"let s:pathMap = {} " unresolved_path => fullpath
let s:nameMap = {} " file_basename => {fullname, pathFixed=0|1}, set by s:getFixedPath()
"let g:vgdb_perl = 0
let g:vgdb_uselibcall=has('libcall')
if g:vgdb_uselibcall
try
let s = libcall(s:vgdb_lib, 'test', 'libcall test')
catch
let g:vgdb_uselibcall = 0
endtry
endif
let s:set_disabled_bp = 0
"}}}
" ====== syntax {{{
highlight DebugBreak guibg=darkred guifg=white ctermbg=darkred ctermfg=white
highlight DisabledBreak guibg=lightred guifg=black ctermbg=lightred ctermfg=black
sign define vgdbBreakpoint linehl=DebugBreak text=B>
sign define vgdbDisabledbp linehl=DisabledBreak text=b>
" sign define current linehl=DebugStop
sign define vgdbCurrent linehl=Search text=>> texthl=Search
" highlight vgdbGoto guifg=Blue
hi def link vgdbKey Statement
hi def link vgdbHiLn Statement
hi def link vgdbGoto Underlined
hi def link vgdbPtr Underlined
hi def link vgdbFrame LineNr
hi def link vgdbCmd Macro
"}}}
" ====== toolkit {{{
let s:match = []
function! s:mymatch(expr, pat)
let s:match = matchlist(a:expr, a:pat)
return len(s:match) >0
endf
function! s:dirname(file)
if s:ismswin
let pos = strridx(a:file, '\')
else
let pos = strridx(a:file, '/')
endif
return strpart(a:file, 0, pos)
endf
function! s:basename(file)
" let f = substitute(file, '\', '/', 'g')
let pos = strridx(a:file, '/')
if pos<0 && s:ismswin
let pos = strridx(a:file, '\')
endif
return strpart(a:file, pos+1)
endf
"}}}
" ====== app toolkit {{{
function! s:gotoGdbWin()
if bufname("%") == s:vgdb_bufname
return
endif
let gdbwin = bufwinnr(s:vgdb_bufname)
if gdbwin == -1
" if multi-tab or the buffer is hidden
call s:VGdb_openWindow()
let gdbwin = bufwinnr(s:vgdb_bufname)
endif
exec gdbwin . "wincmd w"
endf
function! s:gotoTgtWin()
let gdbwin = bufwinnr(s:vgdb_bufname)
if winnr() == gdbwin
exec "wincmd p"
endif
endf
function! s:VGdb_bpkey(file, line)
return a:file . ":" . a:line
endf
function! s:VGdb_curpos()
" ???? filename ????
let file = expand("%:t")
let line = line(".")
return s:VGdb_bpkey(file, line)
endf
function! s:placebp(id, line, bnr, disabled)
let name = (!a:disabled)? "vgdbBreakpoint": "vgdbDisabledbp"
execute "sign place " . a:id . " name=" . name . " line=" . a:line. " buffer=" . a:bnr
endf
function! s:unplacebp(id)
execute "sign unplace ". a:id
endf
function! s:setbp(file, lineno, disabled)
if a:file == "" || a:lineno == 0
let key = s:VGdb_curpos()
else
let key = s:VGdb_bpkey(a:file, a:lineno)
endif
let s:set_disabled_bp = a:disabled
call VGdb("break ".key)
let s:set_disabled_bp = 0
" will auto call back s:VGdb_cb_setbp
endf
function! s:delbp(id)
call VGdb("delete ".a:id)
call s:VGdb_cb_delbp(a:id)
" call VGdb("clear ".key)
endf
"}}}
" ====== functions {{{
" Get ready for communication
function! s:VGdb_openWindow()
let bufnum = bufnr(s:vgdb_bufname)
if bufnum == -1
" Create a new buffer
let wcmd = s:vgdb_bufname
else
" Edit the existing buffer
let wcmd = '+buffer' . bufnum
endif
" Create the tag explorer window
exe 'silent! botright ' . s:vgdb_winheight . 'split ' . wcmd
endfunction
" NOTE: this function will be called by vgdb script.
function! VGdb_open()
" save current setting and restore when vgdb quits via 'so .exrc'
mk!
set nocursorline
set nocursorcolumn
call s:VGdb_openWindow()
" Mark the buffer as a scratch buffer
setlocal buftype=nofile
setlocal bufhidden=delete
setlocal noswapfile
setlocal nowrap
setlocal nobuflisted
setlocal nonumber
setlocal winfixheight
setlocal cursorline
setlocal foldcolumn=2
setlocal foldtext=VGdb_foldTextExpr()
setlocal foldmarker={,}
setlocal foldmethod=marker
augroup VGdbAutoCommand
" autocmd WinEnter <buffer> if line(".")==line("$") | starti | endif
autocmd WinLeave <buffer> stopi
autocmd BufUnload <buffer> call s:VGdb_bufunload()
augroup end
call s:VGdb_shortcuts()
let s:vgdb_running = 1
call VGdb(".init") " get init msg
starti!
"wincmd p
endfunction
function! s:VGdb_bufunload()
if s:vgdb_running
call VGdb('q')
else
call s:VGdb_cb_close()
endif
endfunction
function! s:VGdb_goto(file, line)
let f = s:getFixedPath(a:file)
if strlen(f) == 0
return
endif
call s:gotoTgtWin()
if bufnr(f) != bufnr("%")
if &modified || bufname("%") == s:vgdb_bufname
execute 'new '.f
else
execute 'e '.f
endif
" resolve bp when entering new buffer
let base = s:basename(a:file)
if has_key(s:unresolved_bplist, base)
let bplist = s:unresolved_bplist[base]
for [id, bp] in items(bplist)
call s:VGdb_cb_setbp(id, bp.file, bp.line)
endfor
unlet s:unresolved_bplist[base]
endif
endif
execute a:line
if has('folding')
silent! foldopen!
endif
redraw
" call winline()
endf
function! s:getFixedPath(file)
if ! filereadable(a:file)
let base = s:basename(a:file)
if has_key(s:nameMap, base)
return s:nameMap[base]
endif
if base == expand("%:t")
let s:nameMap[base] = expand("%:p")
return s:nameMap[base]
endif
let nr = bufnr(base)
if nr != -1
let s:nameMap[base] = bufname(nr)
return s:nameMap[base]
endif
return ""
endif
return a:file
endf
" breakpoint highlight line may move after you edit the file.
" this function re-set such BPs (except disables ones) that don't match the actual line.
function! s:refreshBP()
" get sign list
lan message C
redir => a
sign place
redir end
" e.g.
" Signs for cpp1.cpp:
" line=71 id=1 name=disabledbp
" line=73 id=1 name=disabledbp
" Signs for /usr/share/vim/current/doc/eval.txt:
" line=4 id=1 name=bp1
let confirmed = 0
for line in split(a, "\n")
if s:mymatch(line, '\v\s+line\=(\d+)\s+id\=(\d+)') && has_key(s:bplist, s:match[2])
let lineno = s:match[1]
let id = s:match[2]
let bp = s:bplist[id]
if bp.line != lineno
if !confirmed
let choice = confirm("Breakpoint position changes. Refresh now? (Choose No if the source code does not match the executable.)", "&Yes\n&No")
if choice != 1
break
endif
let confirmed = 1
endif
call s:delbp(id)
call s:setbp(bp.file, lineno, bp.disabled)
endif
endif
endfor
endf
function! s:setDebugging(val)
if s:debugging != a:val
if s:debugging == 0 " 0 -> 1: run/attach
call s:refreshBP()
endif
let s:debugging = a:val
endif
endf
"====== callback {{{
let s:callmap={
\'setdbg': 's:setdbg',
\'setbp': 's:VGdb_cb_setbp',
\'delbp': 's:VGdb_cb_delbp',
\'setpos': 's:VGdb_cb_setpos',
\'delpos': 's:VGdb_cb_delpos',
\'exe': 's:VGdb_cb_exe',
\'quit': 's:VGdb_cb_close'
\ }
function! s:setdbg(dbg)
let s:dbg = a:dbg
if s:dbg == "perldb"
let s:vgdb_prompt = " DB<1> "
elseif s:dbg == 'gdb'
let s:vgdb_prompt = "(gdb) "
endif
endf
function! s:VGdb_cb_setbp(id, file, line, ...)
if has_key(s:bplist, a:id)
return
endif
let hint = a:0>0 ? a:1 : ''
let bp = {'file': a:file, 'line': a:line, 'disabled': s:set_disabled_bp}
let f = s:getFixedPath(a:file)
if (hint == 'pending' && bufnr(a:file) == -1) || strlen(f)==0
let base = s:basename(a:file)
if !has_key(s:unresolved_bplist, base)
let s:unresolved_bplist[base] = {}
endif
let bplist = s:unresolved_bplist[base]
let bplist[a:id] = bp
return
endif
call s:VGdb_goto(f, a:line)
" execute "sign unplace ". a:id
if bp.disabled
call VGdb("disable ".a:id)
endif
call s:placebp(a:id, a:line, bufnr(f), bp.disabled)
let s:bplist[a:id] = bp
endfunction
function! s:VGdb_cb_delbp(id)
if has_key(s:bplist, a:id)
unlet s:bplist[a:id]
call s:unplacebp(a:id)
endif
endf
let s:last_id = 0
function! s:VGdb_cb_setpos(file, line)
if a:line <= 0
call s:setDebugging(1)
return
endif
let s:nameMap[s:basename(a:file)] = a:file
call s:VGdb_goto(a:file, a:line)
call s:setDebugging(1)
" place the next line before unplacing the previous
" otherwise display will jump
let newid = (s:last_id+1) % 2
execute "sign place " . (10000+newid) ." name=vgdbCurrent line=".a:line." buffer=".bufnr(a:file)
execute "sign unplace ". (10000+s:last_id)
let s:last_id = newid
endf
function! s:VGdb_cb_delpos()
execute "sign unplace ". (10000+s:last_id)
call s:setDebugging(0)
endf
function! s:VGdb_cb_exe(cmd)
exe a:cmd
endf
function! s:VGdb_cb_close()
if !s:vgdb_running
return
endif
let s:vgdb_running = 0
let s:bplist = {}
let s:unresolved_bplist = {}
sign unplace *
if has('balloon_eval')
set bexpr&
endif
" If gdb window is open then close it.
call s:gotoGdbWin()
quit
silent! autocmd! VGdbAutoCommand
if s:ismswin
so _exrc
else
so .exrc
endif
endf
"}}}
function! VGdb_call(cmd)
let usercmd = a:cmd
if exists("g:vgdb_useperl") && g:vgdb_useperl
perl <<EOF
open O, ">tmp1";
select O;
my $usercmd = VIM::Eval("usercmd");
{
local @ARGV = ('-c', $usercmd);
do "d:/prog2/vgdb/vgdb";
}
close O;
EOF
let lines = readfile("tmp1")
elseif exists("g:vgdb_uselibcall") && g:vgdb_uselibcall
let lines = libcall(s:vgdb_lib, "tcpcall", usercmd)
else
let usercmd = substitute(usercmd, '["$]', '\\\0', 'g')
let lines = system(s:vgdb_client . " \"" . usercmd . "\"")
endif
return lines
endf
" mode: i|n|c|<empty>
" i - input command in VGDB window and press enter
" n - press enter (or double click) in VGDB window
" c - run Gdb command
function! VGdb(cmd, ...) " [mode]
let usercmd = a:cmd
let mode = a:0>0 ? a:1 : ''
if s:vgdb_running == 0
" let is_loadfile = 0
" let is_loadfile = 1
if !exists('$VGDB_PORT')
if s:ismswin && g:vgdb_uselibcall
" !!!! windows gvim has bug on libcall() - libcall cannot access
" envvar defined in VIM. So here I make the port the same as
" the one in the file vgdbc.c
" LIMITATION: 1 debugging at one time on MSWin with libcall
let $VGDB_PORT = 30899
else
let $VGDB_PORT= 30000 + reltime()[1] % 10000
endif
endif
if s:ismswin
" !!! "!start" is different from "! start"
let startcmd = "!start vgdb.bat -vi " . usercmd
else
if !has('gui')
let startcmd = "!vgdb -vi ".usercmd." &>/dev/null &"
else
let startcmd = "!vgdb -vi ".usercmd." &"
endif
endif
exe 'silent '.startcmd
call VGdb_open()
" if is_loadfile
" sleep 200 m
" call VGdb("@tb main; r")
" return
" endif
return
endif
if s:vgdb_running == 0
echo "vgdb is not running"
return
endif
let curwin = winnr()
let stayInTgtWin = 0
if s:dbg == 'gdb' && usercmd =~ '^\s*(gdb)'
let usercmd = substitute(usercmd, '^\s*(gdb)\s*', '', '')
elseif s:dbg == 'perldb' && usercmd =~ '^\s*DB<'
let usercmd = substitute(usercmd, s:perldbPromptRE, '', '')
elseif mode == 'i'
" trim left and clean the search word
s/^\s\+//e
let @/=''
if line('.') != line('$')
call append('$', s:vgdb_prompt . usercmd)
$
else
exe "normal I" . s:vgdb_prompt
endif
endif
" goto frame
" i br (info breakpoints)
" #0 0x00007fc54f6955e7 in recv () from /lib64/libpthread.so.0
if s:mymatch(usercmd, '\v^#(\d+)') && s:debugging
let usercmd = "@frame " . s:match[1]
let stayInTgtWin = 1
let mode = 'n'
" goto thread and show frames
" i thr (info threads)
" 7 Thread 0x7fc54032b700 (LWP 25787) "java" 0x00007fc54f6955e7 in recv () from /lib64/libpthread.so.0
elseif s:mymatch(usercmd, '\v^\s+(\d+)\s+Thread ') && s:debugging
let usercmd = "@thread " . s:match[1] . "; bt"
" Breakpoint 1, TmScrParser::Parse (this=0x7fffffffbbb0) at ../../BuildBuilder/CreatorDll/TmScrParser.cpp:64
" Breakpoint 14 at 0x7ffff7bbeec1: file ../../BuildBuilder/CreatorDll/RDLL_SboP.cpp, line 111.
" Breakpoint 6 (/home/builder/depot/BUSMB_B1/SBO/9.01_DEV/BuildBuilder/CreatorDll/RDLL_SboP.cpp:92) pending.
" Breakpoint 17 at 0x7fc3f1f8b523: B1FileWriter.cpp:268. (2 locations)
elseif s:mymatch(usercmd, '\v<at %(0x\S+ )?(..[^:]*):(\d+)') || s:mymatch(usercmd, '\vfile ([^,]+), line (\d+)') || s:mymatch(usercmd, '\v\((..[^:]*):(\d+)\)')
call s:VGdb_goto(s:match[1], s:match[2])
return
" for perldb:
" @ = main::getElems(...) called from file `./parse_vc10.pl' line 207
" Note: On windows: perldb uses "'" rather than "`"
" DB::eval called at /usr/lib/perl5/5.10.0/perl5db.pl line 3436
" syntax error at (eval 9)[C:/Perl/lib/perl5db.pl:646] line 2, near "frame 0"
elseif s:mymatch(usercmd, '\v from file [`'']([^'']+)'' line (\d+)') || s:mymatch(usercmd, '\v at ([^ ]+) line (\d+)') || s:mymatch(usercmd, '\v at \(eval \d+\)(..[^:]+):(\d+)')
call s:VGdb_goto(s:match[1], s:match[2])
return
elseif mode == 'n' " mode n: jump to source or current callstack, dont exec other gdb commands
call VGdb_expandPointerExpr()
return
endif
call s:gotoGdbWin()
if getline("$") =~ '^\s*$'
$delete
endif
let lines = split(VGdb_call(usercmd), "\n")
for line in lines
let hideline = 0
if line =~ '^vi:'
let cmd = substitute(line, '\v^vi:(\w+)', '\=s:callmap[submatch(1)]', "")
let hideline = 1
exec 'call ' . cmd
if line =~ ':quit()'
return
endif
endif
if !hideline
call s:gotoGdbWin()
" bugfix: '{0x123}' is wrong treated when foldmethod=marker
let line = substitute(line, '{\ze\S', '{ ', 'g')
call append(line("$"), line)
$
redraw
"let output_{out_count} = substitute(line, "", "", "g")
endif
endfor
if s:dbg == 'perldb' && line =~ s:perldbPromptRE
let s:vgdb_prompt = line
endif
if mode == 'i' && !stayInTgtWin
call s:gotoGdbWin()
if getline('$') != s:vgdb_prompt
call append('$', s:vgdb_prompt)
endif
$
starti!
endif
if stayInTgtWin
call s:gotoTgtWin()
elseif curwin != winnr()
exec curwin."wincmd w"
endif
endf
" Toggle breakpoints
function! VGdb_toggle(forDisable)
call s:gotoTgtWin()
let file = expand("%:t")
let line = line('.')
for [id, bp] in items(s:bplist)
if bp.line == line && s:basename(bp.file) == file
if ! a:forDisable
call s:delbp(id)
else
if bp.disabled
call VGdb("enable ".id)
else
call VGdb("disable ".id)
endif
let bp.disabled = !bp.disabled
call s:placebp(id, bp.line, bufnr("%"), bp.disabled)
endif
return
endif
endfor
if ! a:forDisable
call s:setbp('', 0, 0) " set on current position
endif
endf
function! VGdb_jump()
call s:gotoTgtWin()
let key = s:VGdb_curpos()
" call VGdb("@tb ".key." ; ju ".key)
" call VGdb("set $rbp1=$rbp; set $rsp1=$rsp; @tb ".key." ; ju ".key . "; set $rsp=$rsp1; set $rbp=$rbp1")
call VGdb(".ju ".key)
endf
function! VGdb_runToCursur()
call s:gotoTgtWin()
let key = s:VGdb_curpos()
call VGdb("@tb ".key." ; c")
endf
function! s:VGdb_shortcuts()
" syntax
syn keyword vgdbKey Function Breakpoint Catchpoint
syn match vgdbFrame /\v^#\d+ .*/ contains=vgdbGoto
syn match vgdbGoto /\v<at [^()]+:\d+|file .+, line \d+/
syn match vgdbCmd /^(gdb).*/
syn match vgdbPtr /\v(^|\s+)\zs\$?\w+ \=.{-0,} 0x\w+/
" highlight the whole line for
" returns for info threads | info break | finish | watchpoint
syn match vgdbHiLn /\v^\s*(Id\s+Target Id|Num\s+Type|Value returned is|(Old|New) value =|Hardware watchpoint).*$/
" syntax for perldb
syn match vgdbCmd /^\s*DB<.*/
" syn match vgdbFrame /\v^#\d+ .*/ contains=vgdbGoto
syn match vgdbGoto /\v from file ['`].+' line \d+/
syn match vgdbGoto /\v at ([^ ]+) line (\d+)/
syn match vgdbGoto /\v at \(eval \d+\)..[^:]+:\d+/
" shortcut in VGDB window
inoremap <buffer> <silent> <CR> <c-o>:call VGdb(getline('.'), 'i')<cr>
imap <buffer> <silent> <2-LeftMouse> <cr>
imap <buffer> <silent> <kEnter> <cr>
nnoremap <buffer> <silent> <CR> :call VGdb(getline('.'), 'n')<cr>
nmap <buffer> <silent> <2-LeftMouse> <cr>
nmap <buffer> <silent> <kEnter> <cr>
inoremap <buffer> <silent> <TAB> <C-X><C-L>
"nnoremap <buffer> <silent> : <C-W>p:
nmap <silent> <F9> :call VGdb_toggle(0)<CR>
nmap <silent> <C-F9> :call VGdb_toggle(1)<CR>
nmap <silent> <Leader>ju :call VGdb_jump()<CR>
nmap <silent> <C-S-F10> :call VGdb_jump()<CR>
nmap <silent> <C-F10> :call VGdb_runToCursur()<CR>
" nmap <silent> <F6> :call VGdb("run")<CR>
nmap <silent> <C-P> :VGdb .p <C-R><C-W><CR>
vmap <silent> <C-P> y:VGdb .p <C-R>0<CR>
nmap <silent> <Leader>pr :VGdb p <C-R><C-W><CR>
vmap <silent> <Leader>pr y:VGdb p <C-R>0<CR>
nmap <silent> <Leader>bt :VGdb bt<CR>
map <silent> <F5> :VGdb .c<cr>
map <silent> <S-F5> :VGdb k<cr>
map <silent> <F10> :VGdb n<cr>
map <silent> <F11> :VGdb s<cr>
map <silent> <S-F11> :VGdb finish<cr>
amenu VGdb.Toggle\ breakpoint<tab>F9 :call VGdb_toggle(0)<CR>
amenu VGdb.Run/Continue<tab>F5 :VGdb c<CR>
amenu VGdb.Step\ into<tab>F11 :VGdb s<CR>
amenu VGdb.Next<tab>F10 :VGdb n<CR>
amenu VGdb.Step\ out<tab>Shift-F11 :VGdb finish<CR>
amenu VGdb.Run\ to\ cursor<tab>Ctrl-F10 :call VGdb_runToCursur()<CR>
amenu VGdb.Stop\ debugging\ (Kill)<tab>Shift-F5 :VGdb k<CR>
amenu VGdb.-sep1- :
amenu VGdb.Show\ callstack<tab>\\bt :call VGdb("where")<CR>
amenu VGdb.Set\ next\ statement\ (Jump)<tab>Ctrl-Shift-F10\ or\ \\ju :call VGdb_jump()<CR>
amenu VGdb.Top\ frame :call VGdb("frame 0")<CR>
amenu VGdb.Callstack\ up :call VGdb("up")<CR>
amenu VGdb.Callstack\ down :call VGdb("down")<CR>
amenu VGdb.-sep2- :
amenu VGdb.Preview\ variable<tab>Ctrl-P :VGdb .p <C-R><C-W><CR>
amenu VGdb.Print\ variable<tab>\\pr :VGdb p <C-R><C-W><CR>
amenu VGdb.Show\ breakpoints :VGdb info breakpoints<CR>
amenu VGdb.Show\ locals :VGdb info locals<CR>
amenu VGdb.Show\ args :VGdb info args<CR>
amenu VGdb.Quit :VGdb q<CR>
if has('balloon_eval')
set bexpr=VGdb_balloonExpr()
set balloondelay=500
set ballooneval
endif
endf
function! VGdb_balloonExpr()
return VGdb_call('.p '.v:beval_text)
" return 'Cursor is at line ' . v:beval_lnum .
" \', column ' . v:beval_col .
" \ ' of file ' . bufname(v:beval_bufnr) .
" \ ' on word "' . v:beval_text . '"'
endf
function! VGdb_foldTextExpr()
return getline(v:foldstart) . ' ' . substitute(getline(v:foldstart+1), '\v^\s+', '', '') . ' ... (' . (v:foldend-v:foldstart-1) . ' lines)'
endfunction
" if the value is a pointer ( var = 0x...), expand it by "VGdb .p *var"
" e.g. $11 = (CDBMEnv *) 0x387f6d0
" e.g.
" (CDBMEnv) $22 = {
" m_pTempTables = 0x37c6830,
" ...
" }
function! VGdb_expandPointerExpr()
if ! s:mymatch(getline('.'), '\v((\$|\w)+) \=.{-0,} 0x')
return 0
endif
let cmd = s:match[1]
let lastln = line('.')
while 1
normal [z
if line('.') == lastln
break
endif
let lastln = line('.')
if ! s:mymatch(getline('.'), '\v(([<>$]|\w)+) \=')
return 0
endif
" '<...>' means the base class. Just ignore it. Example:
" (OBserverDBMCInterface) $4 = {
" <__DBMC_ObserverA> = {
" members of __DBMC_ObserverA:
" m_pEnv = 0x378de60
" }, <No data fields>}
if s:match[1][0:0] != '<'
let cmd = s:match[1] . '.' . cmd
endif
endwhile
" call append('$', cmd)
exec "VGdb .p *" . cmd
if foldlevel('.') > 0
" goto beginning of the fold and close it
normal [zzc
" ensure all folds for this var are closed
foldclose!
endif
return 1
endf
"}}}
" ====== commands {{{
command! -nargs=* -complete=file VGdb :call VGdb(<q-args>)
ca gdb VGdb
ca Gdb VGdb
" directly show result; must run after VGdb is running
command! -nargs=* -complete=file VGdbcall :echo VGdb_call(<q-args>)
"}}}
" vim: set foldmethod=marker :