This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add ability to hide the root name of a value
ClosedPublic

Authored by kastiglione on Mar 23 2023, 10:40 PM.

Details

Summary

When printing a value, allow the root value's name to be elided, without omiting the
names of child values.

At the API level, this adds SetHideRootName(), which joins the existing
SetHideName() function.

This functionality is used by dwim-print and expression.

Fixes an issue identified by @jgorbe in https://reviews.llvm.org/D145609.

Diff Detail

Event Timeline

kastiglione created this revision.Mar 23 2023, 10:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2023, 10:40 PM
kastiglione requested review of this revision.Mar 23 2023, 10:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2023, 10:40 PM

I've tried building lldb with this patch applied and it fixes the problem I saw. Thanks for the quick fix!

I'm not very familiar with the code so I'd appreciate if someone else gives their LGTM too but the changes look reasonable to me (just one small nit I've mentioned in an inline comment).

lldb/source/DataFormatters/ValueObjectPrinter.cpp
278

This method name reads like a command, rather than a predicate. What about something like ShouldShowName or ShouldPrintName? This would also match the style of other method names already in this file such as ShouldPrintValueObject.

Rename ShowName to ShouldShowName

jgorbe accepted this revision.Mar 24 2023, 11:31 AM
This revision is now accepted and ready to land.Mar 24 2023, 11:31 AM
kastiglione added inline comments.Mar 24 2023, 11:53 AM
lldb/source/DataFormatters/ValueObjectPrinter.cpp
278

Good call, ShouldShowName is better.

This revision was automatically updated to reflect the committed changes.

I just noticed a minor aesthetic problem with the input of dwim-print when using data formatters. There are some spacing adjustments in this commit but I'm not sure if they are the actual cause (please let me know if you'd prefer me to file a bug instead).

You can reproduce it by defining some random struct X and using settings set auto-one-line-summaries false like you did in the test case for this commit.

If you add a summary string:

type summary add -s "my summary" -e "X"

then the output of dwim-print without persistent results has the wrong spacing:

(lldb) dwim-print my_x
(X)  my summary{
  value = 0
}

(note there are two spaces before "my summary" and no space before the opening brace).

Using expr or dwim-print --persistent-result on -- doesn't have this problem:

(lldb) dwim-print --persistent-result on -- my_x
(X) $2 = my summary {
  value = 0
}

@jgorbe thanks for reporting. I have a fix for the missing space, I will look into the cause of the double space and fix that as well. I'll do this today.