blob: d9fbbf99178d037fb0e706efa683455c2e56f28d [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"
Greg Clayton56939cb2015-09-17 22:23:34 +000027#include "lldb/Symbol/ClangASTContext.h"
28#include "lldb/Symbol/GoASTContext.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000029
30#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
31#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
32#include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h"
Omair Javaid52f825b2015-04-29 10:49:45 +000033#include "Plugins/ABI/SysV-arm/ABISysV_arm.h"
Omair Javaidb78e05f2015-04-29 11:52:35 +000034#include "Plugins/ABI/SysV-arm64/ABISysV_arm64.h"
Greg Claytonb289cba2015-06-25 17:50:15 +000035#include "Plugins/ABI/SysV-i386/ABISysV_i386.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000036#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
37#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
38#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
Bhushan D. Attardea8219f22015-06-18 07:02:10 +000039#include "Plugins/ABI/SysV-mips/ABISysV_mips.h"
Bhushan D. Attarde13f54252015-06-19 04:25:07 +000040#include "Plugins/ABI/SysV-mips64/ABISysV_mips64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000041#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
42#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000043#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000044#include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h"
45#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
Enrico Granata980c0482015-09-01 18:22:39 +000046#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
47#include "Plugins/Language/ObjC/ObjCLanguage.h"
48#include "Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000049#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
50#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
51#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Ryan Brown07a1c452015-10-06 20:29:31 +000052#include "Plugins/LanguageRuntime/Go/GoLanguageRuntime.h"
Colin Riley5ec532a2015-04-09 16:49:25 +000053#include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000054#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
55#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
56#include "Plugins/Process/elf-core/ProcessElfCore.h"
57#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
Zachary Turner2c1f46d2015-07-30 20:28:07 +000058#include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000059#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
60#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
61#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
62#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
63#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
64#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
65#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
66
67#if defined(__APPLE__)
68#include "Plugins/Process/mach-core/ProcessMachCore.h"
69#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
70#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
71#endif
72
73#if defined(__FreeBSD__)
74#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
75#endif
76
Zachary Turnere6e2bb32015-03-31 21:03:22 +000077#if defined(_MSC_VER)
78#include "lldb/Host/windows/windows.h"
Adrian McCarthy27785dd2015-08-24 16:00:51 +000079#include "Plugins/Process/Windows/Live/ProcessWindows.h"
80#include "Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000081#endif
82
Zachary Turnere6e2bb32015-03-31 21:03:22 +000083#include "llvm/Support/TargetSelect.h"
84
85#include <string>
86
87using namespace lldb_private;
88
89#ifndef LLDB_DISABLE_PYTHON
90
91// Defined in the SWIG source file
92extern "C" void
93init_lldb(void);
94
95// these are the Pythonic implementations of the required callbacks
96// these are scripting-language specific, which is why they belong here
97// we still need to use function pointers to them instead of relying
98// on linkage-time resolution because the SWIG stuff and this file
99// get built at different times
100extern "C" bool
101LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
102 const char *session_dictionary_name,
103 const lldb::StackFrameSP& sb_frame,
104 const lldb::BreakpointLocationSP& sb_bp_loc);
105
106extern "C" bool
107LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
108 const char *session_dictionary_name,
109 const lldb::StackFrameSP& sb_frame,
110 const lldb::WatchpointSP& sb_wp);
111
112extern "C" bool
113LLDBSwigPythonCallTypeScript (const char *python_function_name,
114 void *session_dictionary,
115 const lldb::ValueObjectSP& valobj_sp,
116 void** pyfunct_wrapper,
117 const lldb::TypeSummaryOptionsSP& options_sp,
118 std::string& retval);
119
120extern "C" void*
121LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
122 const char *session_dictionary_name,
123 const lldb::ValueObjectSP& valobj_sp);
124
125extern "C" void*
126LLDBSwigPythonCreateCommandObject (const char *python_class_name,
127 const char *session_dictionary_name,
128 const lldb::DebuggerSP debugger_sp);
129
130extern "C" void*
131LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
132 const char *session_dictionary_name,
133 const lldb::ThreadPlanSP& thread_plan_sp);
134
135extern "C" bool
136LLDBSWIGPythonCallThreadPlan (void *implementor,
137 const char *method_name,
138 Event *event_sp,
139 bool &got_error);
140
141extern "C" size_t
142LLDBSwigPython_CalculateNumChildren (void *implementor);
143
144extern "C" void *
145LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
146
147extern "C" int
148LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
149
150extern "C" void *
151LLDBSWIGPython_CastPyObjectToSBValue (void* data);
152
153extern lldb::ValueObjectSP
154LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
155
156extern "C" bool
157LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
158
159extern "C" bool
160LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
161
162extern "C" void *
163LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
164
165extern "C" bool
166LLDBSwigPythonCallCommand (const char *python_function_name,
167 const char *session_dictionary_name,
168 lldb::DebuggerSP& debugger,
169 const char* args,
170 lldb_private::CommandReturnObject &cmd_retobj,
171 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
172
173extern "C" bool
174LLDBSwigPythonCallCommandObject (void *implementor,
175 lldb::DebuggerSP& debugger,
176 const char* args,
177 lldb_private::CommandReturnObject& cmd_retobj,
178 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
179
180extern "C" bool
181LLDBSwigPythonCallModuleInit (const char *python_module_name,
182 const char *session_dictionary_name,
183 lldb::DebuggerSP& debugger);
184
185extern "C" void*
186LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
187 const char *session_dictionary_name,
188 const lldb::ProcessSP& process_sp);
189
190extern "C" bool
191LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
192 const char* session_dictionary_name,
193 lldb::ProcessSP& process,
194 std::string& output);
195
196extern "C" bool
197LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
198 const char* session_dictionary_name,
199 lldb::ThreadSP& thread,
200 std::string& output);
201
202extern "C" bool
203LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
204 const char* session_dictionary_name,
205 lldb::TargetSP& target,
206 std::string& output);
207
208extern "C" bool
209LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
210 const char* session_dictionary_name,
211 lldb::StackFrameSP& frame,
212 std::string& output);
213
214extern "C" bool
215LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
216 const char* session_dictionary_name,
217 lldb::ValueObjectSP& value,
218 std::string& output);
219
220extern "C" void*
221LLDBSWIGPython_GetDynamicSetting (void* module,
222 const char* setting,
223 const lldb::TargetSP& target_sp);
224
225
226#endif
227
228SystemInitializerFull::SystemInitializerFull()
229{
230}
231
232SystemInitializerFull::~SystemInitializerFull()
233{
234}
235
236void
237SystemInitializerFull::Initialize()
238{
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000239 SystemInitializerCommon::Initialize();
Keno Fischer6e776772015-08-23 09:05:29 +0000240 ScriptInterpreterNone::Initialize();
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000241
242#if !defined(LLDB_DISABLE_PYTHON)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000243 InitializeSWIG();
244
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000245 // ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized
246 // so it can compute the python directory etc, so we need to do this after
247 // SystemInitializerCommon::Initialize().
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000248 ScriptInterpreterPython::Initialize();
249#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000250
251 // Initialize LLVM and Clang
252 llvm::InitializeAllTargets();
253 llvm::InitializeAllAsmPrinters();
254 llvm::InitializeAllTargetMCs();
255 llvm::InitializeAllDisassemblers();
256
Greg Clayton56939cb2015-09-17 22:23:34 +0000257 ClangASTContext::Initialize();
258 GoASTContext::Initialize();
259
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000260 ABIMacOSX_i386::Initialize();
261 ABIMacOSX_arm::Initialize();
262 ABIMacOSX_arm64::Initialize();
Omair Javaid52f825b2015-04-29 10:49:45 +0000263 ABISysV_arm::Initialize();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000264 ABISysV_arm64::Initialize();
Greg Claytonb289cba2015-06-25 17:50:15 +0000265 ABISysV_i386::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000266 ABISysV_x86_64::Initialize();
267 ABISysV_ppc::Initialize();
268 ABISysV_ppc64::Initialize();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000269 ABISysV_mips::Initialize();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000270 ABISysV_mips64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000271 DisassemblerLLVMC::Initialize();
272
273 JITLoaderGDB::Initialize();
274 ProcessElfCore::Initialize();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000275#if defined(_MSC_VER)
276 ProcessWinMiniDump::Initialize();
277#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000278 MemoryHistoryASan::Initialize();
279 AddressSanitizerRuntime::Initialize();
280
281 SymbolVendorELF::Initialize();
282 SymbolFileDWARF::Initialize();
283 SymbolFileSymtab::Initialize();
284 UnwindAssemblyInstEmulation::Initialize();
285 UnwindAssembly_x86::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000286 EmulateInstructionARM64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000287 SymbolFileDWARFDebugMap::Initialize();
288 ItaniumABILanguageRuntime::Initialize();
289 AppleObjCRuntimeV2::Initialize();
290 AppleObjCRuntimeV1::Initialize();
291 SystemRuntimeMacOSX::Initialize();
Colin Riley5ec532a2015-04-09 16:49:25 +0000292 RenderScriptRuntime::Initialize();
Ryan Brown07a1c452015-10-06 20:29:31 +0000293 GoLanguageRuntime::Initialize();
Enrico Granata980c0482015-09-01 18:22:39 +0000294
295 CPlusPlusLanguage::Initialize();
296 ObjCLanguage::Initialize();
297 ObjCPlusPlusLanguage::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000298
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000299#if defined(_MSC_VER)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000300 ProcessWindows::Initialize();
301#endif
302#if defined(__FreeBSD__)
303 ProcessFreeBSD::Initialize();
304#endif
305#if defined(__APPLE__)
306 SymbolVendorMacOSX::Initialize();
307 ProcessKDP::Initialize();
308 ProcessMachCore::Initialize();
309#endif
310 //----------------------------------------------------------------------
311 // Platform agnostic plugins
312 //----------------------------------------------------------------------
313 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
314
315 process_gdb_remote::ProcessGDBRemote::Initialize();
316 DynamicLoaderStatic::Initialize();
317
318 // Scan for any system or user LLDB plug-ins
319 PluginManager::Initialize();
320
321 // The process settings need to know about installed plug-ins, so the Settings must be initialized
322 // AFTER PluginManager::Initialize is called.
323
324 Debugger::SettingsInitialize();
325}
326
327void SystemInitializerFull::InitializeSWIG()
328{
329#if !defined(LLDB_DISABLE_PYTHON)
330 ScriptInterpreterPython::InitializeInterpreter(
331 init_lldb,
332 LLDBSwigPythonBreakpointCallbackFunction,
333 LLDBSwigPythonWatchpointCallbackFunction,
334 LLDBSwigPythonCallTypeScript,
335 LLDBSwigPythonCreateSyntheticProvider,
336 LLDBSwigPythonCreateCommandObject,
337 LLDBSwigPython_CalculateNumChildren,
338 LLDBSwigPython_GetChildAtIndex,
339 LLDBSwigPython_GetIndexOfChildWithName,
340 LLDBSWIGPython_CastPyObjectToSBValue,
341 LLDBSWIGPython_GetValueObjectSPFromSBValue,
342 LLDBSwigPython_UpdateSynthProviderInstance,
343 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
344 LLDBSwigPython_GetValueSynthProviderInstance,
345 LLDBSwigPythonCallCommand,
346 LLDBSwigPythonCallCommandObject,
347 LLDBSwigPythonCallModuleInit,
348 LLDBSWIGPythonCreateOSPlugin,
349 LLDBSWIGPythonRunScriptKeywordProcess,
350 LLDBSWIGPythonRunScriptKeywordThread,
351 LLDBSWIGPythonRunScriptKeywordTarget,
352 LLDBSWIGPythonRunScriptKeywordFrame,
353 LLDBSWIGPythonRunScriptKeywordValue,
354 LLDBSWIGPython_GetDynamicSetting,
355 LLDBSwigPythonCreateScriptedThreadPlan,
356 LLDBSWIGPythonCallThreadPlan);
357#endif
358}
359
360void
361SystemInitializerFull::Terminate()
362{
363 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
364
365 Debugger::SettingsTerminate();
366
367 // Terminate and unload and loaded system or user LLDB plug-ins
368 PluginManager::Terminate();
Greg Clayton56939cb2015-09-17 22:23:34 +0000369
370 ClangASTContext::Terminate();
371 GoASTContext::Terminate();
372
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000373 ABIMacOSX_i386::Terminate();
374 ABIMacOSX_arm::Terminate();
375 ABIMacOSX_arm64::Terminate();
Omair Javaid52f825b2015-04-29 10:49:45 +0000376 ABISysV_arm::Terminate();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000377 ABISysV_arm64::Terminate();
Greg Claytonb289cba2015-06-25 17:50:15 +0000378 ABISysV_i386::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000379 ABISysV_x86_64::Terminate();
380 ABISysV_ppc::Terminate();
381 ABISysV_ppc64::Terminate();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000382 ABISysV_mips::Terminate();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000383 ABISysV_mips64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000384 DisassemblerLLVMC::Terminate();
385
386 JITLoaderGDB::Terminate();
387 ProcessElfCore::Terminate();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000388#if defined(_MSC_VER)
389 ProcessWinMiniDump::Terminate();
390#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000391 MemoryHistoryASan::Terminate();
392 AddressSanitizerRuntime::Terminate();
393 SymbolVendorELF::Terminate();
394 SymbolFileDWARF::Terminate();
395 SymbolFileSymtab::Terminate();
396 UnwindAssembly_x86::Terminate();
397 UnwindAssemblyInstEmulation::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000398 EmulateInstructionARM64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000399 SymbolFileDWARFDebugMap::Terminate();
400 ItaniumABILanguageRuntime::Terminate();
401 AppleObjCRuntimeV2::Terminate();
402 AppleObjCRuntimeV1::Terminate();
403 SystemRuntimeMacOSX::Terminate();
Colin Riley5ec532a2015-04-09 16:49:25 +0000404 RenderScriptRuntime::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000405
Enrico Granata980c0482015-09-01 18:22:39 +0000406 CPlusPlusLanguage::Terminate();
407 ObjCLanguage::Terminate();
408 ObjCPlusPlusLanguage::Terminate();
409
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000410#if defined(__APPLE__)
411 ProcessMachCore::Terminate();
412 ProcessKDP::Terminate();
413 SymbolVendorMacOSX::Terminate();
414#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000415
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000416#if defined(__FreeBSD__)
417 ProcessFreeBSD::Terminate();
418#endif
419 Debugger::SettingsTerminate();
420
421 platform_gdb_server::PlatformRemoteGDBServer::Terminate();
422 process_gdb_remote::ProcessGDBRemote::Terminate();
423 DynamicLoaderStatic::Terminate();
424
425 // Now shutdown the common parts, in reverse order.
426 SystemInitializerCommon::Terminate();
427}