Skip to content

[LLDB] Simplify the hint when po-ing an object with no object descrip…#200499

Merged
adrian-prantl merged 1 commit into
llvm:mainfrom
adrian-prantl:simplify-po-hint
May 30, 2026
Merged

[LLDB] Simplify the hint when po-ing an object with no object descrip…#200499
adrian-prantl merged 1 commit into
llvm:mainfrom
adrian-prantl:simplify-po-hint

Conversation

@adrian-prantl
Copy link
Copy Markdown
Contributor

…tion

The current wording of the hint is so long that the output obscures the output of the command, which can be confusing. By shortening the message the command output hopefully comes back into the center of attention.

…tion

The current wording of the hint is so long that the output obscures
the output of the command, which can be confusing. By shortening the
message the command output hopefully comes back into the center of
attention.
@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)

Changes

…tion

The current wording of the hint is so long that the output obscures the output of the command, which can be confusing. By shortening the message the command output hopefully comes back into the center of attention.


Full diff: https://github.com/llvm/llvm-project/pull/200499.diff

2 Files Affected:

  • (modified) lldb/source/Commands/CommandObjectDWIMPrint.cpp (+7-7)
  • (modified) lldb/test/API/lang/objc/objc-po-hint/TestObjcPoHint.py (+2-3)
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 66902eb6f8730..1b0b4c7881cfc 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -109,23 +109,23 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
     // Objective-C
     // "<Name: 0x...>. The regex is:
     // - Start with "<".
-    // - Followed by 1 or more non-whitespace characters.
+    // - Capture 1 or more non-whitespace characters (the class name).
     // - Followed by ": 0x".
     // - Followed by 5 or more hex digits.
     // - Followed by ">".
     // - End with zero or more whitespace characters.
     static const std::regex swift_class_regex(
-        "^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
+        "^<(\\S+): 0x[[:xdigit:]]{5,}>\\s*$");
 
+    std::cmatch match;
     if (GetDebugger().GetShowDontUsePoHint() && !target.IsDummyTarget() &&
         (language.AsLanguageType() == lldb::eLanguageTypeSwift ||
          language.IsObjC()) &&
-        std::regex_match(output.data(), swift_class_regex)) {
+        std::regex_match(output.data(), match, swift_class_regex)) {
 
-      result.AppendNote(
-          "object description requested, but type doesn't implement "
-          "a custom object description. Consider using \"p\" instead of "
-          "\"po\" (this note will only be shown once per debug session)");
+      result.AppendNoteWithFormatv(
+          "{0} has no custom object description, use \"p\" to see its children",
+          match[1].str());
       note_shown = true;
     }
   };
diff --git a/lldb/test/API/lang/objc/objc-po-hint/TestObjcPoHint.py b/lldb/test/API/lang/objc/objc-po-hint/TestObjcPoHint.py
index ba922944f4ce2..d149138012a70 100644
--- a/lldb/test/API/lang/objc/objc-po-hint/TestObjcPoHint.py
+++ b/lldb/test/API/lang/objc/objc-po-hint/TestObjcPoHint.py
@@ -17,8 +17,7 @@ def test_show_po_hint(self):
         self.expect(
             "dwim-print -O -- foo",
             substrs=[
-                "note: object description requested, but type doesn't implement "
-                'a custom object description. Consider using "p" instead of "po"',
+                "note: Foo has no custom object description",
                 "<Foo: 0x",
             ],
         )
@@ -40,6 +39,6 @@ def test_show_po_hint_disabled(self):
         # Make sure the hint is not printed
         self.expect(
             "dwim-print -O -- foo",
-            substrs=["note: object description"],
+            substrs=["note: Foo"],
             matching=False,
         )

Copy link
Copy Markdown
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this is better than the status quo. This still leaves me with the question: why not run p on my behalf (in the spirit of "Do What I Mean", and only when using dwim-print), which is what I suggested in the bug report that prompted this. However that can wait for a separate PR.

@adrian-prantl
Copy link
Copy Markdown
Contributor Author

LGTM, this is better than the status quo. This still leaves me with the question: why not run p on my behalf (in the spirit of "Do What I Mean", and only when using dwim-print), which is what I suggested in the bug report that prompted this. However that can wait for a separate PR.

I didn't want to go down that rabbit hole because the user did ask for the object description, so (in my opinion) LLDB is obligated to return it.But I understand why someone would argue the opposite.

@adrian-prantl adrian-prantl merged commit f561d59 into llvm:main May 30, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants