blob: 43e0f046ac3ac9958d3005167e7bb3ca2cf44d5e [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"
Greg Clayton56939cb2015-09-17 22:23:34 +000027#include "lldb/Symbol/ClangASTContext.h"
28#include "lldb/Symbol/GoASTContext.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000029
30#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
31#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
32#include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h"
Omair Javaid52f825b2015-04-29 10:49:45 +000033#include "Plugins/ABI/SysV-arm/ABISysV_arm.h"
Omair Javaidb78e05f2015-04-29 11:52:35 +000034#include "Plugins/ABI/SysV-arm64/ABISysV_arm64.h"
Greg Claytonb289cba2015-06-25 17:50:15 +000035#include "Plugins/ABI/SysV-i386/ABISysV_i386.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000036#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
37#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
38#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
Bhushan D. Attardea8219f22015-06-18 07:02:10 +000039#include "Plugins/ABI/SysV-mips/ABISysV_mips.h"
Bhushan D. Attarde13f54252015-06-19 04:25:07 +000040#include "Plugins/ABI/SysV-mips64/ABISysV_mips64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000041#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
42#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000043#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000044#include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h"
45#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
Enrico Granata980c0482015-09-01 18:22:39 +000046#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
Ryan Brown2dd84882015-11-05 00:24:36 +000047#include "Plugins/Language/Go/GoLanguage.h"
Enrico Granata980c0482015-09-01 18:22:39 +000048#include "Plugins/Language/ObjC/ObjCLanguage.h"
49#include "Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000050#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
51#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
52#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Ryan Brown07a1c452015-10-06 20:29:31 +000053#include "Plugins/LanguageRuntime/Go/GoLanguageRuntime.h"
Colin Riley5ec532a2015-04-09 16:49:25 +000054#include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000055#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
56#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
57#include "Plugins/Process/elf-core/ProcessElfCore.h"
58#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
Zachary Turner2c1f46d2015-07-30 20:28:07 +000059#include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000060#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
61#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
62#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
63#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
64#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
65#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
66#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
67
68#if defined(__APPLE__)
69#include "Plugins/Process/mach-core/ProcessMachCore.h"
70#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
71#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
72#endif
73
74#if defined(__FreeBSD__)
75#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
76#endif
77
Zachary Turnere6e2bb32015-03-31 21:03:22 +000078#if defined(_MSC_VER)
79#include "lldb/Host/windows/windows.h"
Adrian McCarthy18a9135d2015-10-28 18:21:45 +000080#include "Plugins/Process/Windows/Live/ProcessWindowsLive.h"
Adrian McCarthy27785dd2015-08-24 16:00:51 +000081#include "Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000082#endif
83
Zachary Turnere6e2bb32015-03-31 21:03:22 +000084#include "llvm/Support/TargetSelect.h"
85
86#include <string>
87
88using namespace lldb_private;
89
90#ifndef LLDB_DISABLE_PYTHON
91
92// Defined in the SWIG source file
Zachary Turnerc5b41d62015-10-16 17:52:03 +000093#if PY_MAJOR_VERSION >= 3
94extern "C" PyObject*
95PyInit__lldb(void);
96
97#define LLDBSwigPyInit PyInit__lldb
98
99#else
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000100extern "C" void
101init_lldb(void);
102
Zachary Turnerc5b41d62015-10-16 17:52:03 +0000103#define LLDBSwigPyInit init_lldb
104#endif
105
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000106// these are the Pythonic implementations of the required callbacks
107// these are scripting-language specific, which is why they belong here
108// we still need to use function pointers to them instead of relying
109// on linkage-time resolution because the SWIG stuff and this file
110// get built at different times
111extern "C" bool
112LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
113 const char *session_dictionary_name,
114 const lldb::StackFrameSP& sb_frame,
115 const lldb::BreakpointLocationSP& sb_bp_loc);
116
117extern "C" bool
118LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
119 const char *session_dictionary_name,
120 const lldb::StackFrameSP& sb_frame,
121 const lldb::WatchpointSP& sb_wp);
122
123extern "C" bool
124LLDBSwigPythonCallTypeScript (const char *python_function_name,
125 void *session_dictionary,
126 const lldb::ValueObjectSP& valobj_sp,
127 void** pyfunct_wrapper,
128 const lldb::TypeSummaryOptionsSP& options_sp,
129 std::string& retval);
130
131extern "C" void*
132LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
133 const char *session_dictionary_name,
134 const lldb::ValueObjectSP& valobj_sp);
135
136extern "C" void*
137LLDBSwigPythonCreateCommandObject (const char *python_class_name,
138 const char *session_dictionary_name,
139 const lldb::DebuggerSP debugger_sp);
140
141extern "C" void*
142LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
143 const char *session_dictionary_name,
144 const lldb::ThreadPlanSP& thread_plan_sp);
145
146extern "C" bool
147LLDBSWIGPythonCallThreadPlan (void *implementor,
148 const char *method_name,
149 Event *event_sp,
150 bool &got_error);
151
152extern "C" size_t
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000153LLDBSwigPython_CalculateNumChildren (void *implementor, uint32_t max);
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000154
155extern "C" void *
156LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
157
158extern "C" int
159LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
160
161extern "C" void *
162LLDBSWIGPython_CastPyObjectToSBValue (void* data);
163
164extern lldb::ValueObjectSP
165LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
166
167extern "C" bool
168LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
169
170extern "C" bool
171LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
172
173extern "C" void *
174LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
175
176extern "C" bool
177LLDBSwigPythonCallCommand (const char *python_function_name,
178 const char *session_dictionary_name,
179 lldb::DebuggerSP& debugger,
180 const char* args,
181 lldb_private::CommandReturnObject &cmd_retobj,
182 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
183
184extern "C" bool
185LLDBSwigPythonCallCommandObject (void *implementor,
186 lldb::DebuggerSP& debugger,
187 const char* args,
188 lldb_private::CommandReturnObject& cmd_retobj,
189 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
190
191extern "C" bool
192LLDBSwigPythonCallModuleInit (const char *python_module_name,
193 const char *session_dictionary_name,
194 lldb::DebuggerSP& debugger);
195
196extern "C" void*
197LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
198 const char *session_dictionary_name,
199 const lldb::ProcessSP& process_sp);
200
201extern "C" bool
202LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
203 const char* session_dictionary_name,
204 lldb::ProcessSP& process,
205 std::string& output);
206
207extern "C" bool
208LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
209 const char* session_dictionary_name,
210 lldb::ThreadSP& thread,
211 std::string& output);
212
213extern "C" bool
214LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
215 const char* session_dictionary_name,
216 lldb::TargetSP& target,
217 std::string& output);
218
219extern "C" bool
220LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
221 const char* session_dictionary_name,
222 lldb::StackFrameSP& frame,
223 std::string& output);
224
225extern "C" bool
226LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
227 const char* session_dictionary_name,
228 lldb::ValueObjectSP& value,
229 std::string& output);
230
231extern "C" void*
232LLDBSWIGPython_GetDynamicSetting (void* module,
233 const char* setting,
234 const lldb::TargetSP& target_sp);
235
236
237#endif
238
239SystemInitializerFull::SystemInitializerFull()
240{
241}
242
243SystemInitializerFull::~SystemInitializerFull()
244{
245}
246
247void
248SystemInitializerFull::Initialize()
249{
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000250 SystemInitializerCommon::Initialize();
Keno Fischer6e776772015-08-23 09:05:29 +0000251 ScriptInterpreterNone::Initialize();
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000252
253#if !defined(LLDB_DISABLE_PYTHON)
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000254 InitializeSWIG();
255
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000256 // ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized
257 // so it can compute the python directory etc, so we need to do this after
258 // SystemInitializerCommon::Initialize().
Zachary Turner2c1f46d2015-07-30 20:28:07 +0000259 ScriptInterpreterPython::Initialize();
260#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000261
262 // Initialize LLVM and Clang
263 llvm::InitializeAllTargets();
264 llvm::InitializeAllAsmPrinters();
265 llvm::InitializeAllTargetMCs();
266 llvm::InitializeAllDisassemblers();
267
Greg Clayton56939cb2015-09-17 22:23:34 +0000268 ClangASTContext::Initialize();
269 GoASTContext::Initialize();
270
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000271 ABIMacOSX_i386::Initialize();
272 ABIMacOSX_arm::Initialize();
273 ABIMacOSX_arm64::Initialize();
Omair Javaid52f825b2015-04-29 10:49:45 +0000274 ABISysV_arm::Initialize();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000275 ABISysV_arm64::Initialize();
Greg Claytonb289cba2015-06-25 17:50:15 +0000276 ABISysV_i386::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000277 ABISysV_x86_64::Initialize();
278 ABISysV_ppc::Initialize();
279 ABISysV_ppc64::Initialize();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000280 ABISysV_mips::Initialize();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000281 ABISysV_mips64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000282 DisassemblerLLVMC::Initialize();
283
284 JITLoaderGDB::Initialize();
285 ProcessElfCore::Initialize();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000286#if defined(_MSC_VER)
287 ProcessWinMiniDump::Initialize();
288#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000289 MemoryHistoryASan::Initialize();
290 AddressSanitizerRuntime::Initialize();
291
292 SymbolVendorELF::Initialize();
293 SymbolFileDWARF::Initialize();
294 SymbolFileSymtab::Initialize();
295 UnwindAssemblyInstEmulation::Initialize();
296 UnwindAssembly_x86::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000297 EmulateInstructionARM64::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000298 SymbolFileDWARFDebugMap::Initialize();
299 ItaniumABILanguageRuntime::Initialize();
300 AppleObjCRuntimeV2::Initialize();
301 AppleObjCRuntimeV1::Initialize();
302 SystemRuntimeMacOSX::Initialize();
Colin Riley5ec532a2015-04-09 16:49:25 +0000303 RenderScriptRuntime::Initialize();
Ryan Brown07a1c452015-10-06 20:29:31 +0000304 GoLanguageRuntime::Initialize();
Enrico Granata980c0482015-09-01 18:22:39 +0000305
306 CPlusPlusLanguage::Initialize();
Ryan Brown2dd84882015-11-05 00:24:36 +0000307 GoLanguage::Initialize();
Enrico Granata980c0482015-09-01 18:22:39 +0000308 ObjCLanguage::Initialize();
309 ObjCPlusPlusLanguage::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000310
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000311#if defined(_MSC_VER)
Adrian McCarthy18a9135d2015-10-28 18:21:45 +0000312 ProcessWindowsLive::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000313#endif
314#if defined(__FreeBSD__)
315 ProcessFreeBSD::Initialize();
316#endif
317#if defined(__APPLE__)
318 SymbolVendorMacOSX::Initialize();
319 ProcessKDP::Initialize();
320 ProcessMachCore::Initialize();
321#endif
322 //----------------------------------------------------------------------
323 // Platform agnostic plugins
324 //----------------------------------------------------------------------
325 platform_gdb_server::PlatformRemoteGDBServer::Initialize();
326
327 process_gdb_remote::ProcessGDBRemote::Initialize();
328 DynamicLoaderStatic::Initialize();
329
330 // Scan for any system or user LLDB plug-ins
331 PluginManager::Initialize();
332
333 // The process settings need to know about installed plug-ins, so the Settings must be initialized
334 // AFTER PluginManager::Initialize is called.
335
336 Debugger::SettingsInitialize();
337}
338
339void SystemInitializerFull::InitializeSWIG()
340{
341#if !defined(LLDB_DISABLE_PYTHON)
342 ScriptInterpreterPython::InitializeInterpreter(
Zachary Turnerc5b41d62015-10-16 17:52:03 +0000343 LLDBSwigPyInit,
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000344 LLDBSwigPythonBreakpointCallbackFunction,
345 LLDBSwigPythonWatchpointCallbackFunction,
346 LLDBSwigPythonCallTypeScript,
347 LLDBSwigPythonCreateSyntheticProvider,
348 LLDBSwigPythonCreateCommandObject,
349 LLDBSwigPython_CalculateNumChildren,
350 LLDBSwigPython_GetChildAtIndex,
351 LLDBSwigPython_GetIndexOfChildWithName,
352 LLDBSWIGPython_CastPyObjectToSBValue,
353 LLDBSWIGPython_GetValueObjectSPFromSBValue,
354 LLDBSwigPython_UpdateSynthProviderInstance,
355 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
356 LLDBSwigPython_GetValueSynthProviderInstance,
357 LLDBSwigPythonCallCommand,
358 LLDBSwigPythonCallCommandObject,
359 LLDBSwigPythonCallModuleInit,
360 LLDBSWIGPythonCreateOSPlugin,
361 LLDBSWIGPythonRunScriptKeywordProcess,
362 LLDBSWIGPythonRunScriptKeywordThread,
363 LLDBSWIGPythonRunScriptKeywordTarget,
364 LLDBSWIGPythonRunScriptKeywordFrame,
365 LLDBSWIGPythonRunScriptKeywordValue,
366 LLDBSWIGPython_GetDynamicSetting,
367 LLDBSwigPythonCreateScriptedThreadPlan,
368 LLDBSWIGPythonCallThreadPlan);
369#endif
370}
371
372void
373SystemInitializerFull::Terminate()
374{
375 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
376
377 Debugger::SettingsTerminate();
378
379 // Terminate and unload and loaded system or user LLDB plug-ins
380 PluginManager::Terminate();
Greg Clayton56939cb2015-09-17 22:23:34 +0000381
382 ClangASTContext::Terminate();
383 GoASTContext::Terminate();
384
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000385 ABIMacOSX_i386::Terminate();
386 ABIMacOSX_arm::Terminate();
387 ABIMacOSX_arm64::Terminate();
Omair Javaid52f825b2015-04-29 10:49:45 +0000388 ABISysV_arm::Terminate();
Omair Javaidb78e05f2015-04-29 11:52:35 +0000389 ABISysV_arm64::Terminate();
Greg Claytonb289cba2015-06-25 17:50:15 +0000390 ABISysV_i386::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000391 ABISysV_x86_64::Terminate();
392 ABISysV_ppc::Terminate();
393 ABISysV_ppc64::Terminate();
Bhushan D. Attardea8219f22015-06-18 07:02:10 +0000394 ABISysV_mips::Terminate();
Bhushan D. Attarde13f54252015-06-19 04:25:07 +0000395 ABISysV_mips64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000396 DisassemblerLLVMC::Terminate();
397
398 JITLoaderGDB::Terminate();
399 ProcessElfCore::Terminate();
Adrian McCarthyc96516f2015-08-03 23:01:51 +0000400#if defined(_MSC_VER)
401 ProcessWinMiniDump::Terminate();
402#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000403 MemoryHistoryASan::Terminate();
404 AddressSanitizerRuntime::Terminate();
405 SymbolVendorELF::Terminate();
406 SymbolFileDWARF::Terminate();
407 SymbolFileSymtab::Terminate();
408 UnwindAssembly_x86::Terminate();
409 UnwindAssemblyInstEmulation::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000410 EmulateInstructionARM64::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000411 SymbolFileDWARFDebugMap::Terminate();
412 ItaniumABILanguageRuntime::Terminate();
413 AppleObjCRuntimeV2::Terminate();
414 AppleObjCRuntimeV1::Terminate();
415 SystemRuntimeMacOSX::Terminate();
Colin Riley5ec532a2015-04-09 16:49:25 +0000416 RenderScriptRuntime::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000417
Enrico Granata980c0482015-09-01 18:22:39 +0000418 CPlusPlusLanguage::Terminate();
Ryan Brown2dd84882015-11-05 00:24:36 +0000419 GoLanguage::Terminate();
Enrico Granata980c0482015-09-01 18:22:39 +0000420 ObjCLanguage::Terminate();
421 ObjCPlusPlusLanguage::Terminate();
422
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000423#if defined(__APPLE__)
424 ProcessMachCore::Terminate();
425 ProcessKDP::Terminate();
426 SymbolVendorMacOSX::Terminate();
427#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000428
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000429#if defined(__FreeBSD__)
430 ProcessFreeBSD::Terminate();
431#endif
432 Debugger::SettingsTerminate();
433
434 platform_gdb_server::PlatformRemoteGDBServer::Terminate();
435 process_gdb_remote::ProcessGDBRemote::Terminate();
436 DynamicLoaderStatic::Terminate();
437
438 // Now shutdown the common parts, in reverse order.
439 SystemInitializerCommon::Terminate();
440}