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 TypeSummaryImpl::TypeSummaryImpl (const TypeSummaryImpl::Flags& flags) :
43 StringSummaryFormat::StringSummaryFormat (const TypeSummaryImpl::Flags& flags,
44 const char *format_cstr) :
45 TypeSummaryImpl(flags),
49 m_format.assign(format_cstr);
53 StringSummaryFormat::FormatObject (ValueObject *valobj,
58 retval.assign("NULL ValueObject");
63 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
65 StackFrame *frame = exe_ctx.GetFramePtr();
67 sc = frame->GetSymbolContext(lldb::eSymbolContextEverything);
71 ValueObjectPrinter printer(valobj,&s,DumpValueObjectOptions());
72 printer.PrintChildrenOneLiner(HideNames());
73 retval.assign(s.GetData());
78 if (Debugger::FormatPrompt(m_format.c_str(), &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, valobj))
80 retval.assign(s.GetString());
85 retval.assign("error: summary string parsing error");
92 StringSummaryFormat::GetDescription ()
96 sstr.Printf ("`%s`%s%s%s%s%s%s%s", m_format.c_str(),
97 Cascades() ? "" : " (not cascading)",
98 !DoesPrintChildren() ? "" : " (show children)",
99 !DoesPrintValue() ? " (hide value)" : "",
100 IsOneLiner() ? " (one-line printout)" : "",
101 SkipsPointers() ? " (skip pointers)" : "",
102 SkipsReferences() ? " (skip references)" : "",
103 HideNames() ? " (hide member names)" : "");
104 return sstr.GetString();
107 CXXFunctionSummaryFormat::CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags,
109 const char* description) :
110 TypeSummaryImpl(flags),
112 m_description(description ? description : "")
117 CXXFunctionSummaryFormat::FormatObject (ValueObject *valobj,
122 if (!m_impl || m_impl(*valobj,stream) == false)
124 dest.assign(stream.GetData());
129 CXXFunctionSummaryFormat::GetDescription ()
132 sstr.Printf ("`%s (%p) `%s%s%s%s%s%s%s", m_description.c_str(),m_impl,
133 Cascades() ? "" : " (not cascading)",
134 !DoesPrintChildren() ? "" : " (show children)",
135 !DoesPrintValue() ? " (hide value)" : "",
136 IsOneLiner() ? " (one-line printout)" : "",
137 SkipsPointers() ? " (skip pointers)" : "",
138 SkipsReferences() ? " (skip references)" : "",
139 HideNames() ? " (hide member names)" : "");
140 return sstr.GetString();
143 #ifndef LLDB_DISABLE_PYTHON
146 ScriptSummaryFormat::ScriptSummaryFormat (const TypeSummaryImpl::Flags& flags,
147 const char * function_name,
148 const char * python_script) :
149 TypeSummaryImpl(flags),
152 m_script_function_sp()
155 m_function_name.assign(function_name);
157 m_python_script.assign(python_script);
161 ScriptSummaryFormat::FormatObject (ValueObject *valobj,
164 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
169 Host::SetCrashDescriptionWithFormat("[Python summary] Name: %s - Function: %s",
170 valobj->GetName().AsCString("unknown"),
171 m_function_name.c_str());
173 TargetSP target_sp(valobj->GetTargetSP());
177 retval.assign("error: no target");
181 ScriptInterpreter *script_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
183 if (!script_interpreter)
185 retval.assign("error: no ScriptInterpreter");
189 return script_interpreter->GetScriptedSummary(m_function_name.c_str(),
191 m_script_function_sp,
197 ScriptSummaryFormat::GetDescription ()
200 sstr.Printf ("%s%s%s%s%s%s%s\n%s", Cascades() ? "" : " (not cascading)",
201 !DoesPrintChildren() ? "" : " (show children)",
202 !DoesPrintValue() ? " (hide value)" : "",
203 IsOneLiner() ? " (one-line printout)" : "",
204 SkipsPointers() ? " (skip pointers)" : "",
205 SkipsReferences() ? " (skip references)" : "",
206 HideNames() ? " (hide member names)" : "",
207 m_python_script.c_str());
208 return sstr.GetString();
212 #endif // #ifndef LLDB_DISABLE_PYTHON