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