Author: enrico Date: Fri Nov 4 13:15:39 2016 New Revision: 286003 URL: http://llvm.org/viewvc/llvm-project?rev=286003&view=rev Log: Preliminary plumbing work to make 'parray' able to take offset and stride options
Modified: lldb/trunk/include/lldb/DataFormatters/DumpValueObjectOptions.h lldb/trunk/source/DataFormatters/DumpValueObjectOptions.cpp lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp Modified: lldb/trunk/include/lldb/DataFormatters/DumpValueObjectOptions.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/DumpValueObjectOptions.h?rev=286003&r1=286002&r2=286003&view=diff ============================================================================== --- lldb/trunk/include/lldb/DataFormatters/DumpValueObjectOptions.h (original) +++ lldb/trunk/include/lldb/DataFormatters/DumpValueObjectOptions.h Fri Nov 4 13:15:39 2016 @@ -42,6 +42,22 @@ public: ValueObject *valobj, const std::string &summary); }; + struct PointerAsArraySettings { + size_t m_element_count; + size_t m_base_element; + size_t m_stride; + + PointerAsArraySettings() + : m_element_count(0), m_base_element(0), m_stride() {} + + PointerAsArraySettings(size_t elem_count, size_t base_elem = 0, + size_t stride = 1) + : m_element_count(elem_count), m_base_element(base_elem), + m_stride(stride) {} + + operator bool() { return m_element_count > 0; } + }; + typedef std::function<bool(ConstString, ConstString, const DumpValueObjectOptions &, Stream &)> DeclPrintingHelper; @@ -116,6 +132,9 @@ public: DumpValueObjectOptions &SetElementCount(uint32_t element_count = 0); + DumpValueObjectOptions & + SetPointerAsArray(const PointerAsArraySettings &ptr_array); + public: uint32_t m_max_depth = UINT32_MAX; lldb::DynamicValueType m_use_dynamic = lldb::eNoDynamicValues; @@ -126,7 +145,7 @@ public: lldb::LanguageType m_varformat_language = lldb::eLanguageTypeUnknown; PointerDepth m_max_ptr_depth; DeclPrintingHelper m_decl_printing_helper; - uint32_t m_element_count = 0; + PointerAsArraySettings m_pointer_as_array; bool m_use_synthetic : 1; bool m_scope_already_checked : 1; bool m_flat_output : 1; Modified: lldb/trunk/source/DataFormatters/DumpValueObjectOptions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/DumpValueObjectOptions.cpp?rev=286003&r1=286002&r2=286003&view=diff ============================================================================== --- lldb/trunk/source/DataFormatters/DumpValueObjectOptions.cpp (original) +++ lldb/trunk/source/DataFormatters/DumpValueObjectOptions.cpp Fri Nov 4 13:15:39 2016 @@ -22,7 +22,7 @@ using namespace lldb_private; DumpValueObjectOptions::DumpValueObjectOptions() : m_summary_sp(), m_root_valobj_name(), m_max_ptr_depth(PointerDepth{PointerDepth::Mode::Default, 0}), - m_decl_printing_helper(), m_use_synthetic(true), + 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), @@ -195,6 +195,12 @@ DumpValueObjectOptions::SetRevealEmptyAg DumpValueObjectOptions & DumpValueObjectOptions::SetElementCount(uint32_t element_count) { - m_element_count = element_count; + m_pointer_as_array = PointerAsArraySettings(element_count); + return *this; +} + +DumpValueObjectOptions &DumpValueObjectOptions::SetPointerAsArray( + const PointerAsArraySettings &ptr_array) { + m_pointer_as_array = ptr_array; return *this; } Modified: lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp?rev=286003&r1=286002&r2=286003&view=diff ============================================================================== --- lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp (original) +++ lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp Fri Nov 4 13:15:39 2016 @@ -359,7 +359,7 @@ void ValueObjectPrinter::GetValueSummary lldb::Format format = m_options.m_format; // if I am printing synthetized elements, apply the format to those elements // only - if (m_options.m_element_count > 0) + if (m_options.m_pointer_as_array) m_valobj->GetValueAsCString(lldb::eFormatDefault, value); else if (format != eFormatDefault && format != m_valobj->GetFormat()) m_valobj->GetValueAsCString(format, value); @@ -449,7 +449,7 @@ bool ValueObjectPrinter::PrintObjectDesc if (ShouldPrintValueObject()) { // let's avoid the overly verbose no description error for a nil thing if (m_options.m_use_objc && !IsNil() && !IsUninitialized() && - (m_options.m_element_count == 0)) { + (!m_options.m_pointer_as_array)) { if (!m_options.m_hide_value || !m_options.m_hide_name) m_stream->Printf(" "); const char *object_desc = nullptr; @@ -513,7 +513,7 @@ bool ValueObjectPrinter::ShouldPrintChil // if the user has specified an element count, always print children // as it is explicit user demand being honored - if (m_options.m_element_count > 0) + if (m_options.m_pointer_as_array) return true; TypeSummaryImpl *entry = GetSummaryFormatter(); @@ -583,9 +583,9 @@ void ValueObjectPrinter::PrintChildrenPr void ValueObjectPrinter::PrintChild( ValueObjectSP child_sp, const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) { - const uint32_t consumed_depth = (m_options.m_element_count == 0) ? 1 : 0; + const uint32_t consumed_depth = (!m_options.m_pointer_as_array) ? 1 : 0; const bool does_consume_ptr_depth = - ((IsPtr() && m_options.m_element_count == 0) || IsRef()); + ((IsPtr() && !m_options.m_pointer_as_array) || IsRef()); DumpValueObjectOptions child_options(m_options); child_options.SetFormat(m_options.m_format) @@ -612,8 +612,8 @@ void ValueObjectPrinter::PrintChild( uint32_t ValueObjectPrinter::GetMaxNumChildrenToPrint(bool &print_dotdotdot) { ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration(); - if (m_options.m_element_count > 0) - return m_options.m_element_count; + if (m_options.m_pointer_as_array) + return m_options.m_pointer_as_array.m_element_count; size_t num_children = synth_m_valobj->GetNumChildren(); print_dotdotdot = false; @@ -664,11 +664,20 @@ bool ValueObjectPrinter::ShouldPrintEmpt return true; } +static constexpr size_t PhysicalIndexForLogicalIndex(size_t base, size_t stride, + size_t logical) { + return base + logical * stride; +} + ValueObjectSP ValueObjectPrinter::GenerateChild(ValueObject *synth_valobj, size_t idx) { - if (m_options.m_element_count > 0) { + if (m_options.m_pointer_as_array) { // if generating pointer-as-array children, use GetSyntheticArrayMember - return synth_valobj->GetSyntheticArrayMember(idx, true); + return synth_valobj->GetSyntheticArrayMember( + PhysicalIndexForLogicalIndex( + m_options.m_pointer_as_array.m_base_element, + m_options.m_pointer_as_array.m_stride, idx), + true); } else { // otherwise, do the usual thing return synth_valobj->GetChildAtIndex(idx, true); @@ -779,7 +788,7 @@ void ValueObjectPrinter::PrintChildrenIf bool print_oneline = (curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types || !m_options.m_allow_oneliner_mode || m_options.m_flat_output || - (m_options.m_element_count > 0) || m_options.m_show_location) + (m_options.m_pointer_as_array) || m_options.m_show_location) ? false : DataVisualization::ShouldPrintAsOneLiner(*m_valobj); bool is_instance_ptr = IsInstancePointer(); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits