1 //===-- SystemInitializerFull.cpp -------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/API/SystemInitializerFull.h"
11
12 #include "lldb/Core/Debugger.h"
13 #include "lldb/Core/Timer.h"
14 #include "lldb/Host/Host.h"
15 #include "lldb/Initialization/SystemInitializerCommon.h"
16
17 #include "Plugins/ABI/SysV-arm/ABISysV_arm.h"
18 #include "Plugins/ABI/SysV-arm64/ABISysV_arm64.h"
19 #include "Plugins/ABI/SysV-i386/ABISysV_i386.h"
20 #include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
21 #include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
22 #include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
23 #include "Plugins/ABI/SysV-mips/ABISysV_mips.h"
24 #include "Plugins/ABI/SysV-mips64/ABISysV_mips64.h"
25 #include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
26 #include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
27 #include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
28 #include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h"
29 #include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
30 #include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
31 #include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
32 #include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
33 #include "Plugins/Process/elf-core/ProcessElfCore.h"
34 #include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
35 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
36 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
37 #include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
38 #include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
39 #include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
40 #include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
41
42 #if defined(__APPLE__)
43 #include "Plugins/Process/mach-core/ProcessMachCore.h"
44 #include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
45 #endif
46
47 #if defined(__FreeBSD__)
48 #include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
49 #endif
50
51 #if defined(_MSC_VER)
52 #include "lldb/Host/windows/windows.h"
53 #include "Plugins/Process/Windows/ProcessWindows.h"
54 #endif
55
56 #if !defined(LLDB_DISABLE_PYTHON)
57 #include "lldb/Interpreter/ScriptInterpreterPython.h"
58 #endif
59
60 #include "llvm/Support/TargetSelect.h"
61
62 #include <string>
63
64 using namespace lldb_private;
65
66 #ifndef LLDB_DISABLE_PYTHON
67
68 // Defined in the SWIG source file
69 extern "C" void
70 init_lldb(void);
71
72 // these are the Pythonic implementations of the required callbacks
73 // these are scripting-language specific, which is why they belong here
74 // we still need to use function pointers to them instead of relying
75 // on linkage-time resolution because the SWIG stuff and this file
76 // get built at different times
77 extern "C" bool
78 LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
79 const char *session_dictionary_name,
80 const lldb::StackFrameSP& sb_frame,
81 const lldb::BreakpointLocationSP& sb_bp_loc);
82
83 extern "C" bool
84 LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
85 const char *session_dictionary_name,
86 const lldb::StackFrameSP& sb_frame,
87 const lldb::WatchpointSP& sb_wp);
88
89 extern "C" bool
90 LLDBSwigPythonCallTypeScript (const char *python_function_name,
91 void *session_dictionary,
92 const lldb::ValueObjectSP& valobj_sp,
93 void** pyfunct_wrapper,
94 const lldb::TypeSummaryOptionsSP& options_sp,
95 std::string& retval);
96
97 extern "C" void*
98 LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
99 const char *session_dictionary_name,
100 const lldb::ValueObjectSP& valobj_sp);
101
102 extern "C" void*
103 LLDBSwigPythonCreateCommandObject (const char *python_class_name,
104 const char *session_dictionary_name,
105 const lldb::DebuggerSP debugger_sp);
106
107 extern "C" void*
108 LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
109 const char *session_dictionary_name,
110 const lldb::ThreadPlanSP& thread_plan_sp);
111
112 extern "C" bool
113 LLDBSWIGPythonCallThreadPlan (void *implementor,
114 const char *method_name,
115 Event *event_sp,
116 bool &got_error);
117
118 extern "C" size_t
119 LLDBSwigPython_CalculateNumChildren (void *implementor);
120
121 extern "C" void *
122 LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
123
124 extern "C" int
125 LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
126
127 extern "C" void *
128 LLDBSWIGPython_CastPyObjectToSBValue (void* data);
129
130 extern lldb::ValueObjectSP
131 LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
132
133 extern "C" bool
134 LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
135
136 extern "C" bool
137 LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
138
139 extern "C" void *
140 LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
141
142 extern "C" bool
143 LLDBSwigPythonCallCommand (const char *python_function_name,
144 const char *session_dictionary_name,
145 lldb::DebuggerSP& debugger,
146 const char* args,
147 lldb_private::CommandReturnObject &cmd_retobj,
148 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
149
150 extern "C" bool
151 LLDBSwigPythonCallCommandObject (void *implementor,
152 lldb::DebuggerSP& debugger,
153 const char* args,
154 lldb_private::CommandReturnObject& cmd_retobj,
155 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
156
157 extern "C" bool
158 LLDBSwigPythonCallModuleInit (const char *python_module_name,
159 const char *session_dictionary_name,
160 lldb::DebuggerSP& debugger);
161
162 extern "C" void*
163 LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
164 const char *session_dictionary_name,
165 const lldb::ProcessSP& process_sp);
166
167 extern "C" bool
168 LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
169 const char* session_dictionary_name,
170 lldb::ProcessSP& process,
171 std::string& output);
172
173 extern "C" bool
174 LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
175 const char* session_dictionary_name,
176 lldb::ThreadSP& thread,
177 std::string& output);
178
179 extern "C" bool
180 LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
181 const char* session_dictionary_name,
182 lldb::TargetSP& target,
183 std::string& output);
184
185 extern "C" bool
186 LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
187 const char* session_dictionary_name,
188 lldb::StackFrameSP& frame,
189 std::string& output);
190
191 extern "C" bool
192 LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
193 const char* session_dictionary_name,
194 lldb::ValueObjectSP& value,
195 std::string& output);
196
197 extern "C" void*
198 LLDBSWIGPython_GetDynamicSetting (void* module,
199 const char* setting,
200 const lldb::TargetSP& target_sp);
201
202
203 #endif
204
SystemInitializerFull()205 SystemInitializerFull::SystemInitializerFull()
206 {
207 }
208
~SystemInitializerFull()209 SystemInitializerFull::~SystemInitializerFull()
210 {
211 }
212
213 void
Initialize()214 SystemInitializerFull::Initialize()
215 {
216 InitializeSWIG();
217
218 SystemInitializerCommon::Initialize();
219
220 // Initialize LLVM and Clang
221 llvm::InitializeAllTargets();
222 llvm::InitializeAllAsmPrinters();
223 llvm::InitializeAllTargetMCs();
224 llvm::InitializeAllDisassemblers();
225
226 ABISysV_arm::Initialize();
227 ABISysV_arm64::Initialize();
228 ABISysV_i386::Initialize();
229 ABISysV_x86_64::Initialize();
230 ABISysV_ppc::Initialize();
231 ABISysV_ppc64::Initialize();
232 ABISysV_mips::Initialize();
233 ABISysV_mips64::Initialize();
234 DisassemblerLLVMC::Initialize();
235
236 JITLoaderGDB::Initialize();
237 ProcessElfCore::Initialize();
238 MemoryHistoryASan::Initialize();
239 AddressSanitizerRuntime::Initialize();
240
241 SymbolVendorELF::Initialize();
242 SymbolFileDWARF::Initialize();
243 SymbolFileSymtab::Initialize();
244 UnwindAssemblyInstEmulation::Initialize();
245 UnwindAssembly_x86::Initialize();
246 EmulateInstructionARM64::Initialize();
247 SymbolFileDWARFDebugMap::Initialize();
248 ItaniumABILanguageRuntime::Initialize();
249
250 #if defined(_MSC_VER)
251 ProcessWindows::Initialize();
252 #endif
253 #if defined(__FreeBSD__)
254 ProcessFreeBSD::Initialize();
255 #endif
256 #if defined(__APPLE__)
257 SymbolVendorMacOSX::Initialize();
258 ProcessKDP::Initialize();
259 ProcessMachCore::Initialize();
260 #endif
261 //----------------------------------------------------------------------
262 // Platform agnostic plugins
263 //----------------------------------------------------------------------
264 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
265
266 process_gdb_remote::ProcessGDBRemote::Initialize();
267 DynamicLoaderStatic::Initialize();
268
269 // Scan for any system or user LLDB plug-ins
270 PluginManager::Initialize();
271
272 // The process settings need to know about installed plug-ins, so the Settings must be initialized
273 // AFTER PluginManager::Initialize is called.
274
275 Debugger::SettingsInitialize();
276 }
277
InitializeSWIG()278 void SystemInitializerFull::InitializeSWIG()
279 {
280 #if !defined(LLDB_DISABLE_PYTHON)
281 ScriptInterpreterPython::InitializeInterpreter(
282 init_lldb,
283 LLDBSwigPythonBreakpointCallbackFunction,
284 LLDBSwigPythonWatchpointCallbackFunction,
285 LLDBSwigPythonCallTypeScript,
286 LLDBSwigPythonCreateSyntheticProvider,
287 LLDBSwigPythonCreateCommandObject,
288 LLDBSwigPython_CalculateNumChildren,
289 LLDBSwigPython_GetChildAtIndex,
290 LLDBSwigPython_GetIndexOfChildWithName,
291 LLDBSWIGPython_CastPyObjectToSBValue,
292 LLDBSWIGPython_GetValueObjectSPFromSBValue,
293 LLDBSwigPython_UpdateSynthProviderInstance,
294 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
295 LLDBSwigPython_GetValueSynthProviderInstance,
296 LLDBSwigPythonCallCommand,
297 LLDBSwigPythonCallCommandObject,
298 LLDBSwigPythonCallModuleInit,
299 LLDBSWIGPythonCreateOSPlugin,
300 LLDBSWIGPythonRunScriptKeywordProcess,
301 LLDBSWIGPythonRunScriptKeywordThread,
302 LLDBSWIGPythonRunScriptKeywordTarget,
303 LLDBSWIGPythonRunScriptKeywordFrame,
304 LLDBSWIGPythonRunScriptKeywordValue,
305 LLDBSWIGPython_GetDynamicSetting,
306 LLDBSwigPythonCreateScriptedThreadPlan,
307 LLDBSWIGPythonCallThreadPlan);
308 #endif
309 }
310
311 void
Terminate()312 SystemInitializerFull::Terminate()
313 {
314 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
315
316 Debugger::SettingsTerminate();
317
318 // Terminate and unload and loaded system or user LLDB plug-ins
319 PluginManager::Terminate();
320 ABISysV_arm::Terminate();
321 ABISysV_arm64::Terminate();
322 ABISysV_i386::Terminate();
323 ABISysV_x86_64::Terminate();
324 ABISysV_ppc::Terminate();
325 ABISysV_ppc64::Terminate();
326 ABISysV_mips::Terminate();
327 ABISysV_mips64::Terminate();
328 DisassemblerLLVMC::Terminate();
329
330 JITLoaderGDB::Terminate();
331 ProcessElfCore::Terminate();
332 MemoryHistoryASan::Terminate();
333 AddressSanitizerRuntime::Terminate();
334 SymbolVendorELF::Terminate();
335 SymbolFileDWARF::Terminate();
336 SymbolFileSymtab::Terminate();
337 UnwindAssembly_x86::Terminate();
338 UnwindAssemblyInstEmulation::Terminate();
339 EmulateInstructionARM64::Terminate();
340 SymbolFileDWARFDebugMap::Terminate();
341 ItaniumABILanguageRuntime::Terminate();
342
343 #if defined(__APPLE__)
344 ProcessMachCore::Terminate();
345 ProcessKDP::Terminate();
346 SymbolVendorMacOSX::Terminate();
347 #endif
348
349 #if defined(__FreeBSD__)
350 ProcessFreeBSD::Terminate();
351 #endif
352 Debugger::SettingsTerminate();
353
354 platform_gdb_server::PlatformRemoteGDBServer::Terminate();
355 process_gdb_remote::ProcessGDBRemote::Terminate();
356 DynamicLoaderStatic::Terminate();
357
358 // Now shutdown the common parts, in reverse order.
359 SystemInitializerCommon::Terminate();
360 }
361
TerminateSWIG()362 void SystemInitializerFull::TerminateSWIG()
363 {
364
365 }
366