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