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/Interpreter/CommandInterpreter.h"
27 #include "lldb/Symbol/ClangASTType.h"
28 #include "lldb/Target/StackFrame.h"
29 #include "lldb/Target/Target.h"
31 #include "lldb/Host/Host.h"
34 using namespace lldb_private;
36 TypeSummaryImpl::TypeSummaryImpl (const TypeSummaryImpl::Flags& flags) :
42 StringSummaryFormat::StringSummaryFormat (const TypeSummaryImpl::Flags& flags,
43 const char *format_cstr) :
44 TypeSummaryImpl(flags),
48 m_format.assign(format_cstr);
52 StringSummaryFormat::FormatObject (ValueObject *valobj,
57 retval.assign("NULL ValueObject");
62 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
64 StackFrame *frame = exe_ctx.GetFramePtr();
66 sc = frame->GetSymbolContext(lldb::eSymbolContextEverything);
72 ValueObjectSP synth_valobj = valobj->GetSyntheticValue();
74 object = synth_valobj.get();
78 const uint32_t num_children = object->GetNumChildren();
83 for (uint32_t idx=0; idx<num_children; ++idx)
85 lldb::ValueObjectSP child_sp(object->GetChildAtIndex(idx, true));
92 s.PutCString(child_sp.get()->GetName().AsCString());
95 child_sp.get()->DumpPrintableRepresentation(s,
96 ValueObject::eValueObjectRepresentationStyleSummary,
98 ValueObject::ePrintableRepresentationSpecialCasesDisable);
104 retval.assign(s.GetString());
109 retval.assign("error: oneliner for no children");
116 if (Debugger::FormatPrompt(m_format.c_str(), &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, valobj))
118 retval.assign(s.GetString());
123 retval.assign("error: summary string parsing error");
130 StringSummaryFormat::GetDescription ()
134 sstr.Printf ("`%s`%s%s%s%s%s%s%s", m_format.c_str(),
135 Cascades() ? "" : " (not cascading)",
136 !DoesPrintChildren() ? "" : " (show children)",
137 !DoesPrintValue() ? " (hide value)" : "",
138 IsOneliner() ? " (one-line printout)" : "",
139 SkipsPointers() ? " (skip pointers)" : "",
140 SkipsReferences() ? " (skip references)" : "",
141 HideNames() ? " (hide member names)" : "");
142 return sstr.GetString();
145 CXXFunctionSummaryFormat::CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags,
147 const char* description) :
148 TypeSummaryImpl(flags),
150 m_description(description ? description : "")
155 CXXFunctionSummaryFormat::FormatObject (ValueObject *valobj,
160 if (!m_impl || m_impl(*valobj,stream) == false)
162 dest.assign(stream.GetData());
167 CXXFunctionSummaryFormat::GetDescription ()
170 sstr.Printf ("`%s (%p) `%s%s%s%s%s%s%s", m_description.c_str(),m_impl,
171 Cascades() ? "" : " (not cascading)",
172 !DoesPrintChildren() ? "" : " (show children)",
173 !DoesPrintValue() ? " (hide value)" : "",
174 IsOneliner() ? " (one-line printout)" : "",
175 SkipsPointers() ? " (skip pointers)" : "",
176 SkipsReferences() ? " (skip references)" : "",
177 HideNames() ? " (hide member names)" : "");
178 return sstr.GetString();
181 #ifndef LLDB_DISABLE_PYTHON
184 ScriptSummaryFormat::ScriptSummaryFormat (const TypeSummaryImpl::Flags& flags,
185 const char * function_name,
186 const char * python_script) :
187 TypeSummaryImpl(flags),
190 m_script_function_sp()
193 m_function_name.assign(function_name);
195 m_python_script.assign(python_script);
199 ScriptSummaryFormat::FormatObject (ValueObject *valobj,
202 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
207 Host::SetCrashDescriptionWithFormat("[Python summary] Name: %s - Function: %s",
208 valobj->GetName().AsCString("unknown"),
209 m_function_name.c_str());
211 TargetSP target_sp(valobj->GetTargetSP());
215 retval.assign("error: no target");
219 ScriptInterpreter *script_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
221 if (!script_interpreter)
223 retval.assign("error: no ScriptInterpreter");
227 return script_interpreter->GetScriptedSummary(m_function_name.c_str(),
229 m_script_function_sp,
235 ScriptSummaryFormat::GetDescription ()
238 sstr.Printf ("%s%s%s%s%s%s%s\n%s", Cascades() ? "" : " (not cascading)",
239 !DoesPrintChildren() ? "" : " (show children)",
240 !DoesPrintValue() ? " (hide value)" : "",
241 IsOneliner() ? " (one-line printout)" : "",
242 SkipsPointers() ? " (skip pointers)" : "",
243 SkipsReferences() ? " (skip references)" : "",
244 HideNames() ? " (hide member names)" : "",
245 m_python_script.c_str());
246 return sstr.GetString();
250 #endif // #ifndef LLDB_DISABLE_PYTHON