blob: c69563773915a64aefcfe78c3ed75441b1822bf1 [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 Clayton3c310a12010-12-16 21:36:30 +000022#include "lldb/Target/Target.h"
23#include "lldb/Target/Thread.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000024
Greg Claytone996fd32011-03-08 22:40:15 +000025#include "llvm/ADT/StringRef.h"
26
Peter Collingbourne1b27dac2011-05-19 18:32:34 +000027#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
28#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
Peter Collingbournea09bfca2011-05-19 17:34:40 +000029#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
Sean Callanan95e5c632012-02-17 00:53:45 +000030#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
Caroline Ticead379efc2011-04-05 18:46:00 +000031#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000032#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
Michael Sartaina7499c92013-07-01 19:45:50 +000033#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000034#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"
Greg Clayton078daac2011-04-25 21:07:40 +000039#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
Greg Claytonffc922e32011-04-25 21:05:07 +000040#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
Greg Claytonf754f882011-09-09 20:33:05 +000041#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
Greg Claytond10a0382012-02-27 19:00:34 +000042#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
Greg Claytonea5e0cc2012-02-27 19:12:12 +000043#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
44#include "Plugins/Platform/Linux/PlatformLinux.h"
Daniel Maleae0f8f572013-08-26 23:57:52 +000045#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
Deepak Panickala0154f92013-10-15 12:32:12 +000046#include "Plugins/Platform/Windows/PlatformWindows.h"
Andrew Kaylor7b6376b2012-12-14 21:03:37 +000047#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
Greg Claytonb3e77602012-08-23 21:17:11 +000048#ifndef LLDB_DISABLE_PYTHON
49#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
50#endif
Greg Claytone996fd32011-03-08 22:40:15 +000051#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +000052#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
Greg Clayton944b8282011-08-22 22:30:57 +000053#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
Jim Ingham2a5e0f02010-11-04 18:30:59 +000054#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
55#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000056#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
57#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
Greg Clayton3a29bdb2011-07-17 20:36:25 +000058#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
Greg Claytone996fd32011-03-08 22:40:15 +000059#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
Greg Claytonded470d2011-03-19 01:12:21 +000060#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
Jason Molenda1c627542013-04-05 01:03:25 +000061#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
Greg Clayton722cec22012-02-25 06:56:35 +000062#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000063#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
Greg Claytonc3776bf2012-02-09 06:16:32 +000065#include "Plugins/Process/mach-core/ProcessMachCore.h"
66
Deepak Panickala0154f92013-10-15 12:32:12 +000067#if defined(__linux__) || defined(__FreeBSD__)
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +000068#include "Plugins/Process/elf-core/ProcessElfCore.h"
69#endif
70
Greg Claytone996fd32011-03-08 22:40:15 +000071#if defined (__linux__)
Greg Claytone996fd32011-03-08 22:40:15 +000072#include "Plugins/Process/Linux/ProcessLinux.h"
Stephen Wilsone6f9f662010-07-24 02:19:04 +000073#endif
74
Johnny Chen8f3d8382011-08-02 20:52:42 +000075#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +000076#include "Plugins/Process/POSIX/ProcessPOSIX.h"
77#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
Johnny Chen8f3d8382011-08-02 20:52:42 +000078#endif
79
Greg Clayton1cb64962011-03-24 04:28:38 +000080#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
Daniel Malea97059d42013-01-08 14:55:36 +000081#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
Greg Claytonfc7117a2011-03-05 01:04:56 +000082#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
83
Greg Claytonce6d19a2010-12-16 21:33:41 +000084using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085using namespace lldb_private;
86
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087void
88lldb_private::Initialize ()
89{
90 // Make sure we inialize only once
Caroline Tice2f88aad2011-01-14 00:29:16 +000091 static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092 static bool g_inited = false;
93
94 Mutex::Locker locker(g_inited_mutex);
95 if (!g_inited)
96 {
97 g_inited = true;
Greg Clayton99d0faf2010-11-18 23:32:35 +000098 Log::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099 Timer::Initialize ();
100 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton99d0faf2010-11-18 23:32:35 +0000101
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000102 ABIMacOSX_i386::Initialize();
103 ABIMacOSX_arm::Initialize();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000104 ABISysV_x86_64::Initialize();
Sean Callanan95e5c632012-02-17 00:53:45 +0000105 DisassemblerLLVMC::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106 ObjectContainerBSDArchive::Initialize();
107 ObjectFileELF::Initialize();
Michael Sartaina7499c92013-07-01 19:45:50 +0000108 SymbolVendorELF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 SymbolFileDWARF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110 SymbolFileSymtab::Initialize();
Greg Claytonffc922e32011-04-25 21:05:07 +0000111 UnwindAssemblyInstEmulation::Initialize();
Greg Clayton2ed751b2011-04-26 04:39:08 +0000112 UnwindAssembly_x86::Initialize();
Caroline Ticead379efc2011-04-05 18:46:00 +0000113 EmulateInstructionARM::Initialize ();
Greg Claytonf754f882011-09-09 20:33:05 +0000114 ObjectFilePECOFF::Initialize ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000115 DynamicLoaderPOSIXDYLD::Initialize ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000116 PlatformFreeBSD::Initialize();
117 PlatformLinux::Initialize();
Deepak Panickala0154f92013-10-15 12:32:12 +0000118 PlatformWindows::Initialize();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000119 SymbolFileDWARFDebugMap::Initialize();
120 ItaniumABILanguageRuntime::Initialize();
Greg Claytonb3e77602012-08-23 21:17:11 +0000121#ifndef LLDB_DISABLE_PYTHON
122 OperatingSystemPython::Initialize();
123#endif
124
Greg Claytone996fd32011-03-08 22:40:15 +0000125#if defined (__APPLE__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000126 //----------------------------------------------------------------------
127 // Apple/Darwin hosted plugins
128 //----------------------------------------------------------------------
Eli Friedmane13a8db2010-06-13 19:36:42 +0000129 DynamicLoaderMacOSXDYLD::Initialize();
Greg Clayton944b8282011-08-22 22:30:57 +0000130 DynamicLoaderDarwinKernel::Initialize();
Jim Ingham22777012010-09-23 02:01:19 +0000131 AppleObjCRuntimeV2::Initialize();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000132 AppleObjCRuntimeV1::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000133 ObjectContainerUniversalMachO::Initialize();
134 ObjectFileMachO::Initialize();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000135 ProcessKDP::Initialize();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000136 ProcessMachCore::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000137 SymbolVendorMacOSX::Initialize();
Jason Molenda1c627542013-04-05 01:03:25 +0000138 PlatformDarwinKernel::Initialize();
Greg Claytonded470d2011-03-19 01:12:21 +0000139 PlatformRemoteiOS::Initialize();
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000140 PlatformMacOSX::Initialize();
Greg Clayton722cec22012-02-25 06:56:35 +0000141 PlatformiOSSimulator::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000142#endif
Greg Claytone996fd32011-03-08 22:40:15 +0000143#if defined (__linux__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000144 //----------------------------------------------------------------------
145 // Linux hosted plugins
146 //----------------------------------------------------------------------
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000147 ProcessLinux::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000148#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000149#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000150 ProcessFreeBSD::Initialize();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000151#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000152
Deepak Panickala0154f92013-10-15 12:32:12 +0000153#if defined(__linux__) || defined(__FreeBSD__)
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000154 ProcessElfCore::Initialize();
155#endif
Greg Clayton1cb64962011-03-24 04:28:38 +0000156 //----------------------------------------------------------------------
157 // Platform agnostic plugins
158 //----------------------------------------------------------------------
159 PlatformRemoteGDBServer::Initialize ();
Daniel Malea97059d42013-01-08 14:55:36 +0000160 ProcessGDBRemote::Initialize();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000161 DynamicLoaderStatic::Initialize();
Greg Clayton1cb64962011-03-24 04:28:38 +0000162
Greg Clayton4272cc72011-02-02 02:24:04 +0000163 // Scan for any system or user LLDB plug-ins
164 PluginManager::Initialize();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +0000165
Caroline Tice20bd37f2011-03-10 22:14:10 +0000166 // The process settings need to know about installed plug-ins, so the Settings must be initialized
167 // AFTER PluginManager::Initialize is called.
168
169 Debugger::SettingsInitialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170 }
171}
172
173void
174lldb_private::WillTerminate()
175{
176 Host::WillTerminate();
177}
178
179void
180lldb_private::Terminate ()
181{
182 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton4272cc72011-02-02 02:24:04 +0000183
184 // Terminate and unload and loaded system or user LLDB plug-ins
185 PluginManager::Terminate();
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000186 ABIMacOSX_i386::Terminate();
187 ABIMacOSX_arm::Terminate();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000188 ABISysV_x86_64::Terminate();
Sean Callanan95e5c632012-02-17 00:53:45 +0000189 DisassemblerLLVMC::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 ObjectContainerBSDArchive::Terminate();
191 ObjectFileELF::Terminate();
Michael Sartaina7499c92013-07-01 19:45:50 +0000192 SymbolVendorELF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193 SymbolFileDWARF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194 SymbolFileSymtab::Terminate();
Greg Claytonffc922e32011-04-25 21:05:07 +0000195 UnwindAssembly_x86::Terminate();
196 UnwindAssemblyInstEmulation::Terminate();
Caroline Ticead379efc2011-04-05 18:46:00 +0000197 EmulateInstructionARM::Terminate ();
Greg Claytonf754f882011-09-09 20:33:05 +0000198 ObjectFilePECOFF::Terminate ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000199 DynamicLoaderPOSIXDYLD::Terminate ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000200 PlatformFreeBSD::Terminate();
201 PlatformLinux::Terminate();
Deepak Panickala0154f92013-10-15 12:32:12 +0000202 PlatformWindows::Terminate();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000203 SymbolFileDWARFDebugMap::Terminate();
204 ItaniumABILanguageRuntime::Terminate();
Greg Claytonb3e77602012-08-23 21:17:11 +0000205#ifndef LLDB_DISABLE_PYTHON
206 OperatingSystemPython::Terminate();
207#endif
208
Greg Claytone996fd32011-03-08 22:40:15 +0000209#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +0000210 DynamicLoaderMacOSXDYLD::Terminate();
Greg Clayton944b8282011-08-22 22:30:57 +0000211 DynamicLoaderDarwinKernel::Terminate();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000212 AppleObjCRuntimeV2::Terminate();
213 AppleObjCRuntimeV1::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000214 ObjectContainerUniversalMachO::Terminate();
215 ObjectFileMachO::Terminate();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000216 ProcessMachCore::Terminate();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000217 ProcessKDP::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000218 SymbolVendorMacOSX::Terminate();
Greg Claytone996fd32011-03-08 22:40:15 +0000219 PlatformMacOSX::Terminate();
Jason Molenda1c627542013-04-05 01:03:25 +0000220 PlatformDarwinKernel::Terminate();
Greg Claytonded470d2011-03-19 01:12:21 +0000221 PlatformRemoteiOS::Terminate();
Greg Clayton722cec22012-02-25 06:56:35 +0000222 PlatformiOSSimulator::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000223#endif
224
Caroline Tice20bd37f2011-03-10 22:14:10 +0000225 Debugger::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000226
Greg Claytone996fd32011-03-08 22:40:15 +0000227#if defined (__linux__)
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000228 ProcessLinux::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000229#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000230
231#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000232 ProcessFreeBSD::Terminate();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000233#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000234
Deepak Panickala0154f92013-10-15 12:32:12 +0000235#if defined(__linux__) || defined(__FreeBSD__)
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000236 ProcessElfCore::Terminate();
237#endif
Daniel Malea97059d42013-01-08 14:55:36 +0000238 ProcessGDBRemote::Terminate();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000239 DynamicLoaderStatic::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000240
241 Log::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242}
243
Daniel Malea3b92f002013-02-28 16:51:15 +0000244#if defined (__APPLE__)
Sean Callanan3d27e662013-03-07 22:29:06 +0000245extern "C" const unsigned char liblldb_coreVersionString[];
Greg Clayton7170f3f2013-02-28 18:09:18 +0000246#else
247
248#include "clang/Basic/Version.h"
249
250static const char *
251GetLLDBRevision()
252{
253#ifdef LLDB_REVISION
254 return LLDB_REVISION;
255#else
256 return NULL;
257#endif
258}
259
260static const char *
261GetLLDBRepository()
262{
263#ifdef LLDB_REPOSITORY
264 return LLDB_REPOSITORY;
265#else
266 return NULL;
267#endif
268}
269
Daniel Malea3b92f002013-02-28 16:51:15 +0000270#endif
271
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272const char *
273lldb_private::GetVersion ()
274{
Daniel Malea3b92f002013-02-28 16:51:15 +0000275#if defined (__APPLE__)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276 static char g_version_string[32];
277 if (g_version_string[0] == '\0')
Sean Callanan3d27e662013-03-07 22:29:06 +0000278 {
279 const char *version_string = ::strstr ((const char *)liblldb_coreVersionString, "PROJECT:");
280
281 if (version_string)
282 version_string += sizeof("PROJECT:") - 1;
283 else
284 version_string = "unknown";
285
286 const char *newline_loc = strchr(version_string, '\n');
287
288 size_t version_len = sizeof(g_version_string);
289
290 if (newline_loc && (newline_loc - version_string < version_len))
291 version_len = newline_loc - version_string;
292
293 ::strncpy(g_version_string, version_string, version_len);
294 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000295
296 return g_version_string;
Daniel Malea3b92f002013-02-28 16:51:15 +0000297#else
298 // On Linux/FreeBSD/Windows, report a version number in the same style as the clang tool.
Greg Clayton7170f3f2013-02-28 18:09:18 +0000299 static std::string g_version_str;
300 if (g_version_str.empty())
301 {
302 g_version_str += "lldb version ";
303 g_version_str += CLANG_VERSION_STRING;
304 const char * lldb_repo = GetLLDBRepository();
305 if (lldb_repo)
306 {
307 g_version_str += " (";
308 g_version_str += lldb_repo;
309 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000310
Greg Clayton7170f3f2013-02-28 18:09:18 +0000311 const char *lldb_rev = GetLLDBRevision();
312 if (lldb_rev)
313 {
314 g_version_str += " revision ";
315 g_version_str += lldb_rev;
316 }
317 std::string clang_rev (clang::getClangRevision());
318 if (clang_rev.length() > 0)
319 {
320 g_version_str += " clang revision ";
321 g_version_str += clang_rev;
322 }
323 std::string llvm_rev (clang::getLLVMRevision());
324 if (llvm_rev.length() > 0)
325 {
326 g_version_str += " llvm revision ";
327 g_version_str += llvm_rev;
328 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000329
Greg Clayton7170f3f2013-02-28 18:09:18 +0000330 if (lldb_repo)
331 g_version_str += ")";
332 }
333 return g_version_str.c_str();
Daniel Malea3b92f002013-02-28 16:51:15 +0000334#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335}
336
Greg Clayton2cad65a2010-09-03 17:10:42 +0000337const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000338lldb_private::GetVoteAsCString (Vote vote)
Greg Clayton2cad65a2010-09-03 17:10:42 +0000339{
Greg Clayton1346f7e2010-09-03 22:45:01 +0000340 switch (vote)
341 {
342 case eVoteNo: return "no";
343 case eVoteNoOpinion: return "no opinion";
344 case eVoteYes: return "yes";
Greg Clayton1346f7e2010-09-03 22:45:01 +0000345 }
Greg Clayton2cad65a2010-09-03 17:10:42 +0000346 return "invalid";
347}
348
Greg Clayton89411422010-10-08 00:21:05 +0000349
350const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000351lldb_private::GetSectionTypeAsCString (SectionType sect_type)
Greg Clayton89411422010-10-08 00:21:05 +0000352{
353 switch (sect_type)
354 {
355 case eSectionTypeInvalid: return "invalid";
356 case eSectionTypeCode: return "code";
357 case eSectionTypeContainer: return "container";
358 case eSectionTypeData: return "data";
359 case eSectionTypeDataCString: return "data-cstr";
360 case eSectionTypeDataCStringPointers: return "data-cstr-ptr";
361 case eSectionTypeDataSymbolAddress: return "data-symbol-addr";
362 case eSectionTypeData4: return "data-4-byte";
363 case eSectionTypeData8: return "data-8-byte";
364 case eSectionTypeData16: return "data-16-byte";
365 case eSectionTypeDataPointers: return "data-ptrs";
366 case eSectionTypeDebug: return "debug";
367 case eSectionTypeZeroFill: return "zero-fill";
368 case eSectionTypeDataObjCMessageRefs: return "objc-message-refs";
369 case eSectionTypeDataObjCCFStrings: return "objc-cfstrings";
370 case eSectionTypeDWARFDebugAbbrev: return "dwarf-abbrev";
371 case eSectionTypeDWARFDebugAranges: return "dwarf-aranges";
372 case eSectionTypeDWARFDebugFrame: return "dwarf-frame";
373 case eSectionTypeDWARFDebugInfo: return "dwarf-info";
374 case eSectionTypeDWARFDebugLine: return "dwarf-line";
375 case eSectionTypeDWARFDebugLoc: return "dwarf-loc";
376 case eSectionTypeDWARFDebugMacInfo: return "dwarf-macinfo";
377 case eSectionTypeDWARFDebugPubNames: return "dwarf-pubnames";
378 case eSectionTypeDWARFDebugPubTypes: return "dwarf-pubtypes";
379 case eSectionTypeDWARFDebugRanges: return "dwarf-ranges";
380 case eSectionTypeDWARFDebugStr: return "dwarf-str";
Michael Sartaina7499c92013-07-01 19:45:50 +0000381 case eSectionTypeELFSymbolTable: return "elf-symbol-table";
382 case eSectionTypeELFDynamicSymbols: return "elf-dynamic-symbols";
383 case eSectionTypeELFRelocationEntries: return "elf-relocation-entries";
384 case eSectionTypeELFDynamicLinkInfo: return "elf-dynamic-link-info";
Greg Clayton17674402011-09-28 17:06:40 +0000385 case eSectionTypeDWARFAppleNames: return "apple-names";
386 case eSectionTypeDWARFAppleTypes: return "apple-types";
Greg Clayton7f995132011-10-04 22:41:51 +0000387 case eSectionTypeDWARFAppleNamespaces: return "apple-namespaces";
Greg Clayton5009f9d2011-10-27 17:55:14 +0000388 case eSectionTypeDWARFAppleObjC: return "apple-objc";
Greg Clayton89411422010-10-08 00:21:05 +0000389 case eSectionTypeEHFrame: return "eh-frame";
390 case eSectionTypeOther: return "regular";
391 }
392 return "unknown";
393
394}
395
Greg Claytone996fd32011-03-08 22:40:15 +0000396bool
397lldb_private::NameMatches (const char *name,
Greg Claytone0d378b2011-03-24 21:19:54 +0000398 NameMatchType match_type,
Greg Claytone996fd32011-03-08 22:40:15 +0000399 const char *match)
400{
401 if (match_type == eNameMatchIgnore)
402 return true;
403
404 if (name == match)
405 return true;
406
407 if (name && match)
408 {
409 llvm::StringRef name_sref(name);
410 llvm::StringRef match_sref(match);
411 switch (match_type)
412 {
Sylvestre Ledru6e2c7cb2013-10-14 14:06:28 +0000413 case eNameMatchIgnore: // This case cannot occur: tested before
414 return true;
Greg Claytone996fd32011-03-08 22:40:15 +0000415 case eNameMatchEquals: return name_sref == match_sref;
416 case eNameMatchContains: return name_sref.find (match_sref) != llvm::StringRef::npos;
417 case eNameMatchStartsWith: return name_sref.startswith (match_sref);
418 case eNameMatchEndsWith: return name_sref.endswith (match_sref);
419 case eNameMatchRegularExpression:
420 {
421 RegularExpression regex (match);
422 return regex.Execute (name);
423 }
424 break;
Greg Claytone996fd32011-03-08 22:40:15 +0000425 }
426 }
427 return false;
428}