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