Fixed process attaching for GDB

This commit is contained in:
IdanArye 2014-05-22 17:11:54 +03:00
parent e846941323
commit 3012df9a85

View File

@ -15,24 +15,50 @@ endfunction
"the user selects
function! vebugger#util#selectProcessOfFile(ofFile)
let l:fileName=fnamemodify(a:ofFile,':t')
let l:resultLines=split(vimproc#system('ps -o pid,user,comm,start,state,tt -C '.fnameescape(l:fileName)),'\r\n\|\n\|\r')
if len(l:resultLines)<=1
if has('win32')
"Get the process data in CSV format
let l:resultLines=split(vimproc#system('tasklist /FO csv /FI "IMAGENAME eq '.l:fileName.'"'),'\r\n\|\n\|\r')
if l:resultLines[0]=~'\V\^INFO:'
throw 'No matching process found'
endif
"Parse(sort of) the CSV:
let l:resultLinesParsed=map(l:resultLines,'eval("[".v:val."]")')
let l:resultLinesParsed[0][2]='Session'
"Format for output
let l:linesForPrinting=map(copy(l:resultLinesParsed),'v:val[1]."\t".v:val[2]."\t\t".v:val[0]')
else
let l:resultLines=split(vimproc#system('ps -o pid,user,comm,start,state,tt -C '.fnameescape(l:fileName)),'\r\n\|\n\|\r')
let l:linesForPrinting=copy(l:resultLines)
endif
if len(l:linesForPrinting)<=1
throw 'No matching process found'
endif
if &lines<len(l:resultLines)
if &lines<len(l:linesForPrinting)
throw 'Too many matching processes found'
endif
let l:resultLines[0]=' '.l:resultLines[0]
for l:i in range(1,len(l:resultLines)-1)
let l:resultLines[l:i]=repeat(' ',3-len(l:i)).l:i.') '.(l:resultLines[l:i])
"Add numbers to the lines
for l:i in range(1,len(l:linesForPrinting)-1)
let l:linesForPrinting[l:i]=repeat(' ',3-len(l:i)).l:i.') '.(l:linesForPrinting[l:i])
endfor
let l:chosenId=inputlist(l:resultLines)
"Indent the title line(since it doesn't have a number)
let l:linesForPrinting[0]=' '.l:linesForPrinting[0]
"Get the selection
let l:chosenId=inputlist(l:linesForPrinting)
if l:chosenId<1
\|| len(l:resultLines)<=l:chosenId
return 0
endif
let l:chosenLine=l:resultLines[l:chosenId]
return str2nr(matchlist(l:chosenLine,'\v^\s*\d+\)\s+(\d+)')[1])
if has('win32')
return str2nr(l:resultLinesParsed[l:chosenId][1])
else
let l:chosenLine=l:resultLines[l:chosenId]
return str2nr(matchlist(l:chosenLine,'\v^\s*\d+\)\s+(\d+)')[1])
endif
endfunction
"Escape args(from a debugger's extra arguments) as a command line arguments