blob: 52357a38a8ae1190b02b81cd18fc4ad42da06ea1 [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
10#include "lldb/API/SystemInitializerFull.h"
11
12#include "lldb/Core/Debugger.h"
13#include "lldb/Core/Timer.h"
14#include "lldb/Host/Host.h"
15#include "lldb/Initialization/SystemInitializerCommon.h"
16
17#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
18#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
19#include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h"
Omair Javaid52f825b2015-04-29 10:49:45 +000020#include "Plugins/ABI/SysV-arm/ABISysV_arm.h"
Omair Javaidb78e05f2015-04-29 11:52:35 +000021#include "Plugins/ABI/SysV-arm64/ABISysV_arm64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000022#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
23#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
24#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
Bhushan D. Attardea8219f22015-06-18 07:02:10 +000025#include "Plugins/ABI/SysV-mips/ABISysV_mips.h"
Bhushan D. Attarde13f54252015-06-19 04:25:07 +000026#include "Plugins/ABI/SysV-mips64/ABISysV_mips64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000027#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
28#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000029#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000030#include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h"
31#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
32#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
33#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
34#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Colin Riley5ec532a2015-04-09 16:49:25 +000035#include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000036#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
37#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
38#include "Plugins/Process/elf-core/ProcessElfCore.h"
39#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
40#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
41#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
42#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
43#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
44#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
45#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
46#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
47
48#if defined(__APPLE__)
49#include "Plugins/Process/mach-core/ProcessMachCore.h"
50#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
51#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
52#endif
53
54#if defined(__FreeBSD__)
55#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
56#endif
57
Zachary Turnere6e2bb32015-03-31 21:03:22 +000058#if defined(_MSC_VER)
59#include "lldb/Host/windows/windows.h"
60#include "Plugins/Process/Windows/DynamicLoaderWindows.h"
61#include "Plugins/Process/Windows/ProcessWindows.h"
62#endif
63
64#if !defined(LLDB_DISABLE_PYTHON)
65#include "lldb/Interpreter/ScriptInterpreterPython.h"
66#endif
67
68#include "llvm/Support/TargetSelect.h"
69
70#include <string>
71
72using namespace lldb_private;
73
74#ifndef LLDB_DISABLE_PYTHON
75
76// Defined in the SWIG source file
77extern "C" void
78init_lldb(void);
79
80// these are the Pythonic implementations of the required callbacks
81// these are scripting-language specific, which is why they belong here
82// we still need to use function pointers to them instead of relying
83// on linkage-time resolution because the SWIG stuff and this file
84// get built at different times
85extern "C" bool
86LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
87 const char *session_dictionary_name,
88 const lldb::StackFrameSP& sb_frame,
89 const lldb::BreakpointLocationSP& sb_bp_loc);
90
91extern "C" bool
92LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
93 const char *session_dictionary_name,
94 const lldb::StackFrameSP& sb_frame,
95 const lldb::WatchpointSP& sb_wp);
96
97extern "C" bool
98LLDBSwigPythonCallTypeScript (const char *python_function_name,
99 void *session_dictionary,
100 const lldb::ValueObjectSP& valobj_sp,
101 void** pyfunct_wrapper,
102 const lldb::TypeSummaryOptionsSP& options_sp,
103 std::string& retval);
104
105extern "C" void*
106LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
107 const char *session_dictionary_name,
108 const lldb::ValueObjectSP& valobj_sp);
109
110extern "C" void*
111LLDBSwigPythonCreateCommandObject (const char *python_class_name,
112 const char *session_dictionary_name,
113 const lldb::DebuggerSP debugger_sp);
114
115extern "C" void*
116LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
117 const char *session_dictionary_name,
118 const lldb::ThreadPlanSP& thread_plan_sp);
119
120extern "C" bool
121LLDBSWIGPythonCallThreadPlan (void *implementor,
122 const char *method_name,
123 Event *event_sp,
124 bool &got_error);
125
126extern "C" size_t
127LLDBSwigPython_CalculateNumChildren (void *implementor);
128
129extern "C" void *
130LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
131
132extern "C" int
133LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
134
135extern "C" void *
136LLDBSWIGPython_CastPyObjectToSBValue (void* data);
137
138extern lldb::ValueObjectSP
139LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
140
141extern "C" bool
142LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
143
144extern "C" bool
145LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
146
147extern "C" void *
148LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
149
150extern "C" bool
151LLDBSwigPythonCallCommand (const char *python_function_name,
152 const char *session_dictionary_name,
153 lldb::DebuggerSP& debugger,
154 const char* args,
155 lldb_private::CommandReturnObject &cmd_retobj,
156 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
157
158extern "C" bool
159LLDBSwigPythonCallCommandObject (void *implementor,
160 lldb::DebuggerSP& debugger,
161 const char* args,
162 lldb_private::CommandReturnObject& cmd_retobj,
163 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
164
165extern "C" bool
166LLDBSwigPythonCallModuleInit (const char *python_module_name,
167 const char *session_dictionary_name,
168 lldb::DebuggerSP& debugger);
169
170extern "C" void*
171LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
172 const char *session_dictionary_name,
173 const lldb::ProcessSP& process_sp);
174
175extern "C" bool
176LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
177 const char* session_dictionary_name,
178 lldb::ProcessSP& process,
179 std::string& output);
180
181extern "C" bool
182LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
183 const char* session_dictionary_name,
184 lldb::ThreadSP& thread,
185 std::string& output);
186
187extern "C" bool
188LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
189 const char* session_dictionary_name,
190 lldb::TargetSP& target,
191 std::string& output);
192
193extern "C" bool
194LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
195 const char* session_dictionary_name,
196 lldb::StackFrameSP& frame,
197 std::string& output);
198
199extern "C" bool
200LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
201 const char* session_dictionary_name,
202 lldb::ValueObjectSP& value,
203 std::string& output);
204
205extern "C" void*
206LLDBSWIGPython_GetDynamicSetting (void* module,
207 const char* setting,
208 const lldb::TargetSP& target_sp);
209
210
211#endif
212
213SystemInitializerFull::SystemInitializerFull()
214{
215}
216
217SystemInitializerFull::~SystemInitializerFull()
218{
219}
220
221void
222SystemInitializerFull::Initialize()
223{
224 InitializeSWIG();
225
226 SystemInitializerCommon::Initialize();
227
228 // Initialize LLVM and Clang
229 llvm::InitializeAllTargets();
230 llvm::InitializeAllAsmPrinters();
231 llvm::InitializeAllTargetMCs();
232 llvm::InitializeAllDisassemblers();
233
234 ABIMacOSX_i386::Initialize();
235 ABIMacOSX_arm::Initialize();
236 ABIMacOSX_arm64::Initialize();
Omair Javaid52f825b2015-04-29 10:49:45 +0000237 ABISysV_arm::Initialize();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000238 ABISysV_arm64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000239 ABISysV_x86_64::Initialize();
240 ABISysV_ppc::Initialize();
241 ABISysV_ppc64::Initialize();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000242 ABISysV_mips::Initialize();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000243 ABISysV_mips64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000244 DisassemblerLLVMC::Initialize();
245
246 JITLoaderGDB::Initialize();
247 ProcessElfCore::Initialize();
248 MemoryHistoryASan::Initialize();
249 AddressSanitizerRuntime::Initialize();
250
251 SymbolVendorELF::Initialize();
252 SymbolFileDWARF::Initialize();
253 SymbolFileSymtab::Initialize();
254 UnwindAssemblyInstEmulation::Initialize();
255 UnwindAssembly_x86::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000256 EmulateInstructionARM64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000257 SymbolFileDWARFDebugMap::Initialize();
258 ItaniumABILanguageRuntime::Initialize();
259 AppleObjCRuntimeV2::Initialize();
260 AppleObjCRuntimeV1::Initialize();
261 SystemRuntimeMacOSX::Initialize();
Colin Riley5ec532a2015-04-09 16:49:25 +0000262 RenderScriptRuntime::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000263
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000264#if defined(_MSC_VER)
265 DynamicLoaderWindows::Initialize();
266 ProcessWindows::Initialize();
267#endif
268#if defined(__FreeBSD__)
269 ProcessFreeBSD::Initialize();
270#endif
271#if defined(__APPLE__)
272 SymbolVendorMacOSX::Initialize();
273 ProcessKDP::Initialize();
274 ProcessMachCore::Initialize();
275#endif
276 //----------------------------------------------------------------------
277 // Platform agnostic plugins
278 //----------------------------------------------------------------------
279 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
280
281 process_gdb_remote::ProcessGDBRemote::Initialize();
282 DynamicLoaderStatic::Initialize();
283
284 // Scan for any system or user LLDB plug-ins
285 PluginManager::Initialize();
286
287 // The process settings need to know about installed plug-ins, so the Settings must be initialized
288 // AFTER PluginManager::Initialize is called.
289
290 Debugger::SettingsInitialize();
291}
292
293void SystemInitializerFull::InitializeSWIG()
294{
295#if !defined(LLDB_DISABLE_PYTHON)
296 ScriptInterpreterPython::InitializeInterpreter(
297 init_lldb,
298 LLDBSwigPythonBreakpointCallbackFunction,
299 LLDBSwigPythonWatchpointCallbackFunction,
300 LLDBSwigPythonCallTypeScript,
301 LLDBSwigPythonCreateSyntheticProvider,
302 LLDBSwigPythonCreateCommandObject,
303 LLDBSwigPython_CalculateNumChildren,
304 LLDBSwigPython_GetChildAtIndex,
305 LLDBSwigPython_GetIndexOfChildWithName,
306 LLDBSWIGPython_CastPyObjectToSBValue,
307 LLDBSWIGPython_GetValueObjectSPFromSBValue,
308 LLDBSwigPython_UpdateSynthProviderInstance,
309 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
310 LLDBSwigPython_GetValueSynthProviderInstance,
311 LLDBSwigPythonCallCommand,
312 LLDBSwigPythonCallCommandObject,
313 LLDBSwigPythonCallModuleInit,
314 LLDBSWIGPythonCreateOSPlugin,
315 LLDBSWIGPythonRunScriptKeywordProcess,
316 LLDBSWIGPythonRunScriptKeywordThread,
317 LLDBSWIGPythonRunScriptKeywordTarget,
318 LLDBSWIGPythonRunScriptKeywordFrame,
319 LLDBSWIGPythonRunScriptKeywordValue,
320 LLDBSWIGPython_GetDynamicSetting,
321 LLDBSwigPythonCreateScriptedThreadPlan,
322 LLDBSWIGPythonCallThreadPlan);
323#endif
324}
325
326void
327SystemInitializerFull::Terminate()
328{
329 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
330
331 Debugger::SettingsTerminate();
332
333 // Terminate and unload and loaded system or user LLDB plug-ins
334 PluginManager::Terminate();
335 ABIMacOSX_i386::Terminate();
336 ABIMacOSX_arm::Terminate();
337 ABIMacOSX_arm64::Terminate();
Omair Javaid52f825b2015-04-29 10:49:45 +0000338 ABISysV_arm::Terminate();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000339 ABISysV_arm64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000340 ABISysV_x86_64::Terminate();
341 ABISysV_ppc::Terminate();
342 ABISysV_ppc64::Terminate();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000343 ABISysV_mips::Terminate();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000344 ABISysV_mips64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000345 DisassemblerLLVMC::Terminate();
346
347 JITLoaderGDB::Terminate();
348 ProcessElfCore::Terminate();
349 MemoryHistoryASan::Terminate();
350 AddressSanitizerRuntime::Terminate();
351 SymbolVendorELF::Terminate();
352 SymbolFileDWARF::Terminate();
353 SymbolFileSymtab::Terminate();
354 UnwindAssembly_x86::Terminate();
355 UnwindAssemblyInstEmulation::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000356 EmulateInstructionARM64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000357 SymbolFileDWARFDebugMap::Terminate();
358 ItaniumABILanguageRuntime::Terminate();
359 AppleObjCRuntimeV2::Terminate();
360 AppleObjCRuntimeV1::Terminate();
361 SystemRuntimeMacOSX::Terminate();
Colin Riley5ec532a2015-04-09 16:49:25 +0000362 RenderScriptRuntime::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000363
364#if defined(__APPLE__)
365 ProcessMachCore::Terminate();
366 ProcessKDP::Terminate();
367 SymbolVendorMacOSX::Terminate();
368#endif
369#if defined(_MSC_VER)
370 DynamicLoaderWindows::Terminate();
371#endif
372
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000373#if defined(__FreeBSD__)
374 ProcessFreeBSD::Terminate();
375#endif
376 Debugger::SettingsTerminate();
377
378 platform_gdb_server::PlatformRemoteGDBServer::Terminate();
379 process_gdb_remote::ProcessGDBRemote::Terminate();
380 DynamicLoaderStatic::Terminate();
381
382 // Now shutdown the common parts, in reverse order.
383 SystemInitializerCommon::Terminate();
384}
385
386void SystemInitializerFull::TerminateSWIG()
387{
388
389}