Improved locating the currently debugged program position
(the old algorithm had problems with double frees for example)
This commit is contained in:
parent
c7304dc1f1
commit
d78fa68a72
@ -56,8 +56,8 @@ endfunction
|
|||||||
|
|
||||||
function! vebugger#lldb#_readWhere(pipeName,line,readResult,debugger)
|
function! vebugger#lldb#_readWhere(pipeName,line,readResult,debugger)
|
||||||
if 'out'==a:pipeName
|
if 'out'==a:pipeName
|
||||||
\&&a:line=~'\v^debugger_output:'
|
\&&a:line=~'\v^where:'
|
||||||
let l:matches=matchlist(a:line,'\v^debugger_output:\s\*\s([^:]+):(\d+)')
|
let l:matches=matchlist(a:line,'\v^where:\s([^:]+):(\d+)')
|
||||||
if 2<len(l:matches)
|
if 2<len(l:matches)
|
||||||
let l:file=l:matches[1]
|
let l:file=l:matches[1]
|
||||||
let l:file=fnamemodify(l:file,':~:.')
|
let l:file=fnamemodify(l:file,':~:.')
|
||||||
|
@ -7,11 +7,17 @@ from __future__ import print_function
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|
||||||
|
import collections
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
FilePosition = collections.namedtuple('FilePosition', ['filepath', 'linenumber'])
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Just try for LLDB in case PYTHONPATH is already correctly setup
|
# Just try for LLDB in case PYTHONPATH is already correctly setup
|
||||||
import lldb
|
import lldb
|
||||||
@ -86,6 +92,18 @@ class Debugger(object):
|
|||||||
self._state_dict = None
|
self._state_dict = None
|
||||||
self._breakpoint_manager = self.BreakpointManager()
|
self._breakpoint_manager = self.BreakpointManager()
|
||||||
self._custom_commands = ['br', 'clear']
|
self._custom_commands = ['br', 'clear']
|
||||||
|
self._set_options()
|
||||||
|
|
||||||
|
def _set_options(self):
|
||||||
|
# -> first read lldbinit
|
||||||
|
try:
|
||||||
|
with open(os.path.expanduser('~/.lldbinit')) as f:
|
||||||
|
for line in f:
|
||||||
|
self.run_command(line)
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
self.run_command('settings set frame-format frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{ at:${line.file.fullpath}:${line.number}}\n')
|
||||||
|
self.run_command('settings set auto-confirm 1')
|
||||||
|
|
||||||
def run_command(self, commandline):
|
def run_command(self, commandline):
|
||||||
if self._is_custom_command(commandline):
|
if self._is_custom_command(commandline):
|
||||||
@ -134,6 +152,29 @@ class Debugger(object):
|
|||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
@property
|
||||||
|
def where(self):
|
||||||
|
def extract_where(backtrace):
|
||||||
|
where = None
|
||||||
|
pattern = re.compile('at:([^:]+):(\d+)')
|
||||||
|
backtrace_lines = backtrace.split('\n')
|
||||||
|
for line in backtrace_lines:
|
||||||
|
match_obj = pattern.search(line)
|
||||||
|
if match_obj:
|
||||||
|
filepath = match_obj.group(1)
|
||||||
|
linenumber = int(match_obj.group(2))
|
||||||
|
if os.access(filepath, os.R_OK):
|
||||||
|
where = FilePosition(filepath, linenumber)
|
||||||
|
break
|
||||||
|
return where
|
||||||
|
|
||||||
|
where = None
|
||||||
|
self.run_command('bt')
|
||||||
|
debugger_output = self.debugger_output
|
||||||
|
if debugger_output is not None:
|
||||||
|
where = extract_where(debugger_output)
|
||||||
|
return where
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def program_stdout(self):
|
def program_stdout(self):
|
||||||
stdout = []
|
stdout = []
|
||||||
@ -186,17 +227,6 @@ def main():
|
|||||||
executable = sys.argv[1]
|
executable = sys.argv[1]
|
||||||
debugger = Debugger(executable)
|
debugger = Debugger(executable)
|
||||||
|
|
||||||
# set debugger options
|
|
||||||
# -> first read lldbinit
|
|
||||||
try:
|
|
||||||
with open(os.path.expanduser('~/.lldbinit')) as f:
|
|
||||||
for line in f:
|
|
||||||
debugger.run_command(line)
|
|
||||||
except IOError:
|
|
||||||
pass
|
|
||||||
debugger.run_command('settings set thread-format ${file.fullpath}:${line.number}')
|
|
||||||
debugger.run_command('settings set auto-confirm 1')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
line = raw_input()
|
line = raw_input()
|
||||||
@ -211,6 +241,9 @@ def main():
|
|||||||
if program_stderr:
|
if program_stderr:
|
||||||
print(prefix_output(program_stderr, 'program_stderr: '))
|
print(prefix_output(program_stderr, 'program_stderr: '))
|
||||||
print(prefix_output(debugger.debugger_output, 'debugger_output: '))
|
print(prefix_output(debugger.debugger_output, 'debugger_output: '))
|
||||||
|
where = debugger.where
|
||||||
|
if where:
|
||||||
|
print(prefix_output('{:s}:{:d}'.format(where.filepath, where.linenumber), 'where: '))
|
||||||
print(prefix_output(debugger.program_state, 'program_state: '))
|
print(prefix_output(debugger.program_state, 'program_state: '))
|
||||||
except EOFError:
|
except EOFError:
|
||||||
print('Exiting')
|
print('Exiting')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user