LLDB  mainline
LibStdcppTuple.cpp
Go to the documentation of this file.
1 //===-- LibStdcppTuple.cpp --------------------------------------*- C++ -*-===//
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 "LibStdcpp.h"
10 
11 #include "lldb/Core/ValueObject.h"
15 
16 #include <memory>
17 #include <vector>
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 using namespace lldb_private::formatters;
22 
23 namespace {
24 
25 class LibStdcppTupleSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
26 public:
27  explicit LibStdcppTupleSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
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  std::vector<ValueObjectSP> m_members;
41 };
42 
43 } // end of anonymous namespace
44 
45 LibStdcppTupleSyntheticFrontEnd::LibStdcppTupleSyntheticFrontEnd(
46  lldb::ValueObjectSP valobj_sp)
47  : SyntheticChildrenFrontEnd(*valobj_sp) {
48  Update();
49 }
50 
51 bool LibStdcppTupleSyntheticFrontEnd::Update() {
52  m_members.clear();
53 
54  ValueObjectSP valobj_backend_sp = m_backend.GetSP();
55  if (!valobj_backend_sp)
56  return false;
57 
58  ValueObjectSP next_child_sp = valobj_backend_sp->GetNonSyntheticValue();
59  while (next_child_sp != nullptr) {
60  ValueObjectSP current_child = next_child_sp;
61  next_child_sp = nullptr;
62 
63  size_t child_count = current_child->GetNumChildren();
64  for (size_t i = 0; i < child_count; ++i) {
65  ValueObjectSP child_sp = current_child->GetChildAtIndex(i, true);
66  llvm::StringRef name_str = child_sp->GetName().GetStringRef();
67  if (name_str.startswith("std::_Tuple_impl<")) {
68  next_child_sp = child_sp;
69  } else if (name_str.startswith("std::_Head_base<")) {
70  ValueObjectSP value_sp =
71  child_sp->GetChildMemberWithName(ConstString("_M_head_impl"), true);
72  if (value_sp) {
73  StreamString name;
74  name.Printf("[%zd]", m_members.size());
75  m_members.push_back(value_sp->Clone(ConstString(name.GetString())));
76  }
77  }
78  }
79  }
80 
81  return false;
82 }
83 
84 bool LibStdcppTupleSyntheticFrontEnd::MightHaveChildren() { return true; }
85 
86 lldb::ValueObjectSP
87 LibStdcppTupleSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
88  if (idx < m_members.size())
89  return m_members[idx];
90  return lldb::ValueObjectSP();
91 }
92 
94  return m_members.size();
95 }
96 
97 size_t LibStdcppTupleSyntheticFrontEnd::GetIndexOfChildWithName(
98  ConstString name) {
99  return ExtractIndexFromString(name.GetCString());
100 }
101 
104  CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
105  return (valobj_sp ? new LibStdcppTupleSyntheticFrontEnd(valobj_sp) : nullptr);
106 }
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
size_t ExtractIndexFromString(const char *item_name)
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
static size_t CalculateNumChildren(CompilerType container_type, CompilerType element_type, lldb_private::ExecutionContextScope *exe_scope=nullptr)
Definition: VectorType.cpp:168
A uniqued constant string class.
Definition: ConstString.h:38
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:247
Definition: SBAddress.h:15
SyntheticChildrenFrontEnd * LibStdcppTupleSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)