blob: 6988bc2b9030626d9953c93ebdfb8ab2267858a0 [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"
Justin Hibbits6256a0e2014-10-31 02:34:28 +000034#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
35#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
Sean Callanan95e5c632012-02-17 00:53:45 +000036#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000037#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
Caroline Ticead379efc2011-04-05 18:46:00 +000038#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
Jason Molendaa3329782014-03-29 18:54:20 +000039#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
40#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000041#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
42#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000043#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
44#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000045#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
46#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
47#include "Plugins/Platform/Linux/PlatformLinux.h"
48#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
49#include "Plugins/Platform/Windows/PlatformWindows.h"
Todd Fialacfee9632014-07-16 15:03:10 +000050#include "Plugins/Platform/Kalimba/PlatformKalimba.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000051#include "Plugins/Process/elf-core/ProcessElfCore.h"
52#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
53#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000054#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
55#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
56#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
Greg Clayton078daac2011-04-25 21:07:40 +000057#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
Greg Claytonffc922e32011-04-25 21:05:07 +000058#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
Greg Clayton4b047f22014-03-06 00:14:12 +000059
Greg Claytonb3e77602012-08-23 21:17:11 +000060#ifndef LLDB_DISABLE_PYTHON
61#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
62#endif
Greg Claytone996fd32011-03-08 22:40:15 +000063#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +000064#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
Greg Clayton944b8282011-08-22 22:30:57 +000065#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
Jim Ingham2a5e0f02010-11-04 18:30:59 +000066#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
67#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000068#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
69#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
Greg Clayton3a29bdb2011-07-17 20:36:25 +000070#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
Greg Claytone996fd32011-03-08 22:40:15 +000071#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
Greg Claytonded470d2011-03-19 01:12:21 +000072#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
Jason Molenda1c627542013-04-05 01:03:25 +000073#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
Greg Clayton722cec22012-02-25 06:56:35 +000074#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
Jason Molendaa7b5afa2013-11-15 00:17:32 +000075#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
Eli Friedmane13a8db2010-06-13 19:36:42 +000076#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077
Greg Claytonc3776bf2012-02-09 06:16:32 +000078#include "Plugins/Process/mach-core/ProcessMachCore.h"
79
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +000080
Greg Claytone996fd32011-03-08 22:40:15 +000081#if defined (__linux__)
Greg Claytone996fd32011-03-08 22:40:15 +000082#include "Plugins/Process/Linux/ProcessLinux.h"
Stephen Wilsone6f9f662010-07-24 02:19:04 +000083#endif
84
Zachary Turner35ed1322014-07-28 16:45:18 +000085#if defined (_WIN32)
Zachary Turner555a7a62014-12-12 18:10:52 +000086#include "lldb/Host/windows/windows.h"
Zachary Turnercfd3b1a2014-12-05 18:45:53 +000087#include "Plugins/Process/Windows/DynamicLoaderWindows.h"
Zachary Turner35ed1322014-07-28 16:45:18 +000088#include "Plugins/Process/Windows/ProcessWindows.h"
89#endif
90
Johnny Chen8f3d8382011-08-02 20:52:42 +000091#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +000092#include "Plugins/Process/POSIX/ProcessPOSIX.h"
93#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
Johnny Chen8f3d8382011-08-02 20:52:42 +000094#endif
95
Greg Clayton1cb64962011-03-24 04:28:38 +000096#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
Daniel Malea97059d42013-01-08 14:55:36 +000097#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
Greg Claytonfc7117a2011-03-05 01:04:56 +000098#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
Kuba Breckabeed8212014-09-04 01:03:18 +000099#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
Kuba Breckaafdf8422014-10-10 23:43:03 +0000100#include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h"
Greg Claytonfc7117a2011-03-05 01:04:56 +0000101
Greg Claytonce6d19a2010-12-16 21:33:41 +0000102using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103using namespace lldb_private;
104
Sean Callanan0de7ecd2014-08-23 00:47:22 +0000105static void fatal_error_handler(void *user_data, const std::string& reason,
106 bool gen_crash_diag) {
107 Host::SetCrashDescription(reason.c_str());
108 ::abort();
109}
110
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111void
112lldb_private::Initialize ()
113{
114 // Make sure we inialize only once
Caroline Tice2f88aad2011-01-14 00:29:16 +0000115 static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116 static bool g_inited = false;
117
118 Mutex::Locker locker(g_inited_mutex);
119 if (!g_inited)
120 {
121 g_inited = true;
Zachary Turner555a7a62014-12-12 18:10:52 +0000122
123#if defined(_MSC_VER)
124 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
125 if (disable_crash_dialog_var && llvm::StringRef(disable_crash_dialog_var).equals_lower("true"))
126 {
127 // This will prevent Windows from displaying a dialog box requiring user interaction when
128 // LLDB crashes. This is mostly useful when automating LLDB, for example via the test
129 // suite, so that a crash in LLDB does not prevent completion of the test suite.
130 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
131
132 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
133 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
134 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
135 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
136 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
137 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
138 }
139#endif
140
Greg Clayton99d0faf2010-11-18 23:32:35 +0000141 Log::Initialize();
Zachary Turner673b6e42014-08-21 17:57:03 +0000142 HostInfo::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143 Timer::Initialize ();
144 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Sean Callanan0de7ecd2014-08-23 00:47:22 +0000145
146 // Initialize LLVM and Clang
147 llvm::InitializeAllTargets();
148 llvm::InitializeAllAsmPrinters();
149 llvm::InitializeAllTargetMCs();
150 llvm::InitializeAllDisassemblers();
151 llvm::install_fatal_error_handler(fatal_error_handler, 0);
152
153 // Initialize plug-ins
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000154 ABIMacOSX_i386::Initialize();
155 ABIMacOSX_arm::Initialize();
Jason Molendaa3329782014-03-29 18:54:20 +0000156 ABIMacOSX_arm64::Initialize();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000157 ABISysV_x86_64::Initialize();
Justin Hibbits6256a0e2014-10-31 02:34:28 +0000158 ABISysV_ppc::Initialize();
159 ABISysV_ppc64::Initialize();
Sean Callanan95e5c632012-02-17 00:53:45 +0000160 DisassemblerLLVMC::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161 ObjectContainerBSDArchive::Initialize();
162 ObjectFileELF::Initialize();
Michael Sartaina7499c92013-07-01 19:45:50 +0000163 SymbolVendorELF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164 SymbolFileDWARF::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165 SymbolFileSymtab::Initialize();
Greg Claytonffc922e32011-04-25 21:05:07 +0000166 UnwindAssemblyInstEmulation::Initialize();
Greg Clayton2ed751b2011-04-26 04:39:08 +0000167 UnwindAssembly_x86::Initialize();
Caroline Ticead379efc2011-04-05 18:46:00 +0000168 EmulateInstructionARM::Initialize ();
Jason Molendaa3329782014-03-29 18:54:20 +0000169 EmulateInstructionARM64::Initialize ();
Greg Claytonf754f882011-09-09 20:33:05 +0000170 ObjectFilePECOFF::Initialize ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000171 DynamicLoaderPOSIXDYLD::Initialize ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000172 PlatformFreeBSD::Initialize();
173 PlatformLinux::Initialize();
Deepak Panickala0154f92013-10-15 12:32:12 +0000174 PlatformWindows::Initialize();
Todd Fialacfee9632014-07-16 15:03:10 +0000175 PlatformKalimba::Initialize();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000176 SymbolFileDWARFDebugMap::Initialize();
177 ItaniumABILanguageRuntime::Initialize();
Greg Claytonb3e77602012-08-23 21:17:11 +0000178#ifndef LLDB_DISABLE_PYTHON
Greg Clayton44d93782014-01-27 23:43:24 +0000179 ScriptInterpreterPython::InitializePrivate();
Greg Claytonb3e77602012-08-23 21:17:11 +0000180 OperatingSystemPython::Initialize();
181#endif
Greg Clayton4b047f22014-03-06 00:14:12 +0000182 JITLoaderGDB::Initialize();
183 ProcessElfCore::Initialize();
Kuba Breckabeed8212014-09-04 01:03:18 +0000184 MemoryHistoryASan::Initialize();
Kuba Breckaafdf8422014-10-10 23:43:03 +0000185 AddressSanitizerRuntime::Initialize();
Greg Clayton4b047f22014-03-06 00:14:12 +0000186
Greg Claytone996fd32011-03-08 22:40:15 +0000187#if defined (__APPLE__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000188 //----------------------------------------------------------------------
189 // Apple/Darwin hosted plugins
190 //----------------------------------------------------------------------
Eli Friedmane13a8db2010-06-13 19:36:42 +0000191 DynamicLoaderMacOSXDYLD::Initialize();
Greg Clayton944b8282011-08-22 22:30:57 +0000192 DynamicLoaderDarwinKernel::Initialize();
Jim Ingham22777012010-09-23 02:01:19 +0000193 AppleObjCRuntimeV2::Initialize();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000194 AppleObjCRuntimeV1::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000195 ObjectContainerUniversalMachO::Initialize();
196 ObjectFileMachO::Initialize();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000197 ProcessKDP::Initialize();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000198 ProcessMachCore::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000199 SymbolVendorMacOSX::Initialize();
Jason Molenda1c627542013-04-05 01:03:25 +0000200 PlatformDarwinKernel::Initialize();
Greg Claytonded470d2011-03-19 01:12:21 +0000201 PlatformRemoteiOS::Initialize();
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000202 PlatformMacOSX::Initialize();
Greg Clayton722cec22012-02-25 06:56:35 +0000203 PlatformiOSSimulator::Initialize();
Jason Molendaa7b5afa2013-11-15 00:17:32 +0000204 SystemRuntimeMacOSX::Initialize();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000205#endif
Greg Claytone996fd32011-03-08 22:40:15 +0000206#if defined (__linux__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000207 //----------------------------------------------------------------------
208 // Linux hosted plugins
209 //----------------------------------------------------------------------
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000210 ProcessLinux::Initialize();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000211#endif
Hafiz Abid Qadeerc4d5ed02015-02-11 10:14:13 +0000212#if defined(_MSC_VER)
Zachary Turnercfd3b1a2014-12-05 18:45:53 +0000213 DynamicLoaderWindows::Initialize();
Zachary Turner35ed1322014-07-28 16:45:18 +0000214 ProcessWindows::Initialize();
215#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000216#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000217 ProcessFreeBSD::Initialize();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000218#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000219
Greg Clayton1cb64962011-03-24 04:28:38 +0000220 //----------------------------------------------------------------------
221 // Platform agnostic plugins
222 //----------------------------------------------------------------------
223 PlatformRemoteGDBServer::Initialize ();
Daniel Malea97059d42013-01-08 14:55:36 +0000224 ProcessGDBRemote::Initialize();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000225 DynamicLoaderStatic::Initialize();
Greg Clayton1cb64962011-03-24 04:28:38 +0000226
Greg Clayton4272cc72011-02-02 02:24:04 +0000227 // Scan for any system or user LLDB plug-ins
228 PluginManager::Initialize();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +0000229
Caroline Tice20bd37f2011-03-10 22:14:10 +0000230 // The process settings need to know about installed plug-ins, so the Settings must be initialized
231 // AFTER PluginManager::Initialize is called.
232
233 Debugger::SettingsInitialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234 }
235}
236
237void
238lldb_private::WillTerminate()
239{
240 Host::WillTerminate();
241}
242
243void
244lldb_private::Terminate ()
245{
246 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton4272cc72011-02-02 02:24:04 +0000247
248 // Terminate and unload and loaded system or user LLDB plug-ins
249 PluginManager::Terminate();
Peter Collingbourne1b27dac2011-05-19 18:32:34 +0000250 ABIMacOSX_i386::Terminate();
251 ABIMacOSX_arm::Terminate();
Jason Molendaa3329782014-03-29 18:54:20 +0000252 ABIMacOSX_arm64::Terminate();
Peter Collingbournea09bfca2011-05-19 17:34:40 +0000253 ABISysV_x86_64::Terminate();
Justin Hibbitsdb39cdf2014-10-31 15:57:52 +0000254 ABISysV_ppc::Terminate();
Justin Hibbits6256a0e2014-10-31 02:34:28 +0000255 ABISysV_ppc64::Terminate();
Sean Callanan95e5c632012-02-17 00:53:45 +0000256 DisassemblerLLVMC::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000257 ObjectContainerBSDArchive::Terminate();
258 ObjectFileELF::Terminate();
Michael Sartaina7499c92013-07-01 19:45:50 +0000259 SymbolVendorELF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000260 SymbolFileDWARF::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261 SymbolFileSymtab::Terminate();
Greg Claytonffc922e32011-04-25 21:05:07 +0000262 UnwindAssembly_x86::Terminate();
263 UnwindAssemblyInstEmulation::Terminate();
Caroline Ticead379efc2011-04-05 18:46:00 +0000264 EmulateInstructionARM::Terminate ();
Jason Molendaa3329782014-03-29 18:54:20 +0000265 EmulateInstructionARM64::Terminate ();
Greg Claytonf754f882011-09-09 20:33:05 +0000266 ObjectFilePECOFF::Terminate ();
Bill Wendlinge50ab402012-04-05 17:38:07 +0000267 DynamicLoaderPOSIXDYLD::Terminate ();
Greg Claytonea5e0cc2012-02-27 19:12:12 +0000268 PlatformFreeBSD::Terminate();
269 PlatformLinux::Terminate();
Deepak Panickala0154f92013-10-15 12:32:12 +0000270 PlatformWindows::Terminate();
Todd Fialacfee9632014-07-16 15:03:10 +0000271 PlatformKalimba::Terminate();
Andrew Kaylor7b6376b2012-12-14 21:03:37 +0000272 SymbolFileDWARFDebugMap::Terminate();
273 ItaniumABILanguageRuntime::Terminate();
Greg Claytonb3e77602012-08-23 21:17:11 +0000274#ifndef LLDB_DISABLE_PYTHON
275 OperatingSystemPython::Terminate();
276#endif
Greg Clayton4b047f22014-03-06 00:14:12 +0000277 JITLoaderGDB::Terminate();
278 ProcessElfCore::Terminate();
Kuba Breckabeed8212014-09-04 01:03:18 +0000279 MemoryHistoryASan::Terminate();
Kuba Breckaafdf8422014-10-10 23:43:03 +0000280 AddressSanitizerRuntime::Terminate();
Greg Clayton0e4b6052014-03-06 23:29:58 +0000281
Greg Claytone996fd32011-03-08 22:40:15 +0000282#if defined (__APPLE__)
Eli Friedmane13a8db2010-06-13 19:36:42 +0000283 DynamicLoaderMacOSXDYLD::Terminate();
Greg Clayton944b8282011-08-22 22:30:57 +0000284 DynamicLoaderDarwinKernel::Terminate();
Jim Ingham2a5e0f02010-11-04 18:30:59 +0000285 AppleObjCRuntimeV2::Terminate();
286 AppleObjCRuntimeV1::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000287 ObjectContainerUniversalMachO::Terminate();
288 ObjectFileMachO::Terminate();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000289 ProcessMachCore::Terminate();
Jason Molenda382dcfd2012-06-01 01:39:46 +0000290 ProcessKDP::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000291 SymbolVendorMacOSX::Terminate();
Greg Claytone996fd32011-03-08 22:40:15 +0000292 PlatformMacOSX::Terminate();
Jason Molenda1c627542013-04-05 01:03:25 +0000293 PlatformDarwinKernel::Terminate();
Greg Claytonded470d2011-03-19 01:12:21 +0000294 PlatformRemoteiOS::Terminate();
Greg Clayton722cec22012-02-25 06:56:35 +0000295 PlatformiOSSimulator::Terminate();
Jason Molendaa7b5afa2013-11-15 00:17:32 +0000296 SystemRuntimeMacOSX::Terminate();
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000297#endif
298
Caroline Tice20bd37f2011-03-10 22:14:10 +0000299 Debugger::SettingsTerminate ();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000300
Hafiz Abid Qadeerc4d5ed02015-02-11 10:14:13 +0000301#if defined(_MSC_VER)
Zachary Turnercfd3b1a2014-12-05 18:45:53 +0000302 DynamicLoaderWindows::Terminate();
303#endif
304
Greg Claytone996fd32011-03-08 22:40:15 +0000305#if defined (__linux__)
Stephen Wilsone6f9f662010-07-24 02:19:04 +0000306 ProcessLinux::Terminate();
Eli Friedmane13a8db2010-06-13 19:36:42 +0000307#endif
Johnny Chen8f3d8382011-08-02 20:52:42 +0000308
309#if defined (__FreeBSD__)
Johnny Chen30213ff2012-01-05 19:17:38 +0000310 ProcessFreeBSD::Terminate();
Johnny Chen8f3d8382011-08-02 20:52:42 +0000311#endif
Ashok Thirumurthi4f01ff82013-07-17 16:06:12 +0000312
Daniel Malea97059d42013-01-08 14:55:36 +0000313 ProcessGDBRemote::Terminate();
Greg Claytonfc7117a2011-03-05 01:04:56 +0000314 DynamicLoaderStatic::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000315
316 Log::Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317}
318
Daniel Malea3b92f002013-02-28 16:51:15 +0000319#if defined (__APPLE__)
Sean Callanan3d27e662013-03-07 22:29:06 +0000320extern "C" const unsigned char liblldb_coreVersionString[];
Greg Clayton7170f3f2013-02-28 18:09:18 +0000321#else
322
323#include "clang/Basic/Version.h"
324
325static const char *
326GetLLDBRevision()
327{
328#ifdef LLDB_REVISION
329 return LLDB_REVISION;
330#else
331 return NULL;
332#endif
333}
334
335static const char *
336GetLLDBRepository()
337{
338#ifdef LLDB_REPOSITORY
339 return LLDB_REPOSITORY;
340#else
341 return NULL;
342#endif
343}
344
Daniel Malea3b92f002013-02-28 16:51:15 +0000345#endif
346
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347const char *
348lldb_private::GetVersion ()
349{
Daniel Malea3b92f002013-02-28 16:51:15 +0000350#if defined (__APPLE__)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351 static char g_version_string[32];
352 if (g_version_string[0] == '\0')
Sean Callanan3d27e662013-03-07 22:29:06 +0000353 {
354 const char *version_string = ::strstr ((const char *)liblldb_coreVersionString, "PROJECT:");
355
356 if (version_string)
357 version_string += sizeof("PROJECT:") - 1;
358 else
359 version_string = "unknown";
360
361 const char *newline_loc = strchr(version_string, '\n');
362
363 size_t version_len = sizeof(g_version_string);
364
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000365 if (newline_loc &&
366 (newline_loc - version_string < static_cast<ptrdiff_t>(version_len)))
Sean Callanan3d27e662013-03-07 22:29:06 +0000367 version_len = newline_loc - version_string;
368
369 ::strncpy(g_version_string, version_string, version_len);
370 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371
372 return g_version_string;
Daniel Malea3b92f002013-02-28 16:51:15 +0000373#else
374 // On Linux/FreeBSD/Windows, report a version number in the same style as the clang tool.
Greg Clayton7170f3f2013-02-28 18:09:18 +0000375 static std::string g_version_str;
376 if (g_version_str.empty())
377 {
378 g_version_str += "lldb version ";
379 g_version_str += CLANG_VERSION_STRING;
380 const char * lldb_repo = GetLLDBRepository();
381 if (lldb_repo)
382 {
383 g_version_str += " (";
384 g_version_str += lldb_repo;
385 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000386
Greg Clayton7170f3f2013-02-28 18:09:18 +0000387 const char *lldb_rev = GetLLDBRevision();
388 if (lldb_rev)
389 {
390 g_version_str += " revision ";
391 g_version_str += lldb_rev;
392 }
393 std::string clang_rev (clang::getClangRevision());
394 if (clang_rev.length() > 0)
395 {
396 g_version_str += " clang revision ";
397 g_version_str += clang_rev;
398 }
399 std::string llvm_rev (clang::getLLVMRevision());
400 if (llvm_rev.length() > 0)
401 {
402 g_version_str += " llvm revision ";
403 g_version_str += llvm_rev;
404 }
Daniel Malea3b92f002013-02-28 16:51:15 +0000405
Greg Clayton7170f3f2013-02-28 18:09:18 +0000406 if (lldb_repo)
407 g_version_str += ")";
408 }
409 return g_version_str.c_str();
Daniel Malea3b92f002013-02-28 16:51:15 +0000410#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411}
412
Greg Clayton2cad65a2010-09-03 17:10:42 +0000413const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000414lldb_private::GetVoteAsCString (Vote vote)
Greg Clayton2cad65a2010-09-03 17:10:42 +0000415{
Greg Clayton1346f7e2010-09-03 22:45:01 +0000416 switch (vote)
417 {
418 case eVoteNo: return "no";
419 case eVoteNoOpinion: return "no opinion";
420 case eVoteYes: return "yes";
Greg Clayton1346f7e2010-09-03 22:45:01 +0000421 }
Greg Clayton2cad65a2010-09-03 17:10:42 +0000422 return "invalid";
423}
424
Greg Clayton89411422010-10-08 00:21:05 +0000425
426const char *
Greg Claytone0d378b2011-03-24 21:19:54 +0000427lldb_private::GetSectionTypeAsCString (SectionType sect_type)
Greg Clayton89411422010-10-08 00:21:05 +0000428{
429 switch (sect_type)
430 {
431 case eSectionTypeInvalid: return "invalid";
432 case eSectionTypeCode: return "code";
433 case eSectionTypeContainer: return "container";
434 case eSectionTypeData: return "data";
435 case eSectionTypeDataCString: return "data-cstr";
436 case eSectionTypeDataCStringPointers: return "data-cstr-ptr";
437 case eSectionTypeDataSymbolAddress: return "data-symbol-addr";
438 case eSectionTypeData4: return "data-4-byte";
439 case eSectionTypeData8: return "data-8-byte";
440 case eSectionTypeData16: return "data-16-byte";
441 case eSectionTypeDataPointers: return "data-ptrs";
442 case eSectionTypeDebug: return "debug";
443 case eSectionTypeZeroFill: return "zero-fill";
444 case eSectionTypeDataObjCMessageRefs: return "objc-message-refs";
445 case eSectionTypeDataObjCCFStrings: return "objc-cfstrings";
446 case eSectionTypeDWARFDebugAbbrev: return "dwarf-abbrev";
447 case eSectionTypeDWARFDebugAranges: return "dwarf-aranges";
448 case eSectionTypeDWARFDebugFrame: return "dwarf-frame";
449 case eSectionTypeDWARFDebugInfo: return "dwarf-info";
450 case eSectionTypeDWARFDebugLine: return "dwarf-line";
451 case eSectionTypeDWARFDebugLoc: return "dwarf-loc";
452 case eSectionTypeDWARFDebugMacInfo: return "dwarf-macinfo";
453 case eSectionTypeDWARFDebugPubNames: return "dwarf-pubnames";
454 case eSectionTypeDWARFDebugPubTypes: return "dwarf-pubtypes";
455 case eSectionTypeDWARFDebugRanges: return "dwarf-ranges";
456 case eSectionTypeDWARFDebugStr: return "dwarf-str";
Michael Sartaina7499c92013-07-01 19:45:50 +0000457 case eSectionTypeELFSymbolTable: return "elf-symbol-table";
458 case eSectionTypeELFDynamicSymbols: return "elf-dynamic-symbols";
459 case eSectionTypeELFRelocationEntries: return "elf-relocation-entries";
460 case eSectionTypeELFDynamicLinkInfo: return "elf-dynamic-link-info";
Greg Clayton17674402011-09-28 17:06:40 +0000461 case eSectionTypeDWARFAppleNames: return "apple-names";
462 case eSectionTypeDWARFAppleTypes: return "apple-types";
Greg Clayton7f995132011-10-04 22:41:51 +0000463 case eSectionTypeDWARFAppleNamespaces: return "apple-namespaces";
Greg Clayton5009f9d2011-10-27 17:55:14 +0000464 case eSectionTypeDWARFAppleObjC: return "apple-objc";
Greg Clayton89411422010-10-08 00:21:05 +0000465 case eSectionTypeEHFrame: return "eh-frame";
Jason Molendae589e7e2014-12-08 03:09:00 +0000466 case eSectionTypeCompactUnwind: return "compact-unwind";
Greg Clayton89411422010-10-08 00:21:05 +0000467 case eSectionTypeOther: return "regular";
468 }
469 return "unknown";
470
471}
472
Greg Claytone996fd32011-03-08 22:40:15 +0000473bool
474lldb_private::NameMatches (const char *name,
Greg Claytone0d378b2011-03-24 21:19:54 +0000475 NameMatchType match_type,
Greg Claytone996fd32011-03-08 22:40:15 +0000476 const char *match)
477{
478 if (match_type == eNameMatchIgnore)
479 return true;
480
481 if (name == match)
482 return true;
483
484 if (name && match)
485 {
486 llvm::StringRef name_sref(name);
487 llvm::StringRef match_sref(match);
488 switch (match_type)
489 {
Sylvestre Ledru6e2c7cb2013-10-14 14:06:28 +0000490 case eNameMatchIgnore: // This case cannot occur: tested before
491 return true;
Greg Claytone996fd32011-03-08 22:40:15 +0000492 case eNameMatchEquals: return name_sref == match_sref;
493 case eNameMatchContains: return name_sref.find (match_sref) != llvm::StringRef::npos;
494 case eNameMatchStartsWith: return name_sref.startswith (match_sref);
495 case eNameMatchEndsWith: return name_sref.endswith (match_sref);
496 case eNameMatchRegularExpression:
497 {
498 RegularExpression regex (match);
499 return regex.Execute (name);
500 }
501 break;
Greg Claytone996fd32011-03-08 22:40:15 +0000502 }
503 }
504 return false;
505}