blob: 538a26c40e0368795d9611951e9892e5d50fc407 [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"
Andrew Kaylor7b6376b2012-12-14 21:03:37 +000046#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
Greg Claytonb3e77602012-08-23 21:17:11 +000047#ifndef LLDB_DISABLE_PYTHON
48#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
49#endif
Greg Claytone996fd32011-03-08 22:40:15 +000050#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +000051#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
Greg Clayton944b8282011-08-22 22:30:57 +000052#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
Jim Ingham2a5e0f02010-11-04 18:30:59 +000053#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
54#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000055#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
56#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
Greg Clayton3a29bdb2011-07-17 20:36:25 +000057#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
Greg Claytone996fd32011-03-08 22:40:15 +000058#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
Greg Claytonded470d2011-03-19 01:12:21 +000059#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
Jason Molenda1c627542013-04-05 01:03:25 +000060#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
Greg Clayton722cec22012-02-25 06:56:35 +000061#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000062#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
Greg Claytonc3776bf2012-02-09 06:16:32 +000064#include "Plugins/Process/mach-core/ProcessMachCore.h"
65
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +000066#if defined(__linux__) or defined(__FreeBSD__)
67#include "Plugins/Process/elf-core/ProcessElfCore.h"
68#endif
69
Greg Claytone996fd32011-03-08 22:40:15 +000070#if defined (__linux__)
Greg Claytone996fd32011-03-08 22:40:15 +000071#include "Plugins/Process/Linux/ProcessLinux.h"
Stephen Wilsone6f9f662010-07-24 02:19:04 +000072#endif
73
Johnny Chen8f3d8382011-08-02 20:52:42 +000074#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +000075#include "Plugins/Process/POSIX/ProcessPOSIX.h"
76#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
Johnny Chen8f3d8382011-08-02 20:52:42 +000077#endif
78
Greg Clayton1cb64962011-03-24 04:28:38 +000079#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
Daniel Malea97059d42013-01-08 14:55:36 +000080#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
Greg Claytonfc7117a2011-03-05 01:04:56 +000081#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
82
Greg Claytonce6d19a2010-12-16 21:33:41 +000083using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084using namespace lldb_private;
85
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086void
87lldb_private::Initialize ()
88{
89 // Make sure we inialize only once
Caroline Tice2f88aad2011-01-14 00:29:16 +000090 static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091 static bool g_inited = false;
92
93 Mutex::Locker locker(g_inited_mutex);
94 if (!g_inited)
95 {
96 g_inited = true;
Greg Clayton99d0faf2010-11-18 23:32:35 +000097 Log::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098 Timer::Initialize ();
99 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton99d0faf2010-11-18 23:32:35 +0000100
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000101 ABIMacOSX_i386::Initialize();
102 ABIMacOSX_arm::Initialize();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000103 ABISysV_x86_64::Initialize();
Sean Callanan95e5c632012-02-17 00:53:45 +0000104 DisassemblerLLVMC::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105 ObjectContainerBSDArchive::Initialize();
106 ObjectFileELF::Initialize();
Michael Sartaina7499c92013-07-01 19:45:50 +0000107 SymbolVendorELF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108 SymbolFileDWARF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 SymbolFileSymtab::Initialize();
Greg Claytonffc922e32011-04-25 21:05:07 +0000110 UnwindAssemblyInstEmulation::Initialize();
Greg Clayton2ed751b2011-04-26 04:39:08 +0000111 UnwindAssembly_x86::Initialize();
Caroline Ticead379efc2011-04-05 18:46:00 +0000112 EmulateInstructionARM::Initialize ();
Greg Claytonf754f882011-09-09 20:33:05 +0000113 ObjectFilePECOFF::Initialize ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000114 DynamicLoaderPOSIXDYLD::Initialize ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000115 PlatformFreeBSD::Initialize();
116 PlatformLinux::Initialize();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000117 SymbolFileDWARFDebugMap::Initialize();
118 ItaniumABILanguageRuntime::Initialize();
Greg Claytonb3e77602012-08-23 21:17:11 +0000119#ifndef LLDB_DISABLE_PYTHON
120 OperatingSystemPython::Initialize();
121#endif
122
Greg Claytone996fd32011-03-08 22:40:15 +0000123#if defined (__APPLE__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000124 //----------------------------------------------------------------------
125 // Apple/Darwin hosted plugins
126 //----------------------------------------------------------------------
Eli Friedmane13a8db2010-06-13 19:36:42 +0000127 DynamicLoaderMacOSXDYLD::Initialize();
Greg Clayton944b8282011-08-22 22:30:57 +0000128 DynamicLoaderDarwinKernel::Initialize();
Jim Ingham22777012010-09-23 02:01:19 +0000129 AppleObjCRuntimeV2::Initialize();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000130 AppleObjCRuntimeV1::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000131 ObjectContainerUniversalMachO::Initialize();
132 ObjectFileMachO::Initialize();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000133 ProcessKDP::Initialize();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000134 ProcessMachCore::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000135 SymbolVendorMacOSX::Initialize();
Jason Molenda1c627542013-04-05 01:03:25 +0000136 PlatformDarwinKernel::Initialize();
Greg Claytonded470d2011-03-19 01:12:21 +0000137 PlatformRemoteiOS::Initialize();
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000138 PlatformMacOSX::Initialize();
Greg Clayton722cec22012-02-25 06:56:35 +0000139 PlatformiOSSimulator::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000140#endif
Greg Claytone996fd32011-03-08 22:40:15 +0000141#if defined (__linux__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000142 //----------------------------------------------------------------------
143 // Linux hosted plugins
144 //----------------------------------------------------------------------
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000145 ProcessLinux::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000146#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000147#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000148 ProcessFreeBSD::Initialize();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000149#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000150
151#if defined(__linux__) or defined(__FreeBSD__)
152 ProcessElfCore::Initialize();
153#endif
Greg Clayton1cb64962011-03-24 04:28:38 +0000154 //----------------------------------------------------------------------
155 // Platform agnostic plugins
156 //----------------------------------------------------------------------
157 PlatformRemoteGDBServer::Initialize ();
Daniel Malea97059d42013-01-08 14:55:36 +0000158 ProcessGDBRemote::Initialize();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000159 DynamicLoaderStatic::Initialize();
Greg Clayton1cb64962011-03-24 04:28:38 +0000160
Greg Clayton4272cc72011-02-02 02:24:04 +0000161 // Scan for any system or user LLDB plug-ins
162 PluginManager::Initialize();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +0000163
Caroline Tice20bd37f2011-03-10 22:14:10 +0000164 // The process settings need to know about installed plug-ins, so the Settings must be initialized
165 // AFTER PluginManager::Initialize is called.
166
167 Debugger::SettingsInitialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168 }
169}
170
171void
172lldb_private::WillTerminate()
173{
174 Host::WillTerminate();
175}
176
177void
178lldb_private::Terminate ()
179{
180 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton4272cc72011-02-02 02:24:04 +0000181
182 // Terminate and unload and loaded system or user LLDB plug-ins
183 PluginManager::Terminate();
184
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000185 ABIMacOSX_i386::Terminate();
186 ABIMacOSX_arm::Terminate();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000187 ABISysV_x86_64::Terminate();
Sean Callanan95e5c632012-02-17 00:53:45 +0000188 DisassemblerLLVMC::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189 ObjectContainerBSDArchive::Terminate();
190 ObjectFileELF::Terminate();
Michael Sartaina7499c92013-07-01 19:45:50 +0000191 SymbolVendorELF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 SymbolFileDWARF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193 SymbolFileSymtab::Terminate();
Greg Claytonffc922e32011-04-25 21:05:07 +0000194 UnwindAssembly_x86::Terminate();
195 UnwindAssemblyInstEmulation::Terminate();
Caroline Ticead379efc2011-04-05 18:46:00 +0000196 EmulateInstructionARM::Terminate ();
Greg Claytonf754f882011-09-09 20:33:05 +0000197 ObjectFilePECOFF::Terminate ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000198 DynamicLoaderPOSIXDYLD::Terminate ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000199 PlatformFreeBSD::Terminate();
200 PlatformLinux::Terminate();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000201 SymbolFileDWARFDebugMap::Terminate();
202 ItaniumABILanguageRuntime::Terminate();
Greg Claytonb3e77602012-08-23 21:17:11 +0000203#ifndef LLDB_DISABLE_PYTHON
204 OperatingSystemPython::Terminate();
205#endif
206
Greg Claytone996fd32011-03-08 22:40:15 +0000207#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +0000208 DynamicLoaderMacOSXDYLD::Terminate();
Greg Clayton944b8282011-08-22 22:30:57 +0000209 DynamicLoaderDarwinKernel::Terminate();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000210 AppleObjCRuntimeV2::Terminate();
211 AppleObjCRuntimeV1::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000212 ObjectContainerUniversalMachO::Terminate();
213 ObjectFileMachO::Terminate();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000214 ProcessMachCore::Terminate();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000215 ProcessKDP::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000216 SymbolVendorMacOSX::Terminate();
Greg Claytone996fd32011-03-08 22:40:15 +0000217 PlatformMacOSX::Terminate();
Jason Molenda1c627542013-04-05 01:03:25 +0000218 PlatformDarwinKernel::Terminate();
Greg Claytonded470d2011-03-19 01:12:21 +0000219 PlatformRemoteiOS::Terminate();
Greg Clayton722cec22012-02-25 06:56:35 +0000220 PlatformiOSSimulator::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000221#endif
222
Caroline Tice20bd37f2011-03-10 22:14:10 +0000223 Debugger::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000224
Greg Claytone996fd32011-03-08 22:40:15 +0000225#if defined (__linux__)
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000226 ProcessLinux::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000227#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000228
229#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000230 ProcessFreeBSD::Terminate();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000231#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000232
233#if defined(__linux__) or defined(__FreeBSD__)
234 ProcessElfCore::Terminate();
235#endif
Daniel Malea97059d42013-01-08 14:55:36 +0000236 ProcessGDBRemote::Terminate();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000237 DynamicLoaderStatic::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000238
239 Log::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240}
241
Daniel Malea3b92f002013-02-28 16:51:15 +0000242#if defined (__APPLE__)
Sean Callanan3d27e662013-03-07 22:29:06 +0000243extern "C" const unsigned char liblldb_coreVersionString[];
Greg Clayton7170f3f2013-02-28 18:09:18 +0000244#else
245
246#include "clang/Basic/Version.h"
247
248static const char *
249GetLLDBRevision()
250{
251#ifdef LLDB_REVISION
252 return LLDB_REVISION;
253#else
254 return NULL;
255#endif
256}
257
258static const char *
259GetLLDBRepository()
260{
261#ifdef LLDB_REPOSITORY
262 return LLDB_REPOSITORY;
263#else
264 return NULL;
265#endif
266}
267
Daniel Malea3b92f002013-02-28 16:51:15 +0000268#endif
269
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270const char *
271lldb_private::GetVersion ()
272{
Daniel Malea3b92f002013-02-28 16:51:15 +0000273#if defined (__APPLE__)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 static char g_version_string[32];
275 if (g_version_string[0] == '\0')
Sean Callanan3d27e662013-03-07 22:29:06 +0000276 {
277 const char *version_string = ::strstr ((const char *)liblldb_coreVersionString, "PROJECT:");
278
279 if (version_string)
280 version_string += sizeof("PROJECT:") - 1;
281 else
282 version_string = "unknown";
283
284 const char *newline_loc = strchr(version_string, '\n');
285
286 size_t version_len = sizeof(g_version_string);
287
288 if (newline_loc && (newline_loc - version_string < version_len))
289 version_len = newline_loc - version_string;
290
291 ::strncpy(g_version_string, version_string, version_len);
292 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293
294 return g_version_string;
Daniel Malea3b92f002013-02-28 16:51:15 +0000295#else
296 // On Linux/FreeBSD/Windows, report a version number in the same style as the clang tool.
Greg Clayton7170f3f2013-02-28 18:09:18 +0000297 static std::string g_version_str;
298 if (g_version_str.empty())
299 {
300 g_version_str += "lldb version ";
301 g_version_str += CLANG_VERSION_STRING;
302 const char * lldb_repo = GetLLDBRepository();
303 if (lldb_repo)
304 {
305 g_version_str += " (";
306 g_version_str += lldb_repo;
307 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000308
Greg Clayton7170f3f2013-02-28 18:09:18 +0000309 const char *lldb_rev = GetLLDBRevision();
310 if (lldb_rev)
311 {
312 g_version_str += " revision ";
313 g_version_str += lldb_rev;
314 }
315 std::string clang_rev (clang::getClangRevision());
316 if (clang_rev.length() > 0)
317 {
318 g_version_str += " clang revision ";
319 g_version_str += clang_rev;
320 }
321 std::string llvm_rev (clang::getLLVMRevision());
322 if (llvm_rev.length() > 0)
323 {
324 g_version_str += " llvm revision ";
325 g_version_str += llvm_rev;
326 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000327
Greg Clayton7170f3f2013-02-28 18:09:18 +0000328 if (lldb_repo)
329 g_version_str += ")";
330 }
331 return g_version_str.c_str();
Daniel Malea3b92f002013-02-28 16:51:15 +0000332#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333}
334
Greg Clayton2cad65a2010-09-03 17:10:42 +0000335const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000336lldb_private::GetVoteAsCString (Vote vote)
Greg Clayton2cad65a2010-09-03 17:10:42 +0000337{
Greg Clayton1346f7e2010-09-03 22:45:01 +0000338 switch (vote)
339 {
340 case eVoteNo: return "no";
341 case eVoteNoOpinion: return "no opinion";
342 case eVoteYes: return "yes";
Greg Clayton1346f7e2010-09-03 22:45:01 +0000343 }
Greg Clayton2cad65a2010-09-03 17:10:42 +0000344 return "invalid";
345}
346
Greg Clayton89411422010-10-08 00:21:05 +0000347
348const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000349lldb_private::GetSectionTypeAsCString (SectionType sect_type)
Greg Clayton89411422010-10-08 00:21:05 +0000350{
351 switch (sect_type)
352 {
353 case eSectionTypeInvalid: return "invalid";
354 case eSectionTypeCode: return "code";
355 case eSectionTypeContainer: return "container";
356 case eSectionTypeData: return "data";
357 case eSectionTypeDataCString: return "data-cstr";
358 case eSectionTypeDataCStringPointers: return "data-cstr-ptr";
359 case eSectionTypeDataSymbolAddress: return "data-symbol-addr";
360 case eSectionTypeData4: return "data-4-byte";
361 case eSectionTypeData8: return "data-8-byte";
362 case eSectionTypeData16: return "data-16-byte";
363 case eSectionTypeDataPointers: return "data-ptrs";
364 case eSectionTypeDebug: return "debug";
365 case eSectionTypeZeroFill: return "zero-fill";
366 case eSectionTypeDataObjCMessageRefs: return "objc-message-refs";
367 case eSectionTypeDataObjCCFStrings: return "objc-cfstrings";
368 case eSectionTypeDWARFDebugAbbrev: return "dwarf-abbrev";
369 case eSectionTypeDWARFDebugAranges: return "dwarf-aranges";
370 case eSectionTypeDWARFDebugFrame: return "dwarf-frame";
371 case eSectionTypeDWARFDebugInfo: return "dwarf-info";
372 case eSectionTypeDWARFDebugLine: return "dwarf-line";
373 case eSectionTypeDWARFDebugLoc: return "dwarf-loc";
374 case eSectionTypeDWARFDebugMacInfo: return "dwarf-macinfo";
375 case eSectionTypeDWARFDebugPubNames: return "dwarf-pubnames";
376 case eSectionTypeDWARFDebugPubTypes: return "dwarf-pubtypes";
377 case eSectionTypeDWARFDebugRanges: return "dwarf-ranges";
378 case eSectionTypeDWARFDebugStr: return "dwarf-str";
Michael Sartaina7499c92013-07-01 19:45:50 +0000379 case eSectionTypeELFSymbolTable: return "elf-symbol-table";
380 case eSectionTypeELFDynamicSymbols: return "elf-dynamic-symbols";
381 case eSectionTypeELFRelocationEntries: return "elf-relocation-entries";
382 case eSectionTypeELFDynamicLinkInfo: return "elf-dynamic-link-info";
Greg Clayton17674402011-09-28 17:06:40 +0000383 case eSectionTypeDWARFAppleNames: return "apple-names";
384 case eSectionTypeDWARFAppleTypes: return "apple-types";
Greg Clayton7f995132011-10-04 22:41:51 +0000385 case eSectionTypeDWARFAppleNamespaces: return "apple-namespaces";
Greg Clayton5009f9d2011-10-27 17:55:14 +0000386 case eSectionTypeDWARFAppleObjC: return "apple-objc";
Greg Clayton89411422010-10-08 00:21:05 +0000387 case eSectionTypeEHFrame: return "eh-frame";
388 case eSectionTypeOther: return "regular";
389 }
390 return "unknown";
391
392}
393
Greg Claytone996fd32011-03-08 22:40:15 +0000394bool
395lldb_private::NameMatches (const char *name,
Greg Claytone0d378b2011-03-24 21:19:54 +0000396 NameMatchType match_type,
Greg Claytone996fd32011-03-08 22:40:15 +0000397 const char *match)
398{
399 if (match_type == eNameMatchIgnore)
400 return true;
401
402 if (name == match)
403 return true;
404
405 if (name && match)
406 {
407 llvm::StringRef name_sref(name);
408 llvm::StringRef match_sref(match);
409 switch (match_type)
410 {
Sylvestre Ledru6e2c7cb2013-10-14 14:06:28 +0000411 case eNameMatchIgnore: // This case cannot occur: tested before
412 return true;
Greg Claytone996fd32011-03-08 22:40:15 +0000413 case eNameMatchEquals: return name_sref == match_sref;
414 case eNameMatchContains: return name_sref.find (match_sref) != llvm::StringRef::npos;
415 case eNameMatchStartsWith: return name_sref.startswith (match_sref);
416 case eNameMatchEndsWith: return name_sref.endswith (match_sref);
417 case eNameMatchRegularExpression:
418 {
419 RegularExpression regex (match);
420 return regex.Execute (name);
421 }
422 break;
Greg Claytone996fd32011-03-08 22:40:15 +0000423 }
424 }
425 return false;
426}