Skip to content

Commit 170e1fe

Browse files
authored
[lldb] Fix regex support in SBTarget.modules_access (llvm#116452)
First, `SRE_Pattern` does not exist on newer Python's, use `type(re.compile(''))` like other Python extensions do. The dynamic type is because some earlier versions of Python 3 do not have `re.Pattern`. Second, `SBModule` has a `file` property, not a `path` property.
1 parent e914d97 commit 170e1fe

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

lldb/bindings/interface/SBTargetExtensions.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, lldb::eDescriptionLevelBrief)
7979
module = self.sbtarget.GetModuleAtIndex(idx)
8080
if module.uuid == key:
8181
return module
82-
elif type(key) is re.SRE_Pattern:
82+
elif isinstance(key, type(re.compile(''))):
8383
matching_modules = []
8484
for idx in range(num_modules):
8585
module = self.sbtarget.GetModuleAtIndex(idx)
86-
re_match = key.search(module.path.fullpath)
86+
re_match = key.search(module.file.fullpath)
8787
if re_match:
8888
matching_modules.append(module)
8989
return matching_modules

lldb/test/API/lang/cpp/stl/TestStdCXXDisassembly.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import os
6+
import re
67
import lldb
78
from lldbsuite.test.lldbtest import *
89
import lldbsuite.test.lldbutil as lldbutil
@@ -30,15 +31,11 @@ def test_stdcxx_disasm(self):
3031
self.runCmd("disassemble -n '%s'" % function.GetName())
3132

3233
lib_stdcxx = "FAILHORRIBLYHERE"
33-
# Iterate through the available modules, looking for stdc++ library...
34-
for i in range(target.GetNumModules()):
35-
module = target.GetModuleAtIndex(i)
36-
fs = module.GetFileSpec()
37-
if fs.GetFilename().startswith("libstdc++") or fs.GetFilename().startswith(
38-
"libc++"
39-
):
40-
lib_stdcxx = str(fs)
41-
break
34+
# Find the stdc++ library...
35+
stdlib_regex = re.compile(r"/lib(std)?c\+\+")
36+
for module in target.module[stdlib_regex]:
37+
lib_stdcxx = module.file.fullpath
38+
break
4239

4340
# At this point, lib_stdcxx is the full path to the stdc++ library and
4441
# module is the corresponding SBModule.

0 commit comments

Comments
 (0)