This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Utility] Add GetDescription(Stream&) to StructureData::*
ClosedPublic

Authored by mib on Oct 9 2022, 4:38 PM.

Details

Summary

This patch improves the StructuredData classes to provide a
GetDescription(lldb_private::Stream&) affordance.

This is very convenient compared to the Dump method because this try to
pretty print the structure instead of just serializing it into a JSON.

This patch also updates some parts of lldb (i.e. extended crash info) to
use this new affordance instead of StructuredData::Dump.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Oct 9 2022, 4:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 9 2022, 4:38 PM
mib requested review of this revision.Oct 9 2022, 4:38 PM

The change looks good but this needs unit tests.

mib updated this revision to Diff 466624.Oct 10 2022, 2:37 PM

Address @JDevlieghere comment:

  • Add unittest
mib updated this revision to Diff 466626.Oct 10 2022, 2:38 PM

Add test file

The change looks good but I'd like to see a few more unit tests to cover edge cases (empty array, dict, etc),

lldb/unittests/Utility/StructuredDataTest.cpp
40–43

Maybe use a string literal to make it clear what the formatted text looks like?

mib marked an inline comment as done.Nov 1 2022, 6:35 PM
mib updated this revision to Diff 472475.Nov 1 2022, 6:41 PM

Address @JDevlieghere comments:

  • Fix indentation bug on nested structures
  • Add tests
  • Use string literals for expected string in tests
mib added inline comments.Nov 1 2022, 6:47 PM
lldb/include/lldb/Utility/StructuredData.h
584

@JDevlieghere Not sure if it would be worth to inline this

mib updated this revision to Diff 472497.Nov 1 2022, 8:38 PM
JDevlieghere accepted this revision.Nov 3 2022, 9:20 AM

LGMT with the missing periods fixed.

lldb/source/Utility/StructuredData.cpp
208

Comments should include punctuation.

This revision is now accepted and ready to land.Nov 3 2022, 9:20 AM
mib marked an inline comment as done.Nov 3 2022, 11:25 AM
This revision was automatically updated to reflect the committed changes.
shafik added a subscriber: shafik.Nov 4 2022, 11:22 AM
shafik added inline comments.
lldb/unittests/Utility/StructuredDataTest.cpp
41

When doing a build I am seeing:

warning: comparison of integers of different signs: 'const int' and 'const unsigned long' [-Wsign-compare]
mib added inline comments.Nov 4 2022, 11:24 AM
lldb/unittests/Utility/StructuredDataTest.cpp
41

I'll fix that! Thanks @shafik :) !