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