blob: cb2af8a081d9e134e4d8f435277a93bd3e9ed58e [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/lldb-private.h"
13#include "lldb/lldb-private-log.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000014#include "lldb/Core/ArchSpec.h"
Stephen Wilson28c16d92011-03-13 00:00:32 +000015#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Core/Log.h"
Greg Clayton4272cc72011-02-02 02:24:04 +000017#include "lldb/Core/PluginManager.h"
Greg Claytone996fd32011-03-08 22:40:15 +000018#include "lldb/Core/RegularExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/Timer.h"
20#include "lldb/Host/Host.h"
Zachary Turner673b6e42014-08-21 17:57:03 +000021#include "lldb/Host/HostInfo.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000022#include "lldb/Host/Mutex.h"
Greg Clayton44d93782014-01-27 23:43:24 +000023#include "lldb/Interpreter/ScriptInterpreterPython.h"
Greg Clayton3c310a12010-12-16 21:36:30 +000024#include "lldb/Target/Target.h"
25#include "lldb/Target/Thread.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000026
Greg Claytone996fd32011-03-08 22:40:15 +000027#include "llvm/ADT/StringRef.h"
Sean Callanan0de7ecd2014-08-23 00:47:22 +000028#include "llvm/Support/TargetSelect.h"
Greg Claytone996fd32011-03-08 22:40:15 +000029
Peter Collingbourne1b27dac2011-05-19 18:32:34 +000030#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
31#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
Jason Molendaa3329782014-03-29 18:54:20 +000032#include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h"
Peter Collingbournea09bfca2011-05-19 17:34:40 +000033#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
Sean Callanan95e5c632012-02-17 00:53:45 +000034#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000035#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
Caroline Ticead379efc2011-04-05 18:46:00 +000036#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
Jason Molendaa3329782014-03-29 18:54:20 +000037#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
38#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000039#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
40#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000041#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
42#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000043#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
44#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
45#include "Plugins/Platform/Linux/PlatformLinux.h"
46#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
47#include "Plugins/Platform/Windows/PlatformWindows.h"
Todd Fialacfee9632014-07-16 15:03:10 +000048#include "Plugins/Platform/Kalimba/PlatformKalimba.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000049#include "Plugins/Process/elf-core/ProcessElfCore.h"
50#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
51#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000052#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
53#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
54#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
Greg Clayton078daac2011-04-25 21:07:40 +000055#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
Greg Claytonffc922e32011-04-25 21:05:07 +000056#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000057
Greg Claytonb3e77602012-08-23 21:17:11 +000058#ifndef LLDB_DISABLE_PYTHON
59#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
60#endif
Greg Claytone996fd32011-03-08 22:40:15 +000061#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +000062#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
Greg Clayton944b8282011-08-22 22:30:57 +000063#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
Jim Ingham2a5e0f02010-11-04 18:30:59 +000064#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
65#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000066#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
67#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
Greg Clayton3a29bdb2011-07-17 20:36:25 +000068#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
Greg Claytone996fd32011-03-08 22:40:15 +000069#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
Greg Claytonded470d2011-03-19 01:12:21 +000070#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
Jason Molenda1c627542013-04-05 01:03:25 +000071#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
Greg Clayton722cec22012-02-25 06:56:35 +000072#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
Jason Molendaa7b5afa2013-11-15 00:17:32 +000073#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000074#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075
Greg Claytonc3776bf2012-02-09 06:16:32 +000076#include "Plugins/Process/mach-core/ProcessMachCore.h"
77
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +000078
Greg Claytone996fd32011-03-08 22:40:15 +000079#if defined (__linux__)
Greg Claytone996fd32011-03-08 22:40:15 +000080#include "Plugins/Process/Linux/ProcessLinux.h"
Stephen Wilsone6f9f662010-07-24 02:19:04 +000081#endif
82
Zachary Turner35ed1322014-07-28 16:45:18 +000083#if defined (_WIN32)
84#include "Plugins/Process/Windows/ProcessWindows.h"
85#endif
86
Johnny Chen8f3d8382011-08-02 20:52:42 +000087#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +000088#include "Plugins/Process/POSIX/ProcessPOSIX.h"
89#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
Johnny Chen8f3d8382011-08-02 20:52:42 +000090#endif
91
Greg Clayton1cb64962011-03-24 04:28:38 +000092#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
Daniel Malea97059d42013-01-08 14:55:36 +000093#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
Greg Claytonfc7117a2011-03-05 01:04:56 +000094#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
Kuba Breckabeed8212014-09-04 01:03:18 +000095#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
Greg Claytonfc7117a2011-03-05 01:04:56 +000096
Greg Claytonce6d19a2010-12-16 21:33:41 +000097using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098using namespace lldb_private;
99
Sean Callanan0de7ecd2014-08-23 00:47:22 +0000100static void fatal_error_handler(void *user_data, const std::string& reason,
101 bool gen_crash_diag) {
102 Host::SetCrashDescription(reason.c_str());
103 ::abort();
104}
105
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106void
107lldb_private::Initialize ()
108{
109 // Make sure we inialize only once
Caroline Tice2f88aad2011-01-14 00:29:16 +0000110 static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111 static bool g_inited = false;
112
113 Mutex::Locker locker(g_inited_mutex);
114 if (!g_inited)
115 {
116 g_inited = true;
Greg Clayton99d0faf2010-11-18 23:32:35 +0000117 Log::Initialize();
Zachary Turner673b6e42014-08-21 17:57:03 +0000118 HostInfo::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119 Timer::Initialize ();
120 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Sean Callanan0de7ecd2014-08-23 00:47:22 +0000121
122 // Initialize LLVM and Clang
123 llvm::InitializeAllTargets();
124 llvm::InitializeAllAsmPrinters();
125 llvm::InitializeAllTargetMCs();
126 llvm::InitializeAllDisassemblers();
127 llvm::install_fatal_error_handler(fatal_error_handler, 0);
128
129 // Initialize plug-ins
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000130 ABIMacOSX_i386::Initialize();
131 ABIMacOSX_arm::Initialize();
Jason Molendaa3329782014-03-29 18:54:20 +0000132 ABIMacOSX_arm64::Initialize();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000133 ABISysV_x86_64::Initialize();
Sean Callanan95e5c632012-02-17 00:53:45 +0000134 DisassemblerLLVMC::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135 ObjectContainerBSDArchive::Initialize();
136 ObjectFileELF::Initialize();
Michael Sartaina7499c92013-07-01 19:45:50 +0000137 SymbolVendorELF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138 SymbolFileDWARF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139 SymbolFileSymtab::Initialize();
Greg Claytonffc922e32011-04-25 21:05:07 +0000140 UnwindAssemblyInstEmulation::Initialize();
Greg Clayton2ed751b2011-04-26 04:39:08 +0000141 UnwindAssembly_x86::Initialize();
Caroline Ticead379efc2011-04-05 18:46:00 +0000142 EmulateInstructionARM::Initialize ();
Jason Molendaa3329782014-03-29 18:54:20 +0000143 EmulateInstructionARM64::Initialize ();
Greg Claytonf754f882011-09-09 20:33:05 +0000144 ObjectFilePECOFF::Initialize ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000145 DynamicLoaderPOSIXDYLD::Initialize ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000146 PlatformFreeBSD::Initialize();
147 PlatformLinux::Initialize();
Deepak Panickala0154f92013-10-15 12:32:12 +0000148 PlatformWindows::Initialize();
Todd Fialacfee9632014-07-16 15:03:10 +0000149 PlatformKalimba::Initialize();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000150 SymbolFileDWARFDebugMap::Initialize();
151 ItaniumABILanguageRuntime::Initialize();
Greg Claytonb3e77602012-08-23 21:17:11 +0000152#ifndef LLDB_DISABLE_PYTHON
Greg Clayton44d93782014-01-27 23:43:24 +0000153 ScriptInterpreterPython::InitializePrivate();
Greg Claytonb3e77602012-08-23 21:17:11 +0000154 OperatingSystemPython::Initialize();
155#endif
Greg Clayton4b047f22014-03-06 00:14:12 +0000156 JITLoaderGDB::Initialize();
157 ProcessElfCore::Initialize();
Kuba Breckabeed8212014-09-04 01:03:18 +0000158 MemoryHistoryASan::Initialize();
Greg Clayton4b047f22014-03-06 00:14:12 +0000159
Greg Claytone996fd32011-03-08 22:40:15 +0000160#if defined (__APPLE__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000161 //----------------------------------------------------------------------
162 // Apple/Darwin hosted plugins
163 //----------------------------------------------------------------------
Eli Friedmane13a8db2010-06-13 19:36:42 +0000164 DynamicLoaderMacOSXDYLD::Initialize();
Greg Clayton944b8282011-08-22 22:30:57 +0000165 DynamicLoaderDarwinKernel::Initialize();
Jim Ingham22777012010-09-23 02:01:19 +0000166 AppleObjCRuntimeV2::Initialize();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000167 AppleObjCRuntimeV1::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000168 ObjectContainerUniversalMachO::Initialize();
169 ObjectFileMachO::Initialize();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000170 ProcessKDP::Initialize();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000171 ProcessMachCore::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000172 SymbolVendorMacOSX::Initialize();
Jason Molenda1c627542013-04-05 01:03:25 +0000173 PlatformDarwinKernel::Initialize();
Greg Claytonded470d2011-03-19 01:12:21 +0000174 PlatformRemoteiOS::Initialize();
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000175 PlatformMacOSX::Initialize();
Greg Clayton722cec22012-02-25 06:56:35 +0000176 PlatformiOSSimulator::Initialize();
Jason Molendaa7b5afa2013-11-15 00:17:32 +0000177 SystemRuntimeMacOSX::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000178#endif
Greg Claytone996fd32011-03-08 22:40:15 +0000179#if defined (__linux__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000180 //----------------------------------------------------------------------
181 // Linux hosted plugins
182 //----------------------------------------------------------------------
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000183 ProcessLinux::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000184#endif
Zachary Turner35ed1322014-07-28 16:45:18 +0000185#if defined(_WIN32)
186 ProcessWindows::Initialize();
187#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000188#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000189 ProcessFreeBSD::Initialize();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000190#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000191
Greg Clayton1cb64962011-03-24 04:28:38 +0000192 //----------------------------------------------------------------------
193 // Platform agnostic plugins
194 //----------------------------------------------------------------------
195 PlatformRemoteGDBServer::Initialize ();
Daniel Malea97059d42013-01-08 14:55:36 +0000196 ProcessGDBRemote::Initialize();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000197 DynamicLoaderStatic::Initialize();
Greg Clayton1cb64962011-03-24 04:28:38 +0000198
Greg Clayton4272cc72011-02-02 02:24:04 +0000199 // Scan for any system or user LLDB plug-ins
200 PluginManager::Initialize();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +0000201
Caroline Tice20bd37f2011-03-10 22:14:10 +0000202 // The process settings need to know about installed plug-ins, so the Settings must be initialized
203 // AFTER PluginManager::Initialize is called.
204
205 Debugger::SettingsInitialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 }
207}
208
209void
210lldb_private::WillTerminate()
211{
212 Host::WillTerminate();
213}
214
215void
216lldb_private::Terminate ()
217{
218 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton4272cc72011-02-02 02:24:04 +0000219
220 // Terminate and unload and loaded system or user LLDB plug-ins
221 PluginManager::Terminate();
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000222 ABIMacOSX_i386::Terminate();
223 ABIMacOSX_arm::Terminate();
Jason Molendaa3329782014-03-29 18:54:20 +0000224 ABIMacOSX_arm64::Terminate();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000225 ABISysV_x86_64::Terminate();
Sean Callanan95e5c632012-02-17 00:53:45 +0000226 DisassemblerLLVMC::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227 ObjectContainerBSDArchive::Terminate();
228 ObjectFileELF::Terminate();
Michael Sartaina7499c92013-07-01 19:45:50 +0000229 SymbolVendorELF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230 SymbolFileDWARF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231 SymbolFileSymtab::Terminate();
Greg Claytonffc922e32011-04-25 21:05:07 +0000232 UnwindAssembly_x86::Terminate();
233 UnwindAssemblyInstEmulation::Terminate();
Caroline Ticead379efc2011-04-05 18:46:00 +0000234 EmulateInstructionARM::Terminate ();
Jason Molendaa3329782014-03-29 18:54:20 +0000235 EmulateInstructionARM64::Terminate ();
Greg Claytonf754f882011-09-09 20:33:05 +0000236 ObjectFilePECOFF::Terminate ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000237 DynamicLoaderPOSIXDYLD::Terminate ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000238 PlatformFreeBSD::Terminate();
239 PlatformLinux::Terminate();
Deepak Panickala0154f92013-10-15 12:32:12 +0000240 PlatformWindows::Terminate();
Todd Fialacfee9632014-07-16 15:03:10 +0000241 PlatformKalimba::Terminate();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000242 SymbolFileDWARFDebugMap::Terminate();
243 ItaniumABILanguageRuntime::Terminate();
Greg Claytonb3e77602012-08-23 21:17:11 +0000244#ifndef LLDB_DISABLE_PYTHON
245 OperatingSystemPython::Terminate();
246#endif
Greg Clayton4b047f22014-03-06 00:14:12 +0000247 JITLoaderGDB::Terminate();
248 ProcessElfCore::Terminate();
Kuba Breckabeed8212014-09-04 01:03:18 +0000249 MemoryHistoryASan::Terminate();
Greg Clayton0e4b6052014-03-06 23:29:58 +0000250
Greg Claytone996fd32011-03-08 22:40:15 +0000251#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +0000252 DynamicLoaderMacOSXDYLD::Terminate();
Greg Clayton944b8282011-08-22 22:30:57 +0000253 DynamicLoaderDarwinKernel::Terminate();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000254 AppleObjCRuntimeV2::Terminate();
255 AppleObjCRuntimeV1::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000256 ObjectContainerUniversalMachO::Terminate();
257 ObjectFileMachO::Terminate();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000258 ProcessMachCore::Terminate();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000259 ProcessKDP::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000260 SymbolVendorMacOSX::Terminate();
Greg Claytone996fd32011-03-08 22:40:15 +0000261 PlatformMacOSX::Terminate();
Jason Molenda1c627542013-04-05 01:03:25 +0000262 PlatformDarwinKernel::Terminate();
Greg Claytonded470d2011-03-19 01:12:21 +0000263 PlatformRemoteiOS::Terminate();
Greg Clayton722cec22012-02-25 06:56:35 +0000264 PlatformiOSSimulator::Terminate();
Jason Molendaa7b5afa2013-11-15 00:17:32 +0000265 SystemRuntimeMacOSX::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000266#endif
267
Caroline Tice20bd37f2011-03-10 22:14:10 +0000268 Debugger::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000269
Greg Claytone996fd32011-03-08 22:40:15 +0000270#if defined (__linux__)
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000271 ProcessLinux::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000272#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000273
274#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000275 ProcessFreeBSD::Terminate();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000276#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000277
Daniel Malea97059d42013-01-08 14:55:36 +0000278 ProcessGDBRemote::Terminate();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000279 DynamicLoaderStatic::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000280
281 Log::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282}
283
Daniel Malea3b92f002013-02-28 16:51:15 +0000284#if defined (__APPLE__)
Sean Callanan3d27e662013-03-07 22:29:06 +0000285extern "C" const unsigned char liblldb_coreVersionString[];
Greg Clayton7170f3f2013-02-28 18:09:18 +0000286#else
287
288#include "clang/Basic/Version.h"
289
290static const char *
291GetLLDBRevision()
292{
293#ifdef LLDB_REVISION
294 return LLDB_REVISION;
295#else
296 return NULL;
297#endif
298}
299
300static const char *
301GetLLDBRepository()
302{
303#ifdef LLDB_REPOSITORY
304 return LLDB_REPOSITORY;
305#else
306 return NULL;
307#endif
308}
309
Daniel Malea3b92f002013-02-28 16:51:15 +0000310#endif
311
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312const char *
313lldb_private::GetVersion ()
314{
Daniel Malea3b92f002013-02-28 16:51:15 +0000315#if defined (__APPLE__)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316 static char g_version_string[32];
317 if (g_version_string[0] == '\0')
Sean Callanan3d27e662013-03-07 22:29:06 +0000318 {
319 const char *version_string = ::strstr ((const char *)liblldb_coreVersionString, "PROJECT:");
320
321 if (version_string)
322 version_string += sizeof("PROJECT:") - 1;
323 else
324 version_string = "unknown";
325
326 const char *newline_loc = strchr(version_string, '\n');
327
328 size_t version_len = sizeof(g_version_string);
329
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000330 if (newline_loc &&
331 (newline_loc - version_string < static_cast<ptrdiff_t>(version_len)))
Sean Callanan3d27e662013-03-07 22:29:06 +0000332 version_len = newline_loc - version_string;
333
334 ::strncpy(g_version_string, version_string, version_len);
335 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336
337 return g_version_string;
Daniel Malea3b92f002013-02-28 16:51:15 +0000338#else
339 // On Linux/FreeBSD/Windows, report a version number in the same style as the clang tool.
Greg Clayton7170f3f2013-02-28 18:09:18 +0000340 static std::string g_version_str;
341 if (g_version_str.empty())
342 {
343 g_version_str += "lldb version ";
344 g_version_str += CLANG_VERSION_STRING;
345 const char * lldb_repo = GetLLDBRepository();
346 if (lldb_repo)
347 {
348 g_version_str += " (";
349 g_version_str += lldb_repo;
350 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000351
Greg Clayton7170f3f2013-02-28 18:09:18 +0000352 const char *lldb_rev = GetLLDBRevision();
353 if (lldb_rev)
354 {
355 g_version_str += " revision ";
356 g_version_str += lldb_rev;
357 }
358 std::string clang_rev (clang::getClangRevision());
359 if (clang_rev.length() > 0)
360 {
361 g_version_str += " clang revision ";
362 g_version_str += clang_rev;
363 }
364 std::string llvm_rev (clang::getLLVMRevision());
365 if (llvm_rev.length() > 0)
366 {
367 g_version_str += " llvm revision ";
368 g_version_str += llvm_rev;
369 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000370
Greg Clayton7170f3f2013-02-28 18:09:18 +0000371 if (lldb_repo)
372 g_version_str += ")";
373 }
374 return g_version_str.c_str();
Daniel Malea3b92f002013-02-28 16:51:15 +0000375#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376}
377
Greg Clayton2cad65a2010-09-03 17:10:42 +0000378const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000379lldb_private::GetVoteAsCString (Vote vote)
Greg Clayton2cad65a2010-09-03 17:10:42 +0000380{
Greg Clayton1346f7e2010-09-03 22:45:01 +0000381 switch (vote)
382 {
383 case eVoteNo: return "no";
384 case eVoteNoOpinion: return "no opinion";
385 case eVoteYes: return "yes";
Greg Clayton1346f7e2010-09-03 22:45:01 +0000386 }
Greg Clayton2cad65a2010-09-03 17:10:42 +0000387 return "invalid";
388}
389
Greg Clayton89411422010-10-08 00:21:05 +0000390
391const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000392lldb_private::GetSectionTypeAsCString (SectionType sect_type)
Greg Clayton89411422010-10-08 00:21:05 +0000393{
394 switch (sect_type)
395 {
396 case eSectionTypeInvalid: return "invalid";
397 case eSectionTypeCode: return "code";
398 case eSectionTypeContainer: return "container";
399 case eSectionTypeData: return "data";
400 case eSectionTypeDataCString: return "data-cstr";
401 case eSectionTypeDataCStringPointers: return "data-cstr-ptr";
402 case eSectionTypeDataSymbolAddress: return "data-symbol-addr";
403 case eSectionTypeData4: return "data-4-byte";
404 case eSectionTypeData8: return "data-8-byte";
405 case eSectionTypeData16: return "data-16-byte";
406 case eSectionTypeDataPointers: return "data-ptrs";
407 case eSectionTypeDebug: return "debug";
408 case eSectionTypeZeroFill: return "zero-fill";
409 case eSectionTypeDataObjCMessageRefs: return "objc-message-refs";
410 case eSectionTypeDataObjCCFStrings: return "objc-cfstrings";
411 case eSectionTypeDWARFDebugAbbrev: return "dwarf-abbrev";
412 case eSectionTypeDWARFDebugAranges: return "dwarf-aranges";
413 case eSectionTypeDWARFDebugFrame: return "dwarf-frame";
414 case eSectionTypeDWARFDebugInfo: return "dwarf-info";
415 case eSectionTypeDWARFDebugLine: return "dwarf-line";
416 case eSectionTypeDWARFDebugLoc: return "dwarf-loc";
417 case eSectionTypeDWARFDebugMacInfo: return "dwarf-macinfo";
418 case eSectionTypeDWARFDebugPubNames: return "dwarf-pubnames";
419 case eSectionTypeDWARFDebugPubTypes: return "dwarf-pubtypes";
420 case eSectionTypeDWARFDebugRanges: return "dwarf-ranges";
421 case eSectionTypeDWARFDebugStr: return "dwarf-str";
Michael Sartaina7499c92013-07-01 19:45:50 +0000422 case eSectionTypeELFSymbolTable: return "elf-symbol-table";
423 case eSectionTypeELFDynamicSymbols: return "elf-dynamic-symbols";
424 case eSectionTypeELFRelocationEntries: return "elf-relocation-entries";
425 case eSectionTypeELFDynamicLinkInfo: return "elf-dynamic-link-info";
Greg Clayton17674402011-09-28 17:06:40 +0000426 case eSectionTypeDWARFAppleNames: return "apple-names";
427 case eSectionTypeDWARFAppleTypes: return "apple-types";
Greg Clayton7f995132011-10-04 22:41:51 +0000428 case eSectionTypeDWARFAppleNamespaces: return "apple-namespaces";
Greg Clayton5009f9d2011-10-27 17:55:14 +0000429 case eSectionTypeDWARFAppleObjC: return "apple-objc";
Greg Clayton89411422010-10-08 00:21:05 +0000430 case eSectionTypeEHFrame: return "eh-frame";
431 case eSectionTypeOther: return "regular";
432 }
433 return "unknown";
434
435}
436
Greg Claytone996fd32011-03-08 22:40:15 +0000437bool
438lldb_private::NameMatches (const char *name,
Greg Claytone0d378b2011-03-24 21:19:54 +0000439 NameMatchType match_type,
Greg Claytone996fd32011-03-08 22:40:15 +0000440 const char *match)
441{
442 if (match_type == eNameMatchIgnore)
443 return true;
444
445 if (name == match)
446 return true;
447
448 if (name && match)
449 {
450 llvm::StringRef name_sref(name);
451 llvm::StringRef match_sref(match);
452 switch (match_type)
453 {
Sylvestre Ledru6e2c7cb2013-10-14 14:06:28 +0000454 case eNameMatchIgnore: // This case cannot occur: tested before
455 return true;
Greg Claytone996fd32011-03-08 22:40:15 +0000456 case eNameMatchEquals: return name_sref == match_sref;
457 case eNameMatchContains: return name_sref.find (match_sref) != llvm::StringRef::npos;
458 case eNameMatchStartsWith: return name_sref.startswith (match_sref);
459 case eNameMatchEndsWith: return name_sref.endswith (match_sref);
460 case eNameMatchRegularExpression:
461 {
462 RegularExpression regex (match);
463 return regex.Execute (name);
464 }
465 break;
Greg Claytone996fd32011-03-08 22:40:15 +0000466 }
467 }
468 return false;
469}