Friday, January 09, 2009

DBGpClient v1.0.1 : Vim PHP Debugger Update

Been working all day for this :

###############################################################################
1.0.1 changelog from 1.0.0
###############################################################################

new :
- add option to use dedicated debugging tab (this way you dont have to worry
bout your undo history in other tab would get lost) suggested by Michael
Bahnmiller
- add option to set socket timeout

changes :
- update file header in debugger.py and debugger.vim
- if a debugging command reach code end, and the debugger stop gracefully, the
debugging interface will be closed/restore automatically, user doesnt have to
explicitly press F6
- the TRACE_WINDOW will only visible if the debugger is in debugging mode, or
when g:debuggerDebugMode=1, cause it's the only purpose of a trace window
(logging and tracing), in normal use you wouldn't use this window, it will
save more space
- "Not Connected" message is change to "Debugger is not running" message
- the F5 and F6 doesnt get map directly to python function, but to a VimScript
function, this way user can write a preparation for each debugging start, or
cleanups for every debugging ends
- add "except: NotConnectedException" for every try..except.. wrapper function
which display Not Running message, to make sure each of this command only
used when debugging session is started

bug fixes :
- remove error message duplication
- remove bug when timeout happen(trace window shown up, with a some exception
error) and show "Connection Timeout.." message instead


now we have g:debuggerDedicatedTab which will decide whether debugging session will use it's own tab, so the other tab (the ones to work with) doesnt lost its undo history, if you dont want an extra tab just for debugging set this var to 0, this will lost undo history on the tab where you start the debugging session, but note! if you want to use this *new feature and you are using gVim or vim.gui put this into your ~/.vimrc file

if has("gui_running")
if has("gui_gtk2")
set showtabline=2
endif
endif

the snippet above will make the showtabline option set to 2 (always show) this is needed because theres a bug about vim and gtk (don't know exactly) when vim window get resized

theres also g:debuggerTimeout which will decide how long vim will wait a debug session requested, I've set it to default by 10 second

and the last one is g:debuggerDebugMode, if you want to see what happen between Vim and xDebug engine, you might wanna set this variable to 1 which then will show trace_window, if it set to 0 the trace_window wont be visible

Perhaps I'm not going able to work with this script at least until next month, as usual if theres a bug, diffs, or idea, drop em here... thx !

oh, btw how do I report bugs on vimonline ? I cant seem to update my script page detail ?

download plugin update

10 comments:

ning said...

VERY NICE!!! THANKS SO MUCH!

Although I got a little trouble to make this plugin run, but it finally runs.

That trouble was happened in my MS-Windows XP with SP3 patched: it warned me that vim encounters an invalid buffer name. and I noticed that, the function "set_srcview" resides in debugger.py received an "file" parameter which has an leading "/" before the real path. For instance, if I wanna debugging "D:\myphp.php", but "set_srcview" got "/D:\myphp.php", then it's failed.

I've googled a solution submited by Kevin Dahlhausen from: http://2bits.com/articles/using-vim-and-xdebug-dbgp-for-debugging-drupal-or-any-php-application.html#comment-218.

----------------------------
Empty file name error fix
Submitted by Kevin Dahlhausen (not verified) on Thu, 2007/06/14 - 14:58.

The problem is that the filename is coming across the wire with special characters replaced by the '%xx' notation. The solution is to add the following snippet to the bottom of 'debugger.py':
import urllib
import os
def fixFileName(fileName):
fileName = urllib.unquote(fileName)
if os.name=='nt' and fileName[0]=="/":
fileName = fileName[1:] # strip off initial slash char
return fileName

then filter the file name in handle_init around line 735 like this:
file = res.firstChild.getAttribute('fileuri')[7:]
file = fixFileName(file)
self.ui.set_srcview(file, 1)

I'm still working through this so there may exist other file names that need to be fixed up as well.
----------------------------

By put this:
file = fixFileName(file)
into the front within the body of "set_srcview". That trouble was gonen :-)

Zeft said...

hi, ning, you are so welcome, and THANKS to you too!,

I'm really sorry never had a chance to test this plugin on a windows system, I'll update it as soon as a got the time.

ning said...

Don't say sorry any more, your update is helpful!

Oh, there is one more problem in MS-Windows. According to the Manual of Vim, I have my Vim installed in this dir. hierarchy:

Vim
    vim72 <-- where the $VIMRUNTIME points to
        plugin
        <other dirs>
    vimfiles <-- where the $VIM points to
        plugin
        <other dirs>

Actually, I've put all my Vim plugins in "vimfiles/plugin", they works well. The "debugger.vim" and "debugger.py" also there. But "debugger.vim" warned me that "debugger.py" cannot be found.

So I've made a little change in "debugger.vim" to make it works with "vimfiles", see below:

-------------------------------
if filereadable($VIMRUNTIME."/plugin/debugger.py")
pyfile $VIMRUNTIME/plugin/debugger.py
elseif filereadable($HOME."/.vim/plugin/debugger.py")
pyfile $HOME/.vim/plugin/debugger.py
elseif filereadable($VIM."/vimfiles/plugin/debugger.py")
pyfile $VIM./vimfiles/plugin/debugger.py

else
call confirm('debugger.vim: Unable to find debugger.py. Place it in either your home vim directory or in the Vim runtime directory.', 'OK')
endif
-------------------------------

and it works well :-)

ning said...

Sorry Zeft, I made a mistake in the above comment that, the "$VIM" is not points to "vimfiles", it points to the most top directory "Vim".

Michael Bahnmiller said...

Hey,

Trying out 1.0.1... just noticed one thing.... the functions need a "!" after the keyword "function". like this:

function! s:startDebugging()
... etc ...

I only mention this because I got an error message without it saying that the function was already defined...

-----

Also, it's not allowing me to set and remove breakpoints unless the debugger is running.....


Thanks! :)

Zeft said...

argh...

hi michael :), again thx...

Michael Bahnmiller said...

Very welcome you are :)

lojopez said...

On Windows Vista SP2, gVim v7.2, debugger.vim v1.02

F11 and F12 not working (showing nothing) until I commented out these lines:
142:map :python debugger_watch_input("context_get")A
143:map :python debugger_watch_input("property_get", '')A

Besides, I don't understand why you map F11 and F12 twice (previously mapped at lines 140 and 141)

But the problem I still have is that I can't figure out how to get ,e (eval) working. It returns nothing, does nothing, no matter what I try to eval.

Anonymous said...

nice blog! I like this butt plug!

resume writing service said...

I want to have a chance for realizing my own ideas for life and its future!