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