[Lldb-commits] [lldb] [lldb] Support alternatives for scope format entries (PR #137751)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 30 02:16:34 PDT 2025


================
@@ -153,10 +173,37 @@ constexpr llvm::StringRef lookupStrings[] = {
     "${target.file.fullpath}",
     "${var.dummy-var-to-test-wildcard}"};
 
-TEST(FormatEntity, LookupAllEntriesInTree) {
+TEST_F(FormatEntityTest, LookupAllEntriesInTree) {
   for (const llvm::StringRef testString : lookupStrings) {
     Entry e;
     EXPECT_TRUE(FormatEntity::Parse(testString, e).Success())
         << "Formatting " << testString << " did not succeed";
   }
 }
+
+TEST_F(FormatEntityTest, Scope) {
+  // Scope with  one alternative.
+  EXPECT_THAT_EXPECTED(Format("{${frame.pc}|foo}"), HasValue("foo"));
+
+  // Scope with multiple alternatives.
+  EXPECT_THAT_EXPECTED(Format("{${frame.pc}|${function.name}|foo}"),
+                       HasValue("foo"));
+
+  // Escaped pipe inside a scope.
+  EXPECT_THAT_EXPECTED(Format("{foo\\|bar}"), HasValue("foo|bar"));
+
+  // Unescaped pipe outside a scope.
+  EXPECT_THAT_EXPECTED(Format("foo|bar"), HasValue("foo|bar"));
+
+  // Nested scopes. Note that scopes always resolve.
+  EXPECT_THAT_EXPECTED(Format("{{${frame.pc}|foo}|{bar}}"), HasValue("foo"));
+  EXPECT_THAT_EXPECTED(Format("{{${frame.pc}}|{bar}}"), HasValue(""));
----------------
labath wrote:

That would break literally every existing use of scopes because the only reason to use them was to make expansion failures non-fatal. I'm not saying we can't do that, but I think that's what it is. We could try to split hairs and say this only applies to scopes with more than one alternative, but I don't know if it's worth it. I suppose it might be used to write something like `{common prefix {${foo}|${bar}}| alternative prefix}`, but I don't know if there's a realistic use case for that.

https://github.com/llvm/llvm-project/pull/137751


More information about the lldb-commits mailing list