blob: 5711d0fc584569ae0c00bd05898ef99a6e77af6b [file] [log] [blame]
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001//===-- 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
Zachary Turner2c1f46d2015-07-30 20:28:07 +000010#if !defined(LLDB_DISABLE_PYTHON)
11#include "Plugins/ScriptInterpreter/Python/lldb-python.h"
12#endif
13
Zachary Turnere6e2bb32015-03-31 21:03:22 +000014#include "lldb/API/SystemInitializerFull.h"
15
Zachary Turner2c1f46d2015-07-30 20:28:07 +000016#include "lldb/API/SBCommandInterpreter.h"
17
18#if !defined(LLDB_DISABLE_PYTHON)
19#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
20#endif
21
Zachary Turnere6e2bb32015-03-31 21:03:22 +000022#include "lldb/Core/Debugger.h"
23#include "lldb/Core/Timer.h"
24#include "lldb/Host/Host.h"
25#include "lldb/Initialization/SystemInitializerCommon.h"
Zachary Turner2c1f46d2015-07-30 20:28:07 +000026#include "lldb/Interpreter/CommandInterpreter.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000027
28#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
29#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
30#include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h"
Omair Javaid52f825b2015-04-29 10:49:45 +000031#include "Plugins/ABI/SysV-arm/ABISysV_arm.h"
Omair Javaidb78e05f2015-04-29 11:52:35 +000032#include "Plugins/ABI/SysV-arm64/ABISysV_arm64.h"
Greg Claytonb289cba2015-06-25 17:50:15 +000033#include "Plugins/ABI/SysV-i386/ABISysV_i386.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000034#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
35#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
36#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
Bhushan D. Attardea8219f22015-06-18 07:02:10 +000037#include "Plugins/ABI/SysV-mips/ABISysV_mips.h"
Bhushan D. Attarde13f54252015-06-19 04:25:07 +000038#include "Plugins/ABI/SysV-mips64/ABISysV_mips64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000039#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
40#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000041#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000042#include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h"
43#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
Enrico Granata980c0482015-09-01 18:22:39 +000044#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
45#include "Plugins/Language/ObjC/ObjCLanguage.h"
46#include "Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000047#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
48#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
49#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Colin Riley5ec532a2015-04-09 16:49:25 +000050#include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000051#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
52#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
53#include "Plugins/Process/elf-core/ProcessElfCore.h"
54#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
Zachary Turner2c1f46d2015-07-30 20:28:07 +000055#include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000056#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
57#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
58#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
59#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
60#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
61#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
62#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
63
64#if defined(__APPLE__)
65#include "Plugins/Process/mach-core/ProcessMachCore.h"
66#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
67#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
68#endif
69
70#if defined(__FreeBSD__)
71#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
72#endif
73
Zachary Turnere6e2bb32015-03-31 21:03:22 +000074#if defined(_MSC_VER)
75#include "lldb/Host/windows/windows.h"
Adrian McCarthy27785dd2015-08-24 16:00:51 +000076#include "Plugins/Process/Windows/Live/ProcessWindows.h"
77#include "Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000078#endif
79
Zachary Turnere6e2bb32015-03-31 21:03:22 +000080#include "llvm/Support/TargetSelect.h"
81
82#include <string>
83
84using namespace lldb_private;
85
86#ifndef LLDB_DISABLE_PYTHON
87
88// Defined in the SWIG source file
89extern "C" void
90init_lldb(void);
91
92// these are the Pythonic implementations of the required callbacks
93// these are scripting-language specific, which is why they belong here
94// we still need to use function pointers to them instead of relying
95// on linkage-time resolution because the SWIG stuff and this file
96// get built at different times
97extern "C" bool
98LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
99 const char *session_dictionary_name,
100 const lldb::StackFrameSP& sb_frame,
101 const lldb::BreakpointLocationSP& sb_bp_loc);
102
103extern "C" bool
104LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
105 const char *session_dictionary_name,
106 const lldb::StackFrameSP& sb_frame,
107 const lldb::WatchpointSP& sb_wp);
108
109extern "C" bool
110LLDBSwigPythonCallTypeScript (const char *python_function_name,
111 void *session_dictionary,
112 const lldb::ValueObjectSP& valobj_sp,
113 void** pyfunct_wrapper,
114 const lldb::TypeSummaryOptionsSP& options_sp,
115 std::string& retval);
116
117extern "C" void*
118LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
119 const char *session_dictionary_name,
120 const lldb::ValueObjectSP& valobj_sp);
121
122extern "C" void*
123LLDBSwigPythonCreateCommandObject (const char *python_class_name,
124 const char *session_dictionary_name,
125 const lldb::DebuggerSP debugger_sp);
126
127extern "C" void*
128LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
129 const char *session_dictionary_name,
130 const lldb::ThreadPlanSP& thread_plan_sp);
131
132extern "C" bool
133LLDBSWIGPythonCallThreadPlan (void *implementor,
134 const char *method_name,
135 Event *event_sp,
136 bool &got_error);
137
138extern "C" size_t
139LLDBSwigPython_CalculateNumChildren (void *implementor);
140
141extern "C" void *
142LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
143
144extern "C" int
145LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
146
147extern "C" void *
148LLDBSWIGPython_CastPyObjectToSBValue (void* data);
149
150extern lldb::ValueObjectSP
151LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
152
153extern "C" bool
154LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
155
156extern "C" bool
157LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
158
159extern "C" void *
160LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
161
162extern "C" bool
163LLDBSwigPythonCallCommand (const char *python_function_name,
164 const char *session_dictionary_name,
165 lldb::DebuggerSP& debugger,
166 const char* args,
167 lldb_private::CommandReturnObject &cmd_retobj,
168 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
169
170extern "C" bool
171LLDBSwigPythonCallCommandObject (void *implementor,
172 lldb::DebuggerSP& debugger,
173 const char* args,
174 lldb_private::CommandReturnObject& cmd_retobj,
175 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
176
177extern "C" bool
178LLDBSwigPythonCallModuleInit (const char *python_module_name,
179 const char *session_dictionary_name,
180 lldb::DebuggerSP& debugger);
181
182extern "C" void*
183LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
184 const char *session_dictionary_name,
185 const lldb::ProcessSP& process_sp);
186
187extern "C" bool
188LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
189 const char* session_dictionary_name,
190 lldb::ProcessSP& process,
191 std::string& output);
192
193extern "C" bool
194LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
195 const char* session_dictionary_name,
196 lldb::ThreadSP& thread,
197 std::string& output);
198
199extern "C" bool
200LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
201 const char* session_dictionary_name,
202 lldb::TargetSP& target,
203 std::string& output);
204
205extern "C" bool
206LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
207 const char* session_dictionary_name,
208 lldb::StackFrameSP& frame,
209 std::string& output);
210
211extern "C" bool
212LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
213 const char* session_dictionary_name,
214 lldb::ValueObjectSP& value,
215 std::string& output);
216
217extern "C" void*
218LLDBSWIGPython_GetDynamicSetting (void* module,
219 const char* setting,
220 const lldb::TargetSP& target_sp);
221
222
223#endif
224
225SystemInitializerFull::SystemInitializerFull()
226{
227}
228
229SystemInitializerFull::~SystemInitializerFull()
230{
231}
232
233void
234SystemInitializerFull::Initialize()
235{
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000236 SystemInitializerCommon::Initialize();
Keno Fischer6e776772015-08-23 09:05:29 +0000237 ScriptInterpreterNone::Initialize();
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000238
239#if !defined(LLDB_DISABLE_PYTHON)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000240 InitializeSWIG();
241
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000242 // ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized
243 // so it can compute the python directory etc, so we need to do this after
244 // SystemInitializerCommon::Initialize().
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000245 ScriptInterpreterPython::Initialize();
246#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000247
248 // Initialize LLVM and Clang
249 llvm::InitializeAllTargets();
250 llvm::InitializeAllAsmPrinters();
251 llvm::InitializeAllTargetMCs();
252 llvm::InitializeAllDisassemblers();
253
254 ABIMacOSX_i386::Initialize();
255 ABIMacOSX_arm::Initialize();
256 ABIMacOSX_arm64::Initialize();
Omair Javaid52f825b2015-04-29 10:49:45 +0000257 ABISysV_arm::Initialize();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000258 ABISysV_arm64::Initialize();
Greg Claytonb289cba2015-06-25 17:50:15 +0000259 ABISysV_i386::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000260 ABISysV_x86_64::Initialize();
261 ABISysV_ppc::Initialize();
262 ABISysV_ppc64::Initialize();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000263 ABISysV_mips::Initialize();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000264 ABISysV_mips64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000265 DisassemblerLLVMC::Initialize();
266
267 JITLoaderGDB::Initialize();
268 ProcessElfCore::Initialize();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000269#if defined(_MSC_VER)
270 ProcessWinMiniDump::Initialize();
271#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000272 MemoryHistoryASan::Initialize();
273 AddressSanitizerRuntime::Initialize();
274
275 SymbolVendorELF::Initialize();
276 SymbolFileDWARF::Initialize();
277 SymbolFileSymtab::Initialize();
278 UnwindAssemblyInstEmulation::Initialize();
279 UnwindAssembly_x86::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000280 EmulateInstructionARM64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000281 SymbolFileDWARFDebugMap::Initialize();
282 ItaniumABILanguageRuntime::Initialize();
283 AppleObjCRuntimeV2::Initialize();
284 AppleObjCRuntimeV1::Initialize();
285 SystemRuntimeMacOSX::Initialize();
Colin Riley5ec532a2015-04-09 16:49:25 +0000286 RenderScriptRuntime::Initialize();
Enrico Granata980c0482015-09-01 18:22:39 +0000287
288 CPlusPlusLanguage::Initialize();
289 ObjCLanguage::Initialize();
290 ObjCPlusPlusLanguage::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000291
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000292#if defined(_MSC_VER)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000293 ProcessWindows::Initialize();
294#endif
295#if defined(__FreeBSD__)
296 ProcessFreeBSD::Initialize();
297#endif
298#if defined(__APPLE__)
299 SymbolVendorMacOSX::Initialize();
300 ProcessKDP::Initialize();
301 ProcessMachCore::Initialize();
302#endif
303 //----------------------------------------------------------------------
304 // Platform agnostic plugins
305 //----------------------------------------------------------------------
306 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
307
308 process_gdb_remote::ProcessGDBRemote::Initialize();
309 DynamicLoaderStatic::Initialize();
310
311 // Scan for any system or user LLDB plug-ins
312 PluginManager::Initialize();
313
314 // The process settings need to know about installed plug-ins, so the Settings must be initialized
315 // AFTER PluginManager::Initialize is called.
316
317 Debugger::SettingsInitialize();
318}
319
320void SystemInitializerFull::InitializeSWIG()
321{
322#if !defined(LLDB_DISABLE_PYTHON)
323 ScriptInterpreterPython::InitializeInterpreter(
324 init_lldb,
325 LLDBSwigPythonBreakpointCallbackFunction,
326 LLDBSwigPythonWatchpointCallbackFunction,
327 LLDBSwigPythonCallTypeScript,
328 LLDBSwigPythonCreateSyntheticProvider,
329 LLDBSwigPythonCreateCommandObject,
330 LLDBSwigPython_CalculateNumChildren,
331 LLDBSwigPython_GetChildAtIndex,
332 LLDBSwigPython_GetIndexOfChildWithName,
333 LLDBSWIGPython_CastPyObjectToSBValue,
334 LLDBSWIGPython_GetValueObjectSPFromSBValue,
335 LLDBSwigPython_UpdateSynthProviderInstance,
336 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
337 LLDBSwigPython_GetValueSynthProviderInstance,
338 LLDBSwigPythonCallCommand,
339 LLDBSwigPythonCallCommandObject,
340 LLDBSwigPythonCallModuleInit,
341 LLDBSWIGPythonCreateOSPlugin,
342 LLDBSWIGPythonRunScriptKeywordProcess,
343 LLDBSWIGPythonRunScriptKeywordThread,
344 LLDBSWIGPythonRunScriptKeywordTarget,
345 LLDBSWIGPythonRunScriptKeywordFrame,
346 LLDBSWIGPythonRunScriptKeywordValue,
347 LLDBSWIGPython_GetDynamicSetting,
348 LLDBSwigPythonCreateScriptedThreadPlan,
349 LLDBSWIGPythonCallThreadPlan);
350#endif
351}
352
353void
354SystemInitializerFull::Terminate()
355{
356 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
357
358 Debugger::SettingsTerminate();
359
360 // Terminate and unload and loaded system or user LLDB plug-ins
361 PluginManager::Terminate();
362 ABIMacOSX_i386::Terminate();
363 ABIMacOSX_arm::Terminate();
364 ABIMacOSX_arm64::Terminate();
Omair Javaid52f825b2015-04-29 10:49:45 +0000365 ABISysV_arm::Terminate();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000366 ABISysV_arm64::Terminate();
Greg Claytonb289cba2015-06-25 17:50:15 +0000367 ABISysV_i386::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000368 ABISysV_x86_64::Terminate();
369 ABISysV_ppc::Terminate();
370 ABISysV_ppc64::Terminate();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000371 ABISysV_mips::Terminate();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000372 ABISysV_mips64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000373 DisassemblerLLVMC::Terminate();
374
375 JITLoaderGDB::Terminate();
376 ProcessElfCore::Terminate();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000377#if defined(_MSC_VER)
378 ProcessWinMiniDump::Terminate();
379#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000380 MemoryHistoryASan::Terminate();
381 AddressSanitizerRuntime::Terminate();
382 SymbolVendorELF::Terminate();
383 SymbolFileDWARF::Terminate();
384 SymbolFileSymtab::Terminate();
385 UnwindAssembly_x86::Terminate();
386 UnwindAssemblyInstEmulation::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000387 EmulateInstructionARM64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000388 SymbolFileDWARFDebugMap::Terminate();
389 ItaniumABILanguageRuntime::Terminate();
390 AppleObjCRuntimeV2::Terminate();
391 AppleObjCRuntimeV1::Terminate();
392 SystemRuntimeMacOSX::Terminate();
Colin Riley5ec532a2015-04-09 16:49:25 +0000393 RenderScriptRuntime::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000394
Enrico Granata980c0482015-09-01 18:22:39 +0000395 CPlusPlusLanguage::Terminate();
396 ObjCLanguage::Terminate();
397 ObjCPlusPlusLanguage::Terminate();
398
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000399#if defined(__APPLE__)
400 ProcessMachCore::Terminate();
401 ProcessKDP::Terminate();
402 SymbolVendorMacOSX::Terminate();
403#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000404
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000405#if defined(__FreeBSD__)
406 ProcessFreeBSD::Terminate();
407#endif
408 Debugger::SettingsTerminate();
409
410 platform_gdb_server::PlatformRemoteGDBServer::Terminate();
411 process_gdb_remote::ProcessGDBRemote::Terminate();
412 DynamicLoaderStatic::Terminate();
413
414 // Now shutdown the common parts, in reverse order.
415 SystemInitializerCommon::Terminate();
416}