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 //===----------------------------------------------------------------------===//
14 // Other libraries and framework includes
17 #include "lldb/lldb-public.h"
18 #include "lldb/lldb-enumerations.h"
20 #include "lldb/Core/Debugger.h"
21 #include "lldb/Core/StreamString.h"
22 #include "lldb/Core/Timer.h"
23 #include "lldb/DataFormatters/TypeSummary.h"
24 #include "lldb/DataFormatters/ValueObjectPrinter.h"
25 #include "lldb/Interpreter/CommandInterpreter.h"
26 #include "lldb/Symbol/ClangASTType.h"
27 #include "lldb/Target/StackFrame.h"
28 #include "lldb/Target/Target.h"
30 #include "lldb/Host/Host.h"
33 using namespace lldb_private;
35 TypeSummaryOptions::TypeSummaryOptions () :
36 m_lang(eLanguageTypeUnknown),
37 m_capping(eTypeSummaryCapped)
40 TypeSummaryOptions::TypeSummaryOptions (const TypeSummaryOptions& rhs) :
42 m_capping(rhs.m_capping)
46 TypeSummaryOptions::operator = (const TypeSummaryOptions& rhs)
49 m_capping = rhs.m_capping;
54 TypeSummaryOptions::GetLanguage () const
59 lldb::TypeSummaryCapping
60 TypeSummaryOptions::GetCapping () const
66 TypeSummaryOptions::SetLanguage (lldb::LanguageType lang)
73 TypeSummaryOptions::SetCapping (lldb::TypeSummaryCapping cap)
79 TypeSummaryImpl::TypeSummaryImpl (const TypeSummaryImpl::Flags& flags) :
85 StringSummaryFormat::StringSummaryFormat (const TypeSummaryImpl::Flags& flags,
86 const char *format_cstr) :
87 TypeSummaryImpl(flags),
90 SetSummaryString (format_cstr);
94 StringSummaryFormat::SetSummaryString (const char* format_cstr)
97 if (format_cstr && format_cstr[0])
99 m_format_str = format_cstr;
100 m_error = FormatEntity::Parse(format_cstr, m_format);
104 m_format_str.clear();
112 StringSummaryFormat::FormatObject (ValueObject *valobj,
114 const TypeSummaryOptions& options)
118 retval.assign("NULL ValueObject");
123 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
125 StackFrame *frame = exe_ctx.GetFramePtr();
127 sc = frame->GetSymbolContext(lldb::eSymbolContextEverything);
131 ValueObjectPrinter printer(valobj,&s,DumpValueObjectOptions());
132 printer.PrintChildrenOneLiner(HideNames(valobj));
133 retval.assign(s.GetData());
138 if (FormatEntity::Format(m_format, s, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), valobj, false, false))
140 retval.assign(s.GetString());
145 retval.assign("error: summary string parsing error");
152 StringSummaryFormat::GetDescription ()
156 sstr.Printf ("`%s`%s%s%s%s%s%s%s%s%s",
157 m_format_str.c_str(),
158 m_error.Fail() ? " error: " : "",
159 m_error.Fail() ? m_error.AsCString() : "",
160 Cascades() ? "" : " (not cascading)",
161 !DoesPrintChildren(nullptr) ? "" : " (show children)",
162 !DoesPrintValue(nullptr) ? " (hide value)" : "",
163 IsOneLiner() ? " (one-line printout)" : "",
164 SkipsPointers() ? " (skip pointers)" : "",
165 SkipsReferences() ? " (skip references)" : "",
166 HideNames(nullptr) ? " (hide member names)" : "");
167 return sstr.GetString();
170 CXXFunctionSummaryFormat::CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags,
172 const char* description) :
173 TypeSummaryImpl(flags),
175 m_description(description ? description : "")
180 CXXFunctionSummaryFormat::FormatObject (ValueObject *valobj,
182 const TypeSummaryOptions& options)
186 if (!m_impl || m_impl(*valobj,stream,options) == false)
188 dest.assign(stream.GetData());
193 CXXFunctionSummaryFormat::GetDescription ()
196 sstr.Printf ("`%s (%p) `%s%s%s%s%s%s%s", m_description.c_str(),
197 static_cast<void*>(&m_impl),
198 Cascades() ? "" : " (not cascading)",
199 !DoesPrintChildren(nullptr) ? "" : " (show children)",
200 !DoesPrintValue(nullptr) ? " (hide value)" : "",
201 IsOneLiner() ? " (one-line printout)" : "",
202 SkipsPointers() ? " (skip pointers)" : "",
203 SkipsReferences() ? " (skip references)" : "",
204 HideNames(nullptr) ? " (hide member names)" : "");
205 return sstr.GetString();
208 #ifndef LLDB_DISABLE_PYTHON
211 ScriptSummaryFormat::ScriptSummaryFormat (const TypeSummaryImpl::Flags& flags,
212 const char * function_name,
213 const char * python_script) :
214 TypeSummaryImpl(flags),
217 m_script_function_sp()
220 m_function_name.assign(function_name);
222 m_python_script.assign(python_script);
226 ScriptSummaryFormat::FormatObject (ValueObject *valobj,
228 const TypeSummaryOptions& options)
230 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
235 Host::SetCrashDescriptionWithFormat("[Python summary] Name: %s - Function: %s",
236 valobj->GetName().AsCString("unknown"),
237 m_function_name.c_str());
239 TargetSP target_sp(valobj->GetTargetSP());
243 retval.assign("error: no target");
247 ScriptInterpreter *script_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
249 if (!script_interpreter)
251 retval.assign("error: no ScriptInterpreter");
255 return script_interpreter->GetScriptedSummary(m_function_name.c_str(),
257 m_script_function_sp,
264 ScriptSummaryFormat::GetDescription ()
267 sstr.Printf ("%s%s%s%s%s%s%s\n%s", Cascades() ? "" : " (not cascading)",
268 !DoesPrintChildren(nullptr) ? "" : " (show children)",
269 !DoesPrintValue(nullptr) ? " (hide value)" : "",
270 IsOneLiner() ? " (one-line printout)" : "",
271 SkipsPointers() ? " (skip pointers)" : "",
272 SkipsReferences() ? " (skip references)" : "",
273 HideNames(nullptr) ? " (hide member names)" : "",
274 m_python_script.c_str());
275 return sstr.GetString();
279 #endif // #ifndef LLDB_DISABLE_PYTHON