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 | adb909b | 2010-12-16 21:33:41 +0000 | [diff] [blame] | 51 | using namespace lldb; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | using namespace lldb_private; |
| 53 | |
| 54 | |
| 55 | void |
| 56 | lldb_private::Initialize () |
| 57 | { |
| 58 | // Make sure we inialize only once |
Caroline Tice | 0aa2e55 | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 59 | static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | static bool g_inited = false; |
| 61 | |
| 62 | Mutex::Locker locker(g_inited_mutex); |
| 63 | if (!g_inited) |
| 64 | { |
| 65 | g_inited = true; |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 66 | Log::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | Timer::Initialize (); |
| 68 | Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 69 | |
| 70 | Target::Initialize (); |
| 71 | Process::Initialize (); |
| 72 | Thread::Initialize (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | DisassemblerLLVM::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | ObjectContainerBSDArchive::Initialize(); |
| 75 | ObjectFileELF::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | SymbolFileDWARF::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | SymbolFileSymtab::Initialize(); |
Jason Molenda | 3a4ea24 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 78 | UnwindAssemblyProfiler_x86::Initialize(); |
Jason Molenda | 8280cbe | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 79 | ArchDefaultUnwindPlan_x86::Initialize(); |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 80 | ArchVolatileRegs_x86::Initialize(); |
Caroline Tice | 0aa2e55 | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 81 | ScriptInterpreter::Initialize (); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 82 | |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 83 | #ifdef __APPLE__ |
| 84 | ABIMacOSX_i386::Initialize(); |
| 85 | ABISysV_x86_64::Initialize(); |
| 86 | DynamicLoaderMacOSXDYLD::Initialize(); |
Stephen Wilson | be1acb2 | 2011-01-12 04:22:09 +0000 | [diff] [blame] | 87 | SymbolFileDWARFDebugMap::Initialize(); |
Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 88 | ItaniumABILanguageRuntime::Initialize(); |
| 89 | AppleObjCRuntimeV2::Initialize(); |
Jim Ingham | 2eac2b9 | 2010-11-04 18:30:59 +0000 | [diff] [blame] | 90 | AppleObjCRuntimeV1::Initialize(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 91 | ObjectContainerUniversalMachO::Initialize(); |
| 92 | ObjectFileMachO::Initialize(); |
| 93 | ProcessGDBRemote::Initialize(); |
Caroline Tice | 734b483 | 2010-10-15 21:52:38 +0000 | [diff] [blame] | 94 | //ProcessMacOSX::Initialize(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 95 | SymbolVendorMacOSX::Initialize(); |
| 96 | #endif |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 97 | #ifdef __linux__ |
| 98 | ProcessLinux::Initialize(); |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 99 | DynamicLoaderLinuxDYLD::Initialize(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 100 | #endif |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 101 | // Scan for any system or user LLDB plug-ins |
| 102 | PluginManager::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | void |
| 107 | lldb_private::WillTerminate() |
| 108 | { |
| 109 | Host::WillTerminate(); |
| 110 | } |
| 111 | |
| 112 | void |
| 113 | lldb_private::Terminate () |
| 114 | { |
| 115 | Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 116 | |
| 117 | // Terminate and unload and loaded system or user LLDB plug-ins |
| 118 | PluginManager::Terminate(); |
| 119 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 120 | DisassemblerLLVM::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | ObjectContainerBSDArchive::Terminate(); |
| 122 | ObjectFileELF::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | SymbolFileDWARF::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | SymbolFileSymtab::Terminate(); |
Jason Molenda | 3a4ea24 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 125 | UnwindAssemblyProfiler_x86::Terminate(); |
Jason Molenda | 8280cbe | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 126 | ArchDefaultUnwindPlan_x86::Terminate(); |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 127 | ArchVolatileRegs_x86::Terminate(); |
Caroline Tice | 0aa2e55 | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 128 | ScriptInterpreter::Terminate (); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 129 | |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 130 | #ifdef __APPLE__ |
| 131 | DynamicLoaderMacOSXDYLD::Terminate(); |
Stephen Wilson | be1acb2 | 2011-01-12 04:22:09 +0000 | [diff] [blame] | 132 | SymbolFileDWARFDebugMap::Terminate(); |
Jim Ingham | 2eac2b9 | 2010-11-04 18:30:59 +0000 | [diff] [blame] | 133 | ItaniumABILanguageRuntime::Terminate(); |
| 134 | AppleObjCRuntimeV2::Terminate(); |
| 135 | AppleObjCRuntimeV1::Terminate(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 136 | ObjectContainerUniversalMachO::Terminate(); |
| 137 | ObjectFileMachO::Terminate(); |
| 138 | ProcessGDBRemote::Terminate(); |
Caroline Tice | 734b483 | 2010-10-15 21:52:38 +0000 | [diff] [blame] | 139 | //ProcessMacOSX::Terminate(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 140 | SymbolVendorMacOSX::Terminate(); |
| 141 | #endif |
| 142 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 143 | Thread::Terminate (); |
| 144 | Process::Terminate (); |
| 145 | Target::Terminate (); |
| 146 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 147 | #ifdef __linux__ |
| 148 | ProcessLinux::Terminate(); |
Stephen Wilson | 92241ef | 2011-01-16 19:45:39 +0000 | [diff] [blame] | 149 | DynamicLoaderLinuxDYLD::Terminate(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 150 | #endif |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 151 | |
| 152 | Log::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Benjamin Kramer | c4e0752 | 2010-07-07 09:33:41 +0000 | [diff] [blame] | 155 | extern "C" const double LLDBVersionNumber; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | const char * |
| 157 | lldb_private::GetVersion () |
| 158 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | 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 Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 166 | const char * |
| 167 | lldb_private::GetVoteAsCString (lldb::Vote vote) |
| 168 | { |
Greg Clayton | f04d661 | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 169 | 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 Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 177 | return "invalid"; |
| 178 | } |
| 179 | |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 180 | |
| 181 | const char * |
| 182 | lldb_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 | |