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