blob: 8218eb3f84e7c535037eae8c30998fda482fc3c7 [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"
Adrian McCarthyc96516f2015-08-03 23:01:51 +000074#include "Plugins/Process/win-minidump/ProcessWinMiniDump.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000075#endif
76
Zachary Turnere6e2bb32015-03-31 21:03:22 +000077#include "llvm/Support/TargetSelect.h"
78
79#include <string>
80
81using namespace lldb_private;
82
83#ifndef LLDB_DISABLE_PYTHON
84
85// Defined in the SWIG source file
86extern "C" void
87init_lldb(void);
88
89// these are the Pythonic implementations of the required callbacks
90// these are scripting-language specific, which is why they belong here
91// we still need to use function pointers to them instead of relying
92// on linkage-time resolution because the SWIG stuff and this file
93// get built at different times
94extern "C" bool
95LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
96 const char *session_dictionary_name,
97 const lldb::StackFrameSP& sb_frame,
98 const lldb::BreakpointLocationSP& sb_bp_loc);
99
100extern "C" bool
101LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
102 const char *session_dictionary_name,
103 const lldb::StackFrameSP& sb_frame,
104 const lldb::WatchpointSP& sb_wp);
105
106extern "C" bool
107LLDBSwigPythonCallTypeScript (const char *python_function_name,
108 void *session_dictionary,
109 const lldb::ValueObjectSP& valobj_sp,
110 void** pyfunct_wrapper,
111 const lldb::TypeSummaryOptionsSP& options_sp,
112 std::string& retval);
113
114extern "C" void*
115LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
116 const char *session_dictionary_name,
117 const lldb::ValueObjectSP& valobj_sp);
118
119extern "C" void*
120LLDBSwigPythonCreateCommandObject (const char *python_class_name,
121 const char *session_dictionary_name,
122 const lldb::DebuggerSP debugger_sp);
123
124extern "C" void*
125LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
126 const char *session_dictionary_name,
127 const lldb::ThreadPlanSP& thread_plan_sp);
128
129extern "C" bool
130LLDBSWIGPythonCallThreadPlan (void *implementor,
131 const char *method_name,
132 Event *event_sp,
133 bool &got_error);
134
135extern "C" size_t
136LLDBSwigPython_CalculateNumChildren (void *implementor);
137
138extern "C" void *
139LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
140
141extern "C" int
142LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
143
144extern "C" void *
145LLDBSWIGPython_CastPyObjectToSBValue (void* data);
146
147extern lldb::ValueObjectSP
148LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
149
150extern "C" bool
151LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
152
153extern "C" bool
154LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
155
156extern "C" void *
157LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
158
159extern "C" bool
160LLDBSwigPythonCallCommand (const char *python_function_name,
161 const char *session_dictionary_name,
162 lldb::DebuggerSP& debugger,
163 const char* args,
164 lldb_private::CommandReturnObject &cmd_retobj,
165 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
166
167extern "C" bool
168LLDBSwigPythonCallCommandObject (void *implementor,
169 lldb::DebuggerSP& debugger,
170 const char* args,
171 lldb_private::CommandReturnObject& cmd_retobj,
172 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
173
174extern "C" bool
175LLDBSwigPythonCallModuleInit (const char *python_module_name,
176 const char *session_dictionary_name,
177 lldb::DebuggerSP& debugger);
178
179extern "C" void*
180LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
181 const char *session_dictionary_name,
182 const lldb::ProcessSP& process_sp);
183
184extern "C" bool
185LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
186 const char* session_dictionary_name,
187 lldb::ProcessSP& process,
188 std::string& output);
189
190extern "C" bool
191LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
192 const char* session_dictionary_name,
193 lldb::ThreadSP& thread,
194 std::string& output);
195
196extern "C" bool
197LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
198 const char* session_dictionary_name,
199 lldb::TargetSP& target,
200 std::string& output);
201
202extern "C" bool
203LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
204 const char* session_dictionary_name,
205 lldb::StackFrameSP& frame,
206 std::string& output);
207
208extern "C" bool
209LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
210 const char* session_dictionary_name,
211 lldb::ValueObjectSP& value,
212 std::string& output);
213
214extern "C" void*
215LLDBSWIGPython_GetDynamicSetting (void* module,
216 const char* setting,
217 const lldb::TargetSP& target_sp);
218
219
220#endif
221
222SystemInitializerFull::SystemInitializerFull()
223{
224}
225
226SystemInitializerFull::~SystemInitializerFull()
227{
228}
229
230void
231SystemInitializerFull::Initialize()
232{
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000233 SystemInitializerCommon::Initialize();
234
235#if !defined(LLDB_DISABLE_PYTHON)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000236 InitializeSWIG();
237
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000238 // ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized
239 // so it can compute the python directory etc, so we need to do this after
240 // SystemInitializerCommon::Initialize().
241 ScriptInterpreterNone::Initialize();
242 ScriptInterpreterPython::Initialize();
243#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000244
245 // Initialize LLVM and Clang
246 llvm::InitializeAllTargets();
247 llvm::InitializeAllAsmPrinters();
248 llvm::InitializeAllTargetMCs();
249 llvm::InitializeAllDisassemblers();
250
251 ABIMacOSX_i386::Initialize();
252 ABIMacOSX_arm::Initialize();
253 ABIMacOSX_arm64::Initialize();
Omair Javaid52f825b2015-04-29 10:49:45 +0000254 ABISysV_arm::Initialize();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000255 ABISysV_arm64::Initialize();
Greg Claytonb289cba2015-06-25 17:50:15 +0000256 ABISysV_i386::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000257 ABISysV_x86_64::Initialize();
258 ABISysV_ppc::Initialize();
259 ABISysV_ppc64::Initialize();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000260 ABISysV_mips::Initialize();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000261 ABISysV_mips64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000262 DisassemblerLLVMC::Initialize();
263
264 JITLoaderGDB::Initialize();
265 ProcessElfCore::Initialize();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000266#if defined(_MSC_VER)
267 ProcessWinMiniDump::Initialize();
268#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000269 MemoryHistoryASan::Initialize();
270 AddressSanitizerRuntime::Initialize();
271
272 SymbolVendorELF::Initialize();
273 SymbolFileDWARF::Initialize();
274 SymbolFileSymtab::Initialize();
275 UnwindAssemblyInstEmulation::Initialize();
276 UnwindAssembly_x86::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000277 EmulateInstructionARM64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000278 SymbolFileDWARFDebugMap::Initialize();
279 ItaniumABILanguageRuntime::Initialize();
280 AppleObjCRuntimeV2::Initialize();
281 AppleObjCRuntimeV1::Initialize();
282 SystemRuntimeMacOSX::Initialize();
Colin Riley5ec532a2015-04-09 16:49:25 +0000283 RenderScriptRuntime::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000284
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000285#if defined(_MSC_VER)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000286 ProcessWindows::Initialize();
287#endif
288#if defined(__FreeBSD__)
289 ProcessFreeBSD::Initialize();
290#endif
291#if defined(__APPLE__)
292 SymbolVendorMacOSX::Initialize();
293 ProcessKDP::Initialize();
294 ProcessMachCore::Initialize();
295#endif
296 //----------------------------------------------------------------------
297 // Platform agnostic plugins
298 //----------------------------------------------------------------------
299 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
300
301 process_gdb_remote::ProcessGDBRemote::Initialize();
302 DynamicLoaderStatic::Initialize();
303
304 // Scan for any system or user LLDB plug-ins
305 PluginManager::Initialize();
306
307 // The process settings need to know about installed plug-ins, so the Settings must be initialized
308 // AFTER PluginManager::Initialize is called.
309
310 Debugger::SettingsInitialize();
311}
312
313void SystemInitializerFull::InitializeSWIG()
314{
315#if !defined(LLDB_DISABLE_PYTHON)
316 ScriptInterpreterPython::InitializeInterpreter(
317 init_lldb,
318 LLDBSwigPythonBreakpointCallbackFunction,
319 LLDBSwigPythonWatchpointCallbackFunction,
320 LLDBSwigPythonCallTypeScript,
321 LLDBSwigPythonCreateSyntheticProvider,
322 LLDBSwigPythonCreateCommandObject,
323 LLDBSwigPython_CalculateNumChildren,
324 LLDBSwigPython_GetChildAtIndex,
325 LLDBSwigPython_GetIndexOfChildWithName,
326 LLDBSWIGPython_CastPyObjectToSBValue,
327 LLDBSWIGPython_GetValueObjectSPFromSBValue,
328 LLDBSwigPython_UpdateSynthProviderInstance,
329 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
330 LLDBSwigPython_GetValueSynthProviderInstance,
331 LLDBSwigPythonCallCommand,
332 LLDBSwigPythonCallCommandObject,
333 LLDBSwigPythonCallModuleInit,
334 LLDBSWIGPythonCreateOSPlugin,
335 LLDBSWIGPythonRunScriptKeywordProcess,
336 LLDBSWIGPythonRunScriptKeywordThread,
337 LLDBSWIGPythonRunScriptKeywordTarget,
338 LLDBSWIGPythonRunScriptKeywordFrame,
339 LLDBSWIGPythonRunScriptKeywordValue,
340 LLDBSWIGPython_GetDynamicSetting,
341 LLDBSwigPythonCreateScriptedThreadPlan,
342 LLDBSWIGPythonCallThreadPlan);
343#endif
344}
345
346void
347SystemInitializerFull::Terminate()
348{
349 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
350
351 Debugger::SettingsTerminate();
352
353 // Terminate and unload and loaded system or user LLDB plug-ins
354 PluginManager::Terminate();
355 ABIMacOSX_i386::Terminate();
356 ABIMacOSX_arm::Terminate();
357 ABIMacOSX_arm64::Terminate();
Omair Javaid52f825b2015-04-29 10:49:45 +0000358 ABISysV_arm::Terminate();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000359 ABISysV_arm64::Terminate();
Greg Claytonb289cba2015-06-25 17:50:15 +0000360 ABISysV_i386::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000361 ABISysV_x86_64::Terminate();
362 ABISysV_ppc::Terminate();
363 ABISysV_ppc64::Terminate();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000364 ABISysV_mips::Terminate();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000365 ABISysV_mips64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000366 DisassemblerLLVMC::Terminate();
367
368 JITLoaderGDB::Terminate();
369 ProcessElfCore::Terminate();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000370#if defined(_MSC_VER)
371 ProcessWinMiniDump::Terminate();
372#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000373 MemoryHistoryASan::Terminate();
374 AddressSanitizerRuntime::Terminate();
375 SymbolVendorELF::Terminate();
376 SymbolFileDWARF::Terminate();
377 SymbolFileSymtab::Terminate();
378 UnwindAssembly_x86::Terminate();
379 UnwindAssemblyInstEmulation::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000380 EmulateInstructionARM64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000381 SymbolFileDWARFDebugMap::Terminate();
382 ItaniumABILanguageRuntime::Terminate();
383 AppleObjCRuntimeV2::Terminate();
384 AppleObjCRuntimeV1::Terminate();
385 SystemRuntimeMacOSX::Terminate();
Colin Riley5ec532a2015-04-09 16:49:25 +0000386 RenderScriptRuntime::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000387
388#if defined(__APPLE__)
389 ProcessMachCore::Terminate();
390 ProcessKDP::Terminate();
391 SymbolVendorMacOSX::Terminate();
392#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000393
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000394#if defined(__FreeBSD__)
395 ProcessFreeBSD::Terminate();
396#endif
397 Debugger::SettingsTerminate();
398
399 platform_gdb_server::PlatformRemoteGDBServer::Terminate();
400 process_gdb_remote::ProcessGDBRemote::Terminate();
401 DynamicLoaderStatic::Terminate();
402
403 // Now shutdown the common parts, in reverse order.
404 SystemInitializerCommon::Terminate();
405}