aboutsummaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2024-06-13 09:37:02 -0700
committerGitHub <noreply@github.com>2024-06-13 09:37:02 -0700
commit8f2a4e83554abb2fb67f11d95428c3ff3147e88b (patch)
treed9c3a05c70d603b7f4885bafc8314dc76df60952 /lldb
parent890ab282781c3f78e98b5fc73a9f42d53b2220eb (diff)
downloadllvm-8f2a4e83554abb2fb67f11d95428c3ff3147e88b.zip
llvm-8f2a4e83554abb2fb67f11d95428c3ff3147e88b.tar.gz
llvm-8f2a4e83554abb2fb67f11d95428c3ff3147e88b.tar.bz2
[lldb] Support case-insensitive regex matches (#95350)
Support case-insensitive regex matches for `SBTarget::FindGlobalFunctions` and `SBTarget::FindGlobalVariables`.
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/Utility/RegularExpression.h8
-rw-r--r--lldb/include/lldb/lldb-enumerations.h7
-rw-r--r--lldb/source/API/SBTarget.cpp10
-rw-r--r--lldb/source/Utility/RegularExpression.cpp5
-rw-r--r--lldb/test/API/lang/cpp/class_static/TestStaticVariables.py7
5 files changed, 32 insertions, 5 deletions
diff --git a/lldb/include/lldb/Utility/RegularExpression.h b/lldb/include/lldb/Utility/RegularExpression.h
index 415f1b5..e8bd47b 100644
--- a/lldb/include/lldb/Utility/RegularExpression.h
+++ b/lldb/include/lldb/Utility/RegularExpression.h
@@ -31,7 +31,13 @@ public:
/// \param[in] string
/// An llvm::StringRef that represents the regular expression to compile.
// String is not referenced anymore after the object is constructed.
- explicit RegularExpression(llvm::StringRef string);
+ //
+ /// \param[in] flags
+ /// An llvm::Regex::RegexFlags that modifies the matching behavior. The
+ /// default is NoFlags.
+ explicit RegularExpression(
+ llvm::StringRef string,
+ llvm::Regex::RegexFlags flags = llvm::Regex::NoFlags);
~RegularExpression() = default;
diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h
index 8e05f6b..74ff458 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -1107,7 +1107,12 @@ enum MemberFunctionKind {
};
/// String matching algorithm used by SBTarget.
-enum MatchType { eMatchTypeNormal, eMatchTypeRegex, eMatchTypeStartsWith };
+enum MatchType {
+ eMatchTypeNormal,
+ eMatchTypeRegex,
+ eMatchTypeStartsWith,
+ eMatchTypeRegexInsensitive
+};
/// Bitmask that describes details about a type.
FLAGS_ENUM(TypeFlags){
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index adb9e64..2c33629 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1789,6 +1789,11 @@ lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
target_sp->GetImages().FindFunctions(RegularExpression(name_ref),
function_options, *sb_sc_list);
break;
+ case eMatchTypeRegexInsensitive:
+ target_sp->GetImages().FindFunctions(
+ RegularExpression(name_ref, llvm::Regex::RegexFlags::IgnoreCase),
+ function_options, *sb_sc_list);
+ break;
case eMatchTypeStartsWith:
regexstr = llvm::Regex::escape(name) + ".*";
target_sp->GetImages().FindFunctions(RegularExpression(regexstr),
@@ -1936,6 +1941,11 @@ SBValueList SBTarget::FindGlobalVariables(const char *name,
target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
max_matches, variable_list);
break;
+ case eMatchTypeRegexInsensitive:
+ target_sp->GetImages().FindGlobalVariables(
+ RegularExpression(name_ref, llvm::Regex::IgnoreCase), max_matches,
+ variable_list);
+ break;
case eMatchTypeStartsWith:
regexstr = "^" + llvm::Regex::escape(name) + ".*";
target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),
diff --git a/lldb/source/Utility/RegularExpression.cpp b/lldb/source/Utility/RegularExpression.cpp
index 20bebbf..0267934 100644
--- a/lldb/source/Utility/RegularExpression.cpp
+++ b/lldb/source/Utility/RegularExpression.cpp
@@ -12,10 +12,11 @@
using namespace lldb_private;
-RegularExpression::RegularExpression(llvm::StringRef str)
+RegularExpression::RegularExpression(llvm::StringRef str,
+ llvm::Regex::RegexFlags flags)
: m_regex_text(std::string(str)),
// m_regex does not reference str anymore after it is constructed.
- m_regex(llvm::Regex(str)) {}
+ m_regex(llvm::Regex(str, flags)) {}
RegularExpression::RegularExpression(const RegularExpression &rhs)
: RegularExpression(rhs.GetText()) {}
diff --git a/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py b/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py
index 8211d53..04678ec 100644
--- a/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py
+++ b/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py
@@ -2,7 +2,6 @@
Test display and Python APIs on file and class static variables.
"""
-
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
@@ -263,6 +262,12 @@ class StaticVariableTestCase(TestBase):
self.assertTrue(found_a, "Regex search found A::g_points")
self.assertTrue(found_aa, "Regex search found AA::g_points")
+ # Regex lowercase should find both as well.
+ val_list = target.FindGlobalVariables(
+ "a::g_points", 10, lldb.eMatchTypeRegexInsensitive
+ )
+ self.assertEqual(val_list.GetSize(), 2, "Found A & AA")
+
# Normal search for full name should find one, but it looks like we don't match
# on identifier boundaries here yet:
val_list = target.FindGlobalVariables("A::g_points", 10, lldb.eMatchTypeNormal)