summaryrefslogtreecommitdiffstats
path: root/lldb/source/DataFormatters
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/DataFormatters')
-rw-r--r--lldb/source/DataFormatters/DataVisualization.cpp6
-rw-r--r--lldb/source/DataFormatters/FormatManager.cpp60
-rw-r--r--lldb/source/DataFormatters/TypeSummary.cpp56
-rw-r--r--lldb/source/DataFormatters/ValueObjectPrinter.cpp62
4 files changed, 136 insertions, 48 deletions
diff --git a/lldb/source/DataFormatters/DataVisualization.cpp b/lldb/source/DataFormatters/DataVisualization.cpp
index c1ef359049b..94447fc8ede 100644
--- a/lldb/source/DataFormatters/DataVisualization.cpp
+++ b/lldb/source/DataFormatters/DataVisualization.cpp
@@ -40,6 +40,12 @@ DataVisualization::GetCurrentRevision ()
return GetFormatManager().GetCurrentRevision();
}
+bool
+DataVisualization::ShouldPrintAsOneLiner (ValueObject& valobj)
+{
+ return GetFormatManager().ShouldPrintAsOneLiner(valobj);
+}
+
lldb::TypeFormatImplSP
DataVisualization::ValueFormats::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic)
{
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp
index c4debf9c259..415ecc23dde 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -305,6 +305,66 @@ FormatManager::GetSingleItemFormat(lldb::Format vector_format)
}
}
+bool
+FormatManager::ShouldPrintAsOneLiner (ValueObject& valobj)
+{
+ // if this object has a summary, don't try to do anything special to it
+ // if the user wants one-liner, they can ask for it in summary :)
+ if (valobj.GetSummaryFormat().get() != nullptr)
+ return false;
+
+ // no children, no party
+ if (valobj.GetNumChildren() == 0)
+ return false;
+
+ size_t total_children_name_len = 0;
+
+ for (size_t idx = 0;
+ idx < valobj.GetNumChildren();
+ idx++)
+ {
+ ValueObjectSP child_sp(valobj.GetChildAtIndex(idx, true));
+ // something is wrong here - bail out
+ if (!child_sp)
+ return false;
+ // if we decided to define synthetic children for a type, we probably care enough
+ // to show them, but avoid nesting children in children
+ if (child_sp->GetSyntheticChildren().get() != nullptr)
+ return false;
+
+ total_children_name_len += child_sp->GetName().GetLength();
+
+ // 50 itself is a "randomly" chosen number - the idea is that
+ // overly long structs should not get this treatment
+ // FIXME: maybe make this a user-tweakable setting?
+ if (total_children_name_len > 50)
+ return false;
+
+ // if a summary is there..
+ if (child_sp->GetSummaryFormat())
+ {
+ // and it wants children, then bail out
+ if (child_sp->GetSummaryFormat()->DoesPrintChildren())
+ return false;
+ }
+
+ // if there is a base-class...
+ if (child_sp->IsBaseClass())
+ {
+ // and it has children..
+ if (child_sp->GetNumChildren())
+ {
+ // ...and no summary...
+ // (if it had a summary and the summary wanted children, we would have bailed out anyway
+ // so this only makes us bail out if this has no summary and we would then print children)
+ if (!child_sp->GetSummaryFormat())
+ return false; // then bail out
+ }
+ }
+ }
+ return true;
+}
+
ConstString
FormatManager::GetValidTypeName (const ConstString& type)
{
diff --git a/lldb/source/DataFormatters/TypeSummary.cpp b/lldb/source/DataFormatters/TypeSummary.cpp
index 8c4d3f71c05..4c75b4b87d0 100644
--- a/lldb/source/DataFormatters/TypeSummary.cpp
+++ b/lldb/source/DataFormatters/TypeSummary.cpp
@@ -23,6 +23,7 @@
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Timer.h"
#include "lldb/DataFormatters/TypeSummary.h"
+#include "lldb/DataFormatters/ValueObjectPrinter.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Symbol/ClangASTType.h"
#include "lldb/Target/StackFrame.h"
@@ -65,51 +66,12 @@ StringSummaryFormat::FormatObject (ValueObject *valobj,
if (frame)
sc = frame->GetSymbolContext(lldb::eSymbolContextEverything);
- if (IsOneliner())
+ if (IsOneLiner())
{
- ValueObject* object;
-
- ValueObjectSP synth_valobj = valobj->GetSyntheticValue();
- if (synth_valobj)
- object = synth_valobj.get();
- else
- object = valobj;
-
- const uint32_t num_children = object->GetNumChildren();
- if (num_children)
- {
- s.PutChar('(');
-
- for (uint32_t idx=0; idx<num_children; ++idx)
- {
- lldb::ValueObjectSP child_sp(object->GetChildAtIndex(idx, true));
- if (child_sp.get())
- {
- if (idx)
- s.PutCString(", ");
- if (!HideNames())
- {
- s.PutCString(child_sp.get()->GetName().AsCString());
- s.PutCString(" = ");
- }
- child_sp.get()->DumpPrintableRepresentation(s,
- ValueObject::eValueObjectRepresentationStyleSummary,
- lldb::eFormatInvalid,
- ValueObject::ePrintableRepresentationSpecialCasesDisable);
- }
- }
-
- s.PutChar(')');
-
- retval.assign(s.GetString());
- return true;
- }
- else
- {
- retval.assign("error: oneliner for no children");
- return false;
- }
-
+ ValueObjectPrinter printer(valobj,&s,DumpValueObjectOptions());
+ printer.PrintChildrenOneLiner(HideNames());
+ retval.assign(s.GetData());
+ return true;
}
else
{
@@ -135,7 +97,7 @@ StringSummaryFormat::GetDescription ()
Cascades() ? "" : " (not cascading)",
!DoesPrintChildren() ? "" : " (show children)",
!DoesPrintValue() ? " (hide value)" : "",
- IsOneliner() ? " (one-line printout)" : "",
+ IsOneLiner() ? " (one-line printout)" : "",
SkipsPointers() ? " (skip pointers)" : "",
SkipsReferences() ? " (skip references)" : "",
HideNames() ? " (hide member names)" : "");
@@ -171,7 +133,7 @@ CXXFunctionSummaryFormat::GetDescription ()
Cascades() ? "" : " (not cascading)",
!DoesPrintChildren() ? "" : " (show children)",
!DoesPrintValue() ? " (hide value)" : "",
- IsOneliner() ? " (one-line printout)" : "",
+ IsOneLiner() ? " (one-line printout)" : "",
SkipsPointers() ? " (skip pointers)" : "",
SkipsReferences() ? " (skip references)" : "",
HideNames() ? " (hide member names)" : "");
@@ -238,7 +200,7 @@ ScriptSummaryFormat::GetDescription ()
sstr.Printf ("%s%s%s%s%s%s%s\n%s", Cascades() ? "" : " (not cascading)",
!DoesPrintChildren() ? "" : " (show children)",
!DoesPrintValue() ? " (hide value)" : "",
- IsOneliner() ? " (one-line printout)" : "",
+ IsOneLiner() ? " (one-line printout)" : "",
SkipsPointers() ? " (skip pointers)" : "",
SkipsReferences() ? " (skip references)" : "",
HideNames() ? " (hide member names)" : "",
diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
index cd316cec628..7da5450bcd2 100644
--- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -14,6 +14,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Debugger.h"
+#include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Target/Target.h"
@@ -97,6 +98,8 @@ ValueObjectPrinter::PrintValueObject ()
bool
ValueObjectPrinter::GetDynamicValueIfNeeded ()
{
+ if (m_valobj)
+ return true;
bool update_success = m_orig_valobj->UpdateValueIfNeeded (true);
if (!update_success)
return false;
@@ -522,6 +525,55 @@ ValueObjectPrinter::PrintChildren (uint32_t curr_ptr_depth)
}
}
+bool
+ValueObjectPrinter::PrintChildrenOneLiner (bool hide_names)
+{
+ if (!GetDynamicValueIfNeeded () || m_valobj == nullptr)
+ return false;
+
+ ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration();
+
+ bool print_dotdotdot = false;
+ size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot);
+
+ if (num_children)
+ {
+ m_stream->PutChar('(');
+
+ for (uint32_t idx=0; idx<num_children; ++idx)
+ {
+ lldb::ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true));
+ lldb::ValueObjectSP child_dyn_sp = child_sp.get() ? child_sp->GetDynamicValue(options.m_use_dynamic) : child_sp;
+ if (child_dyn_sp)
+ child_sp = child_dyn_sp;
+ if (child_sp)
+ {
+ if (idx)
+ m_stream->PutCString(", ");
+ if (!hide_names)
+ {
+ const char* name = child_sp.get()->GetName().AsCString();
+ if (name && *name)
+ {
+ m_stream->PutCString(name);
+ m_stream->PutCString(" = ");
+ }
+ }
+ child_sp->DumpPrintableRepresentation(*m_stream,
+ ValueObject::eValueObjectRepresentationStyleSummary,
+ lldb::eFormatInvalid,
+ ValueObject::ePrintableRepresentationSpecialCasesDisable);
+ }
+ }
+
+ if (print_dotdotdot)
+ m_stream->PutCString(", ...)");
+ else
+ m_stream->PutChar(')');
+ }
+ return true;
+}
+
void
ValueObjectPrinter::PrintChildrenIfNeeded (bool value_printed,
bool summary_printed)
@@ -532,10 +584,18 @@ ValueObjectPrinter::PrintChildrenIfNeeded (bool value_printed,
uint32_t curr_ptr_depth = m_ptr_depth;
bool print_children = ShouldPrintChildren (is_failed_description,curr_ptr_depth);
+ bool print_oneline = (curr_ptr_depth > 0 || options.m_show_types) ? false : DataVisualization::ShouldPrintAsOneLiner(*m_valobj);
if (print_children)
{
- PrintChildren (curr_ptr_depth);
+ if (print_oneline)
+ {
+ m_stream->PutChar(' ');
+ PrintChildrenOneLiner (false);
+ m_stream->EOL();
+ }
+ else
+ PrintChildren (curr_ptr_depth);
}
else if (m_curr_depth >= options.m_max_depth && IsAggregate() && ShouldPrintValueObject())
{
OpenPOWER on IntegriCloud