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