[Lldb-commits] [lldb] 69c661a - [lldb] Skip check for conflicting filter/synth when adding a new regex.

Jorge Gorbe Moya via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 6 13:28:11 PDT 2022


Author: Jorge Gorbe Moya
Date: 2022-10-06T13:27:11-07:00
New Revision: 69c661a65ff8c04ce9408a788a77df67481545a1

URL: https://github.com/llvm/llvm-project/commit/69c661a65ff8c04ce9408a788a77df67481545a1
DIFF: https://github.com/llvm/llvm-project/commit/69c661a65ff8c04ce9408a788a77df67481545a1.diff

LOG: [lldb] Skip check for conflicting filter/synth when adding a new regex.

When adding a new synthetic child provider, we check for an existing
conflicting filter in the same category (and vice versa). This is done
by trying to match the new type name against registered formatters.

However, the new type name we're registered can also be a regex
(`type synth add -x`), and in this case the conflict check is just
wrong: it will try to match the new regex as if it was a type name,
against previously registered regexes.

See https://github.com/llvm/llvm-project/issues/57947 for a longer
explanation with concrete examples of incorrect behavior.

Differential Revision: https://reviews.llvm.org/D134570

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index b78f98ce132b..01b3ec2fed14 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -2319,12 +2319,17 @@ bool CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
       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) {
@@ -2442,13 +2447,18 @@ class CommandObjectTypeFilterAdd : public CommandObjectParsed {
         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) {

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py b/lldb/test/API/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py
index 40a26623bccf..7eef1bc990cc 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py
@@ -257,6 +257,22 @@ def cleanup():
         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 
diff erent 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)


        


More information about the lldb-commits mailing list