1 //===-- 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 #if !defined(LLDB_DISABLE_PYTHON) 11 #include "Plugins/ScriptInterpreter/Python/lldb-python.h" 12 #endif 13 14 #include "lldb/API/SystemInitializerFull.h" 15 16 #include "lldb/API/SBCommandInterpreter.h" 17 18 #if !defined(LLDB_DISABLE_PYTHON) 19 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" 20 #endif 21 22 #include "lldb/Core/Debugger.h" 23 #include "lldb/Core/Timer.h" 24 #include "lldb/Host/Host.h" 25 #include "lldb/Initialization/SystemInitializerCommon.h" 26 #include "lldb/Interpreter/CommandInterpreter.h" 27 #include "lldb/Symbol/ClangASTContext.h" 28 #include "lldb/Symbol/GoASTContext.h" 29 #include "lldb/Symbol/JavaASTContext.h" 30 31 #include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h" 32 #include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h" 33 #include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h" 34 #include "Plugins/ABI/SysV-arm/ABISysV_arm.h" 35 #include "Plugins/ABI/SysV-arm64/ABISysV_arm64.h" 36 #include "Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h" 37 #include "Plugins/ABI/SysV-i386/ABISysV_i386.h" 38 #include "Plugins/ABI/SysV-mips/ABISysV_mips.h" 39 #include "Plugins/ABI/SysV-mips64/ABISysV_mips64.h" 40 #include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h" 41 #include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h" 42 #include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h" 43 #include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h" 44 #include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h" 45 #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h" 46 #include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h" 47 #include "Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h" 48 #include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h" 49 #include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h" 50 #include "Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h" 51 #include "Plugins/JITLoader/GDB/JITLoaderGDB.h" 52 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" 53 #include "Plugins/Language/Go/GoLanguage.h" 54 #include "Plugins/Language/Java/JavaLanguage.h" 55 #include "Plugins/Language/ObjC/ObjCLanguage.h" 56 #include "Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h" 57 #include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h" 58 #include "Plugins/LanguageRuntime/Go/GoLanguageRuntime.h" 59 #include "Plugins/LanguageRuntime/Java/JavaLanguageRuntime.h" 60 #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h" 61 #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h" 62 #include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h" 63 #include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h" 64 #include "Plugins/OperatingSystem/Python/OperatingSystemPython.h" 65 #include "Plugins/OperatingSystem/Go/OperatingSystemGo.h" 66 #include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h" 67 #include "Plugins/Process/elf-core/ProcessElfCore.h" 68 #include "Plugins/Process/gdb-remote/ProcessGDBRemote.h" 69 #include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h" 70 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" 71 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h" 72 #include "Plugins/SymbolFile/PDB/SymbolFilePDB.h" 73 #include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h" 74 #include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h" 75 #include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h" 76 #include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h" 77 #include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h" 78 79 #if defined(__APPLE__) 80 #include "Plugins/Process/mach-core/ProcessMachCore.h" 81 #include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h" 82 #include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h" 83 #include "Plugins/Platform/MacOSX/PlatformAppleTVSimulator.h" 84 #include "Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.h" 85 #include "Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h" 86 #include "Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h" 87 #include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h" 88 #endif 89 90 #if defined(__FreeBSD__) 91 #include "Plugins/Process/FreeBSD/ProcessFreeBSD.h" 92 #endif 93 94 #if defined(_MSC_VER) 95 #include "lldb/Host/windows/windows.h" 96 #include "Plugins/Process/Windows/Live/ProcessWindowsLive.h" 97 #include "Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.h" 98 #endif 99 100 #include "llvm/Support/TargetSelect.h" 101 102 #include <string> 103 104 using namespace lldb_private; 105 106 #ifndef LLDB_DISABLE_PYTHON 107 108 // Defined in the SWIG source file 109 #if PY_MAJOR_VERSION >= 3 110 extern "C" PyObject* 111 PyInit__lldb(void); 112 113 #define LLDBSwigPyInit PyInit__lldb 114 115 #else 116 extern "C" void 117 init_lldb(void); 118 119 #define LLDBSwigPyInit init_lldb 120 #endif 121 122 // these are the Pythonic implementations of the required callbacks 123 // these are scripting-language specific, which is why they belong here 124 // we still need to use function pointers to them instead of relying 125 // on linkage-time resolution because the SWIG stuff and this file 126 // get built at different times 127 extern "C" bool 128 LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name, 129 const char *session_dictionary_name, 130 const lldb::StackFrameSP& sb_frame, 131 const lldb::BreakpointLocationSP& sb_bp_loc); 132 133 extern "C" bool 134 LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name, 135 const char *session_dictionary_name, 136 const lldb::StackFrameSP& sb_frame, 137 const lldb::WatchpointSP& sb_wp); 138 139 extern "C" bool 140 LLDBSwigPythonCallTypeScript (const char *python_function_name, 141 void *session_dictionary, 142 const lldb::ValueObjectSP& valobj_sp, 143 void** pyfunct_wrapper, 144 const lldb::TypeSummaryOptionsSP& options_sp, 145 std::string& retval); 146 147 extern "C" void* 148 LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name, 149 const char *session_dictionary_name, 150 const lldb::ValueObjectSP& valobj_sp); 151 152 extern "C" void* 153 LLDBSwigPythonCreateCommandObject (const char *python_class_name, 154 const char *session_dictionary_name, 155 const lldb::DebuggerSP debugger_sp); 156 157 extern "C" void* 158 LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name, 159 const char *session_dictionary_name, 160 const lldb::ThreadPlanSP& thread_plan_sp); 161 162 extern "C" bool 163 LLDBSWIGPythonCallThreadPlan (void *implementor, 164 const char *method_name, 165 Event *event_sp, 166 bool &got_error); 167 168 extern "C" size_t 169 LLDBSwigPython_CalculateNumChildren (void *implementor, uint32_t max); 170 171 extern "C" void * 172 LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx); 173 174 extern "C" int 175 LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name); 176 177 extern "C" void * 178 LLDBSWIGPython_CastPyObjectToSBValue (void* data); 179 180 extern lldb::ValueObjectSP 181 LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data); 182 183 extern "C" bool 184 LLDBSwigPython_UpdateSynthProviderInstance (void* implementor); 185 186 extern "C" bool 187 LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor); 188 189 extern "C" void * 190 LLDBSwigPython_GetValueSynthProviderInstance (void* implementor); 191 192 extern "C" bool 193 LLDBSwigPythonCallCommand (const char *python_function_name, 194 const char *session_dictionary_name, 195 lldb::DebuggerSP& debugger, 196 const char* args, 197 lldb_private::CommandReturnObject &cmd_retobj, 198 lldb::ExecutionContextRefSP exe_ctx_ref_sp); 199 200 extern "C" bool 201 LLDBSwigPythonCallCommandObject (void *implementor, 202 lldb::DebuggerSP& debugger, 203 const char* args, 204 lldb_private::CommandReturnObject& cmd_retobj, 205 lldb::ExecutionContextRefSP exe_ctx_ref_sp); 206 207 extern "C" bool 208 LLDBSwigPythonCallModuleInit (const char *python_module_name, 209 const char *session_dictionary_name, 210 lldb::DebuggerSP& debugger); 211 212 extern "C" void* 213 LLDBSWIGPythonCreateOSPlugin (const char *python_class_name, 214 const char *session_dictionary_name, 215 const lldb::ProcessSP& process_sp); 216 217 extern "C" bool 218 LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name, 219 const char* session_dictionary_name, 220 lldb::ProcessSP& process, 221 std::string& output); 222 223 extern "C" bool 224 LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name, 225 const char* session_dictionary_name, 226 lldb::ThreadSP& thread, 227 std::string& output); 228 229 extern "C" bool 230 LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name, 231 const char* session_dictionary_name, 232 lldb::TargetSP& target, 233 std::string& output); 234 235 extern "C" bool 236 LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name, 237 const char* session_dictionary_name, 238 lldb::StackFrameSP& frame, 239 std::string& output); 240 241 extern "C" bool 242 LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name, 243 const char* session_dictionary_name, 244 lldb::ValueObjectSP& value, 245 std::string& output); 246 247 extern "C" void* 248 LLDBSWIGPython_GetDynamicSetting (void* module, 249 const char* setting, 250 const lldb::TargetSP& target_sp); 251 252 253 #endif 254 255 SystemInitializerFull::SystemInitializerFull() 256 { 257 } 258 259 SystemInitializerFull::~SystemInitializerFull() 260 { 261 } 262 263 void 264 SystemInitializerFull::Initialize() 265 { 266 SystemInitializerCommon::Initialize(); 267 ScriptInterpreterNone::Initialize(); 268 269 #ifndef LLDB_DISABLE_PYTHON 270 OperatingSystemPython::Initialize(); 271 #endif 272 OperatingSystemGo::Initialize(); 273 274 #if !defined(LLDB_DISABLE_PYTHON) 275 InitializeSWIG(); 276 277 // ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized 278 // so it can compute the python directory etc, so we need to do this after 279 // SystemInitializerCommon::Initialize(). 280 ScriptInterpreterPython::Initialize(); 281 #endif 282 283 // Initialize LLVM and Clang 284 llvm::InitializeAllTargets(); 285 llvm::InitializeAllAsmPrinters(); 286 llvm::InitializeAllTargetMCs(); 287 llvm::InitializeAllDisassemblers(); 288 289 ClangASTContext::Initialize(); 290 GoASTContext::Initialize(); 291 JavaASTContext::Initialize(); 292 293 ABIMacOSX_i386::Initialize(); 294 ABIMacOSX_arm::Initialize(); 295 ABIMacOSX_arm64::Initialize(); 296 ABISysV_arm::Initialize(); 297 ABISysV_arm64::Initialize(); 298 ABISysV_hexagon::Initialize(); 299 ABISysV_i386::Initialize(); 300 ABISysV_x86_64::Initialize(); 301 ABISysV_ppc::Initialize(); 302 ABISysV_ppc64::Initialize(); 303 ABISysV_mips::Initialize(); 304 ABISysV_mips64::Initialize(); 305 DisassemblerLLVMC::Initialize(); 306 307 JITLoaderGDB::Initialize(); 308 ProcessElfCore::Initialize(); 309 #if defined(_MSC_VER) 310 ProcessWinMiniDump::Initialize(); 311 #endif 312 MemoryHistoryASan::Initialize(); 313 AddressSanitizerRuntime::Initialize(); 314 ThreadSanitizerRuntime::Initialize(); 315 316 SymbolVendorELF::Initialize(); 317 SymbolFileDWARF::Initialize(); 318 SymbolFilePDB::Initialize(); 319 SymbolFileSymtab::Initialize(); 320 UnwindAssemblyInstEmulation::Initialize(); 321 UnwindAssembly_x86::Initialize(); 322 EmulateInstructionARM64::Initialize(); 323 SymbolFileDWARFDebugMap::Initialize(); 324 ItaniumABILanguageRuntime::Initialize(); 325 AppleObjCRuntimeV2::Initialize(); 326 AppleObjCRuntimeV1::Initialize(); 327 SystemRuntimeMacOSX::Initialize(); 328 RenderScriptRuntime::Initialize(); 329 GoLanguageRuntime::Initialize(); 330 JavaLanguageRuntime::Initialize(); 331 332 CPlusPlusLanguage::Initialize(); 333 GoLanguage::Initialize(); 334 JavaLanguage::Initialize(); 335 ObjCLanguage::Initialize(); 336 ObjCPlusPlusLanguage::Initialize(); 337 338 #if defined(_MSC_VER) 339 ProcessWindowsLive::Initialize(); 340 #endif 341 #if defined(__FreeBSD__) 342 ProcessFreeBSD::Initialize(); 343 #endif 344 #if defined(__APPLE__) 345 SymbolVendorMacOSX::Initialize(); 346 ProcessKDP::Initialize(); 347 ProcessMachCore::Initialize(); 348 PlatformAppleTVSimulator::Initialize(); 349 PlatformAppleWatchSimulator::Initialize(); 350 PlatformRemoteAppleTV::Initialize(); 351 PlatformRemoteAppleWatch::Initialize(); 352 DynamicLoaderDarwinKernel::Initialize(); 353 #endif 354 //---------------------------------------------------------------------- 355 // Platform agnostic plugins 356 //---------------------------------------------------------------------- 357 platform_gdb_server::PlatformRemoteGDBServer::Initialize(); 358 359 process_gdb_remote::ProcessGDBRemote::Initialize(); 360 DynamicLoaderMacOSXDYLD::Initialize(); 361 DynamicLoaderPOSIXDYLD::Initialize(); 362 DynamicLoaderStatic::Initialize(); 363 DynamicLoaderWindowsDYLD::Initialize(); 364 365 // Scan for any system or user LLDB plug-ins 366 PluginManager::Initialize(); 367 368 // The process settings need to know about installed plug-ins, so the Settings must be initialized 369 // AFTER PluginManager::Initialize is called. 370 371 Debugger::SettingsInitialize(); 372 } 373 374 void SystemInitializerFull::InitializeSWIG() 375 { 376 #if !defined(LLDB_DISABLE_PYTHON) 377 ScriptInterpreterPython::InitializeInterpreter( 378 LLDBSwigPyInit, 379 LLDBSwigPythonBreakpointCallbackFunction, 380 LLDBSwigPythonWatchpointCallbackFunction, 381 LLDBSwigPythonCallTypeScript, 382 LLDBSwigPythonCreateSyntheticProvider, 383 LLDBSwigPythonCreateCommandObject, 384 LLDBSwigPython_CalculateNumChildren, 385 LLDBSwigPython_GetChildAtIndex, 386 LLDBSwigPython_GetIndexOfChildWithName, 387 LLDBSWIGPython_CastPyObjectToSBValue, 388 LLDBSWIGPython_GetValueObjectSPFromSBValue, 389 LLDBSwigPython_UpdateSynthProviderInstance, 390 LLDBSwigPython_MightHaveChildrenSynthProviderInstance, 391 LLDBSwigPython_GetValueSynthProviderInstance, 392 LLDBSwigPythonCallCommand, 393 LLDBSwigPythonCallCommandObject, 394 LLDBSwigPythonCallModuleInit, 395 LLDBSWIGPythonCreateOSPlugin, 396 LLDBSWIGPythonRunScriptKeywordProcess, 397 LLDBSWIGPythonRunScriptKeywordThread, 398 LLDBSWIGPythonRunScriptKeywordTarget, 399 LLDBSWIGPythonRunScriptKeywordFrame, 400 LLDBSWIGPythonRunScriptKeywordValue, 401 LLDBSWIGPython_GetDynamicSetting, 402 LLDBSwigPythonCreateScriptedThreadPlan, 403 LLDBSWIGPythonCallThreadPlan); 404 #endif 405 } 406 407 void 408 SystemInitializerFull::Terminate() 409 { 410 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); 411 412 Debugger::SettingsTerminate(); 413 414 // Terminate and unload and loaded system or user LLDB plug-ins 415 PluginManager::Terminate(); 416 417 ClangASTContext::Terminate(); 418 GoASTContext::Terminate(); 419 JavaASTContext::Terminate(); 420 421 ABIMacOSX_i386::Terminate(); 422 ABIMacOSX_arm::Terminate(); 423 ABIMacOSX_arm64::Terminate(); 424 ABISysV_arm::Terminate(); 425 ABISysV_arm64::Terminate(); 426 ABISysV_hexagon::Terminate(); 427 ABISysV_i386::Terminate(); 428 ABISysV_x86_64::Terminate(); 429 ABISysV_ppc::Terminate(); 430 ABISysV_ppc64::Terminate(); 431 ABISysV_mips::Terminate(); 432 ABISysV_mips64::Terminate(); 433 DisassemblerLLVMC::Terminate(); 434 435 JITLoaderGDB::Terminate(); 436 ProcessElfCore::Terminate(); 437 #if defined(_MSC_VER) 438 ProcessWinMiniDump::Terminate(); 439 #endif 440 MemoryHistoryASan::Terminate(); 441 AddressSanitizerRuntime::Terminate(); 442 ThreadSanitizerRuntime::Terminate(); 443 SymbolVendorELF::Terminate(); 444 SymbolFileDWARF::Terminate(); 445 SymbolFilePDB::Terminate(); 446 SymbolFileSymtab::Terminate(); 447 UnwindAssembly_x86::Terminate(); 448 UnwindAssemblyInstEmulation::Terminate(); 449 EmulateInstructionARM64::Terminate(); 450 SymbolFileDWARFDebugMap::Terminate(); 451 ItaniumABILanguageRuntime::Terminate(); 452 AppleObjCRuntimeV2::Terminate(); 453 AppleObjCRuntimeV1::Terminate(); 454 SystemRuntimeMacOSX::Terminate(); 455 RenderScriptRuntime::Terminate(); 456 JavaLanguageRuntime::Terminate(); 457 458 CPlusPlusLanguage::Terminate(); 459 GoLanguage::Terminate(); 460 JavaLanguage::Terminate(); 461 ObjCLanguage::Terminate(); 462 ObjCPlusPlusLanguage::Terminate(); 463 464 #if defined(__APPLE__) 465 DynamicLoaderDarwinKernel::Terminate(); 466 ProcessMachCore::Terminate(); 467 ProcessKDP::Terminate(); 468 SymbolVendorMacOSX::Terminate(); 469 PlatformAppleTVSimulator::Terminate(); 470 PlatformAppleWatchSimulator::Terminate(); 471 PlatformRemoteAppleTV::Terminate(); 472 PlatformRemoteAppleWatch::Terminate(); 473 #endif 474 475 #if defined(__FreeBSD__) 476 ProcessFreeBSD::Terminate(); 477 #endif 478 Debugger::SettingsTerminate(); 479 480 platform_gdb_server::PlatformRemoteGDBServer::Terminate(); 481 process_gdb_remote::ProcessGDBRemote::Terminate(); 482 DynamicLoaderMacOSXDYLD::Terminate(); 483 DynamicLoaderPOSIXDYLD::Terminate(); 484 DynamicLoaderStatic::Terminate(); 485 DynamicLoaderWindowsDYLD::Terminate(); 486 487 #ifndef LLDB_DISABLE_PYTHON 488 OperatingSystemPython::Terminate(); 489 #endif 490 OperatingSystemGo::Terminate(); 491 492 // Now shutdown the common parts, in reverse order. 493 SystemInitializerCommon::Terminate(); 494 } 495