blob: f74fd5d251d7c6b49a7072418160397fe426f2d1 [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
58#if defined(__linux__)
59#include "Plugins/Process/Linux/ProcessLinux.h"
60#endif
61
62#if defined(_MSC_VER)
63#include "lldb/Host/windows/windows.h"
64#include "Plugins/Process/Windows/DynamicLoaderWindows.h"
65#include "Plugins/Process/Windows/ProcessWindows.h"
66#endif
67
68#if !defined(LLDB_DISABLE_PYTHON)
69#include "lldb/Interpreter/ScriptInterpreterPython.h"
70#endif
71
72#include "llvm/Support/TargetSelect.h"
73
74#include <string>
75
76using namespace lldb_private;
77
78#ifndef LLDB_DISABLE_PYTHON
79
80// Defined in the SWIG source file
81extern "C" void
82init_lldb(void);
83
84// these are the Pythonic implementations of the required callbacks
85// these are scripting-language specific, which is why they belong here
86// we still need to use function pointers to them instead of relying
87// on linkage-time resolution because the SWIG stuff and this file
88// get built at different times
89extern "C" bool
90LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
91 const char *session_dictionary_name,
92 const lldb::StackFrameSP& sb_frame,
93 const lldb::BreakpointLocationSP& sb_bp_loc);
94
95extern "C" bool
96LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
97 const char *session_dictionary_name,
98 const lldb::StackFrameSP& sb_frame,
99 const lldb::WatchpointSP& sb_wp);
100
101extern "C" bool
102LLDBSwigPythonCallTypeScript (const char *python_function_name,
103 void *session_dictionary,
104 const lldb::ValueObjectSP& valobj_sp,
105 void** pyfunct_wrapper,
106 const lldb::TypeSummaryOptionsSP& options_sp,
107 std::string& retval);
108
109extern "C" void*
110LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
111 const char *session_dictionary_name,
112 const lldb::ValueObjectSP& valobj_sp);
113
114extern "C" void*
115LLDBSwigPythonCreateCommandObject (const char *python_class_name,
116 const char *session_dictionary_name,
117 const lldb::DebuggerSP debugger_sp);
118
119extern "C" void*
120LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
121 const char *session_dictionary_name,
122 const lldb::ThreadPlanSP& thread_plan_sp);
123
124extern "C" bool
125LLDBSWIGPythonCallThreadPlan (void *implementor,
126 const char *method_name,
127 Event *event_sp,
128 bool &got_error);
129
130extern "C" size_t
131LLDBSwigPython_CalculateNumChildren (void *implementor);
132
133extern "C" void *
134LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
135
136extern "C" int
137LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
138
139extern "C" void *
140LLDBSWIGPython_CastPyObjectToSBValue (void* data);
141
142extern lldb::ValueObjectSP
143LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
144
145extern "C" bool
146LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
147
148extern "C" bool
149LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
150
151extern "C" void *
152LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
153
154extern "C" bool
155LLDBSwigPythonCallCommand (const char *python_function_name,
156 const char *session_dictionary_name,
157 lldb::DebuggerSP& debugger,
158 const char* args,
159 lldb_private::CommandReturnObject &cmd_retobj,
160 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
161
162extern "C" bool
163LLDBSwigPythonCallCommandObject (void *implementor,
164 lldb::DebuggerSP& debugger,
165 const char* args,
166 lldb_private::CommandReturnObject& cmd_retobj,
167 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
168
169extern "C" bool
170LLDBSwigPythonCallModuleInit (const char *python_module_name,
171 const char *session_dictionary_name,
172 lldb::DebuggerSP& debugger);
173
174extern "C" void*
175LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
176 const char *session_dictionary_name,
177 const lldb::ProcessSP& process_sp);
178
179extern "C" bool
180LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
181 const char* session_dictionary_name,
182 lldb::ProcessSP& process,
183 std::string& output);
184
185extern "C" bool
186LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
187 const char* session_dictionary_name,
188 lldb::ThreadSP& thread,
189 std::string& output);
190
191extern "C" bool
192LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
193 const char* session_dictionary_name,
194 lldb::TargetSP& target,
195 std::string& output);
196
197extern "C" bool
198LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
199 const char* session_dictionary_name,
200 lldb::StackFrameSP& frame,
201 std::string& output);
202
203extern "C" bool
204LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
205 const char* session_dictionary_name,
206 lldb::ValueObjectSP& value,
207 std::string& output);
208
209extern "C" void*
210LLDBSWIGPython_GetDynamicSetting (void* module,
211 const char* setting,
212 const lldb::TargetSP& target_sp);
213
214
215#endif
216
217SystemInitializerFull::SystemInitializerFull()
218{
219}
220
221SystemInitializerFull::~SystemInitializerFull()
222{
223}
224
225void
226SystemInitializerFull::Initialize()
227{
228 InitializeSWIG();
229
230 SystemInitializerCommon::Initialize();
231
232 // Initialize LLVM and Clang
233 llvm::InitializeAllTargets();
234 llvm::InitializeAllAsmPrinters();
235 llvm::InitializeAllTargetMCs();
236 llvm::InitializeAllDisassemblers();
237
238 ABIMacOSX_i386::Initialize();
239 ABIMacOSX_arm::Initialize();
240 ABIMacOSX_arm64::Initialize();
Omair Javaid52f825b2015-04-29 10:49:45 +0000241 ABISysV_arm::Initialize();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000242 ABISysV_arm64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000243 ABISysV_x86_64::Initialize();
244 ABISysV_ppc::Initialize();
245 ABISysV_ppc64::Initialize();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000246 ABISysV_mips::Initialize();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000247 ABISysV_mips64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000248 DisassemblerLLVMC::Initialize();
249
250 JITLoaderGDB::Initialize();
251 ProcessElfCore::Initialize();
252 MemoryHistoryASan::Initialize();
253 AddressSanitizerRuntime::Initialize();
254
255 SymbolVendorELF::Initialize();
256 SymbolFileDWARF::Initialize();
257 SymbolFileSymtab::Initialize();
258 UnwindAssemblyInstEmulation::Initialize();
259 UnwindAssembly_x86::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000260 EmulateInstructionARM64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000261 SymbolFileDWARFDebugMap::Initialize();
262 ItaniumABILanguageRuntime::Initialize();
263 AppleObjCRuntimeV2::Initialize();
264 AppleObjCRuntimeV1::Initialize();
265 SystemRuntimeMacOSX::Initialize();
Colin Riley5ec532a2015-04-09 16:49:25 +0000266 RenderScriptRuntime::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000267
268#if defined(__linux__)
269 //----------------------------------------------------------------------
270 // Linux hosted plugins
271 //----------------------------------------------------------------------
Zachary Turneraa7f12b2015-03-31 21:38:21 +0000272 process_linux::ProcessLinux::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000273#endif
274#if defined(_MSC_VER)
275 DynamicLoaderWindows::Initialize();
276 ProcessWindows::Initialize();
277#endif
278#if defined(__FreeBSD__)
279 ProcessFreeBSD::Initialize();
280#endif
281#if defined(__APPLE__)
282 SymbolVendorMacOSX::Initialize();
283 ProcessKDP::Initialize();
284 ProcessMachCore::Initialize();
285#endif
286 //----------------------------------------------------------------------
287 // Platform agnostic plugins
288 //----------------------------------------------------------------------
289 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
290
291 process_gdb_remote::ProcessGDBRemote::Initialize();
292 DynamicLoaderStatic::Initialize();
293
294 // Scan for any system or user LLDB plug-ins
295 PluginManager::Initialize();
296
297 // The process settings need to know about installed plug-ins, so the Settings must be initialized
298 // AFTER PluginManager::Initialize is called.
299
300 Debugger::SettingsInitialize();
301}
302
303void SystemInitializerFull::InitializeSWIG()
304{
305#if !defined(LLDB_DISABLE_PYTHON)
306 ScriptInterpreterPython::InitializeInterpreter(
307 init_lldb,
308 LLDBSwigPythonBreakpointCallbackFunction,
309 LLDBSwigPythonWatchpointCallbackFunction,
310 LLDBSwigPythonCallTypeScript,
311 LLDBSwigPythonCreateSyntheticProvider,
312 LLDBSwigPythonCreateCommandObject,
313 LLDBSwigPython_CalculateNumChildren,
314 LLDBSwigPython_GetChildAtIndex,
315 LLDBSwigPython_GetIndexOfChildWithName,
316 LLDBSWIGPython_CastPyObjectToSBValue,
317 LLDBSWIGPython_GetValueObjectSPFromSBValue,
318 LLDBSwigPython_UpdateSynthProviderInstance,
319 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
320 LLDBSwigPython_GetValueSynthProviderInstance,
321 LLDBSwigPythonCallCommand,
322 LLDBSwigPythonCallCommandObject,
323 LLDBSwigPythonCallModuleInit,
324 LLDBSWIGPythonCreateOSPlugin,
325 LLDBSWIGPythonRunScriptKeywordProcess,
326 LLDBSWIGPythonRunScriptKeywordThread,
327 LLDBSWIGPythonRunScriptKeywordTarget,
328 LLDBSWIGPythonRunScriptKeywordFrame,
329 LLDBSWIGPythonRunScriptKeywordValue,
330 LLDBSWIGPython_GetDynamicSetting,
331 LLDBSwigPythonCreateScriptedThreadPlan,
332 LLDBSWIGPythonCallThreadPlan);
333#endif
334}
335
336void
337SystemInitializerFull::Terminate()
338{
339 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
340
341 Debugger::SettingsTerminate();
342
343 // Terminate and unload and loaded system or user LLDB plug-ins
344 PluginManager::Terminate();
345 ABIMacOSX_i386::Terminate();
346 ABIMacOSX_arm::Terminate();
347 ABIMacOSX_arm64::Terminate();
Omair Javaid52f825b2015-04-29 10:49:45 +0000348 ABISysV_arm::Terminate();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000349 ABISysV_arm64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000350 ABISysV_x86_64::Terminate();
351 ABISysV_ppc::Terminate();
352 ABISysV_ppc64::Terminate();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000353 ABISysV_mips::Terminate();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000354 ABISysV_mips64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000355 DisassemblerLLVMC::Terminate();
356
357 JITLoaderGDB::Terminate();
358 ProcessElfCore::Terminate();
359 MemoryHistoryASan::Terminate();
360 AddressSanitizerRuntime::Terminate();
361 SymbolVendorELF::Terminate();
362 SymbolFileDWARF::Terminate();
363 SymbolFileSymtab::Terminate();
364 UnwindAssembly_x86::Terminate();
365 UnwindAssemblyInstEmulation::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000366 EmulateInstructionARM64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000367 SymbolFileDWARFDebugMap::Terminate();
368 ItaniumABILanguageRuntime::Terminate();
369 AppleObjCRuntimeV2::Terminate();
370 AppleObjCRuntimeV1::Terminate();
371 SystemRuntimeMacOSX::Terminate();
Colin Riley5ec532a2015-04-09 16:49:25 +0000372 RenderScriptRuntime::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000373
374#if defined(__APPLE__)
375 ProcessMachCore::Terminate();
376 ProcessKDP::Terminate();
377 SymbolVendorMacOSX::Terminate();
378#endif
379#if defined(_MSC_VER)
380 DynamicLoaderWindows::Terminate();
381#endif
382
383#if defined(__linux__)
Zachary Turneraa7f12b2015-03-31 21:38:21 +0000384 process_linux::ProcessLinux::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000385#endif
386
387#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}
399
400void SystemInitializerFull::TerminateSWIG()
401{
402
403}