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