LLDB mainline
MsvcStlDeque.cpp
Go to the documentation of this file.
1//===-- MsvcStlDeque.cpp --------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "MsvcStl.h"
10
13
14using namespace lldb;
15
16namespace lldb_private {
17namespace formatters {
18
20public:
22
23 llvm::Expected<uint32_t> CalculateNumChildren() override;
24
25 lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
26
28
29 llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override;
30
31private:
32 ValueObject *m_map = nullptr;
34
35 size_t m_block_size = 0;
36 size_t m_offset = 0;
37 size_t m_map_size = 0;
38
39 size_t m_element_size = 0;
41
42 uint32_t m_size = 0;
43};
44
45} // namespace formatters
46} // namespace lldb_private
47
54
55llvm::Expected<uint32_t> lldb_private::formatters::
57 if (!m_map)
58 return llvm::createStringError("Failed to read size");
59 return m_size;
60}
61
64 uint32_t idx) {
65 if (idx >= m_size || !m_map)
66 return nullptr;
67 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
68 if (!process_sp)
69 return nullptr;
70
71 // _EEN_DS = _Block_size
72 // _Map[(($i + _Myoff) / _EEN_DS) % _Mapsize][($i + _Myoff) % _EEN_DS]
73 size_t first_idx = ((idx + m_offset) / m_block_size) % m_map_size;
74 lldb::addr_t first_address = m_map->GetValueAsUnsigned(0) +
75 first_idx * process_sp->GetAddressByteSize();
76
77 Status err;
78 lldb::addr_t second_base =
79 process_sp->ReadPointerFromMemory(first_address, err);
80 if (err.Fail())
81 return nullptr;
82
83 size_t second_idx = (idx + m_offset) % m_block_size;
84 size_t second_address = second_base + second_idx * m_element_size;
85
86 StreamString name;
87 name.Printf("[%" PRIu64 "]", (uint64_t)idx);
88 return CreateValueObjectFromAddress(name.GetString(), second_address,
89 m_backend.GetExecutionContextRef(),
91}
92
95 m_size = 0;
96 m_map = nullptr;
97 m_element_type.Clear();
98
99 auto storage_sp = m_backend.GetChildAtNamePath({"_Mypair", "_Myval2"});
100 if (!storage_sp)
101 return lldb::eRefetch;
102
103 auto deque_type = m_backend.GetCompilerType();
104 if (!deque_type)
105 return lldb::eRefetch;
106
107 auto block_size_decl = deque_type.GetStaticFieldWithName("_Block_size");
108 if (!block_size_decl)
109 return lldb::eRefetch;
110 auto block_size = block_size_decl.GetConstantValue();
111 if (!block_size.IsValid())
112 return lldb::eRefetch;
113
114 auto element_type = deque_type.GetTypeTemplateArgument(0);
115 if (!element_type)
116 return lldb::eRefetch;
117 auto element_size = element_type.GetByteSize(nullptr);
118 if (!element_size)
119 return lldb::eRefetch;
120
121 auto offset_sp = storage_sp->GetChildMemberWithName("_Myoff");
122 auto map_size_sp = storage_sp->GetChildMemberWithName("_Mapsize");
123 auto map_sp = storage_sp->GetChildMemberWithName("_Map");
124 auto size_sp = storage_sp->GetChildMemberWithName("_Mysize");
125 if (!offset_sp || !map_size_sp || !map_sp || !size_sp)
126 return lldb::eRefetch;
127
128 bool ok = false;
129 uint64_t offset = offset_sp->GetValueAsUnsigned(0, &ok);
130 if (!ok)
131 return lldb::eRefetch;
132
133 uint64_t map_size = map_size_sp->GetValueAsUnsigned(0, &ok);
134 if (!ok)
135 return lldb::eRefetch;
136
137 uint64_t size = size_sp->GetValueAsUnsigned(0, &ok);
138 if (!ok)
139 return lldb::eRefetch;
140
141 m_map = map_sp.get();
142 m_exe_ctx_ref = m_backend.GetExecutionContextRef();
143 m_block_size = block_size.ULongLong();
144 m_offset = offset;
145 m_map_size = map_size;
146 m_element_size = *element_size;
147 m_element_type = element_type;
148 m_size = size;
149 return lldb::eRefetch;
150}
151
154 if (!m_map)
155 return llvm::createStringError("Type has no child named '%s'",
156 name.AsCString());
157 if (auto optional_idx = ExtractIndexFromString(name.GetCString()))
158 return *optional_idx;
159
160 return llvm::createStringError("Type has no child named '%s'",
161 name.AsCString());
162}
163
165 if (auto valobj_sp = valobj.GetNonSyntheticValue())
166 return valobj_sp->GetChildMemberWithName("_Mypair") != nullptr;
167 return false;
168}
169
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
Execution context objects refer to objects in the execution of the program that is being debugged.
An error handling class.
Definition Status.h:118
bool Fail() const
Test for error condition.
Definition Status.cpp:294
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
SyntheticChildrenFrontEnd(ValueObject &backend)
lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true)
virtual lldb::ValueObjectSP GetNonSyntheticValue()
MsvcStlDequeSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
lldb::ChildCacheState Update() override
This function is assumed to always succeed and if it fails, the front-end should know to deal with it...
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override
llvm::Expected< uint32_t > CalculateNumChildren() override
llvm::Expected< size_t > GetIndexOfChildWithName(ConstString name) override
bool IsMsvcStlDeque(ValueObject &valobj)
std::optional< size_t > ExtractIndexFromString(const char *item_name)
SyntheticChildrenFrontEnd * MsvcStlDequeSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp)
A class that represents a running process on the host machine.
ChildCacheState
Specifies if children need to be re-computed after a call to SyntheticChildrenFrontEnd::Update.
@ eRefetch
Children need to be recomputed dynamically.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
uint64_t addr_t
Definition lldb-types.h:80