Index: lldb/include/lldb/Version/Version.h =================================================================== --- /dev/null +++ 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 + +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 Index: lldb/include/lldb/Version/Version.inc.in =================================================================== --- /dev/null +++ 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@" Index: lldb/include/lldb/lldb-private.h =================================================================== --- lldb/include/lldb/lldb-private.h +++ 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 Index: lldb/source/API/CMakeLists.txt =================================================================== --- lldb/source/API/CMakeLists.txt +++ lldb/source/API/CMakeLists.txt @@ -94,7 +94,6 @@ ${lldb_lua_wrapper} LINK_LIBS - lldbBase lldbBreakpoint lldbCore lldbDataFormatters @@ -105,6 +104,7 @@ lldbSymbol lldbTarget lldbUtility + lldbVersion ${LLDB_ALL_PLUGINS} LINK_COMPONENTS Support Index: lldb/source/API/SBDebugger.cpp =================================================================== --- lldb/source/API/SBDebugger.cpp +++ 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" Index: lldb/source/API/SBReproducer.cpp =================================================================== --- lldb/source/API/SBReproducer.cpp +++ 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; Index: lldb/source/CMakeLists.txt =================================================================== --- lldb/source/CMakeLists.txt +++ 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(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. Index: lldb/source/Commands/CMakeLists.txt =================================================================== --- lldb/source/Commands/CMakeLists.txt +++ lldb/source/Commands/CMakeLists.txt @@ -41,7 +41,6 @@ CommandOptionsProcessLaunch.cpp LINK_LIBS - lldbBase lldbBreakpoint lldbCore lldbDataFormatters @@ -51,6 +50,7 @@ lldbSymbol lldbTarget lldbUtility + lldbVersion LINK_COMPONENTS Support Index: lldb/source/Commands/CommandObjectVersion.cpp =================================================================== --- lldb/source/Commands/CommandObjectVersion.cpp +++ 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; Index: lldb/source/Initialization/SystemInitializerCommon.cpp =================================================================== --- lldb/source/Initialization/SystemInitializerCommon.cpp +++ 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" Index: lldb/source/Version/CMakeLists.txt =================================================================== --- /dev/null +++ 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}) Index: lldb/source/Version/Version.cpp =================================================================== --- /dev/null +++ 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(); +} Index: lldb/tools/lldb-server/CMakeLists.txt =================================================================== --- lldb/tools/lldb-server/CMakeLists.txt +++ lldb/tools/lldb-server/CMakeLists.txt @@ -46,9 +46,9 @@ SystemInitializerLLGS.cpp LINK_LIBS - lldbBase lldbHost lldbInitialization + lldbVersion ${LLDB_PLUGINS} lldbPluginInstructionARM lldbPluginInstructionMIPS Index: lldb/tools/lldb-server/lldb-server.cpp =================================================================== --- lldb/tools/lldb-server/lldb-server.cpp +++ 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" Index: lldb/tools/lldb-test/CMakeLists.txt =================================================================== --- lldb/tools/lldb-test/CMakeLists.txt +++ lldb/tools/lldb-test/CMakeLists.txt @@ -6,7 +6,6 @@ SystemInitializerTest.cpp LINK_LIBS - lldbBase lldbBreakpoint lldbCore lldbDataFormatters @@ -17,6 +16,7 @@ lldbSymbol lldbTarget lldbUtility + lldbVersion ${LLDB_ALL_PLUGINS} LINK_COMPONENTS