blob: befcc3c9c91d7cdf82fd431d82fecf0fc67b3e8c [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"
Eli Friedmane13a8db2010-06-13 19:36:42 +000021#include "lldb/Host/Mutex.h"
Greg Clayton44d93782014-01-27 23:43:24 +000022#include "lldb/Interpreter/ScriptInterpreterPython.h"
Greg Clayton3c310a12010-12-16 21:36:30 +000023#include "lldb/Target/Target.h"
24#include "lldb/Target/Thread.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000025
Greg Claytone996fd32011-03-08 22:40:15 +000026#include "llvm/ADT/StringRef.h"
27
Peter Collingbourne1b27dac2011-05-19 18:32:34 +000028#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
29#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
Jason Molendaa3329782014-03-29 18:54:20 +000030#include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h"
Peter Collingbournea09bfca2011-05-19 17:34:40 +000031#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
Sean Callanan95e5c632012-02-17 00:53:45 +000032#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000033#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
Caroline Ticead379efc2011-04-05 18:46:00 +000034#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
Jason Molendaa3329782014-03-29 18:54:20 +000035#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
36#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000037#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
38#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000039#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
40#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000041#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
42#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
43#include "Plugins/Platform/Linux/PlatformLinux.h"
44#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
45#include "Plugins/Platform/Windows/PlatformWindows.h"
Todd Fialacfee9632014-07-16 15:03:10 +000046#include "Plugins/Platform/Kalimba/PlatformKalimba.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000047#include "Plugins/Process/elf-core/ProcessElfCore.h"
48#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
49#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000050#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
51#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
52#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
Greg Clayton078daac2011-04-25 21:07:40 +000053#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
Greg Claytonffc922e32011-04-25 21:05:07 +000054#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000055
Greg Claytonb3e77602012-08-23 21:17:11 +000056#ifndef LLDB_DISABLE_PYTHON
57#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
58#endif
Greg Claytone996fd32011-03-08 22:40:15 +000059#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +000060#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
Greg Clayton944b8282011-08-22 22:30:57 +000061#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
Jim Ingham2a5e0f02010-11-04 18:30:59 +000062#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
63#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000064#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
65#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
Greg Clayton3a29bdb2011-07-17 20:36:25 +000066#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
Greg Claytone996fd32011-03-08 22:40:15 +000067#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
Greg Claytonded470d2011-03-19 01:12:21 +000068#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
Jason Molenda1c627542013-04-05 01:03:25 +000069#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
Greg Clayton722cec22012-02-25 06:56:35 +000070#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
Jason Molendaa7b5afa2013-11-15 00:17:32 +000071#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000072#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073
Greg Claytonc3776bf2012-02-09 06:16:32 +000074#include "Plugins/Process/mach-core/ProcessMachCore.h"
75
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +000076
Greg Claytone996fd32011-03-08 22:40:15 +000077#if defined (__linux__)
Greg Claytone996fd32011-03-08 22:40:15 +000078#include "Plugins/Process/Linux/ProcessLinux.h"
Stephen Wilsone6f9f662010-07-24 02:19:04 +000079#endif
80
Zachary Turner35ed1322014-07-28 16:45:18 +000081#if defined (_WIN32)
82#include "Plugins/Process/Windows/ProcessWindows.h"
83#endif
84
Johnny Chen8f3d8382011-08-02 20:52:42 +000085#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +000086#include "Plugins/Process/POSIX/ProcessPOSIX.h"
87#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
Johnny Chen8f3d8382011-08-02 20:52:42 +000088#endif
89
Greg Clayton1cb64962011-03-24 04:28:38 +000090#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
Daniel Malea97059d42013-01-08 14:55:36 +000091#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
Greg Claytonfc7117a2011-03-05 01:04:56 +000092#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
93
Greg Claytonce6d19a2010-12-16 21:33:41 +000094using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095using namespace lldb_private;
96
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097void
98lldb_private::Initialize ()
99{
100 // Make sure we inialize only once
Caroline Tice2f88aad2011-01-14 00:29:16 +0000101 static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102 static bool g_inited = false;
103
104 Mutex::Locker locker(g_inited_mutex);
105 if (!g_inited)
106 {
107 g_inited = true;
Greg Clayton99d0faf2010-11-18 23:32:35 +0000108 Log::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 Timer::Initialize ();
110 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton99d0faf2010-11-18 23:32:35 +0000111
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000112 ABIMacOSX_i386::Initialize();
113 ABIMacOSX_arm::Initialize();
Jason Molendaa3329782014-03-29 18:54:20 +0000114 ABIMacOSX_arm64::Initialize();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000115 ABISysV_x86_64::Initialize();
Sean Callanan95e5c632012-02-17 00:53:45 +0000116 DisassemblerLLVMC::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117 ObjectContainerBSDArchive::Initialize();
118 ObjectFileELF::Initialize();
Michael Sartaina7499c92013-07-01 19:45:50 +0000119 SymbolVendorELF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120 SymbolFileDWARF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121 SymbolFileSymtab::Initialize();
Greg Claytonffc922e32011-04-25 21:05:07 +0000122 UnwindAssemblyInstEmulation::Initialize();
Greg Clayton2ed751b2011-04-26 04:39:08 +0000123 UnwindAssembly_x86::Initialize();
Caroline Ticead379efc2011-04-05 18:46:00 +0000124 EmulateInstructionARM::Initialize ();
Jason Molendaa3329782014-03-29 18:54:20 +0000125 EmulateInstructionARM64::Initialize ();
Greg Claytonf754f882011-09-09 20:33:05 +0000126 ObjectFilePECOFF::Initialize ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000127 DynamicLoaderPOSIXDYLD::Initialize ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000128 PlatformFreeBSD::Initialize();
129 PlatformLinux::Initialize();
Deepak Panickala0154f92013-10-15 12:32:12 +0000130 PlatformWindows::Initialize();
Todd Fialacfee9632014-07-16 15:03:10 +0000131 PlatformKalimba::Initialize();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000132 SymbolFileDWARFDebugMap::Initialize();
133 ItaniumABILanguageRuntime::Initialize();
Greg Claytonb3e77602012-08-23 21:17:11 +0000134#ifndef LLDB_DISABLE_PYTHON
Greg Clayton44d93782014-01-27 23:43:24 +0000135 ScriptInterpreterPython::InitializePrivate();
Greg Claytonb3e77602012-08-23 21:17:11 +0000136 OperatingSystemPython::Initialize();
137#endif
Greg Clayton4b047f22014-03-06 00:14:12 +0000138 JITLoaderGDB::Initialize();
139 ProcessElfCore::Initialize();
140
Greg Claytone996fd32011-03-08 22:40:15 +0000141#if defined (__APPLE__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000142 //----------------------------------------------------------------------
143 // Apple/Darwin hosted plugins
144 //----------------------------------------------------------------------
Eli Friedmane13a8db2010-06-13 19:36:42 +0000145 DynamicLoaderMacOSXDYLD::Initialize();
Greg Clayton944b8282011-08-22 22:30:57 +0000146 DynamicLoaderDarwinKernel::Initialize();
Jim Ingham22777012010-09-23 02:01:19 +0000147 AppleObjCRuntimeV2::Initialize();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000148 AppleObjCRuntimeV1::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000149 ObjectContainerUniversalMachO::Initialize();
150 ObjectFileMachO::Initialize();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000151 ProcessKDP::Initialize();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000152 ProcessMachCore::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000153 SymbolVendorMacOSX::Initialize();
Jason Molenda1c627542013-04-05 01:03:25 +0000154 PlatformDarwinKernel::Initialize();
Greg Claytonded470d2011-03-19 01:12:21 +0000155 PlatformRemoteiOS::Initialize();
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000156 PlatformMacOSX::Initialize();
Greg Clayton722cec22012-02-25 06:56:35 +0000157 PlatformiOSSimulator::Initialize();
Jason Molendaa7b5afa2013-11-15 00:17:32 +0000158 SystemRuntimeMacOSX::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000159#endif
Greg Claytone996fd32011-03-08 22:40:15 +0000160#if defined (__linux__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000161 //----------------------------------------------------------------------
162 // Linux hosted plugins
163 //----------------------------------------------------------------------
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000164 ProcessLinux::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000165#endif
Zachary Turner35ed1322014-07-28 16:45:18 +0000166#if defined(_WIN32)
167 ProcessWindows::Initialize();
168#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000169#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000170 ProcessFreeBSD::Initialize();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000171#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000172
Greg Clayton1cb64962011-03-24 04:28:38 +0000173 //----------------------------------------------------------------------
174 // Platform agnostic plugins
175 //----------------------------------------------------------------------
176 PlatformRemoteGDBServer::Initialize ();
Daniel Malea97059d42013-01-08 14:55:36 +0000177 ProcessGDBRemote::Initialize();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000178 DynamicLoaderStatic::Initialize();
Greg Clayton1cb64962011-03-24 04:28:38 +0000179
Greg Clayton4272cc72011-02-02 02:24:04 +0000180 // Scan for any system or user LLDB plug-ins
181 PluginManager::Initialize();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +0000182
Caroline Tice20bd37f2011-03-10 22:14:10 +0000183 // The process settings need to know about installed plug-ins, so the Settings must be initialized
184 // AFTER PluginManager::Initialize is called.
185
186 Debugger::SettingsInitialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000187 }
188}
189
190void
191lldb_private::WillTerminate()
192{
193 Host::WillTerminate();
194}
195
196void
197lldb_private::Terminate ()
198{
199 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton4272cc72011-02-02 02:24:04 +0000200
201 // Terminate and unload and loaded system or user LLDB plug-ins
202 PluginManager::Terminate();
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000203 ABIMacOSX_i386::Terminate();
204 ABIMacOSX_arm::Terminate();
Jason Molendaa3329782014-03-29 18:54:20 +0000205 ABIMacOSX_arm64::Terminate();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000206 ABISysV_x86_64::Terminate();
Sean Callanan95e5c632012-02-17 00:53:45 +0000207 DisassemblerLLVMC::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208 ObjectContainerBSDArchive::Terminate();
209 ObjectFileELF::Terminate();
Michael Sartaina7499c92013-07-01 19:45:50 +0000210 SymbolVendorELF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211 SymbolFileDWARF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000212 SymbolFileSymtab::Terminate();
Greg Claytonffc922e32011-04-25 21:05:07 +0000213 UnwindAssembly_x86::Terminate();
214 UnwindAssemblyInstEmulation::Terminate();
Caroline Ticead379efc2011-04-05 18:46:00 +0000215 EmulateInstructionARM::Terminate ();
Jason Molendaa3329782014-03-29 18:54:20 +0000216 EmulateInstructionARM64::Terminate ();
Greg Claytonf754f882011-09-09 20:33:05 +0000217 ObjectFilePECOFF::Terminate ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000218 DynamicLoaderPOSIXDYLD::Terminate ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000219 PlatformFreeBSD::Terminate();
220 PlatformLinux::Terminate();
Deepak Panickala0154f92013-10-15 12:32:12 +0000221 PlatformWindows::Terminate();
Todd Fialacfee9632014-07-16 15:03:10 +0000222 PlatformKalimba::Terminate();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000223 SymbolFileDWARFDebugMap::Terminate();
224 ItaniumABILanguageRuntime::Terminate();
Greg Claytonb3e77602012-08-23 21:17:11 +0000225#ifndef LLDB_DISABLE_PYTHON
226 OperatingSystemPython::Terminate();
227#endif
Greg Clayton4b047f22014-03-06 00:14:12 +0000228 JITLoaderGDB::Terminate();
229 ProcessElfCore::Terminate();
Greg Clayton0e4b6052014-03-06 23:29:58 +0000230
Greg Claytone996fd32011-03-08 22:40:15 +0000231#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +0000232 DynamicLoaderMacOSXDYLD::Terminate();
Greg Clayton944b8282011-08-22 22:30:57 +0000233 DynamicLoaderDarwinKernel::Terminate();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000234 AppleObjCRuntimeV2::Terminate();
235 AppleObjCRuntimeV1::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000236 ObjectContainerUniversalMachO::Terminate();
237 ObjectFileMachO::Terminate();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000238 ProcessMachCore::Terminate();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000239 ProcessKDP::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000240 SymbolVendorMacOSX::Terminate();
Greg Claytone996fd32011-03-08 22:40:15 +0000241 PlatformMacOSX::Terminate();
Jason Molenda1c627542013-04-05 01:03:25 +0000242 PlatformDarwinKernel::Terminate();
Greg Claytonded470d2011-03-19 01:12:21 +0000243 PlatformRemoteiOS::Terminate();
Greg Clayton722cec22012-02-25 06:56:35 +0000244 PlatformiOSSimulator::Terminate();
Jason Molendaa7b5afa2013-11-15 00:17:32 +0000245 SystemRuntimeMacOSX::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000246#endif
247
Caroline Tice20bd37f2011-03-10 22:14:10 +0000248 Debugger::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000249
Greg Claytone996fd32011-03-08 22:40:15 +0000250#if defined (__linux__)
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000251 ProcessLinux::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000252#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000253
254#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000255 ProcessFreeBSD::Terminate();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000256#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000257
Daniel Malea97059d42013-01-08 14:55:36 +0000258 ProcessGDBRemote::Terminate();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000259 DynamicLoaderStatic::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000260
261 Log::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262}
263
Daniel Malea3b92f002013-02-28 16:51:15 +0000264#if defined (__APPLE__)
Sean Callanan3d27e662013-03-07 22:29:06 +0000265extern "C" const unsigned char liblldb_coreVersionString[];
Greg Clayton7170f3f2013-02-28 18:09:18 +0000266#else
267
268#include "clang/Basic/Version.h"
269
270static const char *
271GetLLDBRevision()
272{
273#ifdef LLDB_REVISION
274 return LLDB_REVISION;
275#else
276 return NULL;
277#endif
278}
279
280static const char *
281GetLLDBRepository()
282{
283#ifdef LLDB_REPOSITORY
284 return LLDB_REPOSITORY;
285#else
286 return NULL;
287#endif
288}
289
Daniel Malea3b92f002013-02-28 16:51:15 +0000290#endif
291
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292const char *
293lldb_private::GetVersion ()
294{
Daniel Malea3b92f002013-02-28 16:51:15 +0000295#if defined (__APPLE__)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000296 static char g_version_string[32];
297 if (g_version_string[0] == '\0')
Sean Callanan3d27e662013-03-07 22:29:06 +0000298 {
299 const char *version_string = ::strstr ((const char *)liblldb_coreVersionString, "PROJECT:");
300
301 if (version_string)
302 version_string += sizeof("PROJECT:") - 1;
303 else
304 version_string = "unknown";
305
306 const char *newline_loc = strchr(version_string, '\n');
307
308 size_t version_len = sizeof(g_version_string);
309
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000310 if (newline_loc &&
311 (newline_loc - version_string < static_cast<ptrdiff_t>(version_len)))
Sean Callanan3d27e662013-03-07 22:29:06 +0000312 version_len = newline_loc - version_string;
313
314 ::strncpy(g_version_string, version_string, version_len);
315 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316
317 return g_version_string;
Daniel Malea3b92f002013-02-28 16:51:15 +0000318#else
319 // On Linux/FreeBSD/Windows, report a version number in the same style as the clang tool.
Greg Clayton7170f3f2013-02-28 18:09:18 +0000320 static std::string g_version_str;
321 if (g_version_str.empty())
322 {
323 g_version_str += "lldb version ";
324 g_version_str += CLANG_VERSION_STRING;
325 const char * lldb_repo = GetLLDBRepository();
326 if (lldb_repo)
327 {
328 g_version_str += " (";
329 g_version_str += lldb_repo;
330 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000331
Greg Clayton7170f3f2013-02-28 18:09:18 +0000332 const char *lldb_rev = GetLLDBRevision();
333 if (lldb_rev)
334 {
335 g_version_str += " revision ";
336 g_version_str += lldb_rev;
337 }
338 std::string clang_rev (clang::getClangRevision());
339 if (clang_rev.length() > 0)
340 {
341 g_version_str += " clang revision ";
342 g_version_str += clang_rev;
343 }
344 std::string llvm_rev (clang::getLLVMRevision());
345 if (llvm_rev.length() > 0)
346 {
347 g_version_str += " llvm revision ";
348 g_version_str += llvm_rev;
349 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000350
Greg Clayton7170f3f2013-02-28 18:09:18 +0000351 if (lldb_repo)
352 g_version_str += ")";
353 }
354 return g_version_str.c_str();
Daniel Malea3b92f002013-02-28 16:51:15 +0000355#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356}
357
Greg Clayton2cad65a2010-09-03 17:10:42 +0000358const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000359lldb_private::GetVoteAsCString (Vote vote)
Greg Clayton2cad65a2010-09-03 17:10:42 +0000360{
Greg Clayton1346f7e2010-09-03 22:45:01 +0000361 switch (vote)
362 {
363 case eVoteNo: return "no";
364 case eVoteNoOpinion: return "no opinion";
365 case eVoteYes: return "yes";
Greg Clayton1346f7e2010-09-03 22:45:01 +0000366 }
Greg Clayton2cad65a2010-09-03 17:10:42 +0000367 return "invalid";
368}
369
Greg Clayton89411422010-10-08 00:21:05 +0000370
371const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000372lldb_private::GetSectionTypeAsCString (SectionType sect_type)
Greg Clayton89411422010-10-08 00:21:05 +0000373{
374 switch (sect_type)
375 {
376 case eSectionTypeInvalid: return "invalid";
377 case eSectionTypeCode: return "code";
378 case eSectionTypeContainer: return "container";
379 case eSectionTypeData: return "data";
380 case eSectionTypeDataCString: return "data-cstr";
381 case eSectionTypeDataCStringPointers: return "data-cstr-ptr";
382 case eSectionTypeDataSymbolAddress: return "data-symbol-addr";
383 case eSectionTypeData4: return "data-4-byte";
384 case eSectionTypeData8: return "data-8-byte";
385 case eSectionTypeData16: return "data-16-byte";
386 case eSectionTypeDataPointers: return "data-ptrs";
387 case eSectionTypeDebug: return "debug";
388 case eSectionTypeZeroFill: return "zero-fill";
389 case eSectionTypeDataObjCMessageRefs: return "objc-message-refs";
390 case eSectionTypeDataObjCCFStrings: return "objc-cfstrings";
391 case eSectionTypeDWARFDebugAbbrev: return "dwarf-abbrev";
392 case eSectionTypeDWARFDebugAranges: return "dwarf-aranges";
393 case eSectionTypeDWARFDebugFrame: return "dwarf-frame";
394 case eSectionTypeDWARFDebugInfo: return "dwarf-info";
395 case eSectionTypeDWARFDebugLine: return "dwarf-line";
396 case eSectionTypeDWARFDebugLoc: return "dwarf-loc";
397 case eSectionTypeDWARFDebugMacInfo: return "dwarf-macinfo";
398 case eSectionTypeDWARFDebugPubNames: return "dwarf-pubnames";
399 case eSectionTypeDWARFDebugPubTypes: return "dwarf-pubtypes";
400 case eSectionTypeDWARFDebugRanges: return "dwarf-ranges";
401 case eSectionTypeDWARFDebugStr: return "dwarf-str";
Michael Sartaina7499c92013-07-01 19:45:50 +0000402 case eSectionTypeELFSymbolTable: return "elf-symbol-table";
403 case eSectionTypeELFDynamicSymbols: return "elf-dynamic-symbols";
404 case eSectionTypeELFRelocationEntries: return "elf-relocation-entries";
405 case eSectionTypeELFDynamicLinkInfo: return "elf-dynamic-link-info";
Greg Clayton17674402011-09-28 17:06:40 +0000406 case eSectionTypeDWARFAppleNames: return "apple-names";
407 case eSectionTypeDWARFAppleTypes: return "apple-types";
Greg Clayton7f995132011-10-04 22:41:51 +0000408 case eSectionTypeDWARFAppleNamespaces: return "apple-namespaces";
Greg Clayton5009f9d2011-10-27 17:55:14 +0000409 case eSectionTypeDWARFAppleObjC: return "apple-objc";
Greg Clayton89411422010-10-08 00:21:05 +0000410 case eSectionTypeEHFrame: return "eh-frame";
411 case eSectionTypeOther: return "regular";
412 }
413 return "unknown";
414
415}
416
Greg Claytone996fd32011-03-08 22:40:15 +0000417bool
418lldb_private::NameMatches (const char *name,
Greg Claytone0d378b2011-03-24 21:19:54 +0000419 NameMatchType match_type,
Greg Claytone996fd32011-03-08 22:40:15 +0000420 const char *match)
421{
422 if (match_type == eNameMatchIgnore)
423 return true;
424
425 if (name == match)
426 return true;
427
428 if (name && match)
429 {
430 llvm::StringRef name_sref(name);
431 llvm::StringRef match_sref(match);
432 switch (match_type)
433 {
Sylvestre Ledru6e2c7cb2013-10-14 14:06:28 +0000434 case eNameMatchIgnore: // This case cannot occur: tested before
435 return true;
Greg Claytone996fd32011-03-08 22:40:15 +0000436 case eNameMatchEquals: return name_sref == match_sref;
437 case eNameMatchContains: return name_sref.find (match_sref) != llvm::StringRef::npos;
438 case eNameMatchStartsWith: return name_sref.startswith (match_sref);
439 case eNameMatchEndsWith: return name_sref.endswith (match_sref);
440 case eNameMatchRegularExpression:
441 {
442 RegularExpression regex (match);
443 return regex.Execute (name);
444 }
445 break;
Greg Claytone996fd32011-03-08 22:40:15 +0000446 }
447 }
448 return false;
449}