[Lldb-commits] [PATCH] D134570: [lldb] Skip check for conflicting filter/synth when adding a new regex.

Jorge Gorbe Moya via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 23 18:44:38 PDT 2022


jgorbe updated this revision to Diff 462637.
jgorbe added a comment.

Added a couple of test cases to TestDataFormatterPythonSynth.py.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134570/new/

https://reviews.llvm.org/D134570

Files:
  lldb/source/Commands/CommandObjectType.cpp
  lldb/test/API/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py


Index: lldb/test/API/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py
@@ -257,6 +257,22 @@
         self.expect("frame variable f00_1", matching=False,
                     substrs=['fake_a = '])
 
+        # check that we don't feed a regex into another regex when checking for
+        # existing conflicting synth/filters. The two following expressions
+        # accept different types: one will accept types that look like an array
+        # of MyType, the other will accept types that contain "MyType1" or
+        # "MyType2". But the second regex looks like an array of MyType, so
+        # lldb used to incorrectly reject it.
+        self.runCmd(r'type synth add -l fooSynthProvider -x "^MyType\[[0-9]+]$"')
+        self.runCmd(r'type filter add --child a -x "MyType[12]"')
+
+        # Same, but adding the filter first to verify the check when doing
+        # `type synth add`. We need to delete the synth from the previous test
+        # first.
+        self.runCmd(r'type synth delete "^MyType\[[0-9]+]$"')
+        self.runCmd(r'type filter add --child a -x "^MyType\[[0-9]+]$"')
+        self.runCmd(r'type synth add -l fooSynthProvider -x "MyType[12]"')
+
     def rdar10960550_formatter_commands(self):
         """Test that synthetic children persist stoppoints."""
         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
Index: lldb/source/Commands/CommandObjectType.cpp
===================================================================
--- lldb/source/Commands/CommandObjectType.cpp
+++ lldb/source/Commands/CommandObjectType.cpp
@@ -2335,12 +2335,17 @@
       type = eRegexSynth;
   }
 
-  if (category->AnyMatches(type_name, eFormatCategoryItemFilter, false)) {
-    if (error)
-      error->SetErrorStringWithFormat("cannot add synthetic for type %s when "
-                                      "filter is defined in same category!",
-                                      type_name.AsCString());
-    return false;
+  // Only check for conflicting filters in the same category if `type_name` is
+  // an actual type name. Matching a regex string against registered regexes
+  // doesn't work.
+  if (type == eRegularSynth) {
+    if (category->AnyMatches(type_name, eFormatCategoryItemFilter, false)) {
+      if (error)
+        error->SetErrorStringWithFormat("cannot add synthetic for type %s when "
+                                        "filter is defined in same category!",
+                                        type_name.AsCString());
+      return false;
+    }
   }
 
   if (type == eRegexSynth) {
@@ -2458,13 +2463,18 @@
         type = eRegexFilter;
     }
 
-    if (category->AnyMatches(type_name, eFormatCategoryItemSynth, false)) {
-      if (error)
-        error->SetErrorStringWithFormat("cannot add filter for type %s when "
-                                        "synthetic is defined in same "
-                                        "category!",
-                                        type_name.AsCString());
-      return false;
+    // Only check for conflicting synthetic child providers in the same category
+    // if `type_name` is an actual type name. Matching a regex string against
+    // registered regexes doesn't work.
+    if (type == eRegularFilter) {
+      if (category->AnyMatches(type_name, eFormatCategoryItemSynth, false)) {
+        if (error)
+          error->SetErrorStringWithFormat("cannot add filter for type %s when "
+                                          "synthetic is defined in same "
+                                          "category!",
+                                          type_name.AsCString());
+        return false;
+      }
     }
 
     if (type == eRegexFilter) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134570.462637.patch
Type: text/x-patch
Size: 4044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220924/838177f6/attachment.bin>


More information about the lldb-commits mailing list