2013-10-12 01:13:07 +08:00
|
|
|
##===-- breakwin.py ------------------------------------------*- Python -*-===##
|
|
|
|
##
|
|
|
|
## The LLVM Compiler Infrastructure
|
|
|
|
##
|
|
|
|
## This file is distributed under the University of Illinois Open Source
|
|
|
|
## License. See LICENSE.TXT for details.
|
|
|
|
##
|
|
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
|
2013-10-10 06:11:30 +08:00
|
|
|
import cui
|
|
|
|
import curses
|
|
|
|
import lldb, lldbutil
|
2013-10-16 10:01:41 +08:00
|
|
|
import re
|
2013-10-10 06:11:30 +08:00
|
|
|
|
2013-10-16 10:00:21 +08:00
|
|
|
class BreakWin(cui.ListWin):
|
2013-10-10 06:11:30 +08:00
|
|
|
def __init__(self, driver, x, y, w, h):
|
2013-10-16 10:00:21 +08:00
|
|
|
super(BreakWin, self).__init__(x, y, w, h)
|
2013-10-10 06:11:30 +08:00
|
|
|
self.driver = driver
|
2013-10-16 10:00:21 +08:00
|
|
|
self.update()
|
2013-10-16 10:01:41 +08:00
|
|
|
self.showDetails = {}
|
2013-10-10 06:11:30 +08:00
|
|
|
|
|
|
|
def handleEvent(self, event):
|
|
|
|
if isinstance(event, lldb.SBEvent):
|
|
|
|
if lldb.SBBreakpoint.EventIsBreakpointEvent(event):
|
|
|
|
self.update()
|
2013-10-16 10:00:21 +08:00
|
|
|
if isinstance(event, int):
|
|
|
|
if event == ord('d'):
|
|
|
|
self.deleteSelected()
|
2013-10-16 10:01:41 +08:00
|
|
|
if event == curses.ascii.NL or event == curses.ascii.SP:
|
|
|
|
self.toggleSelected()
|
|
|
|
elif event == curses.ascii.TAB:
|
|
|
|
if self.getSelected() != -1:
|
|
|
|
target = self.driver.getTarget()
|
|
|
|
if not target.IsValid():
|
|
|
|
return
|
|
|
|
i = target.GetBreakpointAtIndex(self.getSelected()).id
|
|
|
|
self.showDetails[i] = not self.showDetails[i]
|
|
|
|
self.update()
|
2013-10-16 10:00:21 +08:00
|
|
|
super(BreakWin, self).handleEvent(event)
|
|
|
|
|
2013-10-16 10:01:41 +08:00
|
|
|
def toggleSelected(self):
|
|
|
|
if self.getSelected() == -1:
|
|
|
|
return
|
|
|
|
target = self.driver.getTarget()
|
|
|
|
if not target.IsValid():
|
|
|
|
return
|
|
|
|
bp = target.GetBreakpointAtIndex(self.getSelected())
|
|
|
|
bp.SetEnabled(not bp.IsEnabled())
|
|
|
|
|
2013-10-16 10:00:21 +08:00
|
|
|
def deleteSelected(self):
|
|
|
|
if self.getSelected() == -1:
|
|
|
|
return
|
|
|
|
target = self.driver.getTarget()
|
|
|
|
if not target.IsValid():
|
|
|
|
return
|
|
|
|
bp = target.GetBreakpointAtIndex(self.getSelected())
|
|
|
|
target.BreakpointDelete(bp.id)
|
2013-10-10 06:11:30 +08:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
target = self.driver.getTarget()
|
|
|
|
if not target.IsValid():
|
2013-10-16 10:01:41 +08:00
|
|
|
self.win.erase()
|
|
|
|
self.win.noutrefresh()
|
2013-10-10 06:11:30 +08:00
|
|
|
return
|
2013-10-16 10:00:21 +08:00
|
|
|
selected = self.getSelected()
|
|
|
|
self.clearItems()
|
2013-10-10 06:11:30 +08:00
|
|
|
for i in range(0, target.GetNumBreakpoints()):
|
|
|
|
bp = target.GetBreakpointAtIndex(i)
|
|
|
|
if bp.IsInternal():
|
|
|
|
continue
|
|
|
|
text = lldbutil.get_description(bp)
|
2013-10-16 10:01:41 +08:00
|
|
|
# FIXME: Use an API for this, not parsing the description.
|
|
|
|
match = re.search('SBBreakpoint: id = ([^,]+), (.*)', text)
|
|
|
|
try:
|
|
|
|
id = match.group(1)
|
|
|
|
desc = match.group(2).strip()
|
|
|
|
if bp.IsEnabled():
|
|
|
|
text = '%s: %s' % (id, desc)
|
|
|
|
else:
|
|
|
|
text = '%s: (disabled) %s' % (id, desc)
|
|
|
|
except ValueError as e:
|
|
|
|
# bp unparsable
|
|
|
|
pass
|
|
|
|
|
|
|
|
if self.showDetails.setdefault(bp.id, False):
|
|
|
|
for location in bp:
|
|
|
|
desc = lldbutil.get_description(location, lldb.eDescriptionLevelFull)
|
|
|
|
text += '\n ' + desc
|
2013-10-16 10:00:21 +08:00
|
|
|
self.addItem(text)
|
|
|
|
self.setSelected(selected)
|