This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Introduce dwim-print command

Authored by kastiglione on Nov 18 2022, 11:39 AM.



Implements dwim-print, a printing command that chooses the most direct, efficient, and resilient means of printing a given expression.

DWIM is an acronym for Do What I Mean. From Wikipedia, DWIM is described as:

> attempt to anticipate what users intend to do, correcting trivial errors
> automatically rather than blindly executing users' explicit but
> potentially incorrect input

The dwim-print command serves as a single print command for users who don't yet know, or prefer not to know, the various lldb commands that can be used to print, and when to use them.

This initial implementation is the base foundation for dwim-print. It accepts no flags, only an expression. If the expression is the name of a variable in the frame, then effectively frame variable is used to get, and print, its value. Otherwise, printing falls back to using expression evaluation. In this initial version, frame variable paths will be handled with expression.

Following this, there are a number of improvements that can be made. Some improvements include supporting frame variable expressions or registers.

To provide transparency, especially as the dwim-print command evolves, a new setting is also introduced: dwim-print-verbosity. This setting instructs dwim-print optionally to print a message showing the effective command being run. For example dwim-print var.meth() can print a message such as: "note: ran expression var.meth().

See for the proposal and discussion.

Diff Detail

Event Timeline

kastiglione created this revision.Nov 18 2022, 11:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 18 2022, 11:39 AM
kastiglione requested review of this revision.Nov 18 2022, 11:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 18 2022, 11:39 AM
aeubanks added inline comments.


Add license.

kastiglione marked an inline comment as done.Nov 18 2022, 11:51 AM

Add license in .cpp too.

labath accepted this revision.Nov 28 2022, 5:59 AM
labath added inline comments.

I don't think this will work with a dummy target if you specify eCommandRequiresProcess.


If the expectation is that the users should be able to paste this command, then we'd better add a -- here. Otherwise expressions like -foo will not work as they will be confused for options.

This revision is now accepted and ready to land.Nov 28 2022, 5:59 AM

Address @labath's feedback

This revision was automatically updated to reflect the committed changes.