Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 12 | #include "lldb/Core/ArchSpec.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Log.h" |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 14 | #include "lldb/Core/PluginManager.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Timer.h" |
| 16 | #include "lldb/Host/Host.h" |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 17 | #include "lldb/Host/Mutex.h" |
Caroline Tice | 0aa2e55 | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/ScriptInterpreter.h" |
Greg Clayton | e01879a | 2010-12-16 21:36:30 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Target.h" |
| 20 | #include "lldb/Target/Thread.h" |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 21 | |
| 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 Molenda | 3a4ea24 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 29 | #include "Plugins/Process/Utility/UnwindAssemblyProfiler-x86.h" |
| 30 | #include "Plugins/Process/Utility/ArchDefaultUnwindPlan-x86.h" |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 31 | #include "Plugins/Process/Utility/ArchVolatileRegs-x86.h" |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 32 | |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 33 | #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 Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 37 | #include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h" |
Jim Ingham | 2eac2b9 | 2010-11-04 18:30:59 +0000 | [diff] [blame] | 38 | #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h" |
| 39 | #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h" |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 40 | #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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 46 | #ifdef __linux__ |
| 47 | #include "Plugins/Process/Linux/ProcessLinux.h" |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 48 | #include "Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.h" |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 49 | #endif |
| 50 | |
Greg Clayton | bd321c5 | 2011-03-05 01:04:56 +0000 | [diff] [blame^] | 51 | #include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h" |
| 52 | |
Greg Clayton | adb909b | 2010-12-16 21:33:41 +0000 | [diff] [blame] | 53 | using namespace lldb; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | using namespace lldb_private; |
| 55 | |
| 56 | |
| 57 | void |
| 58 | lldb_private::Initialize () |
| 59 | { |
| 60 | // Make sure we inialize only once |
Caroline Tice | 0aa2e55 | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 61 | static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | static bool g_inited = false; |
| 63 | |
| 64 | Mutex::Locker locker(g_inited_mutex); |
| 65 | if (!g_inited) |
| 66 | { |
| 67 | g_inited = true; |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 68 | Log::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | Timer::Initialize (); |
| 70 | Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 71 | |
| 72 | Target::Initialize (); |
| 73 | Process::Initialize (); |
| 74 | Thread::Initialize (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | DisassemblerLLVM::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | ObjectContainerBSDArchive::Initialize(); |
| 77 | ObjectFileELF::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | SymbolFileDWARF::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | SymbolFileSymtab::Initialize(); |
Jason Molenda | 3a4ea24 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 80 | UnwindAssemblyProfiler_x86::Initialize(); |
Greg Clayton | c3c4661 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 81 | ArchDefaultUnwindPlan_x86_64::Initialize(); |
| 82 | ArchDefaultUnwindPlan_i386::Initialize(); |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 83 | ArchVolatileRegs_x86::Initialize(); |
Caroline Tice | 0aa2e55 | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 84 | ScriptInterpreter::Initialize (); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 85 | |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 86 | #ifdef __APPLE__ |
| 87 | ABIMacOSX_i386::Initialize(); |
| 88 | ABISysV_x86_64::Initialize(); |
| 89 | DynamicLoaderMacOSXDYLD::Initialize(); |
Stephen Wilson | be1acb2 | 2011-01-12 04:22:09 +0000 | [diff] [blame] | 90 | SymbolFileDWARFDebugMap::Initialize(); |
Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 91 | ItaniumABILanguageRuntime::Initialize(); |
| 92 | AppleObjCRuntimeV2::Initialize(); |
Jim Ingham | 2eac2b9 | 2010-11-04 18:30:59 +0000 | [diff] [blame] | 93 | AppleObjCRuntimeV1::Initialize(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 94 | ObjectContainerUniversalMachO::Initialize(); |
| 95 | ObjectFileMachO::Initialize(); |
| 96 | ProcessGDBRemote::Initialize(); |
Caroline Tice | 734b483 | 2010-10-15 21:52:38 +0000 | [diff] [blame] | 97 | //ProcessMacOSX::Initialize(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 98 | SymbolVendorMacOSX::Initialize(); |
| 99 | #endif |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 100 | #ifdef __linux__ |
| 101 | ProcessLinux::Initialize(); |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 102 | DynamicLoaderLinuxDYLD::Initialize(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 103 | #endif |
Greg Clayton | bd321c5 | 2011-03-05 01:04:56 +0000 | [diff] [blame^] | 104 | DynamicLoaderStatic::Initialize(); |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 105 | // Scan for any system or user LLDB plug-ins |
| 106 | PluginManager::Initialize(); |
Greg Clayton | d284b66 | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 107 | |
| 108 | // The process needs to know about installed plug-ins |
| 109 | Process::DidInitialize (); |
| 110 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | lldb_private::WillTerminate() |
| 116 | { |
| 117 | Host::WillTerminate(); |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | lldb_private::Terminate () |
| 122 | { |
| 123 | Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 124 | |
| 125 | // Terminate and unload and loaded system or user LLDB plug-ins |
| 126 | PluginManager::Terminate(); |
| 127 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 128 | DisassemblerLLVM::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | ObjectContainerBSDArchive::Terminate(); |
| 130 | ObjectFileELF::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | SymbolFileDWARF::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 132 | SymbolFileSymtab::Terminate(); |
Jason Molenda | 3a4ea24 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 133 | UnwindAssemblyProfiler_x86::Terminate(); |
Greg Clayton | c3c4661 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 134 | ArchDefaultUnwindPlan_i386::Terminate(); |
| 135 | ArchDefaultUnwindPlan_x86_64::Terminate(); |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 136 | ArchVolatileRegs_x86::Terminate(); |
Caroline Tice | 0aa2e55 | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 137 | ScriptInterpreter::Terminate (); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 138 | |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 139 | #ifdef __APPLE__ |
| 140 | DynamicLoaderMacOSXDYLD::Terminate(); |
Stephen Wilson | be1acb2 | 2011-01-12 04:22:09 +0000 | [diff] [blame] | 141 | SymbolFileDWARFDebugMap::Terminate(); |
Jim Ingham | 2eac2b9 | 2010-11-04 18:30:59 +0000 | [diff] [blame] | 142 | ItaniumABILanguageRuntime::Terminate(); |
| 143 | AppleObjCRuntimeV2::Terminate(); |
| 144 | AppleObjCRuntimeV1::Terminate(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 145 | ObjectContainerUniversalMachO::Terminate(); |
| 146 | ObjectFileMachO::Terminate(); |
| 147 | ProcessGDBRemote::Terminate(); |
Caroline Tice | 734b483 | 2010-10-15 21:52:38 +0000 | [diff] [blame] | 148 | //ProcessMacOSX::Terminate(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 149 | SymbolVendorMacOSX::Terminate(); |
| 150 | #endif |
| 151 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 152 | Thread::Terminate (); |
| 153 | Process::Terminate (); |
| 154 | Target::Terminate (); |
| 155 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 156 | #ifdef __linux__ |
| 157 | ProcessLinux::Terminate(); |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 158 | DynamicLoaderLinuxDYLD::Terminate(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 159 | #endif |
Greg Clayton | bd321c5 | 2011-03-05 01:04:56 +0000 | [diff] [blame^] | 160 | |
| 161 | DynamicLoaderStatic::Terminate(); |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 162 | |
| 163 | Log::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Benjamin Kramer | c4e0752 | 2010-07-07 09:33:41 +0000 | [diff] [blame] | 166 | extern "C" const double LLDBVersionNumber; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | const char * |
| 168 | lldb_private::GetVersion () |
| 169 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 170 | static char g_version_string[32]; |
| 171 | if (g_version_string[0] == '\0') |
| 172 | ::snprintf (g_version_string, sizeof(g_version_string), "LLDB-%g", LLDBVersionNumber); |
| 173 | |
| 174 | return g_version_string; |
| 175 | } |
| 176 | |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 177 | const char * |
| 178 | lldb_private::GetVoteAsCString (lldb::Vote vote) |
| 179 | { |
Greg Clayton | f04d661 | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 180 | switch (vote) |
| 181 | { |
| 182 | case eVoteNo: return "no"; |
| 183 | case eVoteNoOpinion: return "no opinion"; |
| 184 | case eVoteYes: return "yes"; |
| 185 | default: |
| 186 | break; |
| 187 | } |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 188 | return "invalid"; |
| 189 | } |
| 190 | |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 191 | |
| 192 | const char * |
| 193 | lldb_private::GetSectionTypeAsCString (lldb::SectionType sect_type) |
| 194 | { |
| 195 | switch (sect_type) |
| 196 | { |
| 197 | case eSectionTypeInvalid: return "invalid"; |
| 198 | case eSectionTypeCode: return "code"; |
| 199 | case eSectionTypeContainer: return "container"; |
| 200 | case eSectionTypeData: return "data"; |
| 201 | case eSectionTypeDataCString: return "data-cstr"; |
| 202 | case eSectionTypeDataCStringPointers: return "data-cstr-ptr"; |
| 203 | case eSectionTypeDataSymbolAddress: return "data-symbol-addr"; |
| 204 | case eSectionTypeData4: return "data-4-byte"; |
| 205 | case eSectionTypeData8: return "data-8-byte"; |
| 206 | case eSectionTypeData16: return "data-16-byte"; |
| 207 | case eSectionTypeDataPointers: return "data-ptrs"; |
| 208 | case eSectionTypeDebug: return "debug"; |
| 209 | case eSectionTypeZeroFill: return "zero-fill"; |
| 210 | case eSectionTypeDataObjCMessageRefs: return "objc-message-refs"; |
| 211 | case eSectionTypeDataObjCCFStrings: return "objc-cfstrings"; |
| 212 | case eSectionTypeDWARFDebugAbbrev: return "dwarf-abbrev"; |
| 213 | case eSectionTypeDWARFDebugAranges: return "dwarf-aranges"; |
| 214 | case eSectionTypeDWARFDebugFrame: return "dwarf-frame"; |
| 215 | case eSectionTypeDWARFDebugInfo: return "dwarf-info"; |
| 216 | case eSectionTypeDWARFDebugLine: return "dwarf-line"; |
| 217 | case eSectionTypeDWARFDebugLoc: return "dwarf-loc"; |
| 218 | case eSectionTypeDWARFDebugMacInfo: return "dwarf-macinfo"; |
| 219 | case eSectionTypeDWARFDebugPubNames: return "dwarf-pubnames"; |
| 220 | case eSectionTypeDWARFDebugPubTypes: return "dwarf-pubtypes"; |
| 221 | case eSectionTypeDWARFDebugRanges: return "dwarf-ranges"; |
| 222 | case eSectionTypeDWARFDebugStr: return "dwarf-str"; |
| 223 | case eSectionTypeEHFrame: return "eh-frame"; |
| 224 | case eSectionTypeOther: return "regular"; |
| 225 | } |
| 226 | return "unknown"; |
| 227 | |
| 228 | } |
| 229 | |