diff options
Diffstat (limited to 'lldb/scripts/interface')
| -rw-r--r-- | lldb/scripts/interface/SBModule.i | 23 | ||||
| -rw-r--r-- | lldb/scripts/interface/SBValue.i | 55 |
2 files changed, 78 insertions, 0 deletions
diff --git a/lldb/scripts/interface/SBModule.i b/lldb/scripts/interface/SBModule.i index 32c3c15dee7..4f6e9fd9cfb 100644 --- a/lldb/scripts/interface/SBModule.i +++ b/lldb/scripts/interface/SBModule.i @@ -8,6 +8,29 @@ namespace lldb { +%pythoncode%{ +# ================================== +# Helper function for SBModule class +# ================================== +def in_range(symbol, section): + """Test whether a symbol is within the range of a section.""" + symSA = symbol.GetStartAddress().GetFileAddress() + symEA = symbol.GetEndAddress().GetFileAddress() + secSA = section.GetFileAddress() + secEA = secSA + section.GetByteSize() + + if symEA != LLDB_INVALID_ADDRESS: + if secSA <= symSA and symEA <= secEA: + return True + else: + return False + else: + if secSA <= symSA and symSA < secEA: + return True + else: + return False +%} + %feature("docstring", "Represents an executable image and its associated object and symbol files. diff --git a/lldb/scripts/interface/SBValue.i b/lldb/scripts/interface/SBValue.i index 99352d82c93..fe5b9a0171f 100644 --- a/lldb/scripts/interface/SBValue.i +++ b/lldb/scripts/interface/SBValue.i @@ -601,6 +601,61 @@ public: child.SetSyntheticChildrenGenerated(True) return child + def __eol_test(val): + """Default function for end of list test takes an SBValue object. + + Return True if val is invalid or it corresponds to a null pointer. + Otherwise, return False. + """ + if not val or val.GetValueAsUnsigned() == 0: + return True + else: + return False + + # ================================================== + # Iterator for lldb.SBValue treated as a linked list + # ================================================== + def linked_list_iter(self, next_item_name, end_of_list_test=__eol_test): + """Generator adaptor to support iteration for SBValue as a linked list. + + linked_list_iter() is a special purpose iterator to treat the SBValue as + the head of a list data structure, where you specify the child member + name which points to the next item on the list and you specify the + end-of-list test function which takes an SBValue for an item and returns + True if EOL is reached and False if not. + + linked_list_iter() also detects infinite loop and bails out early. + + The end_of_list_test arg, if omitted, defaults to the __eol_test + function above. + + For example, + + # Get Frame #0. + ... + + # Get variable 'task_head'. + task_head = frame0.FindVariable('task_head') + ... + + for t in task_head.linked_list_iter('next'): + print t + """ + if end_of_list_test(self): + return + item = self + visited = set() + try: + while not end_of_list_test(item) and not item.GetValueAsUnsigned() in visited: + visited.add(item.GetValueAsUnsigned()) + yield item + # Prepare for the next iteration. + item = item.GetChildMemberWithName(next_item_name) + except: + # Exception occurred. Stop the generator. + pass + + return %} }; |

