1 //===-- TypeSummary.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
16 // Other libraries and framework includes
19 #include "lldb/lldb-public.h"
20 #include "lldb/lldb-enumerations.h"
22 #include "lldb/Core/Debugger.h"
23 #include "lldb/Core/StreamString.h"
24 #include "lldb/Core/Timer.h"
25 #include "lldb/DataFormatters/TypeSummary.h"
26 #include "lldb/DataFormatters/ValueObjectPrinter.h"
27 #include "lldb/Interpreter/CommandInterpreter.h"
28 #include "lldb/Symbol/ClangASTType.h"
29 #include "lldb/Target/StackFrame.h"
30 #include "lldb/Target/Target.h"
32 #include "lldb/Host/Host.h"
35 using namespace lldb_private;
37 TypeSummaryOptions::TypeSummaryOptions () :
38 m_lang(eLanguageTypeUnknown),
39 m_capping(eTypeSummaryCapped)
42 TypeSummaryOptions::TypeSummaryOptions (const TypeSummaryOptions& rhs) :
44 m_capping(rhs.m_capping)
48 TypeSummaryOptions::operator = (const TypeSummaryOptions& rhs)
51 m_capping = rhs.m_capping;
56 TypeSummaryOptions::GetLanguage () const
61 lldb::TypeSummaryCapping
62 TypeSummaryOptions::GetCapping () const
68 TypeSummaryOptions::SetLanguage (lldb::LanguageType lang)
75 TypeSummaryOptions::SetCapping (lldb::TypeSummaryCapping cap)
81 TypeSummaryImpl::TypeSummaryImpl (const TypeSummaryImpl::Flags& flags) :
87 StringSummaryFormat::StringSummaryFormat (const TypeSummaryImpl::Flags& flags,
88 const char *format_cstr) :
89 TypeSummaryImpl(flags),
93 m_format.assign(format_cstr);
97 StringSummaryFormat::FormatObject (ValueObject *valobj,
99 const TypeSummaryOptions& options)
103 retval.assign("NULL ValueObject");
108 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
110 StackFrame *frame = exe_ctx.GetFramePtr();
112 sc = frame->GetSymbolContext(lldb::eSymbolContextEverything);
116 ValueObjectPrinter printer(valobj,&s,DumpValueObjectOptions());
117 printer.PrintChildrenOneLiner(HideNames(valobj));
118 retval.assign(s.GetData());
123 if (Debugger::FormatPrompt(m_format.c_str(), &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, valobj))
125 retval.assign(s.GetString());
130 retval.assign("error: summary string parsing error");
137 StringSummaryFormat::GetDescription ()
141 sstr.Printf ("`%s`%s%s%s%s%s%s%s", m_format.c_str(),
142 Cascades() ? "" : " (not cascading)",
143 !DoesPrintChildren(nullptr) ? "" : " (show children)",
144 !DoesPrintValue(nullptr) ? " (hide value)" : "",
145 IsOneLiner() ? " (one-line printout)" : "",
146 SkipsPointers() ? " (skip pointers)" : "",
147 SkipsReferences() ? " (skip references)" : "",
148 HideNames(nullptr) ? " (hide member names)" : "");
149 return sstr.GetString();
152 CXXFunctionSummaryFormat::CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags,
154 const char* description) :
155 TypeSummaryImpl(flags),
157 m_description(description ? description : "")
162 CXXFunctionSummaryFormat::FormatObject (ValueObject *valobj,
164 const TypeSummaryOptions& options)
168 if (!m_impl || m_impl(*valobj,stream,options) == false)
170 dest.assign(stream.GetData());
175 CXXFunctionSummaryFormat::GetDescription ()
178 sstr.Printf ("`%s (%p) `%s%s%s%s%s%s%s", m_description.c_str(),
179 static_cast<void*>(&m_impl),
180 Cascades() ? "" : " (not cascading)",
181 !DoesPrintChildren(nullptr) ? "" : " (show children)",
182 !DoesPrintValue(nullptr) ? " (hide value)" : "",
183 IsOneLiner() ? " (one-line printout)" : "",
184 SkipsPointers() ? " (skip pointers)" : "",
185 SkipsReferences() ? " (skip references)" : "",
186 HideNames(nullptr) ? " (hide member names)" : "");
187 return sstr.GetString();
190 #ifndef LLDB_DISABLE_PYTHON
193 ScriptSummaryFormat::ScriptSummaryFormat (const TypeSummaryImpl::Flags& flags,
194 const char * function_name,
195 const char * python_script) :
196 TypeSummaryImpl(flags),
199 m_script_function_sp()
202 m_function_name.assign(function_name);
204 m_python_script.assign(python_script);
208 ScriptSummaryFormat::FormatObject (ValueObject *valobj,
210 const TypeSummaryOptions& options)
212 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
217 Host::SetCrashDescriptionWithFormat("[Python summary] Name: %s - Function: %s",
218 valobj->GetName().AsCString("unknown"),
219 m_function_name.c_str());
221 TargetSP target_sp(valobj->GetTargetSP());
225 retval.assign("error: no target");
229 ScriptInterpreter *script_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
231 if (!script_interpreter)
233 retval.assign("error: no ScriptInterpreter");
237 return script_interpreter->GetScriptedSummary(m_function_name.c_str(),
239 m_script_function_sp,
246 ScriptSummaryFormat::GetDescription ()
249 sstr.Printf ("%s%s%s%s%s%s%s\n%s", Cascades() ? "" : " (not cascading)",
250 !DoesPrintChildren(nullptr) ? "" : " (show children)",
251 !DoesPrintValue(nullptr) ? " (hide value)" : "",
252 IsOneLiner() ? " (one-line printout)" : "",
253 SkipsPointers() ? " (skip pointers)" : "",
254 SkipsReferences() ? " (skip references)" : "",
255 HideNames(nullptr) ? " (hide member names)" : "",
256 m_python_script.c_str());
257 return sstr.GetString();
261 #endif // #ifndef LLDB_DISABLE_PYTHON