LLDB mainline
GenericErrorCode.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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 "Generic.h"
10
12#include "llvm/Support/ErrorExtras.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
17namespace {
18
19ValueObjectSP GetValue(ValueObject &valobj) {
20 ValueObjectSP value_sp = valobj.GetChildMemberWithName("_Myval"); // MSVC STL.
21 if (!value_sp)
22 value_sp = valobj.GetChildMemberWithName("_M_value"); // libstdc++.
23 return value_sp;
24}
25
26ValueObjectSP GetCategory(ValueObject &valobj) {
27 ValueObjectSP category_sp =
28 valobj.GetChildMemberWithName("_Mycat"); // MSVC STL.
29 if (!category_sp)
30 category_sp = valobj.GetChildMemberWithName("_M_cat"); // libstdc++.
31 return category_sp;
32}
33
34class GenericErrorCodeFrontend : public SyntheticChildrenFrontEnd {
35public:
36 explicit GenericErrorCodeFrontend(ValueObject &valobj)
37 : SyntheticChildrenFrontEnd(valobj) {
38 Update();
39 }
40
41 llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
42 if (name == "Category" && m_category)
43 return 0;
44 return llvm::createStringErrorV("type has no child named '{0}'", name);
45 }
46
47 llvm::Expected<uint32_t> CalculateNumChildren() override {
48 return m_category ? 1U : 0U;
49 }
50
51 ValueObjectSP GetChildAtIndex(uint32_t idx) override {
52 if (idx != 0 || !m_category)
53 return {};
54 return m_category->Clone(ConstString("Category"));
55 }
56
57 lldb::ChildCacheState Update() override {
58 m_category = GetCategory(m_backend).get();
60 }
61
62private:
63 // Children derived from the backend share its ClusterManager. Keeping a
64 // shared pointer here would create an ownership cycle.
65 ValueObject *m_category = nullptr;
66};
67
68} // namespace
69
71 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
72 ValueObjectSP valobj_sp = valobj.GetNonSyntheticValue();
73 if (!valobj_sp)
74 return false;
75
76 ValueObjectSP value_sp = GetValue(*valobj_sp);
77 if (!value_sp)
78 return false;
79
80 const char *value = value_sp->GetValueAsCString();
81 if (!value)
82 return false;
83
84 stream.Printf("value=%s", value);
85 return true;
86}
87
91 if (!valobj_sp)
92 return nullptr;
93 return new GenericErrorCodeFrontend(*valobj_sp);
94}
static std::optional< size_t > CalculateNumChildren(CompilerType container_elem_type, uint64_t num_elements, CompilerType element_type)
Calculates the number of elements stored in a container (with element type 'container_elem_type') as ...
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:134
virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, bool can_create=true)
virtual lldb::ValueObjectSP GetNonSyntheticValue()
SyntheticChildrenFrontEnd * GenericErrorCodeSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp)
bool GenericErrorCodeSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
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