Skip to content

Commit 8f2a4e8

Browse files
authored
[lldb] Support case-insensitive regex matches (llvm#95350)
Support case-insensitive regex matches for `SBTarget::FindGlobalFunctions` and `SBTarget::FindGlobalVariables`.
1 parent 890ab28 commit 8f2a4e8

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

lldb/include/lldb/Utility/RegularExpression.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ class RegularExpression {
3131
/// \param[in] string
3232
/// An llvm::StringRef that represents the regular expression to compile.
3333
// String is not referenced anymore after the object is constructed.
34-
explicit RegularExpression(llvm::StringRef string);
34+
//
35+
/// \param[in] flags
36+
/// An llvm::Regex::RegexFlags that modifies the matching behavior. The
37+
/// default is NoFlags.
38+
explicit RegularExpression(
39+
llvm::StringRef string,
40+
llvm::Regex::RegexFlags flags = llvm::Regex::NoFlags);
3541

3642
~RegularExpression() = default;
3743

lldb/include/lldb/lldb-enumerations.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,12 @@ enum MemberFunctionKind {
11071107
};
11081108

11091109
/// String matching algorithm used by SBTarget.
1110-
enum MatchType { eMatchTypeNormal, eMatchTypeRegex, eMatchTypeStartsWith };
1110+
enum MatchType {
1111+
eMatchTypeNormal,
1112+
eMatchTypeRegex,
1113+
eMatchTypeStartsWith,
1114+
eMatchTypeRegexInsensitive
1115+
};
11111116

11121117
/// Bitmask that describes details about a type.
11131118
FLAGS_ENUM(TypeFlags){

lldb/source/API/SBTarget.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,11 @@ lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
17891789
target_sp->GetImages().FindFunctions(RegularExpression(name_ref),
17901790
function_options, *sb_sc_list);
17911791
break;
1792+
case eMatchTypeRegexInsensitive:
1793+
target_sp->GetImages().FindFunctions(
1794+
RegularExpression(name_ref, llvm::Regex::RegexFlags::IgnoreCase),
1795+
function_options, *sb_sc_list);
1796+
break;
17921797
case eMatchTypeStartsWith:
17931798
regexstr = llvm::Regex::escape(name) + ".*";
17941799
target_sp->GetImages().FindFunctions(RegularExpression(regexstr),
@@ -1936,6 +1941,11 @@ SBValueList SBTarget::FindGlobalVariables(const char *name,
19361941
target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
19371942
max_matches, variable_list);
19381943
break;
1944+
case eMatchTypeRegexInsensitive:
1945+
target_sp->GetImages().FindGlobalVariables(
1946+
RegularExpression(name_ref, llvm::Regex::IgnoreCase), max_matches,
1947+
variable_list);
1948+
break;
19391949
case eMatchTypeStartsWith:
19401950
regexstr = "^" + llvm::Regex::escape(name) + ".*";
19411951
target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),

lldb/source/Utility/RegularExpression.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212

1313
using namespace lldb_private;
1414

15-
RegularExpression::RegularExpression(llvm::StringRef str)
15+
RegularExpression::RegularExpression(llvm::StringRef str,
16+
llvm::Regex::RegexFlags flags)
1617
: m_regex_text(std::string(str)),
1718
// m_regex does not reference str anymore after it is constructed.
18-
m_regex(llvm::Regex(str)) {}
19+
m_regex(llvm::Regex(str, flags)) {}
1920

2021
RegularExpression::RegularExpression(const RegularExpression &rhs)
2122
: RegularExpression(rhs.GetText()) {}

lldb/test/API/lang/cpp/class_static/TestStaticVariables.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Test display and Python APIs on file and class static variables.
33
"""
44

5-
65
import lldb
76
from lldbsuite.test.decorators import *
87
from lldbsuite.test.lldbtest import *
@@ -263,6 +262,12 @@ def test_with_python_FindGlobalVariables(self):
263262
self.assertTrue(found_a, "Regex search found A::g_points")
264263
self.assertTrue(found_aa, "Regex search found AA::g_points")
265264

265+
# Regex lowercase should find both as well.
266+
val_list = target.FindGlobalVariables(
267+
"a::g_points", 10, lldb.eMatchTypeRegexInsensitive
268+
)
269+
self.assertEqual(val_list.GetSize(), 2, "Found A & AA")
270+
266271
# Normal search for full name should find one, but it looks like we don't match
267272
# on identifier boundaries here yet:
268273
val_list = target.FindGlobalVariables("A::g_points", 10, lldb.eMatchTypeNormal)

0 commit comments

Comments
 (0)