[Lldb-commits] [lldb] r192766 - lui: clean up breakpoint window, and allow multi-line list items

Ben Langmuir ben.langmuir at intel.com
Tue Oct 15 19:01:42 PDT 2013


Author: benlangmuir
Date: Tue Oct 15 21:01:41 2013
New Revision: 192766

URL: http://llvm.org/viewvc/llvm-project?rev=192766&view=rev
Log:
lui: clean up breakpoint window, and allow multi-line list items

* Clean the SBBreakpoint: id = out of the output
* clamp output to window width (eventually we should be able to scroll
left/right)
* On 'tab', expand a breakpoint to show its locations
* Allow enter/space to toggle breakpoints

Modified:
    lldb/trunk/utils/lui/breakwin.py
    lldb/trunk/utils/lui/cui.py

Modified: lldb/trunk/utils/lui/breakwin.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/lui/breakwin.py?rev=192766&r1=192765&r2=192766&view=diff
==============================================================================
--- lldb/trunk/utils/lui/breakwin.py (original)
+++ lldb/trunk/utils/lui/breakwin.py Tue Oct 15 21:01:41 2013
@@ -10,12 +10,14 @@
 import cui
 import curses
 import lldb, lldbutil
+import re
 
 class BreakWin(cui.ListWin):
   def __init__(self, driver, x, y, w, h):
     super(BreakWin, self).__init__(x, y, w, h)
     self.driver = driver
     self.update()
+    self.showDetails = {}
 
   def handleEvent(self, event):
     if isinstance(event, lldb.SBEvent):
@@ -24,8 +26,27 @@ class BreakWin(cui.ListWin):
     if isinstance(event, int):
       if event == ord('d'):
         self.deleteSelected()
+      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()
     super(BreakWin, self).handleEvent(event)
 
+  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())
+
   def deleteSelected(self):
     if self.getSelected() == -1:
       return
@@ -38,6 +59,8 @@ class BreakWin(cui.ListWin):
   def update(self):
     target = self.driver.getTarget()
     if not target.IsValid():
+      self.win.erase()
+      self.win.noutrefresh()
       return
     selected = self.getSelected()
     self.clearItems()
@@ -46,5 +69,22 @@ class BreakWin(cui.ListWin):
       if bp.IsInternal():
         continue
       text = lldbutil.get_description(bp)
+      # 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
       self.addItem(text)
     self.setSelected(selected)

Modified: lldb/trunk/utils/lui/cui.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/lui/cui.py?rev=192766&r1=192765&r2=192766&view=diff
==============================================================================
--- lldb/trunk/utils/lui/cui.py (original)
+++ lldb/trunk/utils/lui/cui.py Tue Oct 15 21:01:41 2013
@@ -78,26 +78,53 @@ class ListWin(CursesWin):
     self.items = []
     self.selected = 0
     self.first_drawn = 0
+    self.win.leaveok(True)
 
   def draw(self):
+    if len(self.items) == 0:
+      self.win.erase()
+      return
+
     h, w = self.win.getmaxyx()
-    if self.selected < self.first_drawn:
-      self.first_drawn = self.selected
-    if self.selected >= self.first_drawn + h:
-      self.first_drawn = self.selected - h + 1
+
+    allLines = []
+    firstSelected = -1
+    lastSelected = -1
+    for i, item in enumerate(self.items):
+      lines = self.items[i].split('\n')
+      lines = lines if lines[len(lines)-1] != '' else lines[:-1]
+      if len(lines) == 0:
+        lines = ['']
+
+      if i == self.getSelected():
+        firstSelected = len(allLines)
+      allLines.extend(lines)
+      if i == self.selected:
+        lastSelected = len(allLines) - 1
+
+    if firstSelected < self.first_drawn:
+      self.first_drawn = firstSelected
+    elif lastSelected >= self.first_drawn + h:
+      self.first_drawn = lastSelected - h + 1
 
     self.win.clear()
 
     begin = self.first_drawn
     end = begin + h
-    for i, item in enumerate(self.items[begin:end]):
-      text = item
-      if i + begin == self.selected:
-        attr = curses.A_REVERSE 
-        text = '{0:{width}}'.format(text, width=w-1)
-      else:
-        attr = curses.A_NORMAL
-      self.win.addstr(i, 0, text, attr)
+
+    y = 0
+    for i, line in list(enumerate(allLines))[begin:end]:
+      attr = curses.A_NORMAL
+      if i >= firstSelected and i <= lastSelected:
+        attr = curses.A_REVERSE
+        line = '{0:{width}}'.format(line, width=w-1)
+
+      # Ignore the error we get from drawing over the bottom-right char.
+      try:
+        self.win.addstr(y, 0, line[:w], attr)
+      except curses.error:
+        pass
+      y += 1
     self.win.noutrefresh()
 
   def getSelected(self):





More information about the lldb-commits mailing list