LLDB  mainline
TypeSynthetic.cpp
Go to the documentation of this file.
1 //===-- TypeSynthetic.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 
10 
11 
12 #include "lldb/lldb-enumerations.h"
13 #include "lldb/lldb-public.h"
14 
15 #include "lldb/Core/Debugger.h"
20 #include "lldb/Target/Target.h"
22 
23 using namespace lldb;
24 using namespace lldb_private;
25 
26 void TypeFilterImpl::AddExpressionPath(const std::string &path) {
27  bool need_add_dot = true;
28  if (path[0] == '.' || (path[0] == '-' && path[1] == '>') || path[0] == '[')
29  need_add_dot = false;
30  // add a '.' symbol to help forgetful users
31  if (!need_add_dot)
32  m_expression_paths.push_back(path);
33  else
34  m_expression_paths.push_back(std::string(".") + path);
35 }
36 
37 bool TypeFilterImpl::SetExpressionPathAtIndex(size_t i,
38  const std::string &path) {
39  if (i >= GetCount())
40  return false;
41  bool need_add_dot = true;
42  if (path[0] == '.' || (path[0] == '-' && path[1] == '>') || path[0] == '[')
43  need_add_dot = false;
44  // add a '.' symbol to help forgetful users
45  if (!need_add_dot)
46  m_expression_paths[i] = path;
47  else
48  m_expression_paths[i] = std::string(".") + path;
49  return true;
50 }
51 
52 size_t
53 TypeFilterImpl::FrontEnd::GetIndexOfChildWithName(ConstString name) {
54  const char *name_cstr = name.GetCString();
55  if (name_cstr) {
56  for (size_t i = 0; i < filter->GetCount(); i++) {
57  const char *expr_cstr = filter->GetExpressionPathAtIndex(i);
58  if (expr_cstr) {
59  if (*expr_cstr == '.')
60  expr_cstr++;
61  else if (*expr_cstr == '-' && *(expr_cstr + 1) == '>')
62  expr_cstr += 2;
63  }
64  if (expr_cstr) {
65  if (!::strcmp(name_cstr, expr_cstr))
66  return i;
67  }
68  }
69  }
70  return UINT32_MAX;
71 }
72 
73 std::string TypeFilterImpl::GetDescription() {
74  StreamString sstr;
75  sstr.Printf("%s%s%s {\n", Cascades() ? "" : " (not cascading)",
76  SkipsPointers() ? " (skip pointers)" : "",
77  SkipsReferences() ? " (skip references)" : "");
78 
79  for (size_t i = 0; i < GetCount(); i++) {
80  sstr.Printf(" %s\n", GetExpressionPathAtIndex(i));
81  }
82 
83  sstr.Printf("}");
84  return std::string(sstr.GetString());
85 }
86 
87 std::string CXXSyntheticChildren::GetDescription() {
88  StreamString sstr;
89  sstr.Printf("%s%s%s %s", Cascades() ? "" : " (not cascading)",
90  SkipsPointers() ? " (skip pointers)" : "",
91  SkipsReferences() ? " (skip references)" : "",
92  m_description.c_str());
93 
94  return std::string(sstr.GetString());
95 }
96 
97 lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromExpression(
98  llvm::StringRef name, llvm::StringRef expression,
99  const ExecutionContext &exe_ctx) {
100  ValueObjectSP valobj_sp(
101  ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx));
102  if (valobj_sp)
103  valobj_sp->SetSyntheticChildrenGenerated(true);
104  return valobj_sp;
105 }
106 
107 lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromAddress(
108  llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx,
109  CompilerType type) {
110  ValueObjectSP valobj_sp(
111  ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type));
112  if (valobj_sp)
113  valobj_sp->SetSyntheticChildrenGenerated(true);
114  return valobj_sp;
115 }
116 
117 lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromData(
118  llvm::StringRef name, const DataExtractor &data,
119  const ExecutionContext &exe_ctx, CompilerType type) {
120  ValueObjectSP valobj_sp(
121  ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type));
122  if (valobj_sp)
123  valobj_sp->SetSyntheticChildrenGenerated(true);
124  return valobj_sp;
125 }
126 
127 ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass,
128  ValueObject &backend)
129  : SyntheticChildrenFrontEnd(backend), m_python_class(pclass),
130  m_wrapper_sp(), m_interpreter(nullptr) {
131  if (backend.GetID() == LLDB_INVALID_UID)
132  return;
133 
134  TargetSP target_sp = backend.GetTargetSP();
135 
136  if (!target_sp)
137  return;
138 
139  m_interpreter = target_sp->GetDebugger().GetScriptInterpreter();
140 
141  if (m_interpreter != nullptr)
143  m_python_class.c_str(), backend.GetSP());
144 }
145 
147 
148 lldb::ValueObjectSP
150  if (!m_wrapper_sp || !m_interpreter)
151  return lldb::ValueObjectSP();
152 
153  return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
154 }
155 
157  return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter);
158 }
159 
161  if (!m_wrapper_sp || m_interpreter == nullptr)
162  return 0;
163  return m_interpreter->CalculateNumChildren(m_wrapper_sp, UINT32_MAX);
164 }
165 
167  if (!m_wrapper_sp || m_interpreter == nullptr)
168  return 0;
169  return m_interpreter->CalculateNumChildren(m_wrapper_sp, max);
170 }
171 
173  if (!m_wrapper_sp || m_interpreter == nullptr)
174  return false;
175 
176  return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
177 }
178 
180  if (!m_wrapper_sp || m_interpreter == nullptr)
181  return false;
182 
183  return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp);
184 }
185 
187  ConstString name) {
188  if (!m_wrapper_sp || m_interpreter == nullptr)
189  return UINT32_MAX;
190  return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp,
191  name.GetCString());
192 }
193 
195  if (!m_wrapper_sp || m_interpreter == nullptr)
196  return nullptr;
197 
198  return m_interpreter->GetSyntheticValue(m_wrapper_sp);
199 }
200 
202  if (!m_wrapper_sp || m_interpreter == nullptr)
203  return ConstString();
204 
205  return m_interpreter->GetSyntheticTypeName(m_wrapper_sp);
206 }
207 
209  StreamString sstr;
210  sstr.Printf("%s%s%s Python class %s", Cascades() ? "" : " (not cascading)",
211  SkipsPointers() ? " (skip pointers)" : "",
212  SkipsReferences() ? " (skip references)" : "",
213  m_python_class.c_str());
214 
215  return std::string(sstr.GetString());
216 }
lldb_private::ScriptedSyntheticChildren::FrontEnd::m_interpreter
ScriptInterpreter * m_interpreter
Definition: TypeSynthetic.h:445
lldb_private::ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override
Definition: TypeSynthetic.cpp:149
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb-public.h
lldb_private::ScriptedSyntheticChildren::FrontEnd::Update
bool Update() override
Definition: TypeSynthetic.cpp:172
lldb_private::ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName
size_t GetIndexOfChildWithName(ConstString name) override
Definition: TypeSynthetic.cpp:186
LLDB_INVALID_UID
#define LLDB_INVALID_UID
Definition: lldb-defines.h:92
lldb_private::SyntheticChildrenFrontEnd
Definition: TypeSynthetic.h:27
lldb_private::ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren
size_t CalculateNumChildren() override
Definition: TypeSynthetic.cpp:160
lldb_private::ScriptedSyntheticChildren::GetDescription
std::string GetDescription() override
Definition: TypeSynthetic.cpp:208
lldb_private::ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue
lldb::ValueObjectSP GetSyntheticValue() override
Definition: TypeSynthetic.cpp:194
Debugger.h
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
Target.h
lldb_private::ScriptedSyntheticChildren::FrontEnd::m_wrapper_sp
StructuredData::ObjectSP m_wrapper_sp
Definition: TypeSynthetic.h:444
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::ValueObject::GetID
lldb::user_id_t GetID() const
Returns a unique id for this ValueObject.
Definition: ValueObject.h:470
lldb_private::ScriptedSyntheticChildren::FrontEnd::~FrontEnd
~FrontEnd() override
lldb_private::ValueObject::GetSP
lldb::ValueObjectSP GetSP()
Definition: ValueObject.h:555
StreamString.h
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StreamString
Definition: StreamString.h:23
lldb-enumerations.h
lldb_private::ScriptedSyntheticChildren::FrontEnd::GetSyntheticTypeName
ConstString GetSyntheticTypeName() override
Definition: TypeSynthetic.cpp:201
lldb_private::ScriptedSyntheticChildren::FrontEnd::m_python_class
std::string m_python_class
Definition: TypeSynthetic.h:443
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
CompilerType.h
lldb_private::SyntheticChildren::SkipsPointers
bool SkipsPointers() const
Definition: TypeSynthetic.h:237
lldb_private::SyntheticChildren::SkipsReferences
bool SkipsReferences() const
Definition: TypeSynthetic.h:239
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
uint32_t
TypeSynthetic.h
lldb_private::ScriptedSyntheticChildren::FrontEnd::IsValid
bool IsValid()
Definition: TypeSynthetic.cpp:156
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
lldb_private::ScriptInterpreter::CreateSyntheticScriptedProvider
virtual StructuredData::ObjectSP CreateSyntheticScriptedProvider(const char *class_name, lldb::ValueObjectSP valobj)
Definition: ScriptInterpreter.h:226
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ScriptedSyntheticChildren::FrontEnd::MightHaveChildren
bool MightHaveChildren() override
Definition: TypeSynthetic.cpp:179
CommandInterpreter.h
lldb_private::ValueObject::GetTargetSP
lldb::TargetSP GetTargetSP() const
Definition: ValueObject.h:334
lldb_private::ScriptedSyntheticChildren::m_python_class
std::string m_python_class
Definition: TypeSynthetic.h:388
ScriptInterpreter.h
lldb
Definition: SBAddress.h:15
lldb_private::SyntheticChildren::Cascades
bool Cascades() const
Definition: TypeSynthetic.h:235