summaryrefslogtreecommitdiffstats
path: root/lldb/examples/python/lldbtk.py
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/examples/python/lldbtk.py')
-rw-r--r--lldb/examples/python/lldbtk.py365
1 files changed, 217 insertions, 148 deletions
diff --git a/lldb/examples/python/lldbtk.py b/lldb/examples/python/lldbtk.py
index 7ada9d77b30..a978b9e0703 100644
--- a/lldb/examples/python/lldbtk.py
+++ b/lldb/examples/python/lldbtk.py
@@ -6,7 +6,9 @@ import sys
from Tkinter import *
import ttk
+
class ValueTreeItemDelegate(object):
+
def __init__(self, value):
self.value = value
@@ -24,36 +26,44 @@ class ValueTreeItemDelegate(object):
if summary is None:
summary = ''
has_children = self.value.MightHaveChildren()
- return { '#0' : name,
- 'typename' : typename,
- 'value' : value,
- 'summary' : summary,
- 'children' : has_children,
- 'tree-item-delegate' : self }
-
+ return {'#0': name,
+ 'typename': typename,
+ 'value': value,
+ 'summary': summary,
+ 'children': has_children,
+ 'tree-item-delegate': self}
+
def get_child_item_dictionaries(self):
item_dicts = list()
for i in range(self.value.num_children):
- item_delegate = ValueTreeItemDelegate(self.value.GetChildAtIndex(i))
+ item_delegate = ValueTreeItemDelegate(
+ self.value.GetChildAtIndex(i))
item_dicts.append(item_delegate.get_item_dictionary())
return item_dicts
+
class FrameTreeItemDelegate(object):
+
def __init__(self, frame):
self.frame = frame
def get_item_dictionary(self):
id = self.frame.GetFrameID()
- name = 'frame #%u' % (id);
+ name = 'frame #%u' % (id)
value = '0x%16.16x' % (self.frame.GetPC())
stream = lldb.SBStream()
self.frame.GetDescription(stream)
summary = stream.GetData().split("`")[1]
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : self.frame.GetVariables(True, True, True, True).GetSize() > 0,
- 'tree-item-delegate' : self }
+ return {
+ '#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': self.frame.GetVariables(
+ True,
+ True,
+ True,
+ True).GetSize() > 0,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
@@ -64,29 +74,33 @@ class FrameTreeItemDelegate(object):
item_dicts.append(item_delegate.get_item_dictionary())
return item_dicts
+
class ThreadTreeItemDelegate(object):
- def __init__(self, thread):
- self.thread = thread
-
- def get_item_dictionary(self):
- num_frames = self.thread.GetNumFrames()
- name = 'thread #%u' % (self.thread.GetIndexID())
- value = '0x%x' % (self.thread.GetThreadID())
- summary = '%u frames' % (num_frames)
- return { '#0' : name,
- 'value': value,
+
+ def __init__(self, thread):
+ self.thread = thread
+
+ def get_item_dictionary(self):
+ num_frames = self.thread.GetNumFrames()
+ name = 'thread #%u' % (self.thread.GetIndexID())
+ value = '0x%x' % (self.thread.GetThreadID())
+ summary = '%u frames' % (num_frames)
+ return {'#0': name,
+ 'value': value,
'summary': summary,
- 'children' : num_frames > 0,
- 'tree-item-delegate' : self }
-
- def get_child_item_dictionaries(self):
- item_dicts = list()
- for frame in self.thread:
- item_delegate = FrameTreeItemDelegate(frame)
- item_dicts.append(item_delegate.get_item_dictionary())
- return item_dicts
-
+ 'children': num_frames > 0,
+ 'tree-item-delegate': self}
+
+ def get_child_item_dictionaries(self):
+ item_dicts = list()
+ for frame in self.thread:
+ item_delegate = FrameTreeItemDelegate(frame)
+ item_dicts.append(item_delegate.get_item_dictionary())
+ return item_dicts
+
+
class ProcessTreeItemDelegate(object):
+
def __init__(self, process):
self.process = process
@@ -95,11 +109,11 @@ class ProcessTreeItemDelegate(object):
num_threads = self.process.GetNumThreads()
value = str(self.process.GetProcessID())
summary = self.process.target.executable.fullpath
- return { '#0' : 'process',
- 'value': value,
- 'summary': summary,
- 'children' : num_threads > 0,
- 'tree-item-delegate' : self }
+ return {'#0': 'process',
+ 'value': value,
+ 'summary': summary,
+ 'children': num_threads > 0,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
@@ -108,18 +122,20 @@ class ProcessTreeItemDelegate(object):
item_dicts.append(item_delegate.get_item_dictionary())
return item_dicts
+
class TargetTreeItemDelegate(object):
+
def __init__(self, target):
self.target = target
def get_item_dictionary(self):
value = str(self.target.triple)
summary = self.target.executable.fullpath
- return { '#0' : 'target',
- 'value': value,
- 'summary': summary,
- 'children' : True,
- 'tree-item-delegate' : self }
+ return {'#0': 'target',
+ 'value': value,
+ 'summary': summary,
+ 'children': True,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
@@ -127,7 +143,9 @@ class TargetTreeItemDelegate(object):
item_dicts.append(image_item_delegate.get_item_dictionary())
return item_dicts
+
class TargetImagesTreeItemDelegate(object):
+
def __init__(self, target):
self.target = target
@@ -135,21 +153,24 @@ class TargetImagesTreeItemDelegate(object):
value = str(self.target.triple)
summary = self.target.executable.fullpath
num_modules = self.target.GetNumModules()
- return { '#0' : 'images',
- 'value': '',
- 'summary': '%u images' % num_modules,
- 'children' : num_modules > 0,
- 'tree-item-delegate' : self }
+ return {'#0': 'images',
+ 'value': '',
+ 'summary': '%u images' % num_modules,
+ 'children': num_modules > 0,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
for i in range(self.target.GetNumModules()):
module = self.target.GetModuleAtIndex(i)
- image_item_delegate = ModuleTreeItemDelegate(self.target, module, i)
+ image_item_delegate = ModuleTreeItemDelegate(
+ self.target, module, i)
item_dicts.append(image_item_delegate.get_item_dictionary())
return item_dicts
+
class ModuleTreeItemDelegate(object):
+
def __init__(self, target, module, index):
self.target = target
self.module = module
@@ -159,25 +180,30 @@ class ModuleTreeItemDelegate(object):
name = 'module %u' % (self.index)
value = self.module.file.basename
summary = self.module.file.dirname
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : True,
- 'tree-item-delegate' : self }
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': True,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
- sections_item_delegate = ModuleSectionsTreeItemDelegate(self.target, self.module)
+ sections_item_delegate = ModuleSectionsTreeItemDelegate(
+ self.target, self.module)
item_dicts.append(sections_item_delegate.get_item_dictionary())
- symbols_item_delegate = ModuleSymbolsTreeItemDelegate(self.target, self.module)
+ symbols_item_delegate = ModuleSymbolsTreeItemDelegate(
+ self.target, self.module)
item_dicts.append(symbols_item_delegate.get_item_dictionary())
- comp_units_item_delegate = ModuleCompileUnitsTreeItemDelegate(self.target, self.module)
+ comp_units_item_delegate = ModuleCompileUnitsTreeItemDelegate(
+ self.target, self.module)
item_dicts.append(comp_units_item_delegate.get_item_dictionary())
return item_dicts
+
class ModuleSectionsTreeItemDelegate(object):
+
def __init__(self, target, module):
self.target = target
self.module = module
@@ -186,11 +212,11 @@ class ModuleSectionsTreeItemDelegate(object):
name = 'sections'
value = ''
summary = '%u sections' % (self.module.GetNumSections())
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : True,
- 'tree-item-delegate' : self }
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': True,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
@@ -201,7 +227,9 @@ class ModuleSectionsTreeItemDelegate(object):
item_dicts.append(image_item_delegate.get_item_dictionary())
return item_dicts
+
class SectionTreeItemDelegate(object):
+
def __init__(self, target, section):
self.target = target
self.section = section
@@ -214,11 +242,11 @@ class SectionTreeItemDelegate(object):
else:
value = '0x%16.16x *' % (self.section.file_addr)
summary = ''
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : self.section.GetNumSubSections() > 0,
- 'tree-item-delegate' : self }
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': self.section.GetNumSubSections() > 0,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
@@ -226,10 +254,12 @@ class SectionTreeItemDelegate(object):
for i in range(num_sections):
section = self.section.GetSubSectionAtIndex(i)
image_item_delegate = SectionTreeItemDelegate(self.target, section)
- item_dicts.append(image_item_delegate.get_item_dictionary())
+ item_dicts.append(image_item_delegate.get_item_dictionary())
return item_dicts
+
class ModuleCompileUnitsTreeItemDelegate(object):
+
def __init__(self, target, module):
self.target = target
self.module = module
@@ -238,11 +268,11 @@ class ModuleCompileUnitsTreeItemDelegate(object):
name = 'compile units'
value = ''
summary = '%u compile units' % (self.module.GetNumSections())
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : self.module.GetNumCompileUnits() > 0,
- 'tree-item-delegate' : self }
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': self.module.GetNumCompileUnits() > 0,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
@@ -253,7 +283,9 @@ class ModuleCompileUnitsTreeItemDelegate(object):
item_dicts.append(image_item_delegate.get_item_dictionary())
return item_dicts
+
class CompileUnitTreeItemDelegate(object):
+
def __init__(self, target, cu):
self.target = target
self.cu = cu
@@ -263,11 +295,11 @@ class CompileUnitTreeItemDelegate(object):
value = ''
num_lines = self.cu.GetNumLineEntries()
summary = ''
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : num_lines > 0,
- 'tree-item-delegate' : self }
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': num_lines > 0,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
@@ -275,7 +307,9 @@ class CompileUnitTreeItemDelegate(object):
item_dicts.append(item_delegate.get_item_dictionary())
return item_dicts
+
class LineTableTreeItemDelegate(object):
+
def __init__(self, target, cu):
self.target = target
self.cu = cu
@@ -285,22 +319,25 @@ class LineTableTreeItemDelegate(object):
value = ''
num_lines = self.cu.GetNumLineEntries()
summary = '%u line entries' % (num_lines)
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : num_lines > 0,
- 'tree-item-delegate' : self }
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': num_lines > 0,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
num_lines = self.cu.GetNumLineEntries()
for i in range(num_lines):
line_entry = self.cu.GetLineEntryAtIndex(i)
- item_delegate = LineEntryTreeItemDelegate(self.target, line_entry, i)
+ item_delegate = LineEntryTreeItemDelegate(
+ self.target, line_entry, i)
item_dicts.append(item_delegate.get_item_dictionary())
return item_dicts
+
class LineEntryTreeItemDelegate(object):
+
def __init__(self, target, line_entry, index):
self.target = target
self.line_entry = line_entry
@@ -314,18 +351,21 @@ class LineEntryTreeItemDelegate(object):
value = '0x%16.16x' % (load_addr)
else:
value = '0x%16.16x *' % (address.file_addr)
- summary = self.line_entry.GetFileSpec().fullpath + ':' + str(self.line_entry.line)
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : False,
- 'tree-item-delegate' : self }
+ summary = self.line_entry.GetFileSpec().fullpath + ':' + \
+ str(self.line_entry.line)
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': False,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
return item_dicts
+
class InstructionTreeItemDelegate(object):
+
def __init__(self, target, instr):
self.target = target
self.instr = instr
@@ -337,15 +377,18 @@ class InstructionTreeItemDelegate(object):
name = '0x%16.16x' % (load_addr)
else:
name = '0x%16.16x *' % (address.file_addr)
- value = self.instr.GetMnemonic(self.target) + ' ' + self.instr.GetOperands(self.target)
+ value = self.instr.GetMnemonic(
+ self.target) + ' ' + self.instr.GetOperands(self.target)
summary = self.instr.GetComment(self.target)
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : False,
- 'tree-item-delegate' : self }
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': False,
+ 'tree-item-delegate': self}
+
class ModuleSymbolsTreeItemDelegate(object):
+
def __init__(self, target, module):
self.target = target
self.module = module
@@ -354,22 +397,25 @@ class ModuleSymbolsTreeItemDelegate(object):
name = 'symbols'
value = ''
summary = '%u symbols' % (self.module.GetNumSymbols())
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : True,
- 'tree-item-delegate' : self }
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': True,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
num_symbols = self.module.GetNumSymbols()
for i in range(num_symbols):
symbol = self.module.GetSymbolAtIndex(i)
- image_item_delegate = SymbolTreeItemDelegate(self.target, symbol, i)
+ image_item_delegate = SymbolTreeItemDelegate(
+ self.target, symbol, i)
item_dicts.append(image_item_delegate.get_item_dictionary())
return item_dicts
+
class SymbolTreeItemDelegate(object):
+
def __init__(self, target, symbol, index):
self.target = target
self.symbol = symbol
@@ -384,20 +430,19 @@ class SymbolTreeItemDelegate(object):
else:
value = '0x%16.16x *' % (address.file_addr)
summary = self.symbol.name
- return { '#0' : name,
- 'value': value,
- 'summary': summary,
- 'children' : False,
- 'tree-item-delegate' : self }
+ return {'#0': name,
+ 'value': value,
+ 'summary': summary,
+ 'children': False,
+ 'tree-item-delegate': self}
def get_child_item_dictionaries(self):
item_dicts = list()
return item_dicts
-
class DelegateTree(ttk.Frame):
-
+
def __init__(self, column_dicts, delegate, title, name):
ttk.Frame.__init__(self, name=name)
self.pack(expand=Y, fill=BOTH)
@@ -409,36 +454,42 @@ class DelegateTree(ttk.Frame):
frame.pack(side=TOP, fill=BOTH, expand=Y)
self._create_treeview(frame)
self._populate_root()
-
+
def _create_treeview(self, parent):
frame = ttk.Frame(parent)
frame.pack(side=TOP, fill=BOTH, expand=Y)
-
+
column_ids = list()
- for i in range(1,len(self.columns_dicts)):
+ for i in range(1, len(self.columns_dicts)):
column_ids.append(self.columns_dicts[i]['id'])
# create the tree and scrollbars
self.tree = ttk.Treeview(columns=column_ids)
-
- scroll_bar_v = ttk.Scrollbar(orient=VERTICAL, command= self.tree.yview)
- scroll_bar_h = ttk.Scrollbar(orient=HORIZONTAL, command= self.tree.xview)
+
+ scroll_bar_v = ttk.Scrollbar(orient=VERTICAL, command=self.tree.yview)
+ scroll_bar_h = ttk.Scrollbar(
+ orient=HORIZONTAL, command=self.tree.xview)
self.tree['yscroll'] = scroll_bar_v.set
self.tree['xscroll'] = scroll_bar_h.set
-
+
# setup column headings and columns properties
for columns_dict in self.columns_dicts:
- self.tree.heading(columns_dict['id'], text=columns_dict['text'], anchor=columns_dict['anchor'])
- self.tree.column(columns_dict['id'], stretch=columns_dict['stretch'])
-
+ self.tree.heading(
+ columns_dict['id'],
+ text=columns_dict['text'],
+ anchor=columns_dict['anchor'])
+ self.tree.column(
+ columns_dict['id'],
+ stretch=columns_dict['stretch'])
+
# add tree and scrollbars to frame
self.tree.grid(in_=frame, row=0, column=0, sticky=NSEW)
scroll_bar_v.grid(in_=frame, row=0, column=1, sticky=NS)
scroll_bar_h.grid(in_=frame, row=1, column=0, sticky=EW)
-
+
# set frame resizing priorities
frame.rowconfigure(0, weight=1)
frame.columnconfigure(0, weight=1)
-
+
# action to perform when a node is expanded
self.tree.bind('<<TreeviewOpen>>', self._update_tree)
@@ -453,22 +504,22 @@ class DelegateTree(ttk.Frame):
first = False
else:
values.append(item_dict[columns_dict['id']])
- item_id = self.tree.insert (parent_id, # root item has an empty name
- END,
- text=name,
- values=values)
+ item_id = self.tree.insert(parent_id, # root item has an empty name
+ END,
+ text=name,
+ values=values)
self.item_id_to_item_dict[item_id] = item_dict
if item_dict['children']:
self.tree.insert(item_id, END, text='dummy')
-
+
def _populate_root(self):
# use current directory as root node
self.insert_items('', self.delegate.get_child_item_dictionaries())
-
+
def _update_tree(self, event):
# user expanded a node - build the related directory
- item_id = self.tree.focus() # the id of the expanded node
- children = self.tree.get_children (item_id)
+ item_id = self.tree.focus() # the id of the expanded node
+ children = self.tree.get_children(item_id)
if len(children):
first_child = children[0]
# if the node only has a 'dummy' child, remove it and
@@ -477,12 +528,15 @@ class DelegateTree(ttk.Frame):
if self.tree.item(first_child, option='text') == 'dummy':
self.tree.delete(first_child)
item_dict = self.item_id_to_item_dict[item_id]
- item_dicts = item_dict['tree-item-delegate'].get_child_item_dictionaries()
+ item_dicts = item_dict[
+ 'tree-item-delegate'].get_child_item_dictionaries()
self.insert_items(item_id, item_dicts)
+
@lldb.command("tk-variables")
def tk_variable_display(debugger, command, result, dict):
- sys.argv = ['tk-variables'] # needed for tree creation in TK library as it uses sys.argv...
+ # needed for tree creation in TK library as it uses sys.argv...
+ sys.argv = ['tk-variables']
target = debugger.GetSelectedTarget()
if not target:
print >>result, "invalid target"
@@ -501,16 +555,22 @@ def tk_variable_display(debugger, command, result, dict):
return
# Parse command line args
command_args = shlex.split(command)
- column_dicts = [{ 'id' : '#0' , 'text' : 'Name' , 'anchor' : W , 'stretch' : 0 },
- { 'id' : 'typename', 'text' : 'Type' , 'anchor' : W , 'stretch' : 0 },
- { 'id' : 'value' , 'text' : 'Value' , 'anchor' : W , 'stretch' : 0 },
- { 'id' : 'summary' , 'text' : 'Summary', 'anchor' : W , 'stretch' : 1 }]
- tree = DelegateTree(column_dicts, FrameTreeItemDelegate(frame), 'Variables', 'lldb-tk-variables')
+ column_dicts = [{'id': '#0', 'text': 'Name', 'anchor': W, 'stretch': 0},
+ {'id': 'typename', 'text': 'Type', 'anchor': W, 'stretch': 0},
+ {'id': 'value', 'text': 'Value', 'anchor': W, 'stretch': 0},
+ {'id': 'summary', 'text': 'Summary', 'anchor': W, 'stretch': 1}]
+ tree = DelegateTree(
+ column_dicts,
+ FrameTreeItemDelegate(frame),
+ 'Variables',
+ 'lldb-tk-variables')
tree.mainloop()
+
@lldb.command("tk-process")
def tk_process_display(debugger, command, result, dict):
- sys.argv = ['tk-process'] # needed for tree creation in TK library as it uses sys.argv...
+ # needed for tree creation in TK library as it uses sys.argv...
+ sys.argv = ['tk-process']
target = debugger.GetSelectedTarget()
if not target:
print >>result, "invalid target"
@@ -520,25 +580,34 @@ def tk_process_display(debugger, command, result, dict):
print >>result, "invalid process"
return
# Parse command line args
- columnd_dicts = [{ 'id' : '#0' , 'text' : 'Name' , 'anchor' : W , 'stretch' : 0 },
- { 'id' : 'value' , 'text' : 'Value' , 'anchor' : W , 'stretch' : 0 },
- { 'id' : 'summary', 'text' : 'Summary', 'anchor' : W , 'stretch' : 1 }];
+ columnd_dicts = [{'id': '#0', 'text': 'Name', 'anchor': W, 'stretch': 0},
+ {'id': 'value', 'text': 'Value', 'anchor': W, 'stretch': 0},
+ {'id': 'summary', 'text': 'Summary', 'anchor': W, 'stretch': 1}]
command_args = shlex.split(command)
- tree = DelegateTree(columnd_dicts, ProcessTreeItemDelegate(process), 'Process', 'lldb-tk-process')
+ tree = DelegateTree(
+ columnd_dicts,
+ ProcessTreeItemDelegate(process),
+ 'Process',
+ 'lldb-tk-process')
tree.mainloop()
+
@lldb.command("tk-target")
def tk_target_display(debugger, command, result, dict):
- sys.argv = ['tk-target'] # needed for tree creation in TK library as it uses sys.argv...
+ # needed for tree creation in TK library as it uses sys.argv...
+ sys.argv = ['tk-target']
target = debugger.GetSelectedTarget()
if not target:
print >>result, "invalid target"
return
# Parse command line args
- columnd_dicts = [{ 'id' : '#0' , 'text' : 'Name' , 'anchor' : W , 'stretch' : 0 },
- { 'id' : 'value' , 'text' : 'Value' , 'anchor' : W , 'stretch' : 0 },
- { 'id' : 'summary', 'text' : 'Summary', 'anchor' : W , 'stretch' : 1 }];
+ columnd_dicts = [{'id': '#0', 'text': 'Name', 'anchor': W, 'stretch': 0},
+ {'id': 'value', 'text': 'Value', 'anchor': W, 'stretch': 0},
+ {'id': 'summary', 'text': 'Summary', 'anchor': W, 'stretch': 1}]
command_args = shlex.split(command)
- tree = DelegateTree(columnd_dicts, TargetTreeItemDelegate(target), 'Target', 'lldb-tk-target')
+ tree = DelegateTree(
+ columnd_dicts,
+ TargetTreeItemDelegate(target),
+ 'Target',
+ 'lldb-tk-target')
tree.mainloop()
-
OpenPOWER on IntegriCloud