blob: cccd9876be93c485fa65706a5ccefaa7fcc9ffd0 [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"
44#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
45#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
46#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Colin Riley5ec532a2015-04-09 16:49:25 +000047#include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000048#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
49#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
50#include "Plugins/Process/elf-core/ProcessElfCore.h"
51#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
Zachary Turner2c1f46d2015-07-30 20:28:07 +000052#include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000053#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
54#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
55#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
56#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
57#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
58#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
59#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
60
61#if defined(__APPLE__)
62#include "Plugins/Process/mach-core/ProcessMachCore.h"
63#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
64#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
65#endif
66
67#if defined(__FreeBSD__)
68#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
69#endif
70
Zachary Turnere6e2bb32015-03-31 21:03:22 +000071#if defined(_MSC_VER)
72#include "lldb/Host/windows/windows.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000073#include "Plugins/Process/Windows/ProcessWindows.h"
74#endif
75
Zachary Turnere6e2bb32015-03-31 21:03:22 +000076#include "llvm/Support/TargetSelect.h"
77
78#include <string>
79
80using namespace lldb_private;
81
82#ifndef LLDB_DISABLE_PYTHON
83
84// Defined in the SWIG source file
85extern "C" void
86init_lldb(void);
87
88// these are the Pythonic implementations of the required callbacks
89// these are scripting-language specific, which is why they belong here
90// we still need to use function pointers to them instead of relying
91// on linkage-time resolution because the SWIG stuff and this file
92// get built at different times
93extern "C" bool
94LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
95 const char *session_dictionary_name,
96 const lldb::StackFrameSP& sb_frame,
97 const lldb::BreakpointLocationSP& sb_bp_loc);
98
99extern "C" bool
100LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
101 const char *session_dictionary_name,
102 const lldb::StackFrameSP& sb_frame,
103 const lldb::WatchpointSP& sb_wp);
104
105extern "C" bool
106LLDBSwigPythonCallTypeScript (const char *python_function_name,
107 void *session_dictionary,
108 const lldb::ValueObjectSP& valobj_sp,
109 void** pyfunct_wrapper,
110 const lldb::TypeSummaryOptionsSP& options_sp,
111 std::string& retval);
112
113extern "C" void*
114LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
115 const char *session_dictionary_name,
116 const lldb::ValueObjectSP& valobj_sp);
117
118extern "C" void*
119LLDBSwigPythonCreateCommandObject (const char *python_class_name,
120 const char *session_dictionary_name,
121 const lldb::DebuggerSP debugger_sp);
122
123extern "C" void*
124LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
125 const char *session_dictionary_name,
126 const lldb::ThreadPlanSP& thread_plan_sp);
127
128extern "C" bool
129LLDBSWIGPythonCallThreadPlan (void *implementor,
130 const char *method_name,
131 Event *event_sp,
132 bool &got_error);
133
134extern "C" size_t
135LLDBSwigPython_CalculateNumChildren (void *implementor);
136
137extern "C" void *
138LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
139
140extern "C" int
141LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
142
143extern "C" void *
144LLDBSWIGPython_CastPyObjectToSBValue (void* data);
145
146extern lldb::ValueObjectSP
147LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
148
149extern "C" bool
150LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
151
152extern "C" bool
153LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
154
155extern "C" void *
156LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
157
158extern "C" bool
159LLDBSwigPythonCallCommand (const char *python_function_name,
160 const char *session_dictionary_name,
161 lldb::DebuggerSP& debugger,
162 const char* args,
163 lldb_private::CommandReturnObject &cmd_retobj,
164 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
165
166extern "C" bool
167LLDBSwigPythonCallCommandObject (void *implementor,
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
174LLDBSwigPythonCallModuleInit (const char *python_module_name,
175 const char *session_dictionary_name,
176 lldb::DebuggerSP& debugger);
177
178extern "C" void*
179LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
180 const char *session_dictionary_name,
181 const lldb::ProcessSP& process_sp);
182
183extern "C" bool
184LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
185 const char* session_dictionary_name,
186 lldb::ProcessSP& process,
187 std::string& output);
188
189extern "C" bool
190LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
191 const char* session_dictionary_name,
192 lldb::ThreadSP& thread,
193 std::string& output);
194
195extern "C" bool
196LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
197 const char* session_dictionary_name,
198 lldb::TargetSP& target,
199 std::string& output);
200
201extern "C" bool
202LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
203 const char* session_dictionary_name,
204 lldb::StackFrameSP& frame,
205 std::string& output);
206
207extern "C" bool
208LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
209 const char* session_dictionary_name,
210 lldb::ValueObjectSP& value,
211 std::string& output);
212
213extern "C" void*
214LLDBSWIGPython_GetDynamicSetting (void* module,
215 const char* setting,
216 const lldb::TargetSP& target_sp);
217
218
219#endif
220
221SystemInitializerFull::SystemInitializerFull()
222{
223}
224
225SystemInitializerFull::~SystemInitializerFull()
226{
227}
228
229void
230SystemInitializerFull::Initialize()
231{
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000232 SystemInitializerCommon::Initialize();
233
234#if !defined(LLDB_DISABLE_PYTHON)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000235 InitializeSWIG();
236
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000237 // ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized
238 // so it can compute the python directory etc, so we need to do this after
239 // SystemInitializerCommon::Initialize().
240 ScriptInterpreterNone::Initialize();
241 ScriptInterpreterPython::Initialize();
242#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000243
244 // Initialize LLVM and Clang
245 llvm::InitializeAllTargets();
246 llvm::InitializeAllAsmPrinters();
247 llvm::InitializeAllTargetMCs();
248 llvm::InitializeAllDisassemblers();
249
250 ABIMacOSX_i386::Initialize();
251 ABIMacOSX_arm::Initialize();
252 ABIMacOSX_arm64::Initialize();
Omair Javaid52f825b2015-04-29 10:49:45 +0000253 ABISysV_arm::Initialize();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000254 ABISysV_arm64::Initialize();
Greg Claytonb289cba2015-06-25 17:50:15 +0000255 ABISysV_i386::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000256 ABISysV_x86_64::Initialize();
257 ABISysV_ppc::Initialize();
258 ABISysV_ppc64::Initialize();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000259 ABISysV_mips::Initialize();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000260 ABISysV_mips64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000261 DisassemblerLLVMC::Initialize();
262
263 JITLoaderGDB::Initialize();
264 ProcessElfCore::Initialize();
265 MemoryHistoryASan::Initialize();
266 AddressSanitizerRuntime::Initialize();
267
268 SymbolVendorELF::Initialize();
269 SymbolFileDWARF::Initialize();
270 SymbolFileSymtab::Initialize();
271 UnwindAssemblyInstEmulation::Initialize();
272 UnwindAssembly_x86::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000273 EmulateInstructionARM64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000274 SymbolFileDWARFDebugMap::Initialize();
275 ItaniumABILanguageRuntime::Initialize();
276 AppleObjCRuntimeV2::Initialize();
277 AppleObjCRuntimeV1::Initialize();
278 SystemRuntimeMacOSX::Initialize();
Colin Riley5ec532a2015-04-09 16:49:25 +0000279 RenderScriptRuntime::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000280
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000281#if defined(_MSC_VER)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000282 ProcessWindows::Initialize();
283#endif
284#if defined(__FreeBSD__)
285 ProcessFreeBSD::Initialize();
286#endif
287#if defined(__APPLE__)
288 SymbolVendorMacOSX::Initialize();
289 ProcessKDP::Initialize();
290 ProcessMachCore::Initialize();
291#endif
292 //----------------------------------------------------------------------
293 // Platform agnostic plugins
294 //----------------------------------------------------------------------
295 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
296
297 process_gdb_remote::ProcessGDBRemote::Initialize();
298 DynamicLoaderStatic::Initialize();
299
300 // Scan for any system or user LLDB plug-ins
301 PluginManager::Initialize();
302
303 // The process settings need to know about installed plug-ins, so the Settings must be initialized
304 // AFTER PluginManager::Initialize is called.
305
306 Debugger::SettingsInitialize();
307}
308
309void SystemInitializerFull::InitializeSWIG()
310{
311#if !defined(LLDB_DISABLE_PYTHON)
312 ScriptInterpreterPython::InitializeInterpreter(
313 init_lldb,
314 LLDBSwigPythonBreakpointCallbackFunction,
315 LLDBSwigPythonWatchpointCallbackFunction,
316 LLDBSwigPythonCallTypeScript,
317 LLDBSwigPythonCreateSyntheticProvider,
318 LLDBSwigPythonCreateCommandObject,
319 LLDBSwigPython_CalculateNumChildren,
320 LLDBSwigPython_GetChildAtIndex,
321 LLDBSwigPython_GetIndexOfChildWithName,
322 LLDBSWIGPython_CastPyObjectToSBValue,
323 LLDBSWIGPython_GetValueObjectSPFromSBValue,
324 LLDBSwigPython_UpdateSynthProviderInstance,
325 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
326 LLDBSwigPython_GetValueSynthProviderInstance,
327 LLDBSwigPythonCallCommand,
328 LLDBSwigPythonCallCommandObject,
329 LLDBSwigPythonCallModuleInit,
330 LLDBSWIGPythonCreateOSPlugin,
331 LLDBSWIGPythonRunScriptKeywordProcess,
332 LLDBSWIGPythonRunScriptKeywordThread,
333 LLDBSWIGPythonRunScriptKeywordTarget,
334 LLDBSWIGPythonRunScriptKeywordFrame,
335 LLDBSWIGPythonRunScriptKeywordValue,
336 LLDBSWIGPython_GetDynamicSetting,
337 LLDBSwigPythonCreateScriptedThreadPlan,
338 LLDBSWIGPythonCallThreadPlan);
339#endif
340}
341
342void
343SystemInitializerFull::Terminate()
344{
345 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
346
347 Debugger::SettingsTerminate();
348
349 // Terminate and unload and loaded system or user LLDB plug-ins
350 PluginManager::Terminate();
351 ABIMacOSX_i386::Terminate();
352 ABIMacOSX_arm::Terminate();
353 ABIMacOSX_arm64::Terminate();
Omair Javaid52f825b2015-04-29 10:49:45 +0000354 ABISysV_arm::Terminate();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000355 ABISysV_arm64::Terminate();
Greg Claytonb289cba2015-06-25 17:50:15 +0000356 ABISysV_i386::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000357 ABISysV_x86_64::Terminate();
358 ABISysV_ppc::Terminate();
359 ABISysV_ppc64::Terminate();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000360 ABISysV_mips::Terminate();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000361 ABISysV_mips64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000362 DisassemblerLLVMC::Terminate();
363
364 JITLoaderGDB::Terminate();
365 ProcessElfCore::Terminate();
366 MemoryHistoryASan::Terminate();
367 AddressSanitizerRuntime::Terminate();
368 SymbolVendorELF::Terminate();
369 SymbolFileDWARF::Terminate();
370 SymbolFileSymtab::Terminate();
371 UnwindAssembly_x86::Terminate();
372 UnwindAssemblyInstEmulation::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000373 EmulateInstructionARM64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000374 SymbolFileDWARFDebugMap::Terminate();
375 ItaniumABILanguageRuntime::Terminate();
376 AppleObjCRuntimeV2::Terminate();
377 AppleObjCRuntimeV1::Terminate();
378 SystemRuntimeMacOSX::Terminate();
Colin Riley5ec532a2015-04-09 16:49:25 +0000379 RenderScriptRuntime::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000380
381#if defined(__APPLE__)
382 ProcessMachCore::Terminate();
383 ProcessKDP::Terminate();
384 SymbolVendorMacOSX::Terminate();
385#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000386
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000387#if defined(__FreeBSD__)
388 ProcessFreeBSD::Terminate();
389#endif
390 Debugger::SettingsTerminate();
391
392 platform_gdb_server::PlatformRemoteGDBServer::Terminate();
393 process_gdb_remote::ProcessGDBRemote::Terminate();
394 DynamicLoaderStatic::Terminate();
395
396 // Now shutdown the common parts, in reverse order.
397 SystemInitializerCommon::Terminate();
398}