Skip to content

Commit 69c661a

Browse files
committed
[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 #57947 for a longer explanation with concrete examples of incorrect behavior. Differential Revision: https://reviews.llvm.org/D134570
1 parent 04bb32e commit 69c661a

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

lldb/source/Commands/CommandObjectType.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,12 +2319,17 @@ bool CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
23192319
type = eRegexSynth;
23202320
}
23212321

2322-
if (category->AnyMatches(type_name, eFormatCategoryItemFilter, false)) {
2323-
if (error)
2324-
error->SetErrorStringWithFormat("cannot add synthetic for type %s when "
2325-
"filter is defined in same category!",
2326-
type_name.AsCString());
2327-
return false;
2322+
// Only check for conflicting filters in the same category if `type_name` is
2323+
// an actual type name. Matching a regex string against registered regexes
2324+
// doesn't work.
2325+
if (type == eRegularSynth) {
2326+
if (category->AnyMatches(type_name, eFormatCategoryItemFilter, false)) {
2327+
if (error)
2328+
error->SetErrorStringWithFormat("cannot add synthetic for type %s when "
2329+
"filter is defined in same category!",
2330+
type_name.AsCString());
2331+
return false;
2332+
}
23282333
}
23292334

23302335
if (type == eRegexSynth) {
@@ -2442,13 +2447,18 @@ class CommandObjectTypeFilterAdd : public CommandObjectParsed {
24422447
type = eRegexFilter;
24432448
}
24442449

2445-
if (category->AnyMatches(type_name, eFormatCategoryItemSynth, false)) {
2446-
if (error)
2447-
error->SetErrorStringWithFormat("cannot add filter for type %s when "
2448-
"synthetic is defined in same "
2449-
"category!",
2450-
type_name.AsCString());
2451-
return false;
2450+
// Only check for conflicting synthetic child providers in the same category
2451+
// if `type_name` is an actual type name. Matching a regex string against
2452+
// registered regexes doesn't work.
2453+
if (type == eRegularFilter) {
2454+
if (category->AnyMatches(type_name, eFormatCategoryItemSynth, false)) {
2455+
if (error)
2456+
error->SetErrorStringWithFormat("cannot add filter for type %s when "
2457+
"synthetic is defined in same "
2458+
"category!",
2459+
type_name.AsCString());
2460+
return false;
2461+
}
24522462
}
24532463

24542464
if (type == eRegexFilter) {

lldb/test/API/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ def cleanup():
257257
self.expect("frame variable f00_1", matching=False,
258258
substrs=['fake_a = '])
259259

260+
# check that we don't feed a regex into another regex when checking for
261+
# existing conflicting synth/filters. The two following expressions
262+
# accept different types: one will accept types that look like an array
263+
# of MyType, the other will accept types that contain "MyType1" or
264+
# "MyType2". But the second regex looks like an array of MyType, so
265+
# lldb used to incorrectly reject it.
266+
self.runCmd(r'type synth add -l fooSynthProvider -x "^MyType\[[0-9]+]$"')
267+
self.runCmd(r'type filter add --child a -x "MyType[12]"')
268+
269+
# Same, but adding the filter first to verify the check when doing
270+
# `type synth add`. We need to delete the synth from the previous test
271+
# first.
272+
self.runCmd(r'type synth delete "^MyType\[[0-9]+]$"')
273+
self.runCmd(r'type filter add --child a -x "^MyType\[[0-9]+]$"')
274+
self.runCmd(r'type synth add -l fooSynthProvider -x "MyType[12]"')
275+
260276
def rdar10960550_formatter_commands(self):
261277
"""Test that synthetic children persist stoppoints."""
262278
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

0 commit comments

Comments
 (0)