Permalink
Browse files

Version 1.07

1. Disable all breakpoints with :Bc & Enable all breakpoints with :Bu
2. load dbgpavim.py on demand to speed up vim startup
3. fix some bugs
  • Loading branch information...
1 parent cdfe5a8 commit 5b373520618d4e6e0c5751380e1433d08c119bd4 @brookhong brookhong committed with Apr 29, 2014
Showing with 166 additions and 72 deletions.
  1. +5 −0 doc/tags
  2. +88 −21 plugin/dbgpavim.py
  3. +73 −51 plugin/dbgpavim.vim
View
@@ -0,0 +1,5 @@
+DBGPavim dbgpavim.txt /*DBGPavim*
+Status dbgpavim.txt /*Status*
+Usage dbgpavim.txt /*Usage*
+commands dbgpavim.txt /*commands*
+enhancements dbgpavim.txt /*enhancements*
View
@@ -1,3 +1,4 @@
+# encoding: utf-8
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab
# -*- c--oding: ko_KR.UTF-8 -*-
# remote PHP debugger : remote debugger interface to DBGp protocol
@@ -60,7 +61,7 @@ def DBGPavimTrace(log):
tracelog.write("\n"+log+"\n")
tracelog.flush()
-class VimWindow:
+class VimWindow(object):
""" wrapper class of window of vim """
def __init__(self, name = 'DEBUG_WINDOW'):
""" initialize """
@@ -80,6 +81,7 @@ def prepare(self):
def before_create(self):
vim.command("1wincmd w")
def on_create(self):
+ self.command('setl noswf')
pass
def getwinnr(self):
return int(vim.eval("bufwinnr('"+self.name+"')"))
@@ -98,7 +100,7 @@ def write(self, msg, lineno = 0):
self.buffer[:] = str(msg).split('\n')
else:
if lineno == 0:
- self.buffer.append(str(msg).split('\n'))
+ self.buffer.append(msg.split('\n'))
self.command('normal G')
else:
self.buffer.append(str(msg).split('\n'), lineno)
@@ -160,6 +162,7 @@ def render(self, xml):
lines += str('%-2s %-15s %s:%s\n' % (node.get('level'), wr+fmark, fn, node.get('lineno')))
self.write(lines)
def on_create(self):
+ super(StackWindow, self).on_create()
self.command('highlight CurStack term=reverse ctermfg=White ctermbg=Red gui=reverse')
self.highlight_stack(0)
def highlight_stack(self, no):
@@ -172,10 +175,10 @@ def __init__(self, name = 'WATCH_WINDOW'):
def decode_string(self, msg, encoding):
if encoding == 'base64':
value = base64.decodestring(msg)
- elif encoding == '' or encoding == None:
+ elif encoding == '' or encoding == None or encoding == 'None':
value = msg
else:
- value = "(e:%s) %s" % (encoding, p.text)
+ value = "(e:%s) %s" % (encoding, msg)
return value
def parseNode1(self, p):
fullname = p.get('fullname')
@@ -246,14 +249,15 @@ def render(self, xml, lineno = 0):
out += "\n"
self.write(out, lineno)
def on_create(self):
+ super(WatchWindow, self).on_create()
self.commenter = '// '
if dbgPavim.fileType == 'php':
self.write('<?')
elif dbgPavim.fileType == 'python':
self.commenter = '## '
+ self.command('setl noai nocin')
+ self.command('setl wrap fdm=manual fmr={{{,}}} ft=%s fdl=1' % (dbgPavim.fileType))
self.command('inoremap <buffer> <cr> <esc>:python dbgPavim.debugSession.watch_execute()<cr>')
- self.command('set noai nocin')
- self.command('set wrap fdm=manual fmr={{{,}}} ft=%s fdl=1' % (dbgPavim.fileType))
def input(self, mode, arg = ''):
if arg == '%v%':
arg = vim.eval('@v')
@@ -281,16 +285,39 @@ def __init__(self, name = 'HELP__WINDOW'):
def before_create(self):
pass
def on_create(self):
- self.write( \
+ super(HelpWindow, self).on_create()
+ if vim.eval('g:dbgPavimLang') == 'cn' :
+ self.write( \
+ '[ Function Keys ] | [ Command Mode ] \n' + \
+ ' <F1> 打开帮助窗口 | :Bp [arg] 切换断点[中断条件] \n' + \
+ ' <F2> 逐语句调试 | :Up 切换至上一个文件 \n' + \
+ ' <F3> 逐过程调试 | :Dn 切换至下一个文件 \n' + \
+ ' <F4> 运行至断点 | :Bl 查看所有断点 \n' + \
+ ' <F5> 开始调试 | :Pg 输出当前变量 \n' + \
+ ' <F6> 退出调试 | :Bc 清除所有断点 \n' + \
+ ' <F7> 监视变量 | :Bu 恢复Bc清除的所有断点 \n' + \
+ ' <F8> 切换自动调试模式 | \n' + \
+ ' <F9> 切换监视窗口 | \n' + \
+ ' <F10> 切换断点 | \n' + \
+ ' <F11> 输出所有变量 | \n' + \
+ ' <F12> 输出当前变量 | \n' + \
+ ' 获取帮助和最新版本,请访问 https://github.com/brookhong/DBGPavim \n' + \
+ '')
+ else :
+ self.write( \
'[ Function Keys ] | [ Command Mode ] \n' + \
' <F1> toggle help window | :Bp toggle breakpoint \n' + \
' <F2> step into | :Up stack up \n' + \
' <F3> step over | :Dn stack down \n' + \
' <F4> step out | :Bl list breakpoints \n' + \
' <F5> run | :Pg property get \n' + \
- ' <F6> quit debugging | <F9> toggle layout \n' + \
- ' <F7> eval | <F11> get all context \n' + \
- ' <F8> toggle dbgPavimBreakAtEntry | <F12> get property at cursor\n' + \
+ ' <F6> quit debugging | :Bc disable all breakpoints \n' + \
+ ' <F7> eval | :Bu enabled all breakpoints \n' + \
+ ' <F8> toggle dbgPavimBreakAtEntry | \n' + \
+ ' <F9> toggle layout | \n' + \
+ ' <F10> toggle breakpoint | \n' + \
+ ' <F11> get all context | \n' + \
+ ' <F12> get property at cursor | \n' + \
' \n' + \
' For more instructions and latest version, \n' + \
' pleae refer to https://github.com/brookhong/DBGPavim \n' + \
@@ -303,6 +330,7 @@ def __init__(self, name = 'CONSOLE__WINDOW'):
def before_create(self):
pass
def on_create(self):
+ super(ConsoleWindow, self).on_create()
vim.command('setlocal autoread')
class DebugUI:
@@ -366,18 +394,20 @@ def normal_mode(self):
self.destroy()
# restore session
- vim.command('source ' + self.sessfile)
- vim.command("let &ssop=\""+self.backup_ssop+"\"")
- os.remove(self.sessfile)
+ try:
+ vim.command('source ' + self.sessfile)
+ finally:
+ vim.command("let &ssop=\""+self.backup_ssop+"\"")
+ os.remove(self.sessfile)
- self.set_highlight()
+ self.set_highlight()
- self.winbuf.clear()
- self.file = None
- self.line = None
- self.mode = DebugUI.NORMAL
- self.cursign = None
- self.cliwin = None
+ self.winbuf.clear()
+ self.file = None
+ self.line = None
+ self.mode = DebugUI.NORMAL
+ self.cursign = None
+ self.cliwin = None
def create(self):
""" create windows """
self.totalW = int(vim.eval('winwidth(0)'))
@@ -631,6 +661,7 @@ def send_msg(self, cmd):
def handle_recvd_msg(self, txt):
# log messages
txt = txt.replace('\n','')
+ txt = txt.replace('<?xml version="1.0" encoding="iso-8859-1"?>', '<?xml version="1.0" encoding="utf-8"?>', 1);
DBGPavimTrace(str(self.msgid)+"<"*16+self.address+"\n"+txt)
resDom = ET.fromstring(txt)
tag = resDom.tag.replace("{urn:debugger_protocol_v1}","")
@@ -997,6 +1028,7 @@ def __init__(self):
self.normal_statusline = vim.eval('&statusline')
self.statusline="%<%f\ %h%m%r\ %=%-10.(%l,%c%V%)\ %P\ %=%{(g:dbgPavimBreakAtEntry==1)?'bae':'bap'}"
self.breakpt = BreakPoint()
+ self.breakold = BreakPoint()
self.ui = DebugUI(0.3, 0.4)
self.watchList = []
self.evalList = []
@@ -1214,9 +1246,44 @@ def cli(self, args):
def list(self):
vim.command("lgetexpr []")
+ inCount = 0
for bno in self.breakpt.list():
- vim.command("lad '"+self.breakpt.getfile(bno)+":"+str(self.breakpt.getline(bno))+":1'")
+ inCount = inCount + 1
+ if self.breakpt.getexp(bno) != '':
+ vim.command("lad '"+"\|condition: "+self.breakpt.getexp(bno)+" \| "+self.breakpt.getfile(bno)+":"+str(self.breakpt.getline(bno))+":1'")
+ else:
+ vim.command("lad '"+self.breakpt.getfile(bno)+":"+str(self.breakpt.getline(bno))+":1'")
vim.command("lw")
+ if inCount > 0 :
+ vim.command("wincmd j")
+ vim.command("resize 10")
+
+ def clear(self):
+ for bno in self.breakpt.list():
+ self.breakold.add(self.breakpt.getfile(bno), self.breakpt.getline(bno), self.breakpt.getexp(bno))
+ vim.command('sign unplace ' + str(bno))
+ id = self.debugSession.getbid(bno)
+ if self.debugSession.sock != None and id != None:
+ self.debugSession.command('breakpoint_remove', '-d ' + str(id))
+ self.breakpt.remove(bno)
+
+ def unclear(self):
+ for bno in self.breakold.list():
+ row = self.breakold.getline(bno)
+ file = self.breakold.getfile(bno)
+ exp = self.breakold.getexp(bno)
+ self.breakold.remove(bno)
+ inbno = self.breakpt.find(file, str(row))
+ if inbno == None:
+ inbno = self.breakpt.add(file, row, exp)
+ vim.command('sign place ' + str(inbno) + ' name=breakpt line=' + str(row) + ' file=' + file)
+ if self.debugSession.sock != None:
+ fn = dbgPavim.remotePathOf(self.breakpt.getfile(inbno))
+ msgid = self.debugSession.send_command('breakpoint_set', \
+ '-t line -f ' + fn + ' -n ' + str(self.breakpt.getline(inbno)), \
+ self.breakpt.getexp(inbno))
+ self.debugSession.bptsetlst[msgid] = inbno
+ self.debugSession.ack_command()
def mark(self, exp = ''):
(row, col) = vim.current.window.cursor
View
@@ -87,11 +87,6 @@ endif
" Load dbgpavim.py either from the same path where dbgpavim.vim is
let s:dbgpavim_py = expand("<sfile>:p:h")."/dbgpavim.py"
-if filereadable(s:dbgpavim_py)
- exec 'pyfile '.s:dbgpavim_py
-else
- call confirm('dbgpavim.vim: Unable to find '.s:dbgpavim_py.'. Place it in either your home vim directory or in the Vim runtime directory.', 'OK')
-endif
if !exists('g:dbgPavimPort')
let g:dbgPavimPort = 9000
@@ -159,54 +154,90 @@ endif
if !exists('g:dbgPavimKeySmallWindow')
let g:dbgPavimKeySmallWindow = '<leader>-'
endif
-exec 'map <silent> '.g:dbgPavimKeyRun.' :python dbgPavim.run()<cr>'
-exec 'map <silent> '.g:dbgPavimKeyQuit.' :python dbgPavim.quit()<cr>'
-exec 'map <silent> '.g:dbgPavimKeyToggleBae.' :call Bae()<cr>'
-exec 'map <silent> '.g:dbgPavimKeyToggleBp.' :python dbgPavim.mark()<cr>'
-exec 'map <silent> '.g:dbgPavimKeyLargeWindow.' :call ResizeWindow("+")<cr>'
-exec 'map <silent> '.g:dbgPavimKeySmallWindow.' :call ResizeWindow("-")<cr>'
-command! -nargs=? Bp python dbgPavim.mark('<args>')
-command! -nargs=0 Bl python dbgPavim.list()
-command! -nargs=? Dp python dbgPavim.cli('<args>')
-command! -nargs=? Wc python dbgPavim.watch("<args>")
-command! -nargs=? We python dbgPavim.eval("<args>")
-command! -nargs=0 Wl python dbgPavim.listWatch()
-command! -nargs=1 Children let g:dbgPavimMaxChildren=<args>|python dbgPavim.setMaxChildren()
-command! -nargs=1 Depth let g:dbgPavimMaxDepth=<args>|python dbgPavim.setMaxDepth()
-command! -nargs=1 Length let g:dbgPavimMaxData=<args>|python dbgPavim.setMaxData()
+if !exists('g:dbgPavimLang')
+ let g:dbgPavimLang = ''
+endif
+
+let s:dbgpavim_py_loaded = 0
+function s:LoadDBGPavim()
+ if s:dbgpavim_py_loaded == 0
+ if filereadable(s:dbgpavim_py)
+ exec 'pyfile '.s:dbgpavim_py
+ python dbgPavim_init()
+ let s:dbgpavim_py_loaded = 1
+ autocmd VimLeavePre * python dbgPavim.quit()
+ autocmd BufEnter WATCH_WINDOW nnoremap <silent> <buffer> <Enter> :call <SID>WatchWindowOnEnter()<CR>
+ autocmd BufEnter STACK_WINDOW nnoremap <silent> <buffer> <Enter> :call <SID>StackWindowOnEnter()<CR>
+ autocmd BufLeave HELP__WINDOW :python dbgPavim.ui.helpwin=None
+ exec 'nnoremap <silent> '.g:dbgPavimKeyQuit.' :python dbgPavim.quit()<cr>'
+ exec 'nnoremap <silent> '.g:dbgPavimKeyToggleBae.' :call <SID>Bae()<cr>'
+ exec 'nnoremap <silent> '.g:dbgPavimKeyLargeWindow.' :call <SID>ResizeWindow("+")<cr>'
+ exec 'nnoremap <silent> '.g:dbgPavimKeySmallWindow.' :call <SID>ResizeWindow("-")<cr>'
+ exec 'nnoremap <buffer> <silent> '.g:dbgPavimKeyToggleBp.' :python dbgPavim.mark()<cr>'
+
+ "exec 'autocmd FileType php,python,javascript nnoremap <buffer> <silent> '.g:dbgPavimKeyToggleBp.' :python dbgPavim.mark()<cr>'
-let s:keyMappings = {
- \ g:dbgPavimKeyHelp : ':python dbgPavim.ui.help()<cr>',
- \ g:dbgPavimKeyStepInto : ':python dbgPavim.command(\"step_into\")<cr>',
- \ g:dbgPavimKeyStepOver : ':python dbgPavim.command(\"step_over\")<cr>',
- \ g:dbgPavimKeyStepOut : ':python dbgPavim.command(\"step_out\")<cr>',
- \ g:dbgPavimKeyEval : ':python dbgPavim.watch_input(\"eval\")<cr>A',
- \ g:dbgPavimKeyRelayout : ':python dbgPavim.ui.reLayout()<cr>',
- \ g:dbgPavimKeyContextGet : ':python dbgPavim.context()<cr>',
- \ g:dbgPavimKeyPropertyGet : ':python dbgPavim.property()<cr>',
- \ }
-for key in keys(s:keyMappings)
- exec 'nnoremap <expr> <silent> '.key.' (exists("g:dbgPavimTab")==1 && g:dbgPavimTab == tabpagenr() ? "'.s:keyMappings[key].'" : "'.key.'")'
-endfor
-exec 'vnoremap '.g:dbgPavimKeyPropertyGet.' "vy:python dbgPavim.property("%v%")<CR>'
-exec 'vnoremap '.g:dbgPavimKeyEval.' "vy:python dbgPavim.watch_input("eval", "%v%")<CR>$a<CR>'
-command! -nargs=0 Up python dbgPavim.up()
-command! -nargs=0 Dn python dbgPavim.down()
-command! -nargs=? Pg python dbgPavim.property("<args>")
+ command! -nargs=? Bp python dbgPavim.mark('<args>')
+ command! -nargs=0 Bl python dbgPavim.list()
+ command! -nargs=0 Bc python dbgPavim.clear()
+ command! -nargs=0 Bu python dbgPavim.unclear()
+ command! -nargs=? Dp python dbgPavim.cli('<args>')
+ command! -nargs=? Wc python dbgPavim.watch("<args>")
+ command! -nargs=? We python dbgPavim.eval("<args>")
+ command! -nargs=0 Wl python dbgPavim.listWatch()
+ command! -nargs=1 Children let g:dbgPavimMaxChildren=<args>|python dbgPavim.setMaxChildren()
+ command! -nargs=1 Depth let g:dbgPavimMaxDepth=<args>|python dbgPavim.setMaxDepth()
+ command! -nargs=1 Length let g:dbgPavimMaxData=<args>|python dbgPavim.setMaxData()
+
+ let s:keyMappings = {
+ \ g:dbgPavimKeyHelp : ':python dbgPavim.ui.help()<cr>',
+ \ g:dbgPavimKeyStepInto : ':python dbgPavim.command(\"step_into\")<cr>',
+ \ g:dbgPavimKeyStepOver : ':python dbgPavim.command(\"step_over\")<cr>',
+ \ g:dbgPavimKeyStepOut : ':python dbgPavim.command(\"step_out\")<cr>',
+ \ g:dbgPavimKeyEval : ':python dbgPavim.watch_input(\"eval\")<cr>A',
+ \ g:dbgPavimKeyRelayout : ':python dbgPavim.ui.reLayout()<cr>',
+ \ g:dbgPavimKeyContextGet : ':python dbgPavim.context()<cr>',
+ \ g:dbgPavimKeyPropertyGet : ':python dbgPavim.property()<cr>',
+ \ }
+ for key in keys(s:keyMappings)
+ exec 'nnoremap <expr> <silent> '.key.' (exists("g:dbgPavimTab")==1 && g:dbgPavimTab == tabpagenr() ? "'.s:keyMappings[key].'" : "'.key.'")'
+ endfor
+ exec 'vnoremap '.g:dbgPavimKeyPropertyGet.' "vy:python dbgPavim.property("%v%")<CR>'
+ exec 'vnoremap '.g:dbgPavimKeyEval.' "vy:python dbgPavim.watch_input("eval", "%v%")<CR>$a<CR>'
+ command! -nargs=0 Up python dbgPavim.up()
+ command! -nargs=0 Dn python dbgPavim.down()
+ command! -nargs=? Pg python dbgPavim.property("<args>")
+ set laststatus=2
+ else
+ call confirm('dbgpavim.vim: Unable to find '.s:dbgpavim_py.'. Place it in either your home vim directory or in the Vim runtime directory.', 'OK')
+ endif
+ endif
+ return s:dbgpavim_py_loaded
+endfunction
-function! ResizeWindow(flag)
+function s:ExeDBGPavim(method)
+ if <SID>LoadDBGPavim() == 1
+ exec 'python dbgPavim.'.a:method.'()'
+ endif
+endfunction
+exec 'nnoremap <silent> '.g:dbgPavimKeyRun.' :call <SID>ExeDBGPavim("run")<cr>'
+
+exec 'autocmd FileType php,python,javascript nnoremap <buffer> <silent> '.g:dbgPavimKeyToggleBp.' :call <SID>ExeDBGPavim("mark")<cr>'
+command! -nargs=? Bp :call <SID>ExeDBGPavim("mark")
+
+function! s:ResizeWindow(flag)
let l:width = winwidth("%")
if l:width == &columns
execute 'resize '.a:flag.'5'
else
execute 'vertical resize '.a:flag.'5'
endif
endfunction
-function! Bae()
+function! s:Bae()
let g:dbgPavimBreakAtEntry = (g:dbgPavimBreakAtEntry == 1) ? 0 : 1
execute 'python dbgPavim.breakAtEntry = '.g:dbgPavimBreakAtEntry
endfunction
-function! WatchWindowOnEnter()
+function! s:WatchWindowOnEnter()
let l:line = getline(".")
if l:line =~ "^\\s*.* = (.*)+;$"
let l:var = substitute(line,"\\s*\\(\\S.*\\S\\)\\s*=.*","\\1","g")
@@ -221,7 +252,7 @@ function! WatchWindowOnEnter()
execute 'normal za'
endif
endfunction
-function! StackWindowOnEnter()
+function! s:StackWindowOnEnter()
let l:stackNo = substitute(getline("."),"\\(\\d\\+\\)\\s\\+.*","\\1","g")
if l:stackNo =~ "^\\d\\+$"
execute 'python dbgPavim.debugSession.go('.l:stackNo.')'
@@ -238,7 +269,6 @@ function! CheckPydbgp()
endif
return l:ret
endfunction
-
function! CheckXdebug()
let l:ret = 0
let l:phpinfo = system('php -r "phpinfo();"')
@@ -282,11 +312,3 @@ if !hlexists('DbgBreakPt')
endif
sign define current text=-> texthl=DbgCurrent linehl=DbgCurrent
sign define breakpt text=B> texthl=DbgBreakPt linehl=DbgBreakPt
-
-set laststatus=2
-python dbgPavim_init()
-
-autocmd BufEnter WATCH_WINDOW map <silent> <buffer> <Enter> :call WatchWindowOnEnter()<CR>
-autocmd BufEnter STACK_WINDOW map <silent> <buffer> <Enter> :call StackWindowOnEnter()<CR>
-autocmd BufLeave HELP__WINDOW :python dbgPavim.ui.helpwin=None
-autocmd VimLeavePre * python dbgPavim.quit()

0 comments on commit 5b37352

Please sign in to comment.