/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- LibCxxInitializerList.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 "LibCxx.h" |
10 | | |
11 | | #include "lldb/Core/ValueObject.h" |
12 | | #include "lldb/DataFormatters/FormattersHelpers.h" |
13 | | #include "lldb/Utility/ConstString.h" |
14 | | #include <optional> |
15 | | |
16 | | using namespace lldb; |
17 | | using namespace lldb_private; |
18 | | using namespace lldb_private::formatters; |
19 | | |
20 | | namespace lldb_private { |
21 | | namespace formatters { |
22 | | class LibcxxInitializerListSyntheticFrontEnd |
23 | | : public SyntheticChildrenFrontEnd { |
24 | | public: |
25 | | LibcxxInitializerListSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp); |
26 | | |
27 | | ~LibcxxInitializerListSyntheticFrontEnd() override; |
28 | | |
29 | | size_t CalculateNumChildren() override; |
30 | | |
31 | | lldb::ValueObjectSP GetChildAtIndex(size_t idx) override; |
32 | | |
33 | | bool Update() override; |
34 | | |
35 | | bool MightHaveChildren() override; |
36 | | |
37 | | size_t GetIndexOfChildWithName(ConstString name) override; |
38 | | |
39 | | private: |
40 | | ValueObject *m_start = nullptr; |
41 | | CompilerType m_element_type; |
42 | | uint32_t m_element_size = 0; |
43 | | size_t m_num_elements = 0; |
44 | | }; |
45 | | } // namespace formatters |
46 | | } // namespace lldb_private |
47 | | |
48 | | lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd:: |
49 | | LibcxxInitializerListSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) |
50 | 4 | : SyntheticChildrenFrontEnd(*valobj_sp), m_element_type() { |
51 | 4 | if (valobj_sp) |
52 | 4 | Update(); |
53 | 4 | } |
54 | | |
55 | | lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd:: |
56 | 4 | ~LibcxxInitializerListSyntheticFrontEnd() { |
57 | | // this needs to stay around because it's a child object who will follow its |
58 | | // parent's life cycle |
59 | | // delete m_start; |
60 | 4 | } |
61 | | |
62 | | size_t lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd:: |
63 | 4 | CalculateNumChildren() { |
64 | 4 | m_num_elements = 0; |
65 | 4 | ValueObjectSP size_sp(m_backend.GetChildMemberWithName("__size_")); |
66 | 4 | if (size_sp) |
67 | 4 | m_num_elements = size_sp->GetValueAsUnsigned(0); |
68 | 4 | return m_num_elements; |
69 | 4 | } |
70 | | |
71 | | lldb::ValueObjectSP lldb_private::formatters:: |
72 | 20 | LibcxxInitializerListSyntheticFrontEnd::GetChildAtIndex(size_t idx) { |
73 | 20 | if (!m_start) |
74 | 0 | return lldb::ValueObjectSP(); |
75 | | |
76 | 20 | uint64_t offset = idx * m_element_size; |
77 | 20 | offset = offset + m_start->GetValueAsUnsigned(0); |
78 | 20 | StreamString name; |
79 | 20 | name.Printf("[%" PRIu64 "]", (uint64_t)idx); |
80 | 20 | return CreateValueObjectFromAddress(name.GetString(), offset, |
81 | 20 | m_backend.GetExecutionContextRef(), |
82 | 20 | m_element_type); |
83 | 20 | } |
84 | | |
85 | | bool lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd:: |
86 | 8 | Update() { |
87 | 8 | m_start = nullptr; |
88 | 8 | m_num_elements = 0; |
89 | 8 | m_element_type = m_backend.GetCompilerType().GetTypeTemplateArgument(0); |
90 | 8 | if (!m_element_type.IsValid()) |
91 | 0 | return false; |
92 | | |
93 | 8 | if (std::optional<uint64_t> size = m_element_type.GetByteSize(nullptr)) { |
94 | 8 | m_element_size = *size; |
95 | | // Store raw pointers or end up with a circular dependency. |
96 | 8 | m_start = m_backend.GetChildMemberWithName("__begin_").get(); |
97 | 8 | } |
98 | | |
99 | 8 | return false; |
100 | 8 | } |
101 | | |
102 | | bool lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd:: |
103 | 0 | MightHaveChildren() { |
104 | 0 | return true; |
105 | 0 | } |
106 | | |
107 | | size_t lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd:: |
108 | 0 | GetIndexOfChildWithName(ConstString name) { |
109 | 0 | if (!m_start) |
110 | 0 | return UINT32_MAX; |
111 | 0 | return ExtractIndexFromString(name.GetCString()); |
112 | 0 | } |
113 | | |
114 | | lldb_private::SyntheticChildrenFrontEnd * |
115 | | lldb_private::formatters::LibcxxInitializerListSyntheticFrontEndCreator( |
116 | 4 | CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) { |
117 | 4 | return (valobj_sp ? new LibcxxInitializerListSyntheticFrontEnd(valobj_sp) |
118 | 4 | : nullptr0 ); |
119 | 4 | } |