[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/97754 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/97754 >From b10f76bd6d02106e80315a70a7b72461cb6f2a99 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 4 Jul 2024 13:35:21 +0200 Subject: [PATCH 1/3] [lldb][DataFormatter] Move std::unordered_map::iterator formatter into LibCxxUnorderedMap.cpp --- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 149 - .../Plugins/Language/CPlusPlus/LibCxx.h | 54 + .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 196 ++ 3 files changed, 200 insertions(+), 199 deletions(-) diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 05cfa0568c25d..feaa51a96843a 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -202,155 +202,6 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( return true; } -lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) -: SyntheticChildrenFrontEnd(*valobj_sp) { - if (valobj_sp) -Update(); -} - -lldb::ChildCacheState lldb_private::formatters:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() { - m_pair_sp.reset(); - m_iter_ptr = nullptr; - - ValueObjectSP valobj_sp = m_backend.GetSP(); - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - TargetSP target_sp(valobj_sp->GetTargetSP()); - - if (!target_sp) -return lldb::ChildCacheState::eRefetch; - - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions() - .DontCheckDotVsArrowSyntax() - .SetSyntheticChildrenTraversal( - ValueObject::GetValueForExpressionPathOptions:: - SyntheticChildrenTraversal::None); - - // This must be a ValueObject* because it is a child of the ValueObject we - // are producing children for it if were a ValueObjectSP, we would end up - // with a loop (iterator -> synthetic -> child -> parent == iterator) and - // that would in turn leak memory by never allowing the ValueObjects to die - // and free their memory. - m_iter_ptr = - valobj_sp - ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr, - exprPathOptions, nullptr) - .get(); - - if (m_iter_ptr) { -auto iter_child(valobj_sp->GetChildMemberWithName("__i_")); -if (!iter_child) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -CompilerType node_type(iter_child->GetCompilerType() - .GetTypeTemplateArgument(0) - .GetPointeeType()); - -CompilerType pair_type(node_type.GetTypeTemplateArgument(0)); - -std::string name; -uint64_t bit_offset_ptr; -uint32_t bitfield_bit_size_ptr; -bool is_bitfield_ptr; - -pair_type = pair_type.GetFieldAtIndex( -0, name, _offset_ptr, _bit_size_ptr, _bitfield_ptr); -if (!pair_type) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS); -m_iter_ptr = nullptr; - -if (addr == 0 || addr == LLDB_INVALID_ADDRESS) - return lldb::ChildCacheState::eRefetch; - -auto ts = pair_type.GetTypeSystem(); -auto ast_ctx = ts.dyn_cast_or_null(); -if (!ast_ctx) - return lldb::ChildCacheState::eRefetch; - -// Mimick layout of std::__hash_iterator::__node_ and read it in -// from process memory. -// -// The following shows the contiguous block of memory: -// -// +-+ class __hash_node_base -// __node_ | __next_pointer __next_; | -// +-+ class __hash_node -// | size_t __hash_; | -// | __node_value_type __value_; | <<< our key/value pair -// +-+ -// -CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier( -llvm::StringRef(), -{{"__next_", - ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)}, - {"__value_", pair_type}}); -std::optional size = tree_node_type.GetByteSize(nullptr); -if (!size) - return lldb::ChildCacheState::eRefetch; -WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); -ProcessSP process_sp(target_sp->GetProcessSP()); -Status error; -process_sp->ReadMemory(addr, buffer_sp->GetBytes(), - buffer_sp->GetByteSize(), error); -if (error.Fail()) - return lldb::ChildCacheState::eRefetch; -
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/97754 >From b10f76bd6d02106e80315a70a7b72461cb6f2a99 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 4 Jul 2024 13:35:21 +0200 Subject: [PATCH 1/2] [lldb][DataFormatter] Move std::unordered_map::iterator formatter into LibCxxUnorderedMap.cpp --- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 149 - .../Plugins/Language/CPlusPlus/LibCxx.h | 54 + .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 196 ++ 3 files changed, 200 insertions(+), 199 deletions(-) diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 05cfa0568c25d4..feaa51a96843ab 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -202,155 +202,6 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( return true; } -lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) -: SyntheticChildrenFrontEnd(*valobj_sp) { - if (valobj_sp) -Update(); -} - -lldb::ChildCacheState lldb_private::formatters:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() { - m_pair_sp.reset(); - m_iter_ptr = nullptr; - - ValueObjectSP valobj_sp = m_backend.GetSP(); - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - TargetSP target_sp(valobj_sp->GetTargetSP()); - - if (!target_sp) -return lldb::ChildCacheState::eRefetch; - - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions() - .DontCheckDotVsArrowSyntax() - .SetSyntheticChildrenTraversal( - ValueObject::GetValueForExpressionPathOptions:: - SyntheticChildrenTraversal::None); - - // This must be a ValueObject* because it is a child of the ValueObject we - // are producing children for it if were a ValueObjectSP, we would end up - // with a loop (iterator -> synthetic -> child -> parent == iterator) and - // that would in turn leak memory by never allowing the ValueObjects to die - // and free their memory. - m_iter_ptr = - valobj_sp - ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr, - exprPathOptions, nullptr) - .get(); - - if (m_iter_ptr) { -auto iter_child(valobj_sp->GetChildMemberWithName("__i_")); -if (!iter_child) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -CompilerType node_type(iter_child->GetCompilerType() - .GetTypeTemplateArgument(0) - .GetPointeeType()); - -CompilerType pair_type(node_type.GetTypeTemplateArgument(0)); - -std::string name; -uint64_t bit_offset_ptr; -uint32_t bitfield_bit_size_ptr; -bool is_bitfield_ptr; - -pair_type = pair_type.GetFieldAtIndex( -0, name, _offset_ptr, _bit_size_ptr, _bitfield_ptr); -if (!pair_type) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS); -m_iter_ptr = nullptr; - -if (addr == 0 || addr == LLDB_INVALID_ADDRESS) - return lldb::ChildCacheState::eRefetch; - -auto ts = pair_type.GetTypeSystem(); -auto ast_ctx = ts.dyn_cast_or_null(); -if (!ast_ctx) - return lldb::ChildCacheState::eRefetch; - -// Mimick layout of std::__hash_iterator::__node_ and read it in -// from process memory. -// -// The following shows the contiguous block of memory: -// -// +-+ class __hash_node_base -// __node_ | __next_pointer __next_; | -// +-+ class __hash_node -// | size_t __hash_; | -// | __node_value_type __value_; | <<< our key/value pair -// +-+ -// -CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier( -llvm::StringRef(), -{{"__next_", - ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)}, - {"__value_", pair_type}}); -std::optional size = tree_node_type.GetByteSize(nullptr); -if (!size) - return lldb::ChildCacheState::eRefetch; -WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); -ProcessSP process_sp(target_sp->GetProcessSP()); -Status error; -process_sp->ReadMemory(addr, buffer_sp->GetBytes(), - buffer_sp->GetByteSize(), error); -if (error.Fail()) - return lldb::ChildCacheState::eRefetch; -
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/labath edited https://github.com/llvm/llvm-project/pull/97754 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/labath approved this pull request. https://github.com/llvm/llvm-project/pull/97754 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
@@ -246,3 +270,119 @@ lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEndCreator( return (valobj_sp ? new LibcxxStdUnorderedMapSyntheticFrontEnd(valobj_sp) : nullptr); } + +lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd:: +LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) +: SyntheticChildrenFrontEnd(*valobj_sp) { + if (valobj_sp) +Update(); +} + +lldb::ChildCacheState lldb_private::formatters:: +LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() { + m_pair_sp.reset(); + + ValueObjectSP valobj_sp = m_backend.GetSP(); + if (!valobj_sp) +return lldb::ChildCacheState::eRefetch; + + TargetSP target_sp(valobj_sp->GetTargetSP()); + + if (!target_sp) +return lldb::ChildCacheState::eRefetch; + + // Get the unordered_map::iterator + // m_backend is an 'unordered_map::iterator', aka a + // '__hash_map_iterator<__hash_table::iterator>' + // + // __hash_map_iterator::__i_ is a __hash_table::iterator (aka + // __hash_iterator<__node_pointer>) + auto hash_iter_sp = valobj_sp->GetChildMemberWithName("__i_"); + if (!hash_iter_sp) +return lldb::ChildCacheState::eRefetch; + + // Type is '__hash_iterator<__node_pointer>' + auto hash_iter_type = hash_iter_sp->GetCompilerType(); + if (!hash_iter_type.IsValid()) +return lldb::ChildCacheState::eRefetch; + + // Type is '__node_pointer' + auto node_pointer_type = hash_iter_type.GetTypeTemplateArgument(0); + if (!node_pointer_type.IsValid()) +return lldb::ChildCacheState::eRefetch; + + // Cast the __hash_iterator to a __node_pointer (which stores our key/value + // pair) + auto hash_node_sp = hash_iter_sp->Cast(node_pointer_type); + if (!hash_node_sp) +return lldb::ChildCacheState::eRefetch; + + auto key_value_sp = hash_node_sp->GetChildMemberWithName("__value_"); + if (!key_value_sp) { +// clang-format off +// Since D101206 (ba79fb2e1f), libc++ wraps the `__value_` in an +// anonymous union. +// Child 0: __hash_node_base base class +// Child 1: __hash_ +// Child 2: anonymous union +// clang-format on +auto anon_union_sp = hash_node_sp->GetChildAtIndex(2); +if (!anon_union_sp) + return lldb::ChildCacheState::eRefetch; + +key_value_sp = anon_union_sp->GetChildMemberWithName("__value_"); +if (!key_value_sp) + return lldb::ChildCacheState::eRefetch; + } + + // Create the synthetic child, which is a pair where the key and value can be + // retrieved // by querying the synthetic frontend for labath wrote: remove extra `//` https://github.com/llvm/llvm-project/pull/97754 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/97754 >From b10f76bd6d02106e80315a70a7b72461cb6f2a99 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 4 Jul 2024 13:35:21 +0200 Subject: [PATCH 1/2] [lldb][DataFormatter] Move std::unordered_map::iterator formatter into LibCxxUnorderedMap.cpp --- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 149 - .../Plugins/Language/CPlusPlus/LibCxx.h | 54 + .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 196 ++ 3 files changed, 200 insertions(+), 199 deletions(-) diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 05cfa0568c25d..feaa51a96843a 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -202,155 +202,6 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( return true; } -lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) -: SyntheticChildrenFrontEnd(*valobj_sp) { - if (valobj_sp) -Update(); -} - -lldb::ChildCacheState lldb_private::formatters:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() { - m_pair_sp.reset(); - m_iter_ptr = nullptr; - - ValueObjectSP valobj_sp = m_backend.GetSP(); - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - TargetSP target_sp(valobj_sp->GetTargetSP()); - - if (!target_sp) -return lldb::ChildCacheState::eRefetch; - - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions() - .DontCheckDotVsArrowSyntax() - .SetSyntheticChildrenTraversal( - ValueObject::GetValueForExpressionPathOptions:: - SyntheticChildrenTraversal::None); - - // This must be a ValueObject* because it is a child of the ValueObject we - // are producing children for it if were a ValueObjectSP, we would end up - // with a loop (iterator -> synthetic -> child -> parent == iterator) and - // that would in turn leak memory by never allowing the ValueObjects to die - // and free their memory. - m_iter_ptr = - valobj_sp - ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr, - exprPathOptions, nullptr) - .get(); - - if (m_iter_ptr) { -auto iter_child(valobj_sp->GetChildMemberWithName("__i_")); -if (!iter_child) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -CompilerType node_type(iter_child->GetCompilerType() - .GetTypeTemplateArgument(0) - .GetPointeeType()); - -CompilerType pair_type(node_type.GetTypeTemplateArgument(0)); - -std::string name; -uint64_t bit_offset_ptr; -uint32_t bitfield_bit_size_ptr; -bool is_bitfield_ptr; - -pair_type = pair_type.GetFieldAtIndex( -0, name, _offset_ptr, _bit_size_ptr, _bitfield_ptr); -if (!pair_type) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS); -m_iter_ptr = nullptr; - -if (addr == 0 || addr == LLDB_INVALID_ADDRESS) - return lldb::ChildCacheState::eRefetch; - -auto ts = pair_type.GetTypeSystem(); -auto ast_ctx = ts.dyn_cast_or_null(); -if (!ast_ctx) - return lldb::ChildCacheState::eRefetch; - -// Mimick layout of std::__hash_iterator::__node_ and read it in -// from process memory. -// -// The following shows the contiguous block of memory: -// -// +-+ class __hash_node_base -// __node_ | __next_pointer __next_; | -// +-+ class __hash_node -// | size_t __hash_; | -// | __node_value_type __value_; | <<< our key/value pair -// +-+ -// -CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier( -llvm::StringRef(), -{{"__next_", - ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)}, - {"__value_", pair_type}}); -std::optional size = tree_node_type.GetByteSize(nullptr); -if (!size) - return lldb::ChildCacheState::eRefetch; -WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); -ProcessSP process_sp(target_sp->GetProcessSP()); -Status error; -process_sp->ReadMemory(addr, buffer_sp->GetBytes(), - buffer_sp->GetByteSize(), error); -if (error.Fail()) - return lldb::ChildCacheState::eRefetch; -
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/97754 >From b10f76bd6d02106e80315a70a7b72461cb6f2a99 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 4 Jul 2024 13:35:21 +0200 Subject: [PATCH 1/2] [lldb][DataFormatter] Move std::unordered_map::iterator formatter into LibCxxUnorderedMap.cpp --- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 149 - .../Plugins/Language/CPlusPlus/LibCxx.h | 54 + .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 196 ++ 3 files changed, 200 insertions(+), 199 deletions(-) diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 05cfa0568c25d..feaa51a96843a 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -202,155 +202,6 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( return true; } -lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) -: SyntheticChildrenFrontEnd(*valobj_sp) { - if (valobj_sp) -Update(); -} - -lldb::ChildCacheState lldb_private::formatters:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() { - m_pair_sp.reset(); - m_iter_ptr = nullptr; - - ValueObjectSP valobj_sp = m_backend.GetSP(); - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - TargetSP target_sp(valobj_sp->GetTargetSP()); - - if (!target_sp) -return lldb::ChildCacheState::eRefetch; - - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions() - .DontCheckDotVsArrowSyntax() - .SetSyntheticChildrenTraversal( - ValueObject::GetValueForExpressionPathOptions:: - SyntheticChildrenTraversal::None); - - // This must be a ValueObject* because it is a child of the ValueObject we - // are producing children for it if were a ValueObjectSP, we would end up - // with a loop (iterator -> synthetic -> child -> parent == iterator) and - // that would in turn leak memory by never allowing the ValueObjects to die - // and free their memory. - m_iter_ptr = - valobj_sp - ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr, - exprPathOptions, nullptr) - .get(); - - if (m_iter_ptr) { -auto iter_child(valobj_sp->GetChildMemberWithName("__i_")); -if (!iter_child) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -CompilerType node_type(iter_child->GetCompilerType() - .GetTypeTemplateArgument(0) - .GetPointeeType()); - -CompilerType pair_type(node_type.GetTypeTemplateArgument(0)); - -std::string name; -uint64_t bit_offset_ptr; -uint32_t bitfield_bit_size_ptr; -bool is_bitfield_ptr; - -pair_type = pair_type.GetFieldAtIndex( -0, name, _offset_ptr, _bit_size_ptr, _bitfield_ptr); -if (!pair_type) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS); -m_iter_ptr = nullptr; - -if (addr == 0 || addr == LLDB_INVALID_ADDRESS) - return lldb::ChildCacheState::eRefetch; - -auto ts = pair_type.GetTypeSystem(); -auto ast_ctx = ts.dyn_cast_or_null(); -if (!ast_ctx) - return lldb::ChildCacheState::eRefetch; - -// Mimick layout of std::__hash_iterator::__node_ and read it in -// from process memory. -// -// The following shows the contiguous block of memory: -// -// +-+ class __hash_node_base -// __node_ | __next_pointer __next_; | -// +-+ class __hash_node -// | size_t __hash_; | -// | __node_value_type __value_; | <<< our key/value pair -// +-+ -// -CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier( -llvm::StringRef(), -{{"__next_", - ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)}, - {"__value_", pair_type}}); -std::optional size = tree_node_type.GetByteSize(nullptr); -if (!size) - return lldb::ChildCacheState::eRefetch; -WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); -ProcessSP process_sp(target_sp->GetProcessSP()); -Status error; -process_sp->ReadMemory(addr, buffer_sp->GetBytes(), - buffer_sp->GetByteSize(), error); -if (error.Fail()) - return lldb::ChildCacheState::eRefetch; -
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/97754 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/97754 >From b10f76bd6d02106e80315a70a7b72461cb6f2a99 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 4 Jul 2024 13:35:21 +0200 Subject: [PATCH 1/2] [lldb][DataFormatter] Move std::unordered_map::iterator formatter into LibCxxUnorderedMap.cpp --- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 149 - .../Plugins/Language/CPlusPlus/LibCxx.h | 54 + .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 196 ++ 3 files changed, 200 insertions(+), 199 deletions(-) diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 05cfa0568c25d4..feaa51a96843ab 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -202,155 +202,6 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( return true; } -lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) -: SyntheticChildrenFrontEnd(*valobj_sp) { - if (valobj_sp) -Update(); -} - -lldb::ChildCacheState lldb_private::formatters:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() { - m_pair_sp.reset(); - m_iter_ptr = nullptr; - - ValueObjectSP valobj_sp = m_backend.GetSP(); - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - TargetSP target_sp(valobj_sp->GetTargetSP()); - - if (!target_sp) -return lldb::ChildCacheState::eRefetch; - - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions() - .DontCheckDotVsArrowSyntax() - .SetSyntheticChildrenTraversal( - ValueObject::GetValueForExpressionPathOptions:: - SyntheticChildrenTraversal::None); - - // This must be a ValueObject* because it is a child of the ValueObject we - // are producing children for it if were a ValueObjectSP, we would end up - // with a loop (iterator -> synthetic -> child -> parent == iterator) and - // that would in turn leak memory by never allowing the ValueObjects to die - // and free their memory. - m_iter_ptr = - valobj_sp - ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr, - exprPathOptions, nullptr) - .get(); - - if (m_iter_ptr) { -auto iter_child(valobj_sp->GetChildMemberWithName("__i_")); -if (!iter_child) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -CompilerType node_type(iter_child->GetCompilerType() - .GetTypeTemplateArgument(0) - .GetPointeeType()); - -CompilerType pair_type(node_type.GetTypeTemplateArgument(0)); - -std::string name; -uint64_t bit_offset_ptr; -uint32_t bitfield_bit_size_ptr; -bool is_bitfield_ptr; - -pair_type = pair_type.GetFieldAtIndex( -0, name, _offset_ptr, _bit_size_ptr, _bitfield_ptr); -if (!pair_type) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS); -m_iter_ptr = nullptr; - -if (addr == 0 || addr == LLDB_INVALID_ADDRESS) - return lldb::ChildCacheState::eRefetch; - -auto ts = pair_type.GetTypeSystem(); -auto ast_ctx = ts.dyn_cast_or_null(); -if (!ast_ctx) - return lldb::ChildCacheState::eRefetch; - -// Mimick layout of std::__hash_iterator::__node_ and read it in -// from process memory. -// -// The following shows the contiguous block of memory: -// -// +-+ class __hash_node_base -// __node_ | __next_pointer __next_; | -// +-+ class __hash_node -// | size_t __hash_; | -// | __node_value_type __value_; | <<< our key/value pair -// +-+ -// -CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier( -llvm::StringRef(), -{{"__next_", - ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)}, - {"__value_", pair_type}}); -std::optional size = tree_node_type.GetByteSize(nullptr); -if (!size) - return lldb::ChildCacheState::eRefetch; -WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); -ProcessSP process_sp(target_sp->GetProcessSP()); -Status error; -process_sp->ReadMemory(addr, buffer_sp->GetBytes(), - buffer_sp->GetByteSize(), error); -if (error.Fail()) - return lldb::ChildCacheState::eRefetch; -
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff fbd1b6567ae41d64f1dbb6b32c7cf8a1b710b8d9 9e66b1c4787ad49b7f4ffab9f87746d7c59a4fd5 -- lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp lldb/source/Plugins/Language/CPlusPlus/LibCxx.h lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp index 534a22f98f..19ef2f556f 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp @@ -34,7 +34,7 @@ int main() sium["hello"] = 137; int_vector iv; - iv.push_back(3); +iv.push_back(3); string_vector sv; sv.push_back("hello"); @@ -45,7 +45,7 @@ int main() si_umap_iter siumI = sium.begin(); ivter ivI = iv.begin(); - svter svI = sv.begin(); +svter svI = sv.begin(); return 0; // Set break point at this line. } `` https://github.com/llvm/llvm-project/pull/97754 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) Changes Depends on https://github.com/llvm/llvm-project/pull/97752 This patch changes the way we retrieve the key/value pair in the `std::unordered_map::iterator` formatter (similar to how we are changing it for `std::map::iterator` in https://github.com/llvm/llvm-project/pull/97713, the motivations being the same). The `std::unordered_map` already does it this way, so we align the iterator counterpart to do the same. --- Full diff: https://github.com/llvm/llvm-project/pull/97754.diff 5 Files Affected: - (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp (-149) - (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxx.h (+4-50) - (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp (+150) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py (+16) - (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp (+19-6) ``diff diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 05cfa0568c25d..feaa51a96843a 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -202,155 +202,6 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( return true; } -lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) -: SyntheticChildrenFrontEnd(*valobj_sp) { - if (valobj_sp) -Update(); -} - -lldb::ChildCacheState lldb_private::formatters:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() { - m_pair_sp.reset(); - m_iter_ptr = nullptr; - - ValueObjectSP valobj_sp = m_backend.GetSP(); - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - TargetSP target_sp(valobj_sp->GetTargetSP()); - - if (!target_sp) -return lldb::ChildCacheState::eRefetch; - - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions() - .DontCheckDotVsArrowSyntax() - .SetSyntheticChildrenTraversal( - ValueObject::GetValueForExpressionPathOptions:: - SyntheticChildrenTraversal::None); - - // This must be a ValueObject* because it is a child of the ValueObject we - // are producing children for it if were a ValueObjectSP, we would end up - // with a loop (iterator -> synthetic -> child -> parent == iterator) and - // that would in turn leak memory by never allowing the ValueObjects to die - // and free their memory. - m_iter_ptr = - valobj_sp - ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr, - exprPathOptions, nullptr) - .get(); - - if (m_iter_ptr) { -auto iter_child(valobj_sp->GetChildMemberWithName("__i_")); -if (!iter_child) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -CompilerType node_type(iter_child->GetCompilerType() - .GetTypeTemplateArgument(0) - .GetPointeeType()); - -CompilerType pair_type(node_type.GetTypeTemplateArgument(0)); - -std::string name; -uint64_t bit_offset_ptr; -uint32_t bitfield_bit_size_ptr; -bool is_bitfield_ptr; - -pair_type = pair_type.GetFieldAtIndex( -0, name, _offset_ptr, _bit_size_ptr, _bitfield_ptr); -if (!pair_type) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS); -m_iter_ptr = nullptr; - -if (addr == 0 || addr == LLDB_INVALID_ADDRESS) - return lldb::ChildCacheState::eRefetch; - -auto ts = pair_type.GetTypeSystem(); -auto ast_ctx = ts.dyn_cast_or_null(); -if (!ast_ctx) - return lldb::ChildCacheState::eRefetch; - -// Mimick layout of std::__hash_iterator::__node_ and read it in -// from process memory. -// -// The following shows the contiguous block of memory: -// -// +-+ class __hash_node_base -// __node_ | __next_pointer __next_; | -// +-+ class __hash_node -// | size_t __hash_; | -// | __node_value_type __value_; | <<< our key/value pair -// +-+ -// -CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier( -llvm::StringRef(), -{{"__next_", - ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)}, -
[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/97754 Depends on https://github.com/llvm/llvm-project/pull/97752 This patch changes the way we retrieve the key/value pair in the `std::unordered_map::iterator` formatter (similar to how we are changing it for `std::map::iterator` in https://github.com/llvm/llvm-project/pull/97713, the motivations being the same). The `std::unordered_map` already does it this way, so we align the iterator counterpart to do the same. >From b10f76bd6d02106e80315a70a7b72461cb6f2a99 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 4 Jul 2024 13:35:21 +0200 Subject: [PATCH 1/2] [lldb][DataFormatter] Move std::unordered_map::iterator formatter into LibCxxUnorderedMap.cpp --- .../Plugins/Language/CPlusPlus/LibCxx.cpp | 149 - .../Plugins/Language/CPlusPlus/LibCxx.h | 54 + .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 196 ++ 3 files changed, 200 insertions(+), 199 deletions(-) diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 05cfa0568c25d..feaa51a96843a 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -202,155 +202,6 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider( return true; } -lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) -: SyntheticChildrenFrontEnd(*valobj_sp) { - if (valobj_sp) -Update(); -} - -lldb::ChildCacheState lldb_private::formatters:: -LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() { - m_pair_sp.reset(); - m_iter_ptr = nullptr; - - ValueObjectSP valobj_sp = m_backend.GetSP(); - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - TargetSP target_sp(valobj_sp->GetTargetSP()); - - if (!target_sp) -return lldb::ChildCacheState::eRefetch; - - if (!valobj_sp) -return lldb::ChildCacheState::eRefetch; - - auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions() - .DontCheckDotVsArrowSyntax() - .SetSyntheticChildrenTraversal( - ValueObject::GetValueForExpressionPathOptions:: - SyntheticChildrenTraversal::None); - - // This must be a ValueObject* because it is a child of the ValueObject we - // are producing children for it if were a ValueObjectSP, we would end up - // with a loop (iterator -> synthetic -> child -> parent == iterator) and - // that would in turn leak memory by never allowing the ValueObjects to die - // and free their memory. - m_iter_ptr = - valobj_sp - ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr, - exprPathOptions, nullptr) - .get(); - - if (m_iter_ptr) { -auto iter_child(valobj_sp->GetChildMemberWithName("__i_")); -if (!iter_child) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -CompilerType node_type(iter_child->GetCompilerType() - .GetTypeTemplateArgument(0) - .GetPointeeType()); - -CompilerType pair_type(node_type.GetTypeTemplateArgument(0)); - -std::string name; -uint64_t bit_offset_ptr; -uint32_t bitfield_bit_size_ptr; -bool is_bitfield_ptr; - -pair_type = pair_type.GetFieldAtIndex( -0, name, _offset_ptr, _bit_size_ptr, _bitfield_ptr); -if (!pair_type) { - m_iter_ptr = nullptr; - return lldb::ChildCacheState::eRefetch; -} - -uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS); -m_iter_ptr = nullptr; - -if (addr == 0 || addr == LLDB_INVALID_ADDRESS) - return lldb::ChildCacheState::eRefetch; - -auto ts = pair_type.GetTypeSystem(); -auto ast_ctx = ts.dyn_cast_or_null(); -if (!ast_ctx) - return lldb::ChildCacheState::eRefetch; - -// Mimick layout of std::__hash_iterator::__node_ and read it in -// from process memory. -// -// The following shows the contiguous block of memory: -// -// +-+ class __hash_node_base -// __node_ | __next_pointer __next_; | -// +-+ class __hash_node -// | size_t __hash_; | -// | __node_value_type __value_; | <<< our key/value pair -// +-+ -// -CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier( -llvm::StringRef(), -{{"__next_", - ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)}, - {"__value_", pair_type}}); -std::optional size =