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