blob: 83acbd0d663d6cc0154ea2438befe858500f163a [file] [log] [blame]
Chris Lattner24943d22010-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
10#include "lldb/lldb-private.h"
11#include "lldb/lldb-private-log.h"
Eli Friedmane5cadba2010-06-13 19:36:42 +000012#include "lldb/Core/ArchSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013#include "lldb/Core/Log.h"
Greg Clayton52fd9842011-02-02 02:24:04 +000014#include "lldb/Core/PluginManager.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/Timer.h"
16#include "lldb/Host/Host.h"
Eli Friedmane5cadba2010-06-13 19:36:42 +000017#include "lldb/Host/Mutex.h"
Caroline Tice0aa2e552011-01-14 00:29:16 +000018#include "lldb/Interpreter/ScriptInterpreter.h"
Greg Claytone01879a2010-12-16 21:36:30 +000019#include "lldb/Target/Target.h"
20#include "lldb/Target/Thread.h"
Eli Friedmane5cadba2010-06-13 19:36:42 +000021
22#include "Plugins/Disassembler/llvm/DisassemblerLLVM.h"
23#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
24#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
25#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
26#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
27#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
28#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
Jason Molenda3a4ea242010-09-10 07:49:16 +000029#include "Plugins/Process/Utility/UnwindAssemblyProfiler-x86.h"
30#include "Plugins/Process/Utility/ArchDefaultUnwindPlan-x86.h"
Jason Molendaea0dbca2010-09-22 07:37:07 +000031#include "Plugins/Process/Utility/ArchVolatileRegs-x86.h"
Stephen Wilsonf6f40332010-07-24 02:19:04 +000032
Eli Friedmane5cadba2010-06-13 19:36:42 +000033#ifdef __APPLE__
34#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
35#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
36#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
Jim Ingham642036f2010-09-23 02:01:19 +000037#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
Jim Ingham2eac2b92010-11-04 18:30:59 +000038#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
39#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
Eli Friedmane5cadba2010-06-13 19:36:42 +000040#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
41#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
42#include "Plugins/Process/MacOSX-User/source/ProcessMacOSX.h"
43#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
44#endif
Chris Lattner24943d22010-06-08 16:52:24 +000045
Stephen Wilsonf6f40332010-07-24 02:19:04 +000046#ifdef __linux__
47#include "Plugins/Process/Linux/ProcessLinux.h"
Stephen Wilson92241ef2011-01-16 19:45:39 +000048#include "Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.h"
Stephen Wilsonf6f40332010-07-24 02:19:04 +000049#endif
50
Greg Claytonadb909b2010-12-16 21:33:41 +000051using namespace lldb;
Chris Lattner24943d22010-06-08 16:52:24 +000052using namespace lldb_private;
53
54
55void
56lldb_private::Initialize ()
57{
58 // Make sure we inialize only once
Caroline Tice0aa2e552011-01-14 00:29:16 +000059 static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
Chris Lattner24943d22010-06-08 16:52:24 +000060 static bool g_inited = false;
61
62 Mutex::Locker locker(g_inited_mutex);
63 if (!g_inited)
64 {
65 g_inited = true;
Greg Clayton990de7b2010-11-18 23:32:35 +000066 Log::Initialize();
Chris Lattner24943d22010-06-08 16:52:24 +000067 Timer::Initialize ();
68 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton990de7b2010-11-18 23:32:35 +000069
70 Target::Initialize ();
71 Process::Initialize ();
72 Thread::Initialize ();
Chris Lattner24943d22010-06-08 16:52:24 +000073 DisassemblerLLVM::Initialize();
Chris Lattner24943d22010-06-08 16:52:24 +000074 ObjectContainerBSDArchive::Initialize();
75 ObjectFileELF::Initialize();
Chris Lattner24943d22010-06-08 16:52:24 +000076 SymbolFileDWARF::Initialize();
Chris Lattner24943d22010-06-08 16:52:24 +000077 SymbolFileSymtab::Initialize();
Jason Molenda3a4ea242010-09-10 07:49:16 +000078 UnwindAssemblyProfiler_x86::Initialize();
Jason Molenda8280cbe2010-10-25 11:12:07 +000079 ArchDefaultUnwindPlan_x86::Initialize();
Jason Molendaea0dbca2010-09-22 07:37:07 +000080 ArchVolatileRegs_x86::Initialize();
Caroline Tice0aa2e552011-01-14 00:29:16 +000081 ScriptInterpreter::Initialize ();
Stephen Wilsonf6f40332010-07-24 02:19:04 +000082
Eli Friedmane5cadba2010-06-13 19:36:42 +000083#ifdef __APPLE__
84 ABIMacOSX_i386::Initialize();
85 ABISysV_x86_64::Initialize();
86 DynamicLoaderMacOSXDYLD::Initialize();
Stephen Wilsonbe1acb22011-01-12 04:22:09 +000087 SymbolFileDWARFDebugMap::Initialize();
Jim Ingham642036f2010-09-23 02:01:19 +000088 ItaniumABILanguageRuntime::Initialize();
89 AppleObjCRuntimeV2::Initialize();
Jim Ingham2eac2b92010-11-04 18:30:59 +000090 AppleObjCRuntimeV1::Initialize();
Eli Friedmane5cadba2010-06-13 19:36:42 +000091 ObjectContainerUniversalMachO::Initialize();
92 ObjectFileMachO::Initialize();
93 ProcessGDBRemote::Initialize();
Caroline Tice734b4832010-10-15 21:52:38 +000094 //ProcessMacOSX::Initialize();
Stephen Wilsonf6f40332010-07-24 02:19:04 +000095 SymbolVendorMacOSX::Initialize();
96#endif
Stephen Wilsonf6f40332010-07-24 02:19:04 +000097#ifdef __linux__
98 ProcessLinux::Initialize();
Stephen Wilson92241ef2011-01-16 19:45:39 +000099 DynamicLoaderLinuxDYLD::Initialize();
Eli Friedmane5cadba2010-06-13 19:36:42 +0000100#endif
Greg Clayton52fd9842011-02-02 02:24:04 +0000101 // Scan for any system or user LLDB plug-ins
102 PluginManager::Initialize();
Chris Lattner24943d22010-06-08 16:52:24 +0000103 }
104}
105
106void
107lldb_private::WillTerminate()
108{
109 Host::WillTerminate();
110}
111
112void
113lldb_private::Terminate ()
114{
115 Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Greg Clayton52fd9842011-02-02 02:24:04 +0000116
117 // Terminate and unload and loaded system or user LLDB plug-ins
118 PluginManager::Terminate();
119
Chris Lattner24943d22010-06-08 16:52:24 +0000120 DisassemblerLLVM::Terminate();
Chris Lattner24943d22010-06-08 16:52:24 +0000121 ObjectContainerBSDArchive::Terminate();
122 ObjectFileELF::Terminate();
Chris Lattner24943d22010-06-08 16:52:24 +0000123 SymbolFileDWARF::Terminate();
Chris Lattner24943d22010-06-08 16:52:24 +0000124 SymbolFileSymtab::Terminate();
Jason Molenda3a4ea242010-09-10 07:49:16 +0000125 UnwindAssemblyProfiler_x86::Terminate();
Jason Molenda8280cbe2010-10-25 11:12:07 +0000126 ArchDefaultUnwindPlan_x86::Terminate();
Jason Molendaea0dbca2010-09-22 07:37:07 +0000127 ArchVolatileRegs_x86::Terminate();
Caroline Tice0aa2e552011-01-14 00:29:16 +0000128 ScriptInterpreter::Terminate ();
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000129
Eli Friedmane5cadba2010-06-13 19:36:42 +0000130#ifdef __APPLE__
131 DynamicLoaderMacOSXDYLD::Terminate();
Stephen Wilsonbe1acb22011-01-12 04:22:09 +0000132 SymbolFileDWARFDebugMap::Terminate();
Jim Ingham2eac2b92010-11-04 18:30:59 +0000133 ItaniumABILanguageRuntime::Terminate();
134 AppleObjCRuntimeV2::Terminate();
135 AppleObjCRuntimeV1::Terminate();
Eli Friedmane5cadba2010-06-13 19:36:42 +0000136 ObjectContainerUniversalMachO::Terminate();
137 ObjectFileMachO::Terminate();
138 ProcessGDBRemote::Terminate();
Caroline Tice734b4832010-10-15 21:52:38 +0000139 //ProcessMacOSX::Terminate();
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000140 SymbolVendorMacOSX::Terminate();
141#endif
142
Greg Clayton990de7b2010-11-18 23:32:35 +0000143 Thread::Terminate ();
144 Process::Terminate ();
145 Target::Terminate ();
146
Stephen Wilsonf6f40332010-07-24 02:19:04 +0000147#ifdef __linux__
148 ProcessLinux::Terminate();
Stephen Wilson92241ef2011-01-16 19:45:39 +0000149 DynamicLoaderLinuxDYLD::Terminate();
Eli Friedmane5cadba2010-06-13 19:36:42 +0000150#endif
Greg Clayton990de7b2010-11-18 23:32:35 +0000151
152 Log::Terminate();
Chris Lattner24943d22010-06-08 16:52:24 +0000153}
154
Benjamin Kramerc4e07522010-07-07 09:33:41 +0000155extern "C" const double LLDBVersionNumber;
Chris Lattner24943d22010-06-08 16:52:24 +0000156const char *
157lldb_private::GetVersion ()
158{
Chris Lattner24943d22010-06-08 16:52:24 +0000159 static char g_version_string[32];
160 if (g_version_string[0] == '\0')
161 ::snprintf (g_version_string, sizeof(g_version_string), "LLDB-%g", LLDBVersionNumber);
162
163 return g_version_string;
164}
165
Greg Clayton5205f0b2010-09-03 17:10:42 +0000166const char *
167lldb_private::GetVoteAsCString (lldb::Vote vote)
168{
Greg Claytonf04d6612010-09-03 22:45:01 +0000169 switch (vote)
170 {
171 case eVoteNo: return "no";
172 case eVoteNoOpinion: return "no opinion";
173 case eVoteYes: return "yes";
174 default:
175 break;
176 }
Greg Clayton5205f0b2010-09-03 17:10:42 +0000177 return "invalid";
178}
179
Greg Clayton3fed8b92010-10-08 00:21:05 +0000180
181const char *
182lldb_private::GetSectionTypeAsCString (lldb::SectionType sect_type)
183{
184 switch (sect_type)
185 {
186 case eSectionTypeInvalid: return "invalid";
187 case eSectionTypeCode: return "code";
188 case eSectionTypeContainer: return "container";
189 case eSectionTypeData: return "data";
190 case eSectionTypeDataCString: return "data-cstr";
191 case eSectionTypeDataCStringPointers: return "data-cstr-ptr";
192 case eSectionTypeDataSymbolAddress: return "data-symbol-addr";
193 case eSectionTypeData4: return "data-4-byte";
194 case eSectionTypeData8: return "data-8-byte";
195 case eSectionTypeData16: return "data-16-byte";
196 case eSectionTypeDataPointers: return "data-ptrs";
197 case eSectionTypeDebug: return "debug";
198 case eSectionTypeZeroFill: return "zero-fill";
199 case eSectionTypeDataObjCMessageRefs: return "objc-message-refs";
200 case eSectionTypeDataObjCCFStrings: return "objc-cfstrings";
201 case eSectionTypeDWARFDebugAbbrev: return "dwarf-abbrev";
202 case eSectionTypeDWARFDebugAranges: return "dwarf-aranges";
203 case eSectionTypeDWARFDebugFrame: return "dwarf-frame";
204 case eSectionTypeDWARFDebugInfo: return "dwarf-info";
205 case eSectionTypeDWARFDebugLine: return "dwarf-line";
206 case eSectionTypeDWARFDebugLoc: return "dwarf-loc";
207 case eSectionTypeDWARFDebugMacInfo: return "dwarf-macinfo";
208 case eSectionTypeDWARFDebugPubNames: return "dwarf-pubnames";
209 case eSectionTypeDWARFDebugPubTypes: return "dwarf-pubtypes";
210 case eSectionTypeDWARFDebugRanges: return "dwarf-ranges";
211 case eSectionTypeDWARFDebugStr: return "dwarf-str";
212 case eSectionTypeEHFrame: return "eh-frame";
213 case eSectionTypeOther: return "regular";
214 }
215 return "unknown";
216
217}
218