diff options
| author | Pavel Labath <pavel@labath.sk> | 2019-02-27 14:16:48 +0000 | 
|---|---|---|
| committer | Pavel Labath <pavel@labath.sk> | 2019-02-27 14:16:48 +0000 | 
| commit | 11bc3f49da6c687cea018872c3890fd2237584a5 (patch) | |
| tree | a7e9eecc5b6c9ab8e81f49fd8a0cac611c3876ab /lldb/scripts/interface | |
| parent | 7904231edb1889229bf12e5a64a598defff33edc (diff) | |
| download | bcm5719-llvm-11bc3f49da6c687cea018872c3890fd2237584a5.tar.gz bcm5719-llvm-11bc3f49da6c687cea018872c3890fd2237584a5.zip | |
Insert blocks of python code with swig instead of modify-python-lldb.py
Summary:
Swig is perfectly capable of inserting blocks of python code into its
output (and we use those fascilities already), so there's no need for
this to be done in a post-process step.
lldb_iter is a general-purpose utility used from many classes, so I add
it to the main swig file. The other two blocks are tied to a specific
class, so I add it to the interface file of that class.
Reviewers: zturner, jingham, serge-sans-paille
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D58350
llvm-svn: 354975
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      %}  }; | 

