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