diff --git a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h b/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h --- a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h +++ b/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h @@ -102,6 +102,8 @@ DumpValueObjectOptions &SetHideRootType(bool hide_root_type = false); + DumpValueObjectOptions &SetHideRootName(bool hide_root_name); + DumpValueObjectOptions &SetHideName(bool hide_name = false); DumpValueObjectOptions &SetHideValue(bool hide_value = false); @@ -143,6 +145,7 @@ bool m_show_location : 1; bool m_use_objc : 1; bool m_hide_root_type : 1; + bool m_hide_root_name : 1; bool m_hide_name : 1; bool m_hide_value : 1; bool m_run_validator : 1; diff --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h --- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h +++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h @@ -120,6 +120,8 @@ bool HasReachedMaximumDepth(); private: + bool ShouldShowName() const; + ValueObject *m_orig_valobj; ValueObject *m_valobj; Stream *m_stream; diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp --- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp +++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp @@ -88,7 +88,7 @@ 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 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -456,7 +456,7 @@ 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 --- a/lldb/source/DataFormatters/DumpValueObjectOptions.cpp +++ b/lldb/source/DataFormatters/DumpValueObjectOptions.cpp @@ -19,10 +19,10 @@ 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 @@ 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 --- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp +++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp @@ -275,7 +275,7 @@ 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 @@ 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 @@ 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 @@ // 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 @@ 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 @@ 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; +} diff --git a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py --- a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py +++ b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py @@ -114,3 +114,11 @@ error_msg = "error: 'dwim-print' takes a variable or expression" self.expect(f"dwim-print", error=True, startstr=error_msg) self.expect(f"dwim-print -- ", error=True, startstr=error_msg) + + def test_nested_values(self): + """Test dwim-print with nested values (structs, etc).""" + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c")) + self.runCmd("settings set auto-one-line-summaries false") + self._expect_cmd(f"dwim-print s", "frame variable") + self._expect_cmd(f"dwim-print (struct Structure)s", "expression") diff --git a/lldb/test/API/commands/dwim-print/main.c b/lldb/test/API/commands/dwim-print/main.c --- a/lldb/test/API/commands/dwim-print/main.c +++ b/lldb/test/API/commands/dwim-print/main.c @@ -1,3 +1,10 @@ +struct Structure { + int number; +}; + int main(int argc, char **argv) { + struct Structure s; + s.number = 30; + // break here return 0; }