Start process to debug from Vim #24

Open
serebrov opened this Issue Nov 16, 2012 · 1 comment

Projects

None yet

2 participants

@serebrov

Now vdebug starts only listening process and process to debug should be started manually outside Vim.
For now I use following code in my vimrc to automate the process:

    function! Debug(url)
        let url = a:url
        " add 'http://' if it is not in url
        let http_pos = stridx(url, 'http')
        if http_pos != 0
            let url = 'http://'.url
        endif
        " add 'vim_debug' IDE key to url, this IDE key is also set in vdebug options
        let q_pos = stridx(url, '?')
        if q_pos == -1
            let url = url.'?XDEBUG_SESSION_START=vim_debug'
        else
            let url = url.'&XDEBUG_SESSION_START=vim_debug'
        endif
        " launch browser
        call OpenBrowser(url)
         " start debugging
        python debugger.run()
    endfunction
    command! -nargs=1 Debug call Debug('<args>')

This command allow to launch browser via OpenBrowser plugin and then start vdebug.
I use it like this:

: Debug http://myhost.com/xxx.php

Another one to debug currently edited python script:

    function! DebugPy(...)
        let str_args = join(a:000, ' ')
        " command to launch - uses local path to pydbgp, probably this can be done in a better way
        let last_cmd = '!python -S ~/pydbgp/bin/pydbgp -d localhost:9000 -k vim_debug ' . str_args
        " save last used args, command and its results to files (for debugging of this function)
        execute 'silent !echo "' . str_args . '" > ~/vim.last.arg.txt &'
        execute 'silent !echo "' . last_cmd . '" > ~/vim.last.cmd.txt &'
        " launch command in backgound
        execute 'silent ' . last_cmd . ' > ~/vim.last.out.txt 2> ~/vim.last.err.txt &'
        " start debugging
        python debugger.run()
    endfunction
    command! -nargs=* DebugPy call DebugPy('% <args>')

Now I can do this:

: DebugPy

And debug current python file.

Probably the same can be done in a better way inside the python code and maybe not only for php/python, but for other supported languages as well.

Also another python-based plugin for debugging, vim-debug, can do this

@joonty
Owner

Thanks for that, looks interesting. When I get a chance I'll start looking how to integrate something like this into Vdebug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment