Skip to content

Commit 64af560

Browse files
committed
fixup! remove traces of old layout from map iterator too
1 parent 5dc61f0 commit 64af560

File tree

1 file changed

+65
-104
lines changed

1 file changed

+65
-104
lines changed

lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp

Lines changed: 65 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -202,28 +202,6 @@ bool lldb_private::formatters::LibcxxUniquePointerSummaryProvider(
202202
return true;
203203
}
204204

205-
/*
206-
(lldb) fr var ibeg --raw --ptr-depth 1
207-
(std::__1::__map_iterator<std::__1::__tree_iterator<std::__1::pair<int,
208-
std::__1::basic_string<char, std::__1::char_traits<char>,
209-
std::__1::allocator<char> > >, std::__1::__tree_node<std::__1::pair<int,
210-
std::__1::basic_string<char, std::__1::char_traits<char>,
211-
std::__1::allocator<char> > >, void *> *, long> >) ibeg = {
212-
__i_ = {
213-
__ptr_ = 0x0000000100103870 {
214-
std::__1::__tree_node_base<void *> = {
215-
std::__1::__tree_end_node<std::__1::__tree_node_base<void *> *> = {
216-
__left_ = 0x0000000000000000
217-
}
218-
__right_ = 0x0000000000000000
219-
__parent_ = 0x00000001001038b0
220-
__is_black_ = true
221-
}
222-
__value_ = {
223-
first = 0
224-
second = { std::string }
225-
*/
226-
227205
lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
228206
LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
229207
: SyntheticChildrenFrontEnd(*valobj_sp), m_pair_ptr(), m_pair_sp() {
@@ -252,97 +230,80 @@ lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
252230
// and free their memory
253231
m_pair_ptr = valobj_sp
254232
->GetValueForExpressionPath(
255-
".__i_.__ptr_->__value_", nullptr, nullptr,
233+
".__i_.__ptr_", nullptr, nullptr,
256234
ValueObject::GetValueForExpressionPathOptions()
257235
.DontCheckDotVsArrowSyntax()
258236
.SetSyntheticChildrenTraversal(
259237
ValueObject::GetValueForExpressionPathOptions::
260238
SyntheticChildrenTraversal::None),
261239
nullptr)
262240
.get();
241+
if (!m_pair_ptr)
242+
return lldb::ChildCacheState::eRefetch;
263243

264-
if (!m_pair_ptr) {
265-
m_pair_ptr = valobj_sp
266-
->GetValueForExpressionPath(
267-
".__i_.__ptr_", nullptr, nullptr,
268-
ValueObject::GetValueForExpressionPathOptions()
269-
.DontCheckDotVsArrowSyntax()
270-
.SetSyntheticChildrenTraversal(
271-
ValueObject::GetValueForExpressionPathOptions::
272-
SyntheticChildrenTraversal::None),
273-
nullptr)
274-
.get();
275-
if (m_pair_ptr) {
276-
auto __i_(valobj_sp->GetChildMemberWithName("__i_"));
277-
if (!__i_) {
278-
m_pair_ptr = nullptr;
279-
return lldb::ChildCacheState::eRefetch;
280-
}
281-
CompilerType pair_type(
282-
__i_->GetCompilerType().GetTypeTemplateArgument(0));
283-
std::string name;
284-
uint64_t bit_offset_ptr;
285-
uint32_t bitfield_bit_size_ptr;
286-
bool is_bitfield_ptr;
287-
pair_type = pair_type.GetFieldAtIndex(
288-
0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
289-
if (!pair_type) {
290-
m_pair_ptr = nullptr;
291-
return lldb::ChildCacheState::eRefetch;
292-
}
244+
auto __i_(valobj_sp->GetChildMemberWithName("__i_"));
245+
if (!__i_) {
246+
m_pair_ptr = nullptr;
247+
return lldb::ChildCacheState::eRefetch;
248+
}
249+
CompilerType pair_type(__i_->GetCompilerType().GetTypeTemplateArgument(0));
250+
std::string name;
251+
uint64_t bit_offset_ptr;
252+
uint32_t bitfield_bit_size_ptr;
253+
bool is_bitfield_ptr;
254+
pair_type = pair_type.GetFieldAtIndex(
255+
0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
256+
if (!pair_type) {
257+
m_pair_ptr = nullptr;
258+
return lldb::ChildCacheState::eRefetch;
259+
}
293260

294-
auto addr(m_pair_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS));
295-
m_pair_ptr = nullptr;
296-
if (addr && addr != LLDB_INVALID_ADDRESS) {
297-
auto ts = pair_type.GetTypeSystem();
298-
auto ast_ctx = ts.dyn_cast_or_null<TypeSystemClang>();
299-
if (!ast_ctx)
300-
return lldb::ChildCacheState::eRefetch;
301-
302-
// Mimick layout of std::__tree_iterator::__ptr_ and read it in
303-
// from process memory.
304-
//
305-
// The following shows the contiguous block of memory:
306-
//
307-
// +-----------------------------+ class __tree_end_node
308-
// __ptr_ | pointer __left_; |
309-
// +-----------------------------+ class __tree_node_base
310-
// | pointer __right_; |
311-
// | __parent_pointer __parent_; |
312-
// | bool __is_black_; |
313-
// +-----------------------------+ class __tree_node
314-
// | __node_value_type __value_; | <<< our key/value pair
315-
// +-----------------------------+
316-
//
317-
CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
318-
llvm::StringRef(),
319-
{{"ptr0",
320-
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
321-
{"ptr1",
322-
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
323-
{"ptr2",
324-
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
325-
{"cw", ast_ctx->GetBasicType(lldb::eBasicTypeBool)},
326-
{"payload", pair_type}});
327-
std::optional<uint64_t> size = tree_node_type.GetByteSize(nullptr);
328-
if (!size)
329-
return lldb::ChildCacheState::eRefetch;
330-
WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0));
331-
ProcessSP process_sp(target_sp->GetProcessSP());
332-
Status error;
333-
process_sp->ReadMemory(addr, buffer_sp->GetBytes(),
334-
buffer_sp->GetByteSize(), error);
335-
if (error.Fail())
336-
return lldb::ChildCacheState::eRefetch;
337-
DataExtractor extractor(buffer_sp, process_sp->GetByteOrder(),
338-
process_sp->GetAddressByteSize());
339-
auto pair_sp = CreateValueObjectFromData(
340-
"pair", extractor, valobj_sp->GetExecutionContextRef(),
341-
tree_node_type);
342-
if (pair_sp)
343-
m_pair_sp = pair_sp->GetChildAtIndex(4);
344-
}
345-
}
261+
auto addr(m_pair_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS));
262+
m_pair_ptr = nullptr;
263+
if (addr && addr != LLDB_INVALID_ADDRESS) {
264+
auto ts = pair_type.GetTypeSystem();
265+
auto ast_ctx = ts.dyn_cast_or_null<TypeSystemClang>();
266+
if (!ast_ctx)
267+
return lldb::ChildCacheState::eRefetch;
268+
269+
// Mimick layout of std::__tree_iterator::__ptr_ and read it in
270+
// from process memory.
271+
//
272+
// The following shows the contiguous block of memory:
273+
//
274+
// +-----------------------------+ class __tree_end_node
275+
// __ptr_ | pointer __left_; |
276+
// +-----------------------------+ class __tree_node_base
277+
// | pointer __right_; |
278+
// | __parent_pointer __parent_; |
279+
// | bool __is_black_; |
280+
// +-----------------------------+ class __tree_node
281+
// | __node_value_type __value_; | <<< our key/value pair
282+
// +-----------------------------+
283+
//
284+
CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
285+
llvm::StringRef(),
286+
{{"ptr0", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
287+
{"ptr1", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
288+
{"ptr2", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
289+
{"cw", ast_ctx->GetBasicType(lldb::eBasicTypeBool)},
290+
{"payload", pair_type}});
291+
std::optional<uint64_t> size = tree_node_type.GetByteSize(nullptr);
292+
if (!size)
293+
return lldb::ChildCacheState::eRefetch;
294+
WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0));
295+
ProcessSP process_sp(target_sp->GetProcessSP());
296+
Status error;
297+
process_sp->ReadMemory(addr, buffer_sp->GetBytes(),
298+
buffer_sp->GetByteSize(), error);
299+
if (error.Fail())
300+
return lldb::ChildCacheState::eRefetch;
301+
DataExtractor extractor(buffer_sp, process_sp->GetByteOrder(),
302+
process_sp->GetAddressByteSize());
303+
auto pair_sp = CreateValueObjectFromData(
304+
"pair", extractor, valobj_sp->GetExecutionContextRef(), tree_node_type);
305+
if (pair_sp)
306+
m_pair_sp = pair_sp->GetChildAtIndex(4);
346307
}
347308

348309
return lldb::ChildCacheState::eRefetch;

0 commit comments

Comments
 (0)