comparison runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @ 15129:2090f267b311 v8.1.0575

patch 8.1.0575: Termdebug: clearing multi-breakpoint does not work commit https://github.com/vim/vim/commit/37402ed53475166cd988edbea1269fa4e9918dc4 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 9 15:53:01 2018 +0100 patch 8.1.0575: Termdebug: clearing multi-breakpoint does not work Problem: Termdebug: clearing multi-breakpoint does not work. Solution: Delete all X.Y breakpoints. Keep more information about placed breakpoints. (Ozaki Kiichi, closes #3641)
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 Dec 2018 16:00:06 +0100
parents 8690318105ee
children 0e7615548cef
comparison
equal deleted inserted replaced
15128:16186d27897d 15129:2090f267b311
72 let s:pc_id = 12 72 let s:pc_id = 12
73 let s:break_id = 13 " breakpoint number is added to this 73 let s:break_id = 13 " breakpoint number is added to this
74 let s:stopped = 1 74 let s:stopped = 1
75 75
76 " Take a breakpoint number as used by GDB and turn it into an integer. 76 " Take a breakpoint number as used by GDB and turn it into an integer.
77 " The breakpoint may contain a dot: 123.4 77 " The breakpoint may contain a dot: 123.4 -> 123004
78 func s:Breakpoint2SignNumber(nr) 78 " The main breakpoint has a zero subid.
79 let t = split(a:nr, '\.') 79 func s:Breakpoint2SignNumber(id, subid)
80 return t[0] * 1000 + (len(t) == 2 ? t[1] : 0) 80 return s:break_id + a:id * 1000 + a:subid
81 endfunction 81 endfunction
82 82
83 func s:Highlight(init, old, new) 83 func s:Highlight(init, old, new)
84 let default = a:init ? 'default ' : '' 84 let default = a:init ? 'default ' : ''
85 if a:new ==# 'light' && a:old !=# 'light' 85 if a:new ==# 'light' && a:old !=# 'light'
360 endif 360 endif
361 endif 361 endif
362 362
363 " Contains breakpoints that have been placed, key is a string with the GDB 363 " Contains breakpoints that have been placed, key is a string with the GDB
364 " breakpoint number. 364 " breakpoint number.
365 " Each entry is a dict, containing the sub-breakpoints. Key is the subid.
366 " For a breakpoint that is just a number the subid is zero.
367 " For a breakpoint "123.4" the id is "123" and subid is "4".
368 " Example, when breakpoint "44", "123", "123.1" and "123.2" exist:
369 " {'44': {'0': entry}, '123': {'0': entry, '1': entry, '2': entry}}
365 let s:breakpoints = {} 370 let s:breakpoints = {}
371
372 " Contains breakpoints by file/lnum. The key is "fname:lnum".
373 " Each entry is a list of breakpoint IDs at that position.
374 let s:breakpoint_locations = {}
366 375
367 augroup TermDebug 376 augroup TermDebug
368 au BufRead * call s:BufRead() 377 au BufRead * call s:BufRead()
369 au BufUnload * call s:BufUnloaded() 378 au BufUnload * call s:BufUnloaded()
370 au OptionSet background call s:Highlight(0, v:option_old, v:option_new) 379 au OptionSet background call s:Highlight(0, v:option_old, v:option_new)
681 aunmenu PopUp.Evaluate 690 aunmenu PopUp.Evaluate
682 endif 691 endif
683 endif 692 endif
684 693
685 exe 'sign unplace ' . s:pc_id 694 exe 'sign unplace ' . s:pc_id
686 for key in keys(s:breakpoints) 695 for [id, entries] in items(s:breakpoints)
687 exe 'sign unplace ' . (s:break_id + s:Breakpoint2SignNumber(key)) 696 for subid in keys(entries)
697 exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid)
698 endfor
688 endfor 699 endfor
689 unlet s:breakpoints 700 unlet s:breakpoints
701 unlet s:breakpoint_locations
690 702
691 sign undefine debugPC 703 sign undefine debugPC
692 for val in s:BreakpointSigns 704 for val in s:BreakpointSigns
693 exe "sign undefine debugBreakpoint" . val 705 exe "sign undefine debugBreakpoint" . val
694 endfor 706 endfor
719 731
720 " :Clear - Delete a breakpoint at the cursor position. 732 " :Clear - Delete a breakpoint at the cursor position.
721 func s:ClearBreakpoint() 733 func s:ClearBreakpoint()
722 let fname = fnameescape(expand('%:p')) 734 let fname = fnameescape(expand('%:p'))
723 let lnum = line('.') 735 let lnum = line('.')
724 for [key, val] in items(s:breakpoints) 736 let bploc = printf('%s:%d', fname, lnum)
725 if val['fname'] == fname && val['lnum'] == lnum 737 if has_key(s:breakpoint_locations, bploc)
726 call s:SendCommand('-break-delete ' . key) 738 let idx = 0
727 " Assume this always wors, the reply is simply "^done". 739 for id in s:breakpoint_locations[bploc]
728 exe 'sign unplace ' . (s:break_id + s:Breakpoint2SignNumber(key)) 740 if has_key(s:breakpoints, id)
729 unlet s:breakpoints[key] 741 " Assume this always works, the reply is simply "^done".
730 break 742 call s:SendCommand('-break-delete ' . id)
731 endif 743 for subid in keys(s:breakpoints[id])
732 endfor 744 exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid)
745 endfor
746 unlet s:breakpoints[id]
747 unlet s:breakpoint_locations[bploc][idx]
748 break
749 else
750 let idx += 1
751 endif
752 endfor
753 if empty(s:breakpoint_locations[bploc])
754 unlet s:breakpoint_locations[bploc]
755 endif
756 endif
733 endfunc 757 endfunc
734 758
735 func s:Run(args) 759 func s:Run(args)
736 if a:args != '' 760 if a:args != ''
737 call s:SendCommand('-exec-arguments ' . a:args) 761 call s:SendCommand('-exec-arguments ' . a:args)
871 call win_gotoid(wid) 895 call win_gotoid(wid)
872 endfunc 896 endfunc
873 897
874 let s:BreakpointSigns = [] 898 let s:BreakpointSigns = []
875 899
876 func s:CreateBreakpoint(nr) 900 func s:CreateBreakpoint(id, subid)
877 if index(s:BreakpointSigns, a:nr) == -1 901 let nr = printf('%d.%d', a:id, a:subid)
878 call add(s:BreakpointSigns, a:nr) 902 if index(s:BreakpointSigns, nr) == -1
879 exe "sign define debugBreakpoint" . a:nr . " text=" . substitute(a:nr, '\..*', '', '') . " texthl=debugBreakpoint" 903 call add(s:BreakpointSigns, nr)
880 endif 904 exe "sign define debugBreakpoint" . nr . " text=" . substitute(nr, '\..*', '', '') . " texthl=debugBreakpoint"
881 endfunc 905 endif
882 906 endfunc
883 func s:SplitMsg(s) 907
884 return split(a:s, '{\%([a-z-]\+=[^,]\+,*\)\+}\zs') 908 func! s:SplitMsg(s)
909 return split(a:s, '{.\{-}}\zs')
885 endfunction 910 endfunction
886 911
887 " Handle setting a breakpoint 912 " Handle setting a breakpoint
888 " Will update the sign that shows the breakpoint 913 " Will update the sign that shows the breakpoint
889 func s:HandleNewBreakpoint(msg) 914 func s:HandleNewBreakpoint(msg)
898 endif 923 endif
899 let nr = substitute(msg, '.*number="\([0-9.]*\)\".*', '\1', '') 924 let nr = substitute(msg, '.*number="\([0-9.]*\)\".*', '\1', '')
900 if empty(nr) 925 if empty(nr)
901 return 926 return
902 endif 927 endif
903 call s:CreateBreakpoint(nr) 928
904 929 " If "nr" is 123 it becomes "123.0" and subid is "0".
905 if has_key(s:breakpoints, nr) 930 " If "nr" is 123.4 it becomes "123.4.0" and subid is "4"; "0" is discarded.
906 let entry = s:breakpoints[nr] 931 let [id, subid; _] = map(split(nr . '.0', '\.'), 'v:val + 0')
932 call s:CreateBreakpoint(id, subid)
933
934 if has_key(s:breakpoints, id)
935 let entries = s:breakpoints[id]
936 else
937 let entries = {}
938 let s:breakpoints[id] = entries
939 endif
940 if has_key(entries, subid)
941 let entry = entries[subid]
907 else 942 else
908 let entry = {} 943 let entry = {}
909 let s:breakpoints[nr] = entry 944 let entries[subid] = entry
910 endif 945 endif
911 946
912 let lnum = substitute(msg, '.*line="\([^"]*\)".*', '\1', '') 947 let lnum = substitute(msg, '.*line="\([^"]*\)".*', '\1', '')
913 let entry['fname'] = fname 948 let entry['fname'] = fname
914 let entry['lnum'] = lnum 949 let entry['lnum'] = lnum
915 950
951 let bploc = printf('%s:%d', fname, lnum)
952 if !has_key(s:breakpoint_locations, bploc)
953 let s:breakpoint_locations[bploc] = []
954 endif
955 let s:breakpoint_locations[bploc] += [id]
956
916 if bufloaded(fname) 957 if bufloaded(fname)
917 call s:PlaceSign(nr, entry) 958 call s:PlaceSign(id, subid, entry)
918 endif 959 endif
919 endfor 960 endfor
920 endfunc 961 endfunc
921 962
922 func s:PlaceSign(nr, entry) 963 func s:PlaceSign(id, subid, entry)
923 exe 'sign place ' . (s:break_id + s:Breakpoint2SignNumber(a:nr)) . ' line=' . a:entry['lnum'] . ' name=debugBreakpoint' . a:nr . ' file=' . a:entry['fname'] 964 let nr = printf('%d.%d', a:id, a:subid)
965 exe 'sign place ' . s:Breakpoint2SignNumber(a:id, a:subid) . ' line=' . a:entry['lnum'] . ' name=debugBreakpoint' . nr . ' file=' . a:entry['fname']
924 let a:entry['placed'] = 1 966 let a:entry['placed'] = 1
925 endfunc 967 endfunc
926 968
927 " Handle deleting a breakpoint 969 " Handle deleting a breakpoint
928 " Will remove the sign that shows the breakpoint 970 " Will remove the sign that shows the breakpoint
929 func s:HandleBreakpointDelete(msg) 971 func s:HandleBreakpointDelete(msg)
930 let key = substitute(a:msg, '.*id="\([0-9.]*\)\".*', '\1', '') 972 let id = substitute(a:msg, '.*id="\([0-9]*\)\".*', '\1', '') + 0
931 if empty(key) 973 if empty(id)
932 return 974 return
933 endif 975 endif
934 for [nr, entry] in items(s:breakpoints) 976 if has_key(s:breakpoints, id)
935 if stridx(nr, key) != 0 977 for [subid, entry] in items(s:breakpoints[id])
936 continue 978 if has_key(entry, 'placed')
937 endif 979 exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid)
938 let entry = s:breakpoints[nr] 980 unlet entry['placed']
939 if has_key(entry, 'placed') 981 endif
940 exe 'sign unplace ' . (s:break_id + s:Breakpoint2SignNumber(nr)) 982 endfor
941 unlet entry['placed'] 983 unlet s:breakpoints[id]
942 endif 984 endif
943 unlet s:breakpoints[nr]
944 endfor
945 endfunc 985 endfunc
946 986
947 " Handle the debugged program starting to run. 987 " Handle the debugged program starting to run.
948 " Will store the process ID in s:pid 988 " Will store the process ID in s:pid
949 func s:HandleProgramRun(msg) 989 func s:HandleProgramRun(msg)
956 endfunc 996 endfunc
957 997
958 " Handle a BufRead autocommand event: place any signs. 998 " Handle a BufRead autocommand event: place any signs.
959 func s:BufRead() 999 func s:BufRead()
960 let fname = expand('<afile>:p') 1000 let fname = expand('<afile>:p')
961 for [nr, entry] in items(s:breakpoints) 1001 for [id, entries] in items(s:breakpoints)
962 if entry['fname'] == fname 1002 for [subid, entry] in items(entries)
963 call s:PlaceSign(nr, entry) 1003 if entry['fname'] == fname
964 endif 1004 call s:PlaceSign(id, subid, entry)
1005 endif
1006 endfor
965 endfor 1007 endfor
966 endfunc 1008 endfunc
967 1009
968 " Handle a BufUnloaded autocommand event: unplace any signs. 1010 " Handle a BufUnloaded autocommand event: unplace any signs.
969 func s:BufUnloaded() 1011 func s:BufUnloaded()
970 let fname = expand('<afile>:p') 1012 let fname = expand('<afile>:p')
971 for [nr, entry] in items(s:breakpoints) 1013 for [id, entries] in items(s:breakpoints)
972 if entry['fname'] == fname 1014 for [subid, entry] in items(entries)
973 let entry['placed'] = 0 1015 if entry['fname'] == fname
974 endif 1016 let entry['placed'] = 0
1017 endif
1018 endfor
975 endfor 1019 endfor
976 endfunc 1020 endfunc
977 1021
978 let &cpo = s:keepcpo 1022 let &cpo = s:keepcpo
979 unlet s:keepcpo 1023 unlet s:keepcpo