[Lldb-commits] [PATCH] D133130: [lldb][bindings] Fix module_access handling of regex
Dave Lee via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Sat Sep 3 10:32:30 PDT 2022
kastiglione updated this revision to Diff 457804.
kastiglione added a comment.
Add a test for subscripting a target.modules using regex
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133130/new/
https://reviews.llvm.org/D133130
Files:
lldb/bindings/interface/SBTarget.i
lldb/test/API/python_api/target/TestTargetAPI.py
Index: lldb/test/API/python_api/target/TestTargetAPI.py
===================================================================
--- lldb/test/API/python_api/target/TestTargetAPI.py
+++ lldb/test/API/python_api/target/TestTargetAPI.py
@@ -2,6 +2,7 @@
Test SBTarget APIs.
"""
+import re
import unittest2
import os
import lldb
@@ -516,3 +517,14 @@
module = target.GetModuleAtIndex(i)
self.assertTrue(target.IsLoaded(module), "Running the target should "
"have loaded its modules.")
+
+ def test_module_subscript_regex(self):
+ """Exercise SBTarget.module subscripting with regex."""
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+ modules = target.module[re.compile(r"/a[.]out$")]
+ self.assertEqual(len(modules), 1)
+ exe_mod = modules[0]
+ self.assertEqual(exe_mod.file.fullpath, exe)
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133130.457804.patch
Type: text/x-patch
Size: 2759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220903/f11e9bfa/attachment.bin>
More information about the lldb-commits
mailing list