kastiglione created this revision. kastiglione added reviewers: mib, JDevlieghere. Herald added a project: All. kastiglione requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Fixes broken support for: `target.module[re.compile("libFoo")]` There were two issues: 1. The type check was expecting `re.SRE_Pattern` 2. The expression to search the module path had a typo In the first case, `re.SRE_Pattern` does not exist in Python 3, and is replaced with `re.Pattern`. While editing this code, I changed the type checks to us `isinstance`, which is the conventional way of type checking. >From the docs on `type()`: > The `isinstance()` built-in function is recommended for testing the type of > an object, because it takes subclasses into account. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D133130 Files: lldb/bindings/interface/SBTarget.i Index: lldb/bindings/interface/SBTarget.i =================================================================== --- lldb/bindings/interface/SBTarget.i +++ lldb/bindings/interface/SBTarget.i @@ -1000,10 +1000,10 @@ def __getitem__(self, key): num_modules = self.sbtarget.GetNumModules() - if type(key) is int: + if isinstance(key, int): if key < num_modules: return self.sbtarget.GetModuleAtIndex(key) - elif type(key) is str: + elif isinstance(key, str): if key.find('/') == -1: for idx in range(num_modules): module = self.sbtarget.GetModuleAtIndex(idx) @@ -1024,16 +1024,16 @@ return module except: return None - elif type(key) is uuid.UUID: + elif isinstance(key, uuid.UUID): for idx in range(num_modules): module = self.sbtarget.GetModuleAtIndex(idx) if module.uuid == key: return module - elif type(key) is re.SRE_Pattern: + elif isinstance(key, re.Pattern): matching_modules = [] for idx in range(num_modules): module = self.sbtarget.GetModuleAtIndex(idx) - re_match = key.search(module.path.fullpath) + re_match = key.search(module.file.fullpath) if re_match: matching_modules.append(module) return matching_modules
Index: lldb/bindings/interface/SBTarget.i =================================================================== --- lldb/bindings/interface/SBTarget.i +++ lldb/bindings/interface/SBTarget.i @@ -1000,10 +1000,10 @@ def __getitem__(self, key): num_modules = self.sbtarget.GetNumModules() - if type(key) is int: + if isinstance(key, int): if key < num_modules: return self.sbtarget.GetModuleAtIndex(key) - elif type(key) is str: + elif isinstance(key, str): if key.find('/') == -1: for idx in range(num_modules): module = self.sbtarget.GetModuleAtIndex(idx) @@ -1024,16 +1024,16 @@ return module except: return None - elif type(key) is uuid.UUID: + elif isinstance(key, uuid.UUID): for idx in range(num_modules): module = self.sbtarget.GetModuleAtIndex(idx) if module.uuid == key: return module - elif type(key) is re.SRE_Pattern: + elif isinstance(key, re.Pattern): matching_modules = [] for idx in range(num_modules): module = self.sbtarget.GetModuleAtIndex(idx) - re_match = key.search(module.path.fullpath) + re_match = key.search(module.file.fullpath) if re_match: matching_modules.append(module) return matching_modules
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits