diff --git a/autoload/vebugger/lldb.vim b/autoload/vebugger/lldb.vim new file mode 100644 index 0000000..c97aa1c --- /dev/null +++ b/autoload/vebugger/lldb.vim @@ -0,0 +1,139 @@ +let s:script_dir_path=expand(':p:h') + +function! vebugger#lldb#start(binaryFile,args) + let l:debuggerExe=vebugger#util#getToolFullPath('python2',get(a:args,'version'),'python2') + let l:debugger=vebugger#std#startDebugger(shellescape(l:debuggerExe) + \.' '.s:script_dir_path.'/lldb_wrapper.py '.fnameescape(a:binaryFile)) + + let l:debugger.state.lldb={} + + if get(a:args,'pid') "Attach to process + call l:debugger.writeLine('process attach --pid '.string(a:args.pid)) + elseif has_key(a:args,'con') "Attach to lldbserver + call l:debugger.writeLine('platform connect connect://'.a:args.con) + else + call l:debugger.writeLine('settings set target.run-args '.vebugger#util#commandLineArgsForProgram(a:args)) + if !has('win32') + call vebugger#std#openShellBuffer(l:debugger) + endif + + " TODO: remove 'and false'; add a temporary breakpoint to lldb + if has_key(a:args,'entry') && 0 + " call l:debugger.writeLine('tbreak '.a:args.entry) + " call l:debugger.writeLine('run') + else + call l:debugger.writeLine('breakpoint set --name main') + call l:debugger.writeLine('process launch') + endif + endif + + + call l:debugger.addReadHandler(function('vebugger#lldb#_readProgramOutput')) + call l:debugger.addReadHandler(function('vebugger#lldb#_readWhere')) + call l:debugger.addReadHandler(function('vebugger#lldb#_readFinish')) + call l:debugger.addReadHandler(function('vebugger#lldb#_readEvaluatedExpressions')) + + call l:debugger.setWriteHandler('std','flow',function('vebugger#lldb#_writeFlow')) + call l:debugger.setWriteHandler('std','breakpoints',function('vebugger#lldb#_writeBreakpoints')) + call l:debugger.setWriteHandler('std','closeDebugger',function('vebugger#lldb#_closeDebugger')) + call l:debugger.setWriteHandler('std','evaluateExpressions',function('vebugger#lldb#_requestEvaluateExpression')) + call l:debugger.setWriteHandler('std','executeStatements',function('vebugger#lldb#_executeStatements')) + + call l:debugger.generateWriteActionsFromTemplate() + + call l:debugger.std_addAllBreakpointActions(g:vebugger_breakpoints) + + return l:debugger +endfunction + +function! vebugger#lldb#_readProgramOutput(pipeName,line,readResult,debugger) + if 'out'==a:pipeName + \&&(a:line=~'\v^program_stdout:' + \||a:line=~'\v^program_stderr:') + let a:readResult.std.programOutput={'line':strpart(a:line, 16)} + endif +endfunction + +function! vebugger#lldb#_readWhere(pipeName,line,readResult,debugger) + if 'out'==a:pipeName + \&&a:line=~'\v^debugger_output:' + let l:matches=matchlist(a:line,'\v^debugger_output:\s\*\s([^:]+):(\d+)') + if 2) +command! -nargs=+ -complete=file VBGstartLLDB call vebugger#lldb#start([][0],{'args':[][1:]}) +function! s:attachLLDB(...) + if 1 == a:0 + let l:processId=vebugger#util#selectProcessOfFile(a:1) + if 0 < l:processId + call vebugger#lldb#start(a:1, {'pid': l:processId}) + endif + elseif 2 == a:0 + if a:2 =~ '\v^\d+$' + call vebugger#lldb#start(a:1,{'pid': str2nr(a:2)}) + else + call vebugger#lldb#start(a:1, {'con': a:2}) + endif + else + throw "Can't call VBGattachLLDB with ".a:0." arguments" + endif +endfunction +command! -nargs=+ -complete=file VBGattachLLDB call s:attachLLDB() command! -nargs=+ -complete=file VBGstartRDebug call vebugger#rdebug#start([][0],{'args':[][1:]}) command! -nargs=+ -complete=file VBGstartPDB call vebugger#pdb#start([][0],{'args':[][1:]}) command! -nargs=+ -complete=file VBGstartPDB2 call vebugger#pdb#start([][0],{'args':[][1:],'version':'2'})