1//===-- lldb.cpp ----------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "VCSVersion.inc"
10#include "lldb/lldb-private.h"
11#include "clang/Basic/Version.h"
12
13using namespace lldb;
14using namespace lldb_private;
15
16// LLDB_VERSION_STRING is set through a define so unlike the other defines
17// expanded with CMake, it lacks the double quotes.
18#define QUOTE(str) #str
19#define EXPAND_AND_QUOTE(str) QUOTE(str)
20
21static const char *GetLLDBVersion() {
22#ifdef LLDB_VERSION_STRING
23 return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
24#else
25 return "lldb version " CLANG_VERSION_STRING;
26#endif
27}
28
29static const char *GetLLDBRevision() {
30#ifdef LLDB_REVISION
31 return LLDB_REVISION;
32#else
33 return NULL;
34#endif
35}
36
37static const char *GetLLDBRepository() {
38#ifdef LLDB_REPOSITORY
39 return LLDB_REPOSITORY;
40#else
41 return NULL;
42#endif
43}
44
45const char *lldb_private::GetVersion() {
46 static std::string g_version_str;
47 if (g_version_str.empty()) {
48 const char *lldb_version = GetLLDBVersion();
49 const char *lldb_repo = GetLLDBRepository();
50 const char *lldb_rev = GetLLDBRevision();
51 g_version_str += lldb_version;
52 if (lldb_repo || lldb_rev) {
53 g_version_str += " (";
54 if (lldb_repo)
55 g_version_str += lldb_repo;
56 if (lldb_repo && lldb_rev)
57 g_version_str += " ";
58 if (lldb_rev) {
59 g_version_str += "revision ";
60 g_version_str += lldb_rev;
61 }
62 g_version_str += ")";
63 }
64
65 std::string clang_rev(clang::getClangRevision());
66 if (clang_rev.length() > 0) {
67 g_version_str += "\n clang revision ";
68 g_version_str += clang_rev;
69 }
70 std::string llvm_rev(clang::getLLVMRevision());
71 if (llvm_rev.length() > 0) {
72 g_version_str += "\n llvm revision ";
73 g_version_str += llvm_rev;
74 }
75 }
76 return g_version_str.c_str();
77}
78