blob: 9e1808e6db2e6c7bc0a3b26fa4db2881febcb084 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Claytonfc7117a2011-03-05 01:04:56 +000011
Greg Claytonce6d19a2010-12-16 21:33:41 +000012using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013using namespace lldb_private;
14
Kate Stoneb9c1b512016-09-06 20:57:50 +000015#if defined(__APPLE__)
Sean Callanan3d27e662013-03-07 22:29:06 +000016extern "C" const unsigned char liblldb_coreVersionString[];
Greg Clayton7170f3f2013-02-28 18:09:18 +000017#else
18
19#include "clang/Basic/Version.h"
20
Chris Bienemanaa098de2016-09-23 23:33:52 +000021#ifdef HAVE_SVN_VERSION_INC
22# include "SVNVersion.inc"
23#endif
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025static const char *GetLLDBRevision() {
Greg Clayton7170f3f2013-02-28 18:09:18 +000026#ifdef LLDB_REVISION
Kate Stoneb9c1b512016-09-06 20:57:50 +000027 return LLDB_REVISION;
Greg Clayton7170f3f2013-02-28 18:09:18 +000028#else
Kate Stoneb9c1b512016-09-06 20:57:50 +000029 return NULL;
Greg Clayton7170f3f2013-02-28 18:09:18 +000030#endif
31}
32
Kate Stoneb9c1b512016-09-06 20:57:50 +000033static const char *GetLLDBRepository() {
Greg Clayton7170f3f2013-02-28 18:09:18 +000034#ifdef LLDB_REPOSITORY
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 return LLDB_REPOSITORY;
Greg Clayton7170f3f2013-02-28 18:09:18 +000036#else
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 return NULL;
Greg Clayton7170f3f2013-02-28 18:09:18 +000038#endif
39}
40
Daniel Malea3b92f002013-02-28 16:51:15 +000041#endif
42
Kate Stoneb9c1b512016-09-06 20:57:50 +000043const 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 Lattner30fdc8d2010-06-08 16:52:24 +000049
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 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 Malea3b92f002013-02-28 16:51:15 +000067#else
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 // 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 Clayton7170f3f2013-02-28 18:09:18 +000078 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000079
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 Malea3b92f002013-02-28 16:51:15 +0000100#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101}