diff options
author | Dave Lee <davelee.com@gmail.com> | 2023-03-23 21:43:32 -0700 |
---|---|---|
committer | Dave Lee <davelee.com@gmail.com> | 2023-03-24 14:07:31 -0700 |
commit | 23349d83a98f23e67ff0321dad7c378b117ce6aa (patch) | |
tree | e92bde6c7ebd3e3e719e9126e91c4dfd2cfc53e6 /lldb/source | |
parent | 9fee241122fdf0d8747f0922741bb1cae0c1c53a (diff) | |
download | llvm-23349d83a98f23e67ff0321dad7c378b117ce6aa.zip llvm-23349d83a98f23e67ff0321dad7c378b117ce6aa.tar.gz llvm-23349d83a98f23e67ff0321dad7c378b117ce6aa.tar.bz2 |
[lldb] Add ability to hide the root name of a value
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.
Differential Revision: https://reviews.llvm.org/D146783
Diffstat (limited to 'lldb/source')
4 files changed, 30 insertions, 12 deletions
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp index ed81619..0b5dde9 100644 --- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp +++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp @@ -88,7 +88,7 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command, DumpValueObjectOptions dump_options = m_varobj_options.GetAsDumpOptions( m_expr_options.m_verbosity, m_format_options.GetFormat()); - dump_options.SetHideName(eval_options.GetSuppressPersistentResult()); + dump_options.SetHideRootName(eval_options.GetSuppressPersistentResult()); // First, try `expr` as the name of a frame variable. if (StackFrame *frame = m_exe_ctx.GetFramePtr()) { diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 2658677..5d68f66 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -456,7 +456,7 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr, DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions( m_command_options.m_verbosity, format)); - options.SetHideName(eval_options.GetSuppressPersistentResult()); + options.SetHideRootName(eval_options.GetSuppressPersistentResult()); options.SetVariableFormatDisplayLanguage( result_valobj_sp->GetPreferredDisplayLanguage()); diff --git a/lldb/source/DataFormatters/DumpValueObjectOptions.cpp b/lldb/source/DataFormatters/DumpValueObjectOptions.cpp index 38de442..3fbff86 100644 --- a/lldb/source/DataFormatters/DumpValueObjectOptions.cpp +++ b/lldb/source/DataFormatters/DumpValueObjectOptions.cpp @@ -19,10 +19,10 @@ DumpValueObjectOptions::DumpValueObjectOptions() m_decl_printing_helper(), m_pointer_as_array(), m_use_synthetic(true), m_scope_already_checked(false), m_flat_output(false), m_ignore_cap(false), m_show_types(false), m_show_location(false), m_use_objc(false), - m_hide_root_type(false), m_hide_name(false), m_hide_value(false), - m_run_validator(false), m_use_type_display_name(true), - m_allow_oneliner_mode(true), m_hide_pointer_value(false), - m_reveal_empty_aggregates(true) {} + m_hide_root_type(false), m_hide_root_name(false), m_hide_name(false), + m_hide_value(false), m_run_validator(false), + m_use_type_display_name(true), m_allow_oneliner_mode(true), + m_hide_pointer_value(false), m_reveal_empty_aggregates(true) {} DumpValueObjectOptions::DumpValueObjectOptions(ValueObject &valobj) : DumpValueObjectOptions() { @@ -143,6 +143,12 @@ DumpValueObjectOptions::SetHideRootType(bool hide_root_type) { return *this; } +DumpValueObjectOptions & +DumpValueObjectOptions::SetHideRootName(bool hide_root_name) { + m_hide_root_name = hide_root_name; + return *this; +} + DumpValueObjectOptions &DumpValueObjectOptions::SetHideName(bool hide_name) { m_hide_name = hide_name; return *this; diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp index 17e9877..5915c04 100644 --- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp +++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp @@ -275,7 +275,7 @@ void ValueObjectPrinter::PrintDecl() { StreamString varName; - if (!m_options.m_hide_name) { + if (ShouldShowName()) { if (m_options.m_flat_output) m_valobj->GetExpressionPath(varName); else @@ -314,7 +314,7 @@ void ValueObjectPrinter::PrintDecl() { m_stream->Printf("(%s) ", typeName.GetData()); if (!varName.Empty()) m_stream->Printf("%s =", varName.GetData()); - else if (!m_options.m_hide_name) + else if (ShouldShowName()) m_stream->Printf(" ="); } } @@ -437,7 +437,7 @@ bool ValueObjectPrinter::PrintValueAndSummaryIfNeeded(bool &value_printed, if (m_options.m_hide_pointer_value && IsPointerValue(m_valobj->GetCompilerType())) { } else { - if (!m_options.m_hide_name) + if (ShouldShowName()) m_stream->PutChar(' '); m_stream->PutCString(m_value); value_printed = true; @@ -459,7 +459,7 @@ bool ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed, // let's avoid the overly verbose no description error for a nil thing if (m_options.m_use_objc && !IsNil() && !IsUninitialized() && (!m_options.m_pointer_as_array)) { - if (!m_options.m_hide_value || !m_options.m_hide_name) + if (!m_options.m_hide_value || ShouldShowName()) m_stream->Printf(" "); const char *object_desc = nullptr; if (value_printed || summary_printed) @@ -565,8 +565,14 @@ void ValueObjectPrinter::PrintChildrenPreamble() { if (ShouldPrintValueObject()) m_stream->EOL(); } else { - if (ShouldPrintValueObject()) - m_stream->PutCString(IsRef() ? ": {\n" : " {\n"); + if (ShouldPrintValueObject()) { + if (IsRef()) { + m_stream->PutCString(": "); + } else if (ShouldShowName()) { + m_stream->PutChar(' '); + } + m_stream->PutCString("{\n"); + } m_stream->IndentMore(); } } @@ -819,3 +825,9 @@ void ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed, bool ValueObjectPrinter::HasReachedMaximumDepth() { return m_curr_depth >= m_options.m_max_depth; } + +bool ValueObjectPrinter::ShouldShowName() const { + if (m_curr_depth == 0) + return !m_options.m_hide_root_name && !m_options.m_hide_name; + return !m_options.m_hide_name; +} |