[LLDB] Simplify the hint when po-ing an object with no object descrip…#200499
Conversation
…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.
|
@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:
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,
)
|
JDevlieghere
left a comment
There was a problem hiding this comment.
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. |
…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.