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