1 //===-- SystemInitializerFull.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 #if !defined(LLDB_DISABLE_PYTHON)
11 #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
14 #include "lldb/API/SystemInitializerFull.h"
16 #include "lldb/API/SBCommandInterpreter.h"
18 #if !defined(LLDB_DISABLE_PYTHON)
19 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
22 #include "lldb/Core/Debugger.h"
23 #include "lldb/Core/Timer.h"
24 #include "lldb/Host/Host.h"
25 #include "lldb/Initialization/SystemInitializerCommon.h"
26 #include "lldb/Interpreter/CommandInterpreter.h"
27 #include "lldb/Symbol/ClangASTContext.h"
28 #include "lldb/Symbol/GoASTContext.h"
30 #include "Plugins/ABI/SysV-arm/ABISysV_arm.h"
31 #include "Plugins/ABI/SysV-arm64/ABISysV_arm64.h"
32 #include "Plugins/ABI/SysV-i386/ABISysV_i386.h"
33 #include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
34 #include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
35 #include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
36 #include "Plugins/ABI/SysV-mips/ABISysV_mips.h"
37 #include "Plugins/ABI/SysV-mips64/ABISysV_mips64.h"
38 #include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
39 #include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
40 #include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
41 #include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h"
42 #include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
43 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
44 #include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
45 #include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
46 #include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
47 #include "Plugins/Process/elf-core/ProcessElfCore.h"
48 #include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
49 #include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h"
50 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
51 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
52 #include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
53 #include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
54 #include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
55 #include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
57 #if defined(__APPLE__)
58 #include "Plugins/Process/mach-core/ProcessMachCore.h"
59 #include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
60 #include "Plugins/Platform/MacOSX/PlatformAppleTVSimulator.h"
61 #include "Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.h"
62 #include "Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h"
63 #include "Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h"
66 #if defined(__FreeBSD__)
67 #include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
71 #include "lldb/Host/windows/windows.h"
72 #include "Plugins/Process/Windows/Live/ProcessWindowsLive.h"
73 #include "Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.h"
76 #include "llvm/Support/TargetSelect.h"
80 using namespace lldb_private;
82 #ifndef LLDB_DISABLE_PYTHON
84 // Defined in the SWIG source file
85 #if PY_MAJOR_VERSION >= 3
89 #define LLDBSwigPyInit PyInit__lldb
95 #define LLDBSwigPyInit init_lldb
98 // these are the Pythonic implementations of the required callbacks
99 // these are scripting-language specific, which is why they belong here
100 // we still need to use function pointers to them instead of relying
101 // on linkage-time resolution because the SWIG stuff and this file
102 // get built at different times
104 LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
105 const char *session_dictionary_name,
106 const lldb::StackFrameSP& sb_frame,
107 const lldb::BreakpointLocationSP& sb_bp_loc);
110 LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
111 const char *session_dictionary_name,
112 const lldb::StackFrameSP& sb_frame,
113 const lldb::WatchpointSP& sb_wp);
116 LLDBSwigPythonCallTypeScript (const char *python_function_name,
117 void *session_dictionary,
118 const lldb::ValueObjectSP& valobj_sp,
119 void** pyfunct_wrapper,
120 const lldb::TypeSummaryOptionsSP& options_sp,
121 std::string& retval);
124 LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
125 const char *session_dictionary_name,
126 const lldb::ValueObjectSP& valobj_sp);
129 LLDBSwigPythonCreateCommandObject (const char *python_class_name,
130 const char *session_dictionary_name,
131 const lldb::DebuggerSP debugger_sp);
134 LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
135 const char *session_dictionary_name,
136 const lldb::ThreadPlanSP& thread_plan_sp);
139 LLDBSWIGPythonCallThreadPlan (void *implementor,
140 const char *method_name,
145 LLDBSwigPython_CalculateNumChildren (void *implementor, uint32_t max);
148 LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
151 LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
154 LLDBSWIGPython_CastPyObjectToSBValue (void* data);
156 extern lldb::ValueObjectSP
157 LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
160 LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
163 LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
166 LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
169 LLDBSwigPythonCallCommand (const char *python_function_name,
170 const char *session_dictionary_name,
171 lldb::DebuggerSP& debugger,
173 lldb_private::CommandReturnObject &cmd_retobj,
174 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
177 LLDBSwigPythonCallCommandObject (void *implementor,
178 lldb::DebuggerSP& debugger,
180 lldb_private::CommandReturnObject& cmd_retobj,
181 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
184 LLDBSwigPythonCallModuleInit (const char *python_module_name,
185 const char *session_dictionary_name,
186 lldb::DebuggerSP& debugger);
189 LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
190 const char *session_dictionary_name,
191 const lldb::ProcessSP& process_sp);
194 LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
195 const char* session_dictionary_name,
196 lldb::ProcessSP& process,
197 std::string& output);
200 LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
201 const char* session_dictionary_name,
202 lldb::ThreadSP& thread,
203 std::string& output);
206 LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
207 const char* session_dictionary_name,
208 lldb::TargetSP& target,
209 std::string& output);
212 LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
213 const char* session_dictionary_name,
214 lldb::StackFrameSP& frame,
215 std::string& output);
218 LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
219 const char* session_dictionary_name,
220 lldb::ValueObjectSP& value,
221 std::string& output);
224 LLDBSWIGPython_GetDynamicSetting (void* module,
226 const lldb::TargetSP& target_sp);
231 SystemInitializerFull::SystemInitializerFull()
235 SystemInitializerFull::~SystemInitializerFull()
240 SystemInitializerFull::Initialize()
242 SystemInitializerCommon::Initialize();
243 ScriptInterpreterNone::Initialize();
245 #if !defined(LLDB_DISABLE_PYTHON)
248 // ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized
249 // so it can compute the python directory etc, so we need to do this after
250 // SystemInitializerCommon::Initialize().
251 ScriptInterpreterPython::Initialize();
254 // Initialize LLVM and Clang
255 llvm::InitializeAllTargets();
256 llvm::InitializeAllAsmPrinters();
257 llvm::InitializeAllTargetMCs();
258 llvm::InitializeAllDisassemblers();
260 ClangASTContext::Initialize();
261 GoASTContext::Initialize();
263 ABISysV_arm::Initialize();
264 ABISysV_arm64::Initialize();
265 ABISysV_i386::Initialize();
266 ABISysV_x86_64::Initialize();
267 ABISysV_ppc::Initialize();
268 ABISysV_ppc64::Initialize();
269 ABISysV_mips::Initialize();
270 ABISysV_mips64::Initialize();
271 DisassemblerLLVMC::Initialize();
273 JITLoaderGDB::Initialize();
274 ProcessElfCore::Initialize();
275 #if defined(_MSC_VER)
276 ProcessWinMiniDump::Initialize();
278 MemoryHistoryASan::Initialize();
279 AddressSanitizerRuntime::Initialize();
281 SymbolVendorELF::Initialize();
282 SymbolFileDWARF::Initialize();
283 SymbolFileSymtab::Initialize();
284 UnwindAssemblyInstEmulation::Initialize();
285 UnwindAssembly_x86::Initialize();
286 EmulateInstructionARM64::Initialize();
287 SymbolFileDWARFDebugMap::Initialize();
288 ItaniumABILanguageRuntime::Initialize();
290 CPlusPlusLanguage::Initialize();
292 #if defined(_MSC_VER)
293 ProcessWindowsLive::Initialize();
295 #if defined(__FreeBSD__)
296 ProcessFreeBSD::Initialize();
298 #if defined(__APPLE__)
299 SymbolVendorMacOSX::Initialize();
300 ProcessKDP::Initialize();
301 ProcessMachCore::Initialize();
302 PlatformAppleTVSimulator::Initialize();
303 PlatformAppleWatchSimulator::Initialize();
304 PlatformRemoteAppleTV::Initialize();
305 PlatformRemoteAppleWatch::Initialize();
307 //----------------------------------------------------------------------
308 // Platform agnostic plugins
309 //----------------------------------------------------------------------
310 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
312 process_gdb_remote::ProcessGDBRemote::Initialize();
313 DynamicLoaderStatic::Initialize();
315 // Scan for any system or user LLDB plug-ins
316 PluginManager::Initialize();
318 // The process settings need to know about installed plug-ins, so the Settings must be initialized
319 // AFTER PluginManager::Initialize is called.
321 Debugger::SettingsInitialize();
324 void SystemInitializerFull::InitializeSWIG()
326 #if !defined(LLDB_DISABLE_PYTHON)
327 ScriptInterpreterPython::InitializeInterpreter(
329 LLDBSwigPythonBreakpointCallbackFunction,
330 LLDBSwigPythonWatchpointCallbackFunction,
331 LLDBSwigPythonCallTypeScript,
332 LLDBSwigPythonCreateSyntheticProvider,
333 LLDBSwigPythonCreateCommandObject,
334 LLDBSwigPython_CalculateNumChildren,
335 LLDBSwigPython_GetChildAtIndex,
336 LLDBSwigPython_GetIndexOfChildWithName,
337 LLDBSWIGPython_CastPyObjectToSBValue,
338 LLDBSWIGPython_GetValueObjectSPFromSBValue,
339 LLDBSwigPython_UpdateSynthProviderInstance,
340 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
341 LLDBSwigPython_GetValueSynthProviderInstance,
342 LLDBSwigPythonCallCommand,
343 LLDBSwigPythonCallCommandObject,
344 LLDBSwigPythonCallModuleInit,
345 LLDBSWIGPythonCreateOSPlugin,
346 LLDBSWIGPythonRunScriptKeywordProcess,
347 LLDBSWIGPythonRunScriptKeywordThread,
348 LLDBSWIGPythonRunScriptKeywordTarget,
349 LLDBSWIGPythonRunScriptKeywordFrame,
350 LLDBSWIGPythonRunScriptKeywordValue,
351 LLDBSWIGPython_GetDynamicSetting,
352 LLDBSwigPythonCreateScriptedThreadPlan,
353 LLDBSWIGPythonCallThreadPlan);
358 SystemInitializerFull::Terminate()
360 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
362 Debugger::SettingsTerminate();
364 // Terminate and unload and loaded system or user LLDB plug-ins
365 PluginManager::Terminate();
367 ClangASTContext::Terminate();
368 GoASTContext::Terminate();
370 ABISysV_arm::Terminate();
371 ABISysV_arm64::Terminate();
372 ABISysV_i386::Terminate();
373 ABISysV_x86_64::Terminate();
374 ABISysV_ppc::Terminate();
375 ABISysV_ppc64::Terminate();
376 ABISysV_mips::Terminate();
377 ABISysV_mips64::Terminate();
378 DisassemblerLLVMC::Terminate();
380 JITLoaderGDB::Terminate();
381 ProcessElfCore::Terminate();
382 #if defined(_MSC_VER)
383 ProcessWinMiniDump::Terminate();
385 MemoryHistoryASan::Terminate();
386 AddressSanitizerRuntime::Terminate();
387 SymbolVendorELF::Terminate();
388 SymbolFileDWARF::Terminate();
389 SymbolFileSymtab::Terminate();
390 UnwindAssembly_x86::Terminate();
391 UnwindAssemblyInstEmulation::Terminate();
392 EmulateInstructionARM64::Terminate();
393 SymbolFileDWARFDebugMap::Terminate();
394 ItaniumABILanguageRuntime::Terminate();
396 CPlusPlusLanguage::Terminate();
398 #if defined(__APPLE__)
399 ProcessMachCore::Terminate();
400 ProcessKDP::Terminate();
401 SymbolVendorMacOSX::Terminate();
402 PlatformAppleTVSimulator::Terminate();
403 PlatformAppleWatchSimulator::Terminate();
404 PlatformRemoteAppleTV::Terminate();
405 PlatformRemoteAppleWatch::Terminate();
408 #if defined(__FreeBSD__)
409 ProcessFreeBSD::Terminate();
411 Debugger::SettingsTerminate();
413 platform_gdb_server::PlatformRemoteGDBServer::Terminate();
414 process_gdb_remote::ProcessGDBRemote::Terminate();
415 DynamicLoaderStatic::Terminate();
417 // Now shutdown the common parts, in reverse order.
418 SystemInitializerCommon::Terminate();