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(valobj));
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(nullptr) ? "" : " (show children)",
99 !DoesPrintValue(nullptr) ? " (hide value)" : "",
100 IsOneLiner() ? " (one-line printout)" : "",
101 SkipsPointers() ? " (skip pointers)" : "",
102 SkipsReferences() ? " (skip references)" : "",
103 HideNames(nullptr) ? " (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(),
133 static_cast<void*>(&m_impl),
134 Cascades() ? "" : " (not cascading)",
135 !DoesPrintChildren(nullptr) ? "" : " (show children)",
136 !DoesPrintValue(nullptr) ? " (hide value)" : "",
137 IsOneLiner() ? " (one-line printout)" : "",
138 SkipsPointers() ? " (skip pointers)" : "",
139 SkipsReferences() ? " (skip references)" : "",
140 HideNames(nullptr) ? " (hide member names)" : "");
141 return sstr.GetString();
144 #ifndef LLDB_DISABLE_PYTHON
147 ScriptSummaryFormat::ScriptSummaryFormat (const TypeSummaryImpl::Flags& flags,
148 const char * function_name,
149 const char * python_script) :
150 TypeSummaryImpl(flags),
153 m_script_function_sp()
156 m_function_name.assign(function_name);
158 m_python_script.assign(python_script);
162 ScriptSummaryFormat::FormatObject (ValueObject *valobj,
165 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
170 Host::SetCrashDescriptionWithFormat("[Python summary] Name: %s - Function: %s",
171 valobj->GetName().AsCString("unknown"),
172 m_function_name.c_str());
174 TargetSP target_sp(valobj->GetTargetSP());
178 retval.assign("error: no target");
182 ScriptInterpreter *script_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
184 if (!script_interpreter)
186 retval.assign("error: no ScriptInterpreter");
190 return script_interpreter->GetScriptedSummary(m_function_name.c_str(),
192 m_script_function_sp,
198 ScriptSummaryFormat::GetDescription ()
201 sstr.Printf ("%s%s%s%s%s%s%s\n%s", Cascades() ? "" : " (not cascading)",
202 !DoesPrintChildren(nullptr) ? "" : " (show children)",
203 !DoesPrintValue(nullptr) ? " (hide value)" : "",
204 IsOneLiner() ? " (one-line printout)" : "",
205 SkipsPointers() ? " (skip pointers)" : "",
206 SkipsReferences() ? " (skip references)" : "",
207 HideNames(nullptr) ? " (hide member names)" : "",
208 m_python_script.c_str());
209 return sstr.GetString();
213 #endif // #ifndef LLDB_DISABLE_PYTHON