This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Print hint if object description is requested but not implemented
ClosedPublic

Authored by augusto2112 on Jun 21 2023, 6:14 PM.

Details

Summary

Lots of users use "po" as their default print command. If the type
doesn't implement the description function the output is often not what
the user wants. Print a hint telling the user that they might prefer
using "p" instead.

Diff Detail

Event Timeline

augusto2112 created this revision.Jun 21 2023, 6:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2023, 6:14 PM
augusto2112 requested review of this revision.Jun 21 2023, 6:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2023, 6:14 PM

@kastiglione I wonder if we should hint in all 3 command objects (expr, frame var and DWIM) or if we should limit this to DWIM instead (since DWIM is the one aliased to p and po and I don't think vo or expr -O are often used unintentionally).

kastiglione added inline comments.Jun 28 2023, 10:28 AM
lldb/source/Commands/CommandObjectDWIMPrint.cpp
81–83

I wonder if there are users who might ignore this, and then find it annoying to see it repeatedly. Should it be a once per session warning? Once per class? Or controlled by a setting.

157–166

I know it would be less "DRY", but it also feels weird to me to pass in a bool that controls whether the function does anything. At the callsite, I think the semantics would be more clear as:

if (is_po)
    MaybeAddPoHintAndDump(*valobj_sp.get(), dump_options, language, 
                          result.GetOutputStream());
186–196
lldb/source/Commands/CommandObjectDWIMPrint.h
46–51 ↗(On Diff #533449)

Should this hint be part of dwim-print only? At this point I see expression as a command you use to do exactly what you ask it to do.

lldb/source/Commands/CommandObjectFrame.cpp
708 ↗(On Diff #533449)

Why is this line added? If this getter has side effects, we should create an appropriately named function that performs the side effects.

I wonder if we should hint in all 3 command objects (expr, frame var and DWIM) or if we should limit this to DWIM instead (since DWIM is the one aliased to p and po and I don't think vo or expr -O are often used unintentionally).

I missed this comment. My instinct is to have only dwim-print produce the hint. It feels more in scope for it.

lldb/source/Commands/CommandObjectDWIMPrint.h
46–51 ↗(On Diff #533449)

I see you asked this same question, and I had missed it at first.

augusto2112 marked 5 inline comments as done.

Addressed comments

kastiglione added inline comments.Jul 6 2023, 3:23 PM
lldb/include/lldb/Target/Target.h
496 ↗(On Diff #535561)

did you mean to use this, or should it be deleted?

lldb/source/Commands/CommandObjectDWIMPrint.cpp
129–130

question: would people want to be warned once per target, or once per type?

If I do like the warning, I might want to know every time I po a type that doesn't support it.

158–162

what do you think of passing in the result's stream into maybe_add_hint? Perhaps I am overlooking something, but I wonder if it would simplify the code to reuse the one stream, instead of separating and then combining two streams.

augusto2112 added inline comments.Jul 6 2023, 4:24 PM
lldb/include/lldb/Target/Target.h
496 ↗(On Diff #535561)

Leftover from a different implementation, I'll delete it.

lldb/source/Commands/CommandObjectDWIMPrint.cpp
129–130

In my opinion once per target should be enough, if we do it for every type that could potentially be too noisy, and hopefully after seeing the hint a few times users will start remembering to try p too.

158–162

I need the two streams to print it in the correct order (hint first, result later)

kastiglione added inline comments.Jul 7 2023, 11:01 AM
lldb/source/Commands/CommandObjectDWIMPrint.cpp
133–135

ok, I have a new suggestion. Since lldb will warn only once per target, and not per type, I think this note should be reworded to focus the guidance on the format of the output, not the type.

My concern is lldb emits basically "this type doesn't need a po", but then the diagnostic is printed for only one type, and never tells you about other types. How will people know that other types should use p not po?

If the message were on the format, and not the type, then I think it makes more sense as a once per target message.

A possible rewording:

note: this po used the default object description, which shows none of the objects properties. When you output like this, consider using p instead of po when you see such output.

158–162

do we have a precedent for before vs after? Maybe I need to see some examples, but I think it should be after. My logic is "here's the output you requested, and then here's a note about it". Also the note would be next to the next prompt, so maybe closer to the eyes? Just figured it was worth hashing out.

augusto2112 marked an inline comment as done.Jul 27 2023, 9:51 AM
augusto2112 added inline comments.
lldb/source/Commands/CommandObjectDWIMPrint.cpp
133–135

Personally I find the new message a bit more confusing for users to understand. Maybe:

note: object description requested, but type doesn't implement a custom object description. Consider using "p" instead of  "po" (this warning will only be displayed once per debug session).

What do you think?

158–162

DWIM print will add the note beforehand, I don't have strong feelings about this either way though. We'd probably still need 2 streams though, since we only want to match what's added by the value object's Dump, and nothing that may already be on the stream.

kastiglione accepted this revision.Aug 1 2023, 2:32 PM
This revision is now accepted and ready to land.Aug 1 2023, 2:32 PM

Addressed comments