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