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