lldb.cpp revision 58e26e0935138225477fd61283215ceff2068899
1//===-- lldb.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/lldb-private.h" 11#include "lldb/lldb-private-log.h" 12#include "lldb/Core/ArchSpec.h" 13#include "lldb/Core/Debugger.h" 14#include "lldb/Core/Log.h" 15#include "lldb/Core/PluginManager.h" 16#include "lldb/Core/RegularExpression.h" 17#include "lldb/Core/Timer.h" 18#include "lldb/Host/Host.h" 19#include "lldb/Host/Mutex.h" 20#include "lldb/Target/Target.h" 21#include "lldb/Target/Thread.h" 22 23#include "llvm/ADT/StringRef.h" 24 25#include "Plugins/Disassembler/llvm/DisassemblerLLVM.h" 26#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h" 27#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" 28#include "Plugins/ObjectFile/ELF/ObjectFileELF.h" 29#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" 30#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h" 31#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h" 32#include "Plugins/Process/Utility/UnwindAssemblyProfiler-x86.h" 33#include "Plugins/Process/Utility/ArchDefaultUnwindPlan-x86.h" 34#include "Plugins/Process/Utility/ArchVolatileRegs-x86.h" 35 36#if defined (__APPLE__) 37#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h" 38#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h" 39#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h" 40#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h" 41#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h" 42#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h" 43#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h" 44#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" 45#include "Plugins/Process/MacOSX-User/source/ProcessMacOSX.h" 46#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h" 47#include "Plugins/Platform/MacOSX/PlatformMacOSX.h" 48#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h" 49#endif 50 51#if defined (__linux__) 52#include "Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.h" 53#include "Plugins/Platform/Linux/PlatformLinux.h" 54#include "Plugins/Process/Linux/ProcessLinux.h" 55#endif 56 57#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h" 58#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h" 59 60using namespace lldb; 61using namespace lldb_private; 62 63 64void 65lldb_private::Initialize () 66{ 67 // Make sure we inialize only once 68 static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive); 69 static bool g_inited = false; 70 71 Mutex::Locker locker(g_inited_mutex); 72 if (!g_inited) 73 { 74 g_inited = true; 75 Log::Initialize(); 76 Timer::Initialize (); 77 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); 78 79 DisassemblerLLVM::Initialize(); 80 ObjectContainerBSDArchive::Initialize(); 81 ObjectFileELF::Initialize(); 82 SymbolFileDWARF::Initialize(); 83 SymbolFileSymtab::Initialize(); 84 UnwindAssemblyProfiler_x86::Initialize(); 85 ArchDefaultUnwindPlan_x86_64::Initialize(); 86 ArchDefaultUnwindPlan_i386::Initialize(); 87 ArchVolatileRegs_x86::Initialize(); 88 89#if defined (__APPLE__) 90 //---------------------------------------------------------------------- 91 // Apple/Darwin hosted plugins 92 //---------------------------------------------------------------------- 93 ABIMacOSX_i386::Initialize(); 94 ABISysV_x86_64::Initialize(); 95 DynamicLoaderMacOSXDYLD::Initialize(); 96 SymbolFileDWARFDebugMap::Initialize(); 97 ItaniumABILanguageRuntime::Initialize(); 98 AppleObjCRuntimeV2::Initialize(); 99 AppleObjCRuntimeV1::Initialize(); 100 ObjectContainerUniversalMachO::Initialize(); 101 ObjectFileMachO::Initialize(); 102 ProcessGDBRemote::Initialize(); 103 //ProcessMacOSX::Initialize(); 104 SymbolVendorMacOSX::Initialize(); 105 PlatformMacOSX::Initialize(); 106 PlatformRemoteiOS::Initialize(); 107#endif 108#if defined (__linux__) 109 //---------------------------------------------------------------------- 110 // Linux hosted plugins 111 //---------------------------------------------------------------------- 112 PlatformLinux::Initialize(); 113 ProcessLinux::Initialize(); 114 DynamicLoaderLinuxDYLD::Initialize(); 115#endif 116 //---------------------------------------------------------------------- 117 // Platform agnostic plugins 118 //---------------------------------------------------------------------- 119 PlatformRemoteGDBServer::Initialize (); 120 DynamicLoaderStatic::Initialize(); 121 122 // Scan for any system or user LLDB plug-ins 123 PluginManager::Initialize(); 124 125 // The process settings need to know about installed plug-ins, so the Settings must be initialized 126 // AFTER PluginManager::Initialize is called. 127 128 Debugger::SettingsInitialize(); 129 } 130} 131 132void 133lldb_private::WillTerminate() 134{ 135 Host::WillTerminate(); 136} 137 138void 139lldb_private::Terminate () 140{ 141 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); 142 143 // Terminate and unload and loaded system or user LLDB plug-ins 144 PluginManager::Terminate(); 145 146 DisassemblerLLVM::Terminate(); 147 ObjectContainerBSDArchive::Terminate(); 148 ObjectFileELF::Terminate(); 149 SymbolFileDWARF::Terminate(); 150 SymbolFileSymtab::Terminate(); 151 UnwindAssemblyProfiler_x86::Terminate(); 152 ArchDefaultUnwindPlan_i386::Terminate(); 153 ArchDefaultUnwindPlan_x86_64::Terminate(); 154 ArchVolatileRegs_x86::Terminate(); 155 156#if defined (__APPLE__) 157 DynamicLoaderMacOSXDYLD::Terminate(); 158 SymbolFileDWARFDebugMap::Terminate(); 159 ItaniumABILanguageRuntime::Terminate(); 160 AppleObjCRuntimeV2::Terminate(); 161 AppleObjCRuntimeV1::Terminate(); 162 ObjectContainerUniversalMachO::Terminate(); 163 ObjectFileMachO::Terminate(); 164 ProcessGDBRemote::Terminate(); 165 //ProcessMacOSX::Terminate(); 166 SymbolVendorMacOSX::Terminate(); 167 PlatformMacOSX::Terminate(); 168 PlatformRemoteiOS::Terminate(); 169#endif 170 171 Debugger::SettingsTerminate (); 172 173#if defined (__linux__) 174 PlatformLinux::Terminate(); 175 ProcessLinux::Terminate(); 176 DynamicLoaderLinuxDYLD::Terminate(); 177#endif 178 179 DynamicLoaderStatic::Terminate(); 180 181 Log::Terminate(); 182} 183 184extern "C" const double liblldb_coreVersionNumber; 185const char * 186lldb_private::GetVersion () 187{ 188 static char g_version_string[32]; 189 if (g_version_string[0] == '\0') 190 ::snprintf (g_version_string, sizeof(g_version_string), "LLDB-%g", liblldb_coreVersionNumber); 191 192 return g_version_string; 193} 194 195const char * 196lldb_private::GetVoteAsCString (lldb::Vote vote) 197{ 198 switch (vote) 199 { 200 case eVoteNo: return "no"; 201 case eVoteNoOpinion: return "no opinion"; 202 case eVoteYes: return "yes"; 203 default: 204 break; 205 } 206 return "invalid"; 207} 208 209 210const char * 211lldb_private::GetSectionTypeAsCString (lldb::SectionType sect_type) 212{ 213 switch (sect_type) 214 { 215 case eSectionTypeInvalid: return "invalid"; 216 case eSectionTypeCode: return "code"; 217 case eSectionTypeContainer: return "container"; 218 case eSectionTypeData: return "data"; 219 case eSectionTypeDataCString: return "data-cstr"; 220 case eSectionTypeDataCStringPointers: return "data-cstr-ptr"; 221 case eSectionTypeDataSymbolAddress: return "data-symbol-addr"; 222 case eSectionTypeData4: return "data-4-byte"; 223 case eSectionTypeData8: return "data-8-byte"; 224 case eSectionTypeData16: return "data-16-byte"; 225 case eSectionTypeDataPointers: return "data-ptrs"; 226 case eSectionTypeDebug: return "debug"; 227 case eSectionTypeZeroFill: return "zero-fill"; 228 case eSectionTypeDataObjCMessageRefs: return "objc-message-refs"; 229 case eSectionTypeDataObjCCFStrings: return "objc-cfstrings"; 230 case eSectionTypeDWARFDebugAbbrev: return "dwarf-abbrev"; 231 case eSectionTypeDWARFDebugAranges: return "dwarf-aranges"; 232 case eSectionTypeDWARFDebugFrame: return "dwarf-frame"; 233 case eSectionTypeDWARFDebugInfo: return "dwarf-info"; 234 case eSectionTypeDWARFDebugLine: return "dwarf-line"; 235 case eSectionTypeDWARFDebugLoc: return "dwarf-loc"; 236 case eSectionTypeDWARFDebugMacInfo: return "dwarf-macinfo"; 237 case eSectionTypeDWARFDebugPubNames: return "dwarf-pubnames"; 238 case eSectionTypeDWARFDebugPubTypes: return "dwarf-pubtypes"; 239 case eSectionTypeDWARFDebugRanges: return "dwarf-ranges"; 240 case eSectionTypeDWARFDebugStr: return "dwarf-str"; 241 case eSectionTypeEHFrame: return "eh-frame"; 242 case eSectionTypeOther: return "regular"; 243 } 244 return "unknown"; 245 246} 247 248bool 249lldb_private::NameMatches (const char *name, 250 lldb::NameMatchType match_type, 251 const char *match) 252{ 253 if (match_type == eNameMatchIgnore) 254 return true; 255 256 if (name == match) 257 return true; 258 259 if (name && match) 260 { 261 llvm::StringRef name_sref(name); 262 llvm::StringRef match_sref(match); 263 switch (match_type) 264 { 265 case eNameMatchIgnore: 266 return true; 267 case eNameMatchEquals: return name_sref == match_sref; 268 case eNameMatchContains: return name_sref.find (match_sref) != llvm::StringRef::npos; 269 case eNameMatchStartsWith: return name_sref.startswith (match_sref); 270 case eNameMatchEndsWith: return name_sref.endswith (match_sref); 271 case eNameMatchRegularExpression: 272 { 273 RegularExpression regex (match); 274 return regex.Execute (name); 275 } 276 break; 277 default: 278 assert (!"unhandled NameMatchType in lldb_private::NameMatches()"); 279 break; 280 } 281 } 282 return false; 283} 284