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/DataFormatters/TypeSummary.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/ValueObject.h"
25 #include "lldb/DataFormatters/ValueObjectPrinter.h"
26 #include "lldb/Interpreter/CommandInterpreter.h"
27 #include "lldb/Symbol/CompilerType.h"
28 #include "lldb/Target/StackFrame.h"
29 #include "lldb/Target/Target.h"
32 using namespace lldb_private;
34 TypeSummaryOptions::TypeSummaryOptions () :
35 m_lang(eLanguageTypeUnknown),
36 m_capping(eTypeSummaryCapped)
39 TypeSummaryOptions::TypeSummaryOptions (const TypeSummaryOptions& rhs) :
41 m_capping(rhs.m_capping)
45 TypeSummaryOptions::operator = (const TypeSummaryOptions& rhs)
48 m_capping = rhs.m_capping;
53 TypeSummaryOptions::GetLanguage () const
58 lldb::TypeSummaryCapping
59 TypeSummaryOptions::GetCapping () const
65 TypeSummaryOptions::SetLanguage (lldb::LanguageType lang)
72 TypeSummaryOptions::SetCapping (lldb::TypeSummaryCapping cap)
78 TypeSummaryImpl::TypeSummaryImpl (Kind kind,
79 const TypeSummaryImpl::Flags& flags) :
86 StringSummaryFormat::StringSummaryFormat (const TypeSummaryImpl::Flags& flags,
87 const char *format_cstr) :
88 TypeSummaryImpl(Kind::eSummaryString,flags),
91 SetSummaryString (format_cstr);
95 StringSummaryFormat::SetSummaryString (const char* format_cstr)
98 if (format_cstr && format_cstr[0])
100 m_format_str = format_cstr;
101 m_error = FormatEntity::Parse(format_cstr, m_format);
105 m_format_str.clear();
113 StringSummaryFormat::FormatObject (ValueObject *valobj,
115 const TypeSummaryOptions& options)
119 retval.assign("NULL ValueObject");
124 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
126 StackFrame *frame = exe_ctx.GetFramePtr();
128 sc = frame->GetSymbolContext(lldb::eSymbolContextEverything);
132 ValueObjectPrinter printer(valobj,&s,DumpValueObjectOptions());
133 printer.PrintChildrenOneLiner(HideNames(valobj));
134 retval.assign(s.GetData());
139 if (FormatEntity::Format(m_format, s, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), valobj, false, false))
141 retval.assign(s.GetString());
146 retval.assign("error: summary string parsing error");
153 StringSummaryFormat::GetDescription ()
157 sstr.Printf ("`%s`%s%s%s%s%s%s%s%s%s",
158 m_format_str.c_str(),
159 m_error.Fail() ? " error: " : "",
160 m_error.Fail() ? m_error.AsCString() : "",
161 Cascades() ? "" : " (not cascading)",
162 !DoesPrintChildren(nullptr) ? "" : " (show children)",
163 !DoesPrintValue(nullptr) ? " (hide value)" : "",
164 IsOneLiner() ? " (one-line printout)" : "",
165 SkipsPointers() ? " (skip pointers)" : "",
166 SkipsReferences() ? " (skip references)" : "",
167 HideNames(nullptr) ? " (hide member names)" : "");
168 return sstr.GetString();
171 CXXFunctionSummaryFormat::CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags,
173 const char* description) :
174 TypeSummaryImpl(Kind::eCallback,flags),
176 m_description(description ? description : "")
181 CXXFunctionSummaryFormat::FormatObject (ValueObject *valobj,
183 const TypeSummaryOptions& options)
187 if (!m_impl || m_impl(*valobj,stream,options) == false)
189 dest.assign(stream.GetData());
194 CXXFunctionSummaryFormat::GetDescription ()
197 sstr.Printf ("%s%s%s%s%s%s%s %s",
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 m_description.c_str());
206 return sstr.GetString();
209 ScriptSummaryFormat::ScriptSummaryFormat (const TypeSummaryImpl::Flags& flags,
210 const char * function_name,
211 const char * python_script) :
212 TypeSummaryImpl(Kind::eScript,flags),
215 m_script_function_sp()
218 m_function_name.assign(function_name);
220 m_python_script.assign(python_script);
224 ScriptSummaryFormat::FormatObject (ValueObject *valobj,
226 const TypeSummaryOptions& options)
231 TargetSP target_sp(valobj->GetTargetSP());
235 retval.assign("error: no target");
239 ScriptInterpreter *script_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
241 if (!script_interpreter)
243 retval.assign("error: no ScriptInterpreter");
247 return script_interpreter->GetScriptedSummary(m_function_name.c_str(),
249 m_script_function_sp,
256 ScriptSummaryFormat::GetDescription ()
259 sstr.Printf ("%s%s%s%s%s%s%s\n ", Cascades() ? "" : " (not cascading)",
260 !DoesPrintChildren(nullptr) ? "" : " (show children)",
261 !DoesPrintValue(nullptr) ? " (hide value)" : "",
262 IsOneLiner() ? " (one-line printout)" : "",
263 SkipsPointers() ? " (skip pointers)" : "",
264 SkipsReferences() ? " (skip references)" : "",
265 HideNames(nullptr) ? " (hide member names)" : "");
266 if (m_python_script.empty())
268 if (m_function_name.empty())
270 sstr.PutCString("no backing script");
274 sstr.PutCString(m_function_name.c_str());
279 sstr.PutCString(m_python_script.c_str());
281 return sstr.GetString();