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