| Chris Lattner | 30fdc8d | 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" |
| Greg Clayton | fc7117a | 2011-03-05 01:04:56 +0000 | [diff] [blame] | 11 | |
| Greg Clayton | ce6d19a | 2010-12-16 21:33:41 +0000 | [diff] [blame] | 12 | using namespace lldb; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | using namespace lldb_private; |
| 14 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 15 | #if defined(__APPLE__) |
| Sean Callanan | 3d27e66 | 2013-03-07 22:29:06 +0000 | [diff] [blame] | 16 | extern "C" const unsigned char liblldb_coreVersionString[]; |
| Greg Clayton | 7170f3f | 2013-02-28 18:09:18 +0000 | [diff] [blame] | 17 | #else |
| 18 | |
| 19 | #include "clang/Basic/Version.h" |
| 20 | |
| Chris Bieneman | aa098de | 2016-09-23 23:33:52 +0000 | [diff] [blame] | 21 | #ifdef HAVE_SVN_VERSION_INC |
| 22 | # include "SVNVersion.inc" |
| 23 | #endif |
| 24 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | static const char *GetLLDBRevision() { |
| Greg Clayton | 7170f3f | 2013-02-28 18:09:18 +0000 | [diff] [blame] | 26 | #ifdef LLDB_REVISION |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | return LLDB_REVISION; |
| Greg Clayton | 7170f3f | 2013-02-28 18:09:18 +0000 | [diff] [blame] | 28 | #else |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | return NULL; |
| Greg Clayton | 7170f3f | 2013-02-28 18:09:18 +0000 | [diff] [blame] | 30 | #endif |
| 31 | } |
| 32 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | static const char *GetLLDBRepository() { |
| Greg Clayton | 7170f3f | 2013-02-28 18:09:18 +0000 | [diff] [blame] | 34 | #ifdef LLDB_REPOSITORY |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | return LLDB_REPOSITORY; |
| Greg Clayton | 7170f3f | 2013-02-28 18:09:18 +0000 | [diff] [blame] | 36 | #else |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | return NULL; |
| Greg Clayton | 7170f3f | 2013-02-28 18:09:18 +0000 | [diff] [blame] | 38 | #endif |
| 39 | } |
| 40 | |
| Daniel Malea | 3b92f00 | 2013-02-28 16:51:15 +0000 | [diff] [blame] | 41 | #endif |
| 42 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | const char *lldb_private::GetVersion() { |
| 44 | #if defined(__APPLE__) |
| 45 | static char g_version_string[32]; |
| 46 | if (g_version_string[0] == '\0') { |
| 47 | const char *version_string = |
| 48 | ::strstr((const char *)liblldb_coreVersionString, "PROJECT:"); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | if (version_string) |
| 51 | version_string += sizeof("PROJECT:") - 1; |
| 52 | else |
| 53 | version_string = "unknown"; |
| 54 | |
| 55 | const char *newline_loc = strchr(version_string, '\n'); |
| 56 | |
| 57 | size_t version_len = sizeof(g_version_string) - 1; |
| 58 | |
| 59 | if (newline_loc && |
| 60 | (newline_loc - version_string < static_cast<ptrdiff_t>(version_len))) |
| 61 | version_len = newline_loc - version_string; |
| 62 | |
| 63 | ::snprintf(g_version_string, version_len + 1, "%s", version_string); |
| 64 | } |
| 65 | |
| 66 | return g_version_string; |
| Daniel Malea | 3b92f00 | 2013-02-28 16:51:15 +0000 | [diff] [blame] | 67 | #else |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | // On platforms other than Darwin, report a version number in the same style |
| 69 | // as the clang tool. |
| 70 | static std::string g_version_str; |
| 71 | if (g_version_str.empty()) { |
| 72 | g_version_str += "lldb version "; |
| 73 | g_version_str += CLANG_VERSION_STRING; |
| 74 | const char *lldb_repo = GetLLDBRepository(); |
| 75 | if (lldb_repo) { |
| 76 | g_version_str += " ("; |
| 77 | g_version_str += lldb_repo; |
| Greg Clayton | 7170f3f | 2013-02-28 18:09:18 +0000 | [diff] [blame] | 78 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | |
| 80 | const char *lldb_rev = GetLLDBRevision(); |
| 81 | if (lldb_rev) { |
| 82 | g_version_str += " revision "; |
| 83 | g_version_str += lldb_rev; |
| 84 | } |
| 85 | std::string clang_rev(clang::getClangRevision()); |
| 86 | if (clang_rev.length() > 0) { |
| 87 | g_version_str += " clang revision "; |
| 88 | g_version_str += clang_rev; |
| 89 | } |
| 90 | std::string llvm_rev(clang::getLLVMRevision()); |
| 91 | if (llvm_rev.length() > 0) { |
| 92 | g_version_str += " llvm revision "; |
| 93 | g_version_str += llvm_rev; |
| 94 | } |
| 95 | |
| 96 | if (lldb_repo) |
| 97 | g_version_str += ")"; |
| 98 | } |
| 99 | return g_version_str.c_str(); |
| Daniel Malea | 3b92f00 | 2013-02-28 16:51:15 +0000 | [diff] [blame] | 100 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 101 | } |