Mercurial > vim
comparison runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @ 23573:e2e2cc5d0856
Update runtime files.
Commit: https://github.com/vim/vim/commit/82be4849eed0b8fbee45bc8da99b685ec89af59a
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 11 19:40:15 2021 +0100
Update runtime files.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 11 Jan 2021 19:45:05 +0100 |
parents | 99ef85ff1af4 |
children | 840665e74421 |
comparison
equal
deleted
inserted
replaced
23572:b35e568d74e6 | 23573:e2e2cc5d0856 |
---|---|
1 " Debugger plugin using gdb. | 1 " Debugger plugin using gdb. |
2 " | 2 " |
3 " Author: Bram Moolenaar | 3 " Author: Bram Moolenaar |
4 " Copyright: Vim license applies, see ":help license" | 4 " Copyright: Vim license applies, see ":help license" |
5 " Last Change: 2020 Dec 07 | 5 " Last Change: 2021 Jan 03 |
6 " | 6 " |
7 " WORK IN PROGRESS - Only the basics work | 7 " WORK IN PROGRESS - Only the basics work |
8 " Note: On MS-Windows you need a recent version of gdb. The one included with | 8 " Note: On MS-Windows you need a recent version of gdb. The one included with |
9 " MingW is too old (7.6.1). | 9 " MingW is too old (7.6.1). |
10 " I used version 7.12 from http://www.equation.com/servlet/equation.cmd?fa=gdb | 10 " I used version 7.12 from http://www.equation.com/servlet/equation.cmd?fa=gdb |
68 if !exists('g:termdebugger') | 68 if !exists('g:termdebugger') |
69 let g:termdebugger = 'gdb' | 69 let g:termdebugger = 'gdb' |
70 endif | 70 endif |
71 | 71 |
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:asm_id = 13 |
74 let s:break_id = 14 " breakpoint number is added to this | |
74 let s:stopped = 1 | 75 let s:stopped = 1 |
76 | |
77 let s:parsing_disasm_msg = 0 | |
78 let s:asm_lines = [] | |
79 let s:asm_addr = '' | |
75 | 80 |
76 " Take a breakpoint number as used by GDB and turn it into an integer. | 81 " Take a breakpoint number as used by GDB and turn it into an integer. |
77 " The breakpoint may contain a dot: 123.4 -> 123004 | 82 " The breakpoint may contain a dot: 123.4 -> 123004 |
78 " The main breakpoint has a zero subid. | 83 " The main breakpoint has a zero subid. |
79 func s:Breakpoint2SignNumber(id, subid) | 84 func s:Breakpoint2SignNumber(id, subid) |
112 return | 117 return |
113 endif | 118 endif |
114 | 119 |
115 let s:ptywin = 0 | 120 let s:ptywin = 0 |
116 let s:pid = 0 | 121 let s:pid = 0 |
122 let s:asmwin = 0 | |
117 | 123 |
118 " Uncomment this line to write logging in "debuglog". | 124 " Uncomment this line to write logging in "debuglog". |
119 " call ch_logfile('debuglog', 'w') | 125 " call ch_logfile('debuglog', 'w') |
120 | 126 |
121 let s:sourcewin = win_getid(winnr()) | 127 let s:sourcewin = win_getid(winnr()) |
150 | 156 |
151 if s:way == 'prompt' | 157 if s:way == 'prompt' |
152 call s:StartDebug_prompt(a:dict) | 158 call s:StartDebug_prompt(a:dict) |
153 else | 159 else |
154 call s:StartDebug_term(a:dict) | 160 call s:StartDebug_term(a:dict) |
161 endif | |
162 | |
163 if exists('g:termdebug_disasm_window') | |
164 if g:termdebug_disasm_window | |
165 let curwinid = win_getid(winnr()) | |
166 call s:GotoAsmwinOrCreateIt() | |
167 call win_gotoid(curwinid) | |
168 endif | |
155 endif | 169 endif |
156 endfunc | 170 endfunc |
157 | 171 |
158 " Use when debugger didn't start or ended. | 172 " Use when debugger didn't start or ended. |
159 func s:CloseBuffers() | 173 func s:CloseBuffers() |
544 let name = substitute(name, '\\\\', '\\', 'g') | 558 let name = substitute(name, '\\\\', '\\', 'g') |
545 endif | 559 endif |
546 return name | 560 return name |
547 endfunc | 561 endfunc |
548 | 562 |
563 " Extract the "addr" value from a gdb message with addr="0x0001234". | |
564 func s:GetAsmAddr(msg) | |
565 if a:msg !~ 'addr=' | |
566 return '' | |
567 endif | |
568 let addr = s:DecodeMessage(substitute(a:msg, '.*addr=', '', '')) | |
569 return addr | |
570 endfunc | |
549 func s:EndTermDebug(job, status) | 571 func s:EndTermDebug(job, status) |
550 exe 'bwipe! ' . s:commbuf | 572 exe 'bwipe! ' . s:commbuf |
551 unlet s:gdbwin | 573 unlet s:gdbwin |
552 | 574 |
553 call s:EndDebugCommon() | 575 call s:EndDebugCommon() |
607 call s:EndDebugCommon() | 629 call s:EndDebugCommon() |
608 unlet s:gdbwin | 630 unlet s:gdbwin |
609 call ch_log("Returning from EndPromptDebug()") | 631 call ch_log("Returning from EndPromptDebug()") |
610 endfunc | 632 endfunc |
611 | 633 |
634 " Disassembly window - added by Michael Sartain | |
635 " | |
636 " - CommOutput: disassemble $pc | |
637 " - CommOutput: &"disassemble $pc\n" | |
638 " - CommOutput: ~"Dump of assembler code for function main(int, char**):\n" | |
639 " - CommOutput: ~" 0x0000555556466f69 <+0>:\tpush rbp\n" | |
640 " ... | |
641 " - CommOutput: ~" 0x0000555556467cd0:\tpop rbp\n" | |
642 " - CommOutput: ~" 0x0000555556467cd1:\tret \n" | |
643 " - CommOutput: ~"End of assembler dump.\n" | |
644 " - CommOutput: ^done | |
645 | |
646 " - CommOutput: disassemble $pc | |
647 " - CommOutput: &"disassemble $pc\n" | |
648 " - CommOutput: &"No function contains specified address.\n" | |
649 " - CommOutput: ^error,msg="No function contains specified address." | |
650 func s:HandleDisasmMsg(msg) | |
651 if a:msg =~ '^\^done' | |
652 let curwinid = win_getid(winnr()) | |
653 if win_gotoid(s:asmwin) | |
654 silent normal! gg0"_dG | |
655 call setline(1, s:asm_lines) | |
656 set nomodified | |
657 set filetype=asm | |
658 | |
659 let lnum = search('^' . s:asm_addr) | |
660 if lnum != 0 | |
661 exe 'sign unplace ' . s:asm_id | |
662 exe 'sign place ' . s:asm_id . ' line=' . lnum . ' name=debugPC' | |
663 endif | |
664 | |
665 call win_gotoid(curwinid) | |
666 endif | |
667 | |
668 let s:parsing_disasm_msg = 0 | |
669 let s:asm_lines = [] | |
670 elseif a:msg =~ '^\^error,msg=' | |
671 if s:parsing_disasm_msg == 1 | |
672 " Disassemble call ran into an error. This can happen when gdb can't | |
673 " find the function frame address, so let's try to disassemble starting | |
674 " at current PC | |
675 call s:SendCommand('disassemble $pc,+100') | |
676 endif | |
677 let s:parsing_disasm_msg = 0 | |
678 elseif a:msg =~ '\&\"disassemble \$pc' | |
679 if a:msg =~ '+100' | |
680 " This is our second disasm attempt | |
681 let s:parsing_disasm_msg = 2 | |
682 endif | |
683 else | |
684 let value = substitute(a:msg, '^\~\"[ ]*', '', '') | |
685 let value = substitute(value, '^=>[ ]*', '', '') | |
686 let value = substitute(value, '\\n\" | |
687 $', '', '') | |
688 let value = substitute(value, '\\n\"$', '', '') | |
689 let value = substitute(value, ' | |
690 ', '', '') | |
691 let value = substitute(value, '\\t', ' ', 'g') | |
692 | |
693 if value != '' || !empty(s:asm_lines) | |
694 call add(s:asm_lines, value) | |
695 endif | |
696 endif | |
697 endfunc | |
698 | |
612 " Handle a message received from gdb on the GDB/MI interface. | 699 " Handle a message received from gdb on the GDB/MI interface. |
613 func s:CommOutput(chan, msg) | 700 func s:CommOutput(chan, msg) |
614 let msgs = split(a:msg, "\r") | 701 let msgs = split(a:msg, "\r") |
615 | 702 |
616 for msg in msgs | 703 for msg in msgs |
617 " remove prefixed NL | 704 " remove prefixed NL |
618 if msg[0] == "\n" | 705 if msg[0] == "\n" |
619 let msg = msg[1:] | 706 let msg = msg[1:] |
620 endif | 707 endif |
621 if msg != '' | 708 |
709 if s:parsing_disasm_msg | |
710 call s:HandleDisasmMsg(msg) | |
711 elseif msg != '' | |
622 if msg =~ '^\(\*stopped\|\*running\|=thread-selected\)' | 712 if msg =~ '^\(\*stopped\|\*running\|=thread-selected\)' |
623 call s:HandleCursor(msg) | 713 call s:HandleCursor(msg) |
624 elseif msg =~ '^\^done,bkpt=' || msg =~ '^=breakpoint-created,' | 714 elseif msg =~ '^\^done,bkpt=' || msg =~ '^=breakpoint-created,' |
625 call s:HandleNewBreakpoint(msg) | 715 call s:HandleNewBreakpoint(msg) |
626 elseif msg =~ '^=breakpoint-deleted,' | 716 elseif msg =~ '^=breakpoint-deleted,' |
629 call s:HandleProgramRun(msg) | 719 call s:HandleProgramRun(msg) |
630 elseif msg =~ '^\^done,value=' | 720 elseif msg =~ '^\^done,value=' |
631 call s:HandleEvaluate(msg) | 721 call s:HandleEvaluate(msg) |
632 elseif msg =~ '^\^error,msg=' | 722 elseif msg =~ '^\^error,msg=' |
633 call s:HandleError(msg) | 723 call s:HandleError(msg) |
724 elseif msg =~ '^disassemble' | |
725 let s:parsing_disasm_msg = 1 | |
726 let s:asm_lines = [] | |
634 endif | 727 endif |
635 endif | 728 endif |
636 endfor | 729 endfor |
637 endfunc | 730 endfunc |
638 | 731 |
669 | 762 |
670 command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>) | 763 command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>) |
671 command Gdb call win_gotoid(s:gdbwin) | 764 command Gdb call win_gotoid(s:gdbwin) |
672 command Program call s:GotoProgram() | 765 command Program call s:GotoProgram() |
673 command Source call s:GotoSourcewinOrCreateIt() | 766 command Source call s:GotoSourcewinOrCreateIt() |
767 command Asm call s:GotoAsmwinOrCreateIt() | |
674 command Winbar call s:InstallWinbar() | 768 command Winbar call s:InstallWinbar() |
675 | 769 |
676 if !exists('g:termdebug_map_K') || g:termdebug_map_K | 770 if !exists('g:termdebug_map_K') || g:termdebug_map_K |
677 let s:k_map_saved = maparg('K', 'n', 0, 1) | 771 let s:k_map_saved = maparg('K', 'n', 0, 1) |
678 nnoremap K :Evaluate<CR> | 772 nnoremap K :Evaluate<CR> |
722 delcommand Continue | 816 delcommand Continue |
723 delcommand Evaluate | 817 delcommand Evaluate |
724 delcommand Gdb | 818 delcommand Gdb |
725 delcommand Program | 819 delcommand Program |
726 delcommand Source | 820 delcommand Source |
821 delcommand Asm | |
727 delcommand Winbar | 822 delcommand Winbar |
728 | 823 |
729 if exists('s:k_map_saved') | 824 if exists('s:k_map_saved') |
730 if empty(s:k_map_saved) | 825 if empty(s:k_map_saved) |
731 nunmap K | 826 nunmap K |
921 let s:sourcewin = win_getid(winnr()) | 1016 let s:sourcewin = win_getid(winnr()) |
922 call s:InstallWinbar() | 1017 call s:InstallWinbar() |
923 endif | 1018 endif |
924 endfunc | 1019 endfunc |
925 | 1020 |
1021 func s:GotoAsmwinOrCreateIt() | |
1022 if !win_gotoid(s:asmwin) | |
1023 if win_gotoid(s:sourcewin) | |
1024 exe 'rightbelow new' | |
1025 else | |
1026 exe 'new' | |
1027 endif | |
1028 | |
1029 let s:asmwin = win_getid(winnr()) | |
1030 | |
1031 setlocal nowrap | |
1032 setlocal number | |
1033 setlocal noswapfile | |
1034 setlocal buftype=nofile | |
1035 | |
1036 let asmbuf = bufnr('Termdebug-asm-listing') | |
1037 if asmbuf > 0 | |
1038 exe 'buffer' . asmbuf | |
1039 else | |
1040 exe 'file Termdebug-asm-listing' | |
1041 endif | |
1042 | |
1043 if exists('g:termdebug_disasm_window') | |
1044 if g:termdebug_disasm_window > 1 | |
1045 exe 'resize ' . g:termdebug_disasm_window | |
1046 endif | |
1047 endif | |
1048 endif | |
1049 | |
1050 if s:asm_addr != '' | |
1051 let lnum = search('^' . s:asm_addr) | |
1052 if lnum == 0 | |
1053 if s:stopped | |
1054 call s:SendCommand('disassemble $pc') | |
1055 endif | |
1056 else | |
1057 exe 'sign unplace ' . s:asm_id | |
1058 exe 'sign place ' . s:asm_id . ' line=' . lnum . ' name=debugPC' | |
1059 endif | |
1060 endif | |
1061 endfunc | |
1062 | |
926 " Handle stopping and running message from gdb. | 1063 " Handle stopping and running message from gdb. |
927 " Will update the sign that shows the current position. | 1064 " Will update the sign that shows the current position. |
928 func s:HandleCursor(msg) | 1065 func s:HandleCursor(msg) |
929 let wid = win_getid(winnr()) | 1066 let wid = win_getid(winnr()) |
930 | 1067 |
939 if a:msg =~ 'fullname=' | 1076 if a:msg =~ 'fullname=' |
940 let fname = s:GetFullname(a:msg) | 1077 let fname = s:GetFullname(a:msg) |
941 else | 1078 else |
942 let fname = '' | 1079 let fname = '' |
943 endif | 1080 endif |
1081 | |
1082 if a:msg =~ 'addr=' | |
1083 let asm_addr = s:GetAsmAddr(a:msg) | |
1084 if asm_addr != '' | |
1085 let s:asm_addr = asm_addr | |
1086 | |
1087 let curwinid = win_getid(winnr()) | |
1088 if win_gotoid(s:asmwin) | |
1089 let lnum = search('^' . s:asm_addr) | |
1090 if lnum == 0 | |
1091 call s:SendCommand('disassemble $pc') | |
1092 else | |
1093 exe 'sign unplace ' . s:asm_id | |
1094 exe 'sign place ' . s:asm_id . ' line=' . lnum . ' name=debugPC' | |
1095 endif | |
1096 | |
1097 call win_gotoid(curwinid) | |
1098 endif | |
1099 endif | |
1100 endif | |
1101 | |
944 if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname) | 1102 if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname) |
945 let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '') | 1103 let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '') |
946 if lnum =~ '^[0-9]*$' | 1104 if lnum =~ '^[0-9]*$' |
947 call s:GotoSourcewinOrCreateIt() | 1105 call s:GotoSourcewinOrCreateIt() |
948 if expand('%:p') != fnamemodify(fname, ':p') | 1106 if expand('%:p') != fnamemodify(fname, ':p') |