LLDB mainline
LibCxxAtomic.cpp
Go to the documentation of this file.
1//===-- LibCxxAtomic.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 "LibCxxAtomic.h"
11#include "llvm/Support/ErrorExtras.h"
12
13using namespace lldb;
14using namespace lldb_private;
15using namespace lldb_private::formatters;
16
17//
18// We are supporting two versions of libc++ std::atomic
19//
20// Given std::atomic<int> i;
21//
22// The previous version of std::atomic was laid out like this
23//
24// (lldb) frame var -L -R i
25// 0x00007ffeefbff9a0: (std::__1::atomic<int>) i = {
26// 0x00007ffeefbff9a0: std::__1::__atomic_base<int, true> = {
27// 0x00007ffeefbff9a0: std::__1::__atomic_base<int, false> = {
28// 0x00007ffeefbff9a0: __a_ = 5
29// }
30// }
31// }
32//
33// In this case we need to obtain __a_ and the current version is laid out as so
34//
35// (lldb) frame var -L -R i
36// 0x00007ffeefbff9b0: (std::__1::atomic<int>) i = {
37// 0x00007ffeefbff9b0: std::__1::__atomic_base<int, true> = {
38// 0x00007ffeefbff9b0: std::__1::__atomic_base<int, false> = {
39// 0x00007ffeefbff9b0: __a_ = {
40// 0x00007ffeefbff9b0: std::__1::__cxx_atomic_base_impl<int> = {
41// 0x00007ffeefbff9b0: __a_value = 5
42// }
43// }
44// }
45// }
46//}
47//
48// In this case we need to obtain __a_value
49//
50// The below method covers both cases and returns the relevant member as a
51// ValueObjectSP
52//
55 ValueObjectSP non_sythetic = valobj.GetNonSyntheticValue();
56 if (!non_sythetic)
57 return {};
58
59 ValueObjectSP member__a_ = non_sythetic->GetChildMemberWithName("__a_");
60 if (!member__a_)
61 return {};
62
63 ValueObjectSP member__a_value =
64 member__a_->GetChildMemberWithName("__a_value");
65 if (!member__a_value)
66 return member__a_;
67
68 return member__a_value;
69}
70
72 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
73
74 if (ValueObjectSP atomic_value = GetLibCxxAtomicValue(valobj)) {
75 std::string summary;
76 if (atomic_value->GetSummaryAsCString(summary, options) &&
77 summary.size() > 0) {
78 stream.Printf("%s", summary.c_str());
79 return true;
80 }
81 }
82
83 return false;
84}
85
86namespace lldb_private {
87namespace formatters {
89public:
91
93
94 llvm::Expected<uint32_t> CalculateNumChildren() override;
95
96 lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
97
99
100 llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override;
101
102private:
104};
105} // namespace formatters
106} // namespace lldb_private
107
111
120
125
128 uint32_t idx) {
129 if (idx == 0)
130 return m_real_child->GetSP()->Clone(ConstString("Value"));
131 return nullptr;
132}
133
134llvm::Expected<size_t>
137 if (name == "Value")
138 return 0;
139 return llvm::createStringErrorV("type has no child named '{0}'", name);
140}
141
145 if (valobj_sp && IsLibCxxAtomic(*valobj_sp))
146 return new LibcxxStdAtomicSyntheticFrontEnd(valobj_sp);
147 return nullptr;
148}
149
151 if (auto valobj_sp = valobj.GetNonSyntheticValue())
152 return valobj_sp->GetChildMemberWithName("__a_") != nullptr;
153 return false;
154}
A uniqued constant string class.
Definition ConstString.h:40
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:132
SyntheticChildrenFrontEnd(ValueObject &backend)
virtual lldb::ValueObjectSP GetNonSyntheticValue()
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< size_t > GetIndexOfChildWithName(ConstString name) override
Determine the index of a named child.
llvm::Expected< uint32_t > CalculateNumChildren() override
bool IsLibCxxAtomic(ValueObject &valobj)
bool LibCxxAtomicSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
SyntheticChildrenFrontEnd * LibcxxAtomicSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
lldb::ValueObjectSP GetLibCxxAtomicValue(ValueObject &valobj)
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