[Lldb-commits] [lldb] ccf1469 - [lldb] Make lldbVersion a full fledged library
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Dec 8 15:14:41 PST 2021
Author: Jonas Devlieghere
Date: 2021-12-08T15:14:34-08:00
New Revision: ccf1469a4cdb03cb2bc7868f76164e85d90ebee1
URL: https://github.com/llvm/llvm-project/commit/ccf1469a4cdb03cb2bc7868f76164e85d90ebee1
DIFF: https://github.com/llvm/llvm-project/commit/ccf1469a4cdb03cb2bc7868f76164e85d90ebee1.diff
LOG: [lldb] Make lldbVersion a full fledged library
Because of its dependency on clang (and potentially other compilers
downstream, such as swift) lldb_private::GetVersion already lives in its
own library called lldbBase. Despite that, its implementation was spread
across unrelated files. This patch improves things by introducing a
Version library with its own directory, header and implementation file.
The benefits of this patch include:
- We can get rid of the ugly quoting macros.
- Other parts of LLDB can read the version number from
lldb/Version/Version.inc.
- The implementation can be swapped out for tools like lldb-server than
don't need to depend on clang at all.
Differential revision: https://reviews.llvm.org/D115211
Added:
lldb/include/lldb/Version/Version.h
lldb/include/lldb/Version/Version.inc.in
lldb/source/Version/CMakeLists.txt
lldb/source/Version/Version.cpp
Modified:
lldb/include/lldb/lldb-private.h
lldb/source/API/CMakeLists.txt
lldb/source/API/SBDebugger.cpp
lldb/source/API/SBReproducer.cpp
lldb/source/CMakeLists.txt
lldb/source/Commands/CMakeLists.txt
lldb/source/Commands/CommandObjectVersion.cpp
lldb/source/Initialization/SystemInitializerCommon.cpp
lldb/tools/lldb-server/CMakeLists.txt
lldb/tools/lldb-server/lldb-server.cpp
lldb/tools/lldb-test/CMakeLists.txt
Removed:
################################################################################
diff --git a/lldb/include/lldb/Version/Version.h b/lldb/include/lldb/Version/Version.h
new file mode 100644
index 0000000000000..15b613560187a
--- /dev/null
+++ b/lldb/include/lldb/Version/Version.h
@@ -0,0 +1,23 @@
+//===-- Version.h -----------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_VERSION_VERSION_H
+#define LLDB_VERSION_VERSION_H
+
+#include <string>
+
+namespace lldb_private {
+
+/// Retrieves a string representing the complete LLDB version, which includes
+/// the lldb version number, as well as embedded compiler versions and the
+/// vendor tag.
+const char *GetVersion();
+
+} // namespace lldb_private
+
+#endif // LLDB_VERSION_VERSION_H
diff --git a/lldb/include/lldb/Version/Version.inc.in b/lldb/include/lldb/Version/Version.inc.in
new file mode 100644
index 0000000000000..5098bb1c2be5a
--- /dev/null
+++ b/lldb/include/lldb/Version/Version.inc.in
@@ -0,0 +1,6 @@
+#define LLDB_VERSION @LLDB_VERSION@
+#define LLDB_VERSION_STRING "@LLDB_VERSION@"
+#define LLDB_VERSION_MAJOR @LLDB_VERSION_MAJOR@
+#define LLDB_VERSION_MINOR @LLDB_VERSION_MINOR@
+#define LLDB_VERSION_PATCHLEVEL @LLDB_VERSION_PATCHLEVEL@
+#cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"
diff --git a/lldb/include/lldb/lldb-private.h b/lldb/include/lldb/lldb-private.h
index d65773aecd6d6..ac07047fb4edb 100644
--- a/lldb/include/lldb/lldb-private.h
+++ b/lldb/include/lldb/lldb-private.h
@@ -17,12 +17,6 @@
#include "lldb/lldb-private-types.h"
#include "lldb/lldb-public.h"
-namespace lldb_private {
-
-const char *GetVersion();
-
-} // namespace lldb_private
-
#endif // defined(__cplusplus)
#endif // LLDB_LLDB_PRIVATE_H
diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 2e33f5c05c1a0..e75cce3ecb070 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -94,7 +94,6 @@ add_lldb_library(liblldb SHARED ${option_framework}
${lldb_lua_wrapper}
LINK_LIBS
- lldbBase
lldbBreakpoint
lldbCore
lldbDataFormatters
@@ -105,6 +104,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
lldbSymbol
lldbTarget
lldbUtility
+ lldbVersion
${LLDB_ALL_PLUGINS}
LINK_COMPONENTS
Support
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 844b91de4cd01..5f92729592e32 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -11,8 +11,6 @@
#include "lldb/API/SBDebugger.h"
-#include "lldb/lldb-private.h"
-
#include "lldb/API/SBBroadcaster.h"
#include "lldb/API/SBCommandInterpreter.h"
#include "lldb/API/SBCommandInterpreterRunOptions.h"
@@ -52,6 +50,7 @@
#include "lldb/Target/TargetList.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/State.h"
+#include "lldb/Version/Version.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
diff --git a/lldb/source/API/SBReproducer.cpp b/lldb/source/API/SBReproducer.cpp
index 68e632da1bde9..3bd82df5c9065 100644
--- a/lldb/source/API/SBReproducer.cpp
+++ b/lldb/source/API/SBReproducer.cpp
@@ -23,7 +23,7 @@
#include "lldb/API/SBHostOS.h"
#include "lldb/API/SBReproducer.h"
#include "lldb/Host/FileSystem.h"
-#include "lldb/lldb-private.h"
+#include "lldb/Version/Version.h"
using namespace lldb;
using namespace lldb_private;
diff --git a/lldb/source/CMakeLists.txt b/lldb/source/CMakeLists.txt
index 6cc89a9fcbaf0..54e7903580662 100644
--- a/lldb/source/CMakeLists.txt
+++ b/lldb/source/CMakeLists.txt
@@ -1,41 +1,5 @@
-include_directories(.)
-
-set(lldbBase_SOURCES
- lldb.cpp
- )
-
-
-find_first_existing_vc_file("${LLDB_SOURCE_DIR}" lldb_vc)
-
-set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
-set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
-
-if(lldb_vc AND LLVM_APPEND_VC_REV)
- set(lldb_source_dir ${LLDB_SOURCE_DIR})
-endif()
-
-add_custom_command(OUTPUT "${version_inc}"
- DEPENDS "${lldb_vc}" "${generate_vcs_version_script}"
- COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
- "-DLLDB_SOURCE_DIR=${lldb_source_dir}"
- "-DHEADER_FILE=${version_inc}"
- -P "${generate_vcs_version_script}")
-
-# Mark the generated header as being generated.
-set_source_files_properties("${version_inc}"
- PROPERTIES GENERATED TRUE
- HEADER_FILE_ONLY TRUE)
-
-list(APPEND lldbBase_SOURCES ${version_inc})
-
-if(LLDB_VERSION_STRING)
- set_property(SOURCE lldb.cpp APPEND PROPERTY
- COMPILE_DEFINITIONS "LLDB_VERSION_STRING=${LLDB_VERSION_STRING}")
-endif()
-
-add_lldb_library(lldbBase
- ${lldbBase_SOURCES}
- )
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(Breakpoint)
add_subdirectory(Commands)
@@ -49,6 +13,7 @@ add_subdirectory(Plugins)
add_subdirectory(Symbol)
add_subdirectory(Target)
add_subdirectory(Utility)
+add_subdirectory(Version)
# Build API last. Since liblldb needs to link against every other target, it needs
# those targets to have already been created.
diff --git a/lldb/source/Commands/CMakeLists.txt b/lldb/source/Commands/CMakeLists.txt
index 4a6d0c5fa86d2..6d2bee8a1ba83 100644
--- a/lldb/source/Commands/CMakeLists.txt
+++ b/lldb/source/Commands/CMakeLists.txt
@@ -41,7 +41,6 @@ add_lldb_library(lldbCommands
CommandOptionsProcessLaunch.cpp
LINK_LIBS
- lldbBase
lldbBreakpoint
lldbCore
lldbDataFormatters
@@ -51,6 +50,7 @@ add_lldb_library(lldbCommands
lldbSymbol
lldbTarget
lldbUtility
+ lldbVersion
LINK_COMPONENTS
Support
diff --git a/lldb/source/Commands/CommandObjectVersion.cpp b/lldb/source/Commands/CommandObjectVersion.cpp
index 20c2d25b745c7..e15faba5661e7 100644
--- a/lldb/source/Commands/CommandObjectVersion.cpp
+++ b/lldb/source/Commands/CommandObjectVersion.cpp
@@ -9,7 +9,7 @@
#include "CommandObjectVersion.h"
#include "lldb/Interpreter/CommandReturnObject.h"
-#include "lldb/lldb-private.h"
+#include "lldb/Version/Version.h"
using namespace lldb;
using namespace lldb_private;
diff --git a/lldb/source/Initialization/SystemInitializerCommon.cpp b/lldb/source/Initialization/SystemInitializerCommon.cpp
index 84c5a472332aa..1c8406f687844 100644
--- a/lldb/source/Initialization/SystemInitializerCommon.cpp
+++ b/lldb/source/Initialization/SystemInitializerCommon.cpp
@@ -15,7 +15,7 @@
#include "lldb/Utility/Log.h"
#include "lldb/Utility/ReproducerProvider.h"
#include "lldb/Utility/Timer.h"
-#include "lldb/lldb-private.h"
+#include "lldb/Version/Version.h"
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
diff --git a/lldb/source/Version/CMakeLists.txt b/lldb/source/Version/CMakeLists.txt
new file mode 100644
index 0000000000000..4d66761739ae2
--- /dev/null
+++ b/lldb/source/Version/CMakeLists.txt
@@ -0,0 +1,42 @@
+if(LLDB_VERSION_STRING)
+ set(LLDB_FULL_VERSION_STRING LLDB_VERSION_STRING)
+endif()
+
+# Configure the VCSVersion.inc file.
+set(vcs_version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
+set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
+
+find_first_existing_vc_file("${LLDB_SOURCE_DIR}" lldb_vc)
+
+if(lldb_vc AND LLVM_APPEND_VC_REV)
+ set(lldb_source_dir ${LLDB_SOURCE_DIR})
+endif()
+
+add_custom_command(OUTPUT "${vcs_version_inc}"
+ DEPENDS "${lldb_vc}" "${generate_vcs_version_script}"
+ COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
+ "-DLLDB_SOURCE_DIR=${lldb_source_dir}"
+ "-DHEADER_FILE=${vcs_version_inc}"
+ -P "${generate_vcs_version_script}")
+
+set_source_files_properties("${vcs_version_inc}"
+ PROPERTIES GENERATED TRUE
+ HEADER_FILE_ONLY TRUE)
+
+# Configure the Version.inc file.
+set(version_inc "${LLDB_BINARY_DIR}/include/lldb/Version/Version.inc")
+
+configure_file(
+ ${LLDB_SOURCE_DIR}/include/lldb/Version/Version.inc.in
+ ${version_inc})
+
+set_source_files_properties("${version_inc}"
+ PROPERTIES GENERATED TRUE
+ HEADER_FILE_ONLY TRUE)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+add_lldb_library(lldbVersion
+ Version.cpp
+ ${vcs_version_inc}
+ ${version_inc})
diff --git a/lldb/source/Version/Version.cpp b/lldb/source/Version/Version.cpp
new file mode 100644
index 0000000000000..ae2d83bd3e5f8
--- /dev/null
+++ b/lldb/source/Version/Version.cpp
@@ -0,0 +1,73 @@
+//===-- Version.cpp -------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Version/Version.h"
+#include "VCSVersion.inc"
+#include "lldb/Version/Version.inc"
+#include "clang/Basic/Version.h"
+
+static const char *GetLLDBVersion() {
+#ifdef LLDB_FULL_VERSION_STRING
+ return LLDB_FULL_VERSION_STRING;
+#else
+ return "lldb version " CLANG_VERSION_STRING;
+#endif
+}
+
+static const char *GetLLDBRevision() {
+#ifdef LLDB_REVISION
+ return LLDB_REVISION;
+#else
+ return nullptr;
+#endif
+}
+
+static const char *GetLLDBRepository() {
+#ifdef LLDB_REPOSITORY
+ return LLDB_REPOSITORY;
+#else
+ return nullptr;
+#endif
+}
+
+const char *lldb_private::GetVersion() {
+ static std::string g_version_str;
+
+ if (g_version_str.empty()) {
+ const char *lldb_version = GetLLDBVersion();
+ const char *lldb_repo = GetLLDBRepository();
+ const char *lldb_rev = GetLLDBRevision();
+ g_version_str += lldb_version;
+ if (lldb_repo || lldb_rev) {
+ g_version_str += " (";
+ if (lldb_repo)
+ g_version_str += lldb_repo;
+ if (lldb_repo && lldb_rev)
+ g_version_str += " ";
+ if (lldb_rev) {
+ g_version_str += "revision ";
+ g_version_str += lldb_rev;
+ }
+ g_version_str += ")";
+ }
+
+ std::string clang_rev(clang::getClangRevision());
+ if (clang_rev.length() > 0) {
+ g_version_str += "\n clang revision ";
+ g_version_str += clang_rev;
+ }
+
+ std::string llvm_rev(clang::getLLVMRevision());
+ if (llvm_rev.length() > 0) {
+ g_version_str += "\n llvm revision ";
+ g_version_str += llvm_rev;
+ }
+ }
+
+ return g_version_str.c_str();
+}
diff --git a/lldb/tools/lldb-server/CMakeLists.txt b/lldb/tools/lldb-server/CMakeLists.txt
index 9ed259295a300..3fb22b0a61098 100644
--- a/lldb/tools/lldb-server/CMakeLists.txt
+++ b/lldb/tools/lldb-server/CMakeLists.txt
@@ -46,9 +46,9 @@ add_lldb_tool(lldb-server
SystemInitializerLLGS.cpp
LINK_LIBS
- lldbBase
lldbHost
lldbInitialization
+ lldbVersion
${LLDB_PLUGINS}
lldbPluginInstructionARM
lldbPluginInstructionMIPS
diff --git a/lldb/tools/lldb-server/lldb-server.cpp b/lldb/tools/lldb-server/lldb-server.cpp
index 1e001ac7185b8..1808ffc0c9790 100644
--- a/lldb/tools/lldb-server/lldb-server.cpp
+++ b/lldb/tools/lldb-server/lldb-server.cpp
@@ -8,7 +8,7 @@
#include "SystemInitializerLLGS.h"
#include "lldb/Initialization/SystemLifetimeManager.h"
-#include "lldb/lldb-private.h"
+#include "lldb/Version/Version.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
diff --git a/lldb/tools/lldb-test/CMakeLists.txt b/lldb/tools/lldb-test/CMakeLists.txt
index bdfcfc5133162..120e3aaa9d20c 100644
--- a/lldb/tools/lldb-test/CMakeLists.txt
+++ b/lldb/tools/lldb-test/CMakeLists.txt
@@ -6,7 +6,6 @@ add_lldb_tool(lldb-test
SystemInitializerTest.cpp
LINK_LIBS
- lldbBase
lldbBreakpoint
lldbCore
lldbDataFormatters
@@ -17,6 +16,7 @@ add_lldb_tool(lldb-test
lldbSymbol
lldbTarget
lldbUtility
+ lldbVersion
${LLDB_ALL_PLUGINS}
LINK_COMPONENTS
More information about the lldb-commits
mailing list