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" |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 25 | |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 26 | #ifdef __APPLE__ |
| 27 | #include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h" |
| 28 | #include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h" |
| 29 | #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h" |
| 30 | #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h" |
| 31 | #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" |
| 32 | #include "Plugins/Process/MacOSX-User/source/ProcessMacOSX.h" |
| 33 | #include "Plugins/Process/gdb-remote/ProcessGDBRemote.h" |
| 34 | #endif |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 36 | #ifdef __linux__ |
| 37 | #include "Plugins/Process/Linux/ProcessLinux.h" |
| 38 | #endif |
| 39 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | using namespace lldb_private; |
| 41 | |
| 42 | |
| 43 | void |
| 44 | lldb_private::Initialize () |
| 45 | { |
| 46 | // Make sure we inialize only once |
| 47 | static Mutex g_inited_mutex(Mutex::eMutexTypeNormal); |
| 48 | static bool g_inited = false; |
| 49 | |
| 50 | Mutex::Locker locker(g_inited_mutex); |
| 51 | if (!g_inited) |
| 52 | { |
| 53 | g_inited = true; |
| 54 | Timer::Initialize (); |
| 55 | Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 56 | |
| 57 | Log::Callbacks log_callbacks = { DisableLog, EnableLog, ListLogCategories }; |
| 58 | |
| 59 | Log::RegisterLogChannel ("lldb", log_callbacks); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | DisassemblerLLVM::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | ObjectContainerBSDArchive::Initialize(); |
| 62 | ObjectFileELF::Initialize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | SymbolFileDWARF::Initialize(); |
| 64 | SymbolFileDWARFDebugMap::Initialize(); |
| 65 | SymbolFileSymtab::Initialize(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 66 | |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 67 | #ifdef __APPLE__ |
| 68 | ABIMacOSX_i386::Initialize(); |
| 69 | ABISysV_x86_64::Initialize(); |
| 70 | DynamicLoaderMacOSXDYLD::Initialize(); |
| 71 | ObjectContainerUniversalMachO::Initialize(); |
| 72 | ObjectFileMachO::Initialize(); |
| 73 | ProcessGDBRemote::Initialize(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 74 | ProcessMacOSX::Initialize(); |
| 75 | SymbolVendorMacOSX::Initialize(); |
| 76 | #endif |
| 77 | |
| 78 | #ifdef __linux__ |
| 79 | ProcessLinux::Initialize(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 80 | #endif |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | lldb_private::WillTerminate() |
| 86 | { |
| 87 | Host::WillTerminate(); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | lldb_private::Terminate () |
| 92 | { |
| 93 | Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 94 | DisassemblerLLVM::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 95 | ObjectContainerBSDArchive::Terminate(); |
| 96 | ObjectFileELF::Terminate(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | SymbolFileDWARF::Terminate(); |
| 98 | SymbolFileDWARFDebugMap::Terminate(); |
| 99 | SymbolFileSymtab::Terminate(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 100 | |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 101 | #ifdef __APPLE__ |
| 102 | DynamicLoaderMacOSXDYLD::Terminate(); |
| 103 | ObjectContainerUniversalMachO::Terminate(); |
| 104 | ObjectFileMachO::Terminate(); |
| 105 | ProcessGDBRemote::Terminate(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 106 | ProcessMacOSX::Terminate(); |
| 107 | SymbolVendorMacOSX::Terminate(); |
| 108 | #endif |
| 109 | |
| 110 | #ifdef __linux__ |
| 111 | ProcessLinux::Terminate(); |
Eli Friedman | e5cadba | 2010-06-13 19:36:42 +0000 | [diff] [blame] | 112 | #endif |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Benjamin Kramer | c4e0752 | 2010-07-07 09:33:41 +0000 | [diff] [blame] | 115 | extern "C" const double LLDBVersionNumber; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | const char * |
| 117 | lldb_private::GetVersion () |
| 118 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | static char g_version_string[32]; |
| 120 | if (g_version_string[0] == '\0') |
| 121 | ::snprintf (g_version_string, sizeof(g_version_string), "LLDB-%g", LLDBVersionNumber); |
| 122 | |
| 123 | return g_version_string; |
| 124 | } |
| 125 | |
| 126 | ArchSpec & |
| 127 | lldb_private::GetDefaultArchitecture () |
| 128 | { |
| 129 | static ArchSpec g_default_arch; |
| 130 | return g_default_arch; |
| 131 | } |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame^] | 132 | |
| 133 | |
| 134 | const char * |
| 135 | lldb_private::GetVoteAsCString (lldb::Vote vote) |
| 136 | { |
| 137 | static const char * g_vote_cstrings[] = { "no", "no opinion", "yes" }; |
| 138 | if (vote >= eVoteNo && vote <= eVoteYes) |
| 139 | return g_vote_cstrings[vote-1]; |
| 140 | return "invalid"; |
| 141 | } |
| 142 | |