blob: 5b09460fd3fefc5bc1f45e247b9091925398dcdd [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 McCarthy18a9135d2015-10-28 18:21:45 +000079#include "Plugins/Process/Windows/Live/ProcessWindowsLive.h"
Adrian McCarthy27785dd2015-08-24 16:00:51 +000080#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
Zachary Turnerc5b41d62015-10-16 17:52:03 +000092#if PY_MAJOR_VERSION >= 3
93extern "C" PyObject*
94PyInit__lldb(void);
95
96#define LLDBSwigPyInit PyInit__lldb
97
98#else
Zachary Turnere6e2bb32015-03-31 21:03:22 +000099extern "C" void
100init_lldb(void);
101
Zachary Turnerc5b41d62015-10-16 17:52:03 +0000102#define LLDBSwigPyInit init_lldb
103#endif
104
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000105// these are the Pythonic implementations of the required callbacks
106// these are scripting-language specific, which is why they belong here
107// we still need to use function pointers to them instead of relying
108// on linkage-time resolution because the SWIG stuff and this file
109// get built at different times
110extern "C" bool
111LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
112 const char *session_dictionary_name,
113 const lldb::StackFrameSP& sb_frame,
114 const lldb::BreakpointLocationSP& sb_bp_loc);
115
116extern "C" bool
117LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
118 const char *session_dictionary_name,
119 const lldb::StackFrameSP& sb_frame,
120 const lldb::WatchpointSP& sb_wp);
121
122extern "C" bool
123LLDBSwigPythonCallTypeScript (const char *python_function_name,
124 void *session_dictionary,
125 const lldb::ValueObjectSP& valobj_sp,
126 void** pyfunct_wrapper,
127 const lldb::TypeSummaryOptionsSP& options_sp,
128 std::string& retval);
129
130extern "C" void*
131LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
132 const char *session_dictionary_name,
133 const lldb::ValueObjectSP& valobj_sp);
134
135extern "C" void*
136LLDBSwigPythonCreateCommandObject (const char *python_class_name,
137 const char *session_dictionary_name,
138 const lldb::DebuggerSP debugger_sp);
139
140extern "C" void*
141LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
142 const char *session_dictionary_name,
143 const lldb::ThreadPlanSP& thread_plan_sp);
144
145extern "C" bool
146LLDBSWIGPythonCallThreadPlan (void *implementor,
147 const char *method_name,
148 Event *event_sp,
149 bool &got_error);
150
151extern "C" size_t
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000152LLDBSwigPython_CalculateNumChildren (void *implementor, uint32_t max);
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000153
154extern "C" void *
155LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
156
157extern "C" int
158LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
159
160extern "C" void *
161LLDBSWIGPython_CastPyObjectToSBValue (void* data);
162
163extern lldb::ValueObjectSP
164LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
165
166extern "C" bool
167LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
168
169extern "C" bool
170LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
171
172extern "C" void *
173LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
174
175extern "C" bool
176LLDBSwigPythonCallCommand (const char *python_function_name,
177 const char *session_dictionary_name,
178 lldb::DebuggerSP& debugger,
179 const char* args,
180 lldb_private::CommandReturnObject &cmd_retobj,
181 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
182
183extern "C" bool
184LLDBSwigPythonCallCommandObject (void *implementor,
185 lldb::DebuggerSP& debugger,
186 const char* args,
187 lldb_private::CommandReturnObject& cmd_retobj,
188 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
189
190extern "C" bool
191LLDBSwigPythonCallModuleInit (const char *python_module_name,
192 const char *session_dictionary_name,
193 lldb::DebuggerSP& debugger);
194
195extern "C" void*
196LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
197 const char *session_dictionary_name,
198 const lldb::ProcessSP& process_sp);
199
200extern "C" bool
201LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
202 const char* session_dictionary_name,
203 lldb::ProcessSP& process,
204 std::string& output);
205
206extern "C" bool
207LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
208 const char* session_dictionary_name,
209 lldb::ThreadSP& thread,
210 std::string& output);
211
212extern "C" bool
213LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
214 const char* session_dictionary_name,
215 lldb::TargetSP& target,
216 std::string& output);
217
218extern "C" bool
219LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
220 const char* session_dictionary_name,
221 lldb::StackFrameSP& frame,
222 std::string& output);
223
224extern "C" bool
225LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
226 const char* session_dictionary_name,
227 lldb::ValueObjectSP& value,
228 std::string& output);
229
230extern "C" void*
231LLDBSWIGPython_GetDynamicSetting (void* module,
232 const char* setting,
233 const lldb::TargetSP& target_sp);
234
235
236#endif
237
238SystemInitializerFull::SystemInitializerFull()
239{
240}
241
242SystemInitializerFull::~SystemInitializerFull()
243{
244}
245
246void
247SystemInitializerFull::Initialize()
248{
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000249 SystemInitializerCommon::Initialize();
Keno Fischer6e776772015-08-23 09:05:29 +0000250 ScriptInterpreterNone::Initialize();
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000251
252#if !defined(LLDB_DISABLE_PYTHON)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000253 InitializeSWIG();
254
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000255 // ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized
256 // so it can compute the python directory etc, so we need to do this after
257 // SystemInitializerCommon::Initialize().
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000258 ScriptInterpreterPython::Initialize();
259#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000260
261 // Initialize LLVM and Clang
262 llvm::InitializeAllTargets();
263 llvm::InitializeAllAsmPrinters();
264 llvm::InitializeAllTargetMCs();
265 llvm::InitializeAllDisassemblers();
266
Greg Clayton56939cb2015-09-17 22:23:34 +0000267 ClangASTContext::Initialize();
268 GoASTContext::Initialize();
269
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000270 ABIMacOSX_i386::Initialize();
271 ABIMacOSX_arm::Initialize();
272 ABIMacOSX_arm64::Initialize();
Omair Javaid52f825b2015-04-29 10:49:45 +0000273 ABISysV_arm::Initialize();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000274 ABISysV_arm64::Initialize();
Greg Claytonb289cba2015-06-25 17:50:15 +0000275 ABISysV_i386::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000276 ABISysV_x86_64::Initialize();
277 ABISysV_ppc::Initialize();
278 ABISysV_ppc64::Initialize();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000279 ABISysV_mips::Initialize();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000280 ABISysV_mips64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000281 DisassemblerLLVMC::Initialize();
282
283 JITLoaderGDB::Initialize();
284 ProcessElfCore::Initialize();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000285#if defined(_MSC_VER)
286 ProcessWinMiniDump::Initialize();
287#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000288 MemoryHistoryASan::Initialize();
289 AddressSanitizerRuntime::Initialize();
290
291 SymbolVendorELF::Initialize();
292 SymbolFileDWARF::Initialize();
293 SymbolFileSymtab::Initialize();
294 UnwindAssemblyInstEmulation::Initialize();
295 UnwindAssembly_x86::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000296 EmulateInstructionARM64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000297 SymbolFileDWARFDebugMap::Initialize();
298 ItaniumABILanguageRuntime::Initialize();
299 AppleObjCRuntimeV2::Initialize();
300 AppleObjCRuntimeV1::Initialize();
301 SystemRuntimeMacOSX::Initialize();
Colin Riley5ec532a2015-04-09 16:49:25 +0000302 RenderScriptRuntime::Initialize();
Ryan Brown07a1c452015-10-06 20:29:31 +0000303 GoLanguageRuntime::Initialize();
Enrico Granata980c0482015-09-01 18:22:39 +0000304
305 CPlusPlusLanguage::Initialize();
306 ObjCLanguage::Initialize();
307 ObjCPlusPlusLanguage::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000308
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000309#if defined(_MSC_VER)
Adrian McCarthy18a9135d2015-10-28 18:21:45 +0000310 ProcessWindowsLive::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000311#endif
312#if defined(__FreeBSD__)
313 ProcessFreeBSD::Initialize();
314#endif
315#if defined(__APPLE__)
316 SymbolVendorMacOSX::Initialize();
317 ProcessKDP::Initialize();
318 ProcessMachCore::Initialize();
319#endif
320 //----------------------------------------------------------------------
321 // Platform agnostic plugins
322 //----------------------------------------------------------------------
323 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
324
325 process_gdb_remote::ProcessGDBRemote::Initialize();
326 DynamicLoaderStatic::Initialize();
327
328 // Scan for any system or user LLDB plug-ins
329 PluginManager::Initialize();
330
331 // The process settings need to know about installed plug-ins, so the Settings must be initialized
332 // AFTER PluginManager::Initialize is called.
333
334 Debugger::SettingsInitialize();
335}
336
337void SystemInitializerFull::InitializeSWIG()
338{
339#if !defined(LLDB_DISABLE_PYTHON)
340 ScriptInterpreterPython::InitializeInterpreter(
Zachary Turnerc5b41d62015-10-16 17:52:03 +0000341 LLDBSwigPyInit,
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000342 LLDBSwigPythonBreakpointCallbackFunction,
343 LLDBSwigPythonWatchpointCallbackFunction,
344 LLDBSwigPythonCallTypeScript,
345 LLDBSwigPythonCreateSyntheticProvider,
346 LLDBSwigPythonCreateCommandObject,
347 LLDBSwigPython_CalculateNumChildren,
348 LLDBSwigPython_GetChildAtIndex,
349 LLDBSwigPython_GetIndexOfChildWithName,
350 LLDBSWIGPython_CastPyObjectToSBValue,
351 LLDBSWIGPython_GetValueObjectSPFromSBValue,
352 LLDBSwigPython_UpdateSynthProviderInstance,
353 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
354 LLDBSwigPython_GetValueSynthProviderInstance,
355 LLDBSwigPythonCallCommand,
356 LLDBSwigPythonCallCommandObject,
357 LLDBSwigPythonCallModuleInit,
358 LLDBSWIGPythonCreateOSPlugin,
359 LLDBSWIGPythonRunScriptKeywordProcess,
360 LLDBSWIGPythonRunScriptKeywordThread,
361 LLDBSWIGPythonRunScriptKeywordTarget,
362 LLDBSWIGPythonRunScriptKeywordFrame,
363 LLDBSWIGPythonRunScriptKeywordValue,
364 LLDBSWIGPython_GetDynamicSetting,
365 LLDBSwigPythonCreateScriptedThreadPlan,
366 LLDBSWIGPythonCallThreadPlan);
367#endif
368}
369
370void
371SystemInitializerFull::Terminate()
372{
373 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
374
375 Debugger::SettingsTerminate();
376
377 // Terminate and unload and loaded system or user LLDB plug-ins
378 PluginManager::Terminate();
Greg Clayton56939cb2015-09-17 22:23:34 +0000379
380 ClangASTContext::Terminate();
381 GoASTContext::Terminate();
382
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000383 ABIMacOSX_i386::Terminate();
384 ABIMacOSX_arm::Terminate();
385 ABIMacOSX_arm64::Terminate();
Omair Javaid52f825b2015-04-29 10:49:45 +0000386 ABISysV_arm::Terminate();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000387 ABISysV_arm64::Terminate();
Greg Claytonb289cba2015-06-25 17:50:15 +0000388 ABISysV_i386::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000389 ABISysV_x86_64::Terminate();
390 ABISysV_ppc::Terminate();
391 ABISysV_ppc64::Terminate();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000392 ABISysV_mips::Terminate();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000393 ABISysV_mips64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000394 DisassemblerLLVMC::Terminate();
395
396 JITLoaderGDB::Terminate();
397 ProcessElfCore::Terminate();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000398#if defined(_MSC_VER)
399 ProcessWinMiniDump::Terminate();
400#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000401 MemoryHistoryASan::Terminate();
402 AddressSanitizerRuntime::Terminate();
403 SymbolVendorELF::Terminate();
404 SymbolFileDWARF::Terminate();
405 SymbolFileSymtab::Terminate();
406 UnwindAssembly_x86::Terminate();
407 UnwindAssemblyInstEmulation::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000408 EmulateInstructionARM64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000409 SymbolFileDWARFDebugMap::Terminate();
410 ItaniumABILanguageRuntime::Terminate();
411 AppleObjCRuntimeV2::Terminate();
412 AppleObjCRuntimeV1::Terminate();
413 SystemRuntimeMacOSX::Terminate();
Colin Riley5ec532a2015-04-09 16:49:25 +0000414 RenderScriptRuntime::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000415
Enrico Granata980c0482015-09-01 18:22:39 +0000416 CPlusPlusLanguage::Terminate();
417 ObjCLanguage::Terminate();
418 ObjCPlusPlusLanguage::Terminate();
419
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000420#if defined(__APPLE__)
421 ProcessMachCore::Terminate();
422 ProcessKDP::Terminate();
423 SymbolVendorMacOSX::Terminate();
424#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000425
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000426#if defined(__FreeBSD__)
427 ProcessFreeBSD::Terminate();
428#endif
429 Debugger::SettingsTerminate();
430
431 platform_gdb_server::PlatformRemoteGDBServer::Terminate();
432 process_gdb_remote::ProcessGDBRemote::Terminate();
433 DynamicLoaderStatic::Terminate();
434
435 // Now shutdown the common parts, in reverse order.
436 SystemInitializerCommon::Terminate();
437}