diff options
2046 files changed, 64725 insertions, 37735 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 00ddcdc1488f..cdf22c4b0fc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,15 +18,6 @@ else() add_definitions( -DLLDB_CONFIGURATION_RELEASE ) endif() -if (CMAKE_SYSTEM_NAME MATCHES "Windows|Android") - set(LLDB_DEFAULT_DISABLE_LIBEDIT 1) -else() - set(LLDB_DEFAULT_DISABLE_LIBEDIT 0) -endif () - -# We need libedit support to go down both the source and -# the scripts directories. -set(LLDB_DISABLE_LIBEDIT ${LLDB_DEFAULT_DISABLE_LIBEDIT} CACHE BOOL "Disables the use of editline.") if (LLDB_DISABLE_LIBEDIT) add_definitions( -DLLDB_DISABLE_LIBEDIT ) else() @@ -37,65 +28,24 @@ if(APPLE) add_definitions(-DLLDB_USE_OS_LOG) endif() -# lldb-suite is a dummy target that encompasses all the necessary tools and -# libraries for building a fully-functioning liblldb. -add_custom_target(lldb-suite) -set(LLDB_SUITE_TARGET lldb-suite) - -option(LLDB_BUILD_FRAMEWORK "Build the Darwin LLDB.framework" Off) -if(LLDB_BUILD_FRAMEWORK) - if (CMAKE_VERSION VERSION_LESS 3.7) - message(FATAL_ERROR "LLDB_BUILD_FRAMEWORK is not supported on CMake < 3.7") - endif() - if (NOT APPLE) - message(FATAL_ERROR "LLDB.framework can only be generated when targeting Apple platforms") - endif() - - # These are used to fill out LLDB-Info.plist. These are relevant when building - # the framework, and must be defined before building liblldb. - set(PRODUCT_NAME "LLDB") - set(EXECUTABLE_NAME "LLDB") - set(CURRENT_PROJECT_VERSION "360.99.0") - set(LLDB_SUITE_TARGET lldb-framework) - - set(LLDB_FRAMEWORK_DIR - ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_FRAMEWORK_INSTALL_DIR}) -endif() - add_subdirectory(docs) if (NOT LLDB_DISABLE_PYTHON) - if(LLDB_USE_SYSTEM_SIX) - set(SIX_EXTRA_ARGS "--useSystemSix") - endif() - - set(LLDB_PYTHON_TARGET_DIR ${LLDB_BINARY_DIR}/scripts) - set(LLDB_WRAP_PYTHON ${LLDB_BINARY_DIR}/scripts/LLDBWrapPython.cpp) - if(LLDB_BUILD_FRAMEWORK) - set(LLDB_PYTHON_TARGET_DIR ${LLDB_FRAMEWORK_DIR}) - set(LLDB_WRAP_PYTHON ${LLDB_PYTHON_TARGET_DIR}/LLDBWrapPython.cpp) - else() - # Don't set -m when building the framework. - set(FINISH_EXTRA_ARGS "-m") - endif() - - add_subdirectory(scripts) endif () - add_subdirectory(source) add_subdirectory(tools) -option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." - ${LLVM_INCLUDE_TESTS}) +option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS}) option(LLDB_TEST_USE_CUSTOM_C_COMPILER "Use the C compiler provided via LLDB_TEST_C_COMPILER for building test inferiors (instead of the just-built compiler). Defaults to OFF." OFF) option(LLDB_TEST_USE_CUSTOM_CXX_COMPILER "Use the C++ compiler provided via LLDB_TEST_CXX_COMPILER for building test inferiors (instead of the just-built compiler). Defaults to OFF." OFF) if(LLDB_INCLUDE_TESTS) - # The difference between the following two paths is significant. The path to - # LLDB will point to LLDB's binary directory, while the other will point to - # LLVM's binary directory in case the two differ. + # Set the path to the default lldb test executable. set(LLDB_DEFAULT_TEST_EXECUTABLE "${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb${CMAKE_EXECUTABLE_SUFFIX}") + + # Set the paths to default llvm tools. set(LLDB_DEFAULT_TEST_DSYMUTIL "${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/dsymutil${CMAKE_EXECUTABLE_SUFFIX}") + set(LLDB_DEFAULT_TEST_FILECHECK "${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/FileCheck${CMAKE_EXECUTABLE_SUFFIX}") if (NOT LLDB_TEST_USE_CUSTOM_C_COMPILER AND TARGET clang) set(LLDB_DEFAULT_TEST_C_COMPILER "${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/clang${CMAKE_EXECUTABLE_SUFFIX}") @@ -113,6 +63,7 @@ if(LLDB_INCLUDE_TESTS) set(LLDB_TEST_C_COMPILER "${LLDB_DEFAULT_TEST_C_COMPILER}" CACHE PATH "C Compiler to use for building LLDB test inferiors") set(LLDB_TEST_CXX_COMPILER "${LLDB_DEFAULT_TEST_CXX_COMPILER}" CACHE PATH "C++ Compiler to use for building LLDB test inferiors") set(LLDB_TEST_DSYMUTIL "${LLDB_DEFAULT_TEST_DSYMUTIL}" CACHE PATH "dsymutil used for generating dSYM bundles") + set(LLDB_TEST_FILECHECK "${LLDB_DEFAULT_TEST_FILECHECK}" CACHE PATH "FileCheck used for testing purposes") if (("${LLDB_TEST_C_COMPILER}" STREQUAL "") OR ("${LLDB_TEST_CXX_COMPILER}" STREQUAL "")) @@ -131,9 +82,7 @@ if(LLDB_INCLUDE_TESTS) endif() if(TARGET debugserver) - if(NOT CMAKE_HOST_APPLE OR LLDB_CODESIGN_IDENTITY) - list(APPEND LLDB_TEST_DEPS debugserver) - endif() + list(APPEND LLDB_TEST_DEPS debugserver) endif() if(TARGET lldb-mi) @@ -148,8 +97,23 @@ if(LLDB_INCLUDE_TESTS) list(APPEND LLDB_TEST_DEPS liblldb) endif() + # Add dependencies if we test with the in-tree clang. + # This works with standalone builds as they import the clang target. if(TARGET clang) list(APPEND LLDB_TEST_DEPS clang) + if(APPLE) + # If we build clang, we should build libcxx. + # FIXME: Standalone builds should import the cxx target as well. + if(LLDB_BUILT_STANDALONE) + # For now check that the include directory exists. + set(cxx_dir "${LLVM_BINARY_DIR}/include/c++") + if(NOT EXISTS ${cxx_dir}) + message(WARNING "LLDB test suite requires libc++ in llvm/projects/libcxx or an existing build symlinked to ${cxx_dir}") + endif() + else() + list(APPEND LLDB_TEST_DEPS cxx) + endif() + endif() endif() if(TARGET dsymutil) @@ -162,46 +126,44 @@ if(LLDB_INCLUDE_TESTS) add_subdirectory(utils/lldb-dotest) endif() -if (LLDB_BUILD_FRAMEWORK) - add_custom_target(lldb-framework) - include(LLDBFramework) -endif() - if (NOT LLDB_DISABLE_PYTHON) + if(NOT LLDB_BUILD_FRAMEWORK) + set(use_python_wrapper_from_src_dir -m) + endif() + if(LLDB_USE_SYSTEM_SIX) + set(use_six_py_from_system --useSystemSix) + endif() + get_target_property(lldb_scripts_dir swig_wrapper BINARY_DIR) + get_target_property(liblldb_build_dir liblldb LIBRARY_OUTPUT_DIRECTORY) + # Add a Post-Build Event to copy over Python files and create the symlink # to liblldb.so for the Python API(hardlink on Windows) add_custom_target(finish_swig ALL COMMAND - ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py + ${PYTHON_EXECUTABLE} ${LLDB_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py --srcRoot=${LLDB_SOURCE_DIR} - --targetDir=${LLDB_PYTHON_TARGET_DIR} - --cfgBldDir=${LLDB_PYTHON_TARGET_DIR} + --targetDir=${liblldb_build_dir} + --cfgBldDir=${lldb_scripts_dir} --prefix=${CMAKE_BINARY_DIR} --cmakeBuildConfiguration=${CMAKE_CFG_INTDIR} --lldbLibDir=lib${LLVM_LIBDIR_SUFFIX} - ${SIX_EXTRA_ARGS} - ${FINISH_EXTRA_ARGS} + ${use_python_wrapper_from_src_dir} + ${use_six_py_from_system} VERBATIM - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py - DEPENDS ${LLDB_PYTHON_TARGET_DIR}/lldb.py + DEPENDS ${LLDB_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py + DEPENDS ${lldb_scripts_dir}/lldb.py COMMENT "Python script sym-linking LLDB Python API") - # We depend on liblldb and lldb-argdumper being built before we can do this step. - add_dependencies(finish_swig ${LLDB_SUITE_TARGET}) - - # If we build the readline module, we depend on that happening - # first. if (TARGET readline) - add_dependencies(finish_swig readline) + set(readline_dep readline) endif() + add_dependencies(finish_swig swig_wrapper liblldb lldb-argdumper ${readline_dep}) # Ensure we do the python post-build step when building lldb. add_dependencies(lldb finish_swig) - if (LLDB_BUILD_FRAMEWORK) - # The target to install libLLDB needs to depend on finish_swig so that the - # framework build properly copies over the Python files. - add_dependencies(install-liblldb finish_swig) + if(LLDB_BUILD_FRAMEWORK) + add_dependencies(lldb-framework finish_swig) endif() # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake index 129a5ef7500d..f7cac3dad837 100644 --- a/cmake/modules/AddLLDB.cmake +++ b/cmake/modules/AddLLDB.cmake @@ -44,21 +44,32 @@ function(add_lldb_library name) if (PARAM_OBJECT) add_library(${name} ${libkind} ${srcs}) else() - llvm_add_library(${name} ${libkind} ${srcs} LINK_LIBS - ${PARAM_LINK_LIBS} - DEPENDS ${PARAM_DEPENDS}) + if(LLDB_NO_INSTALL_DEFAULT_RPATH) + set(pass_NO_INSTALL_RPATH NO_INSTALL_RPATH) + endif() + + llvm_add_library(${name} ${libkind} ${srcs} + LINK_LIBS ${PARAM_LINK_LIBS} + DEPENDS ${PARAM_DEPENDS} + ${pass_NO_INSTALL_RPATH} + ) if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb") if (PARAM_SHARED) - set(out_dir lib${LLVM_LIBDIR_SUFFIX}) if(${name} STREQUAL "liblldb" AND LLDB_BUILD_FRAMEWORK) - set(out_dir ${LLDB_FRAMEWORK_INSTALL_DIR}) + if(LLDB_FRAMEWORK_INSTALL_DIR) + set(install_dir ${LLDB_FRAMEWORK_INSTALL_DIR}) + else() + set(install_dir ".") + endif() + else() + set(install_dir lib${LLVM_LIBDIR_SUFFIX}) endif() install(TARGETS ${name} COMPONENT ${name} RUNTIME DESTINATION bin - LIBRARY DESTINATION ${out_dir} - ARCHIVE DESTINATION ${out_dir}) + LIBRARY DESTINATION ${install_dir} + ARCHIVE DESTINATION ${install_dir}) else() install(TARGETS ${name} COMPONENT ${name} @@ -67,12 +78,13 @@ function(add_lldb_library name) endif() if (NOT CMAKE_CONFIGURATION_TYPES) add_llvm_install_targets(install-${name} - DEPENDS ${name} + DEPENDS $<TARGET_FILE:${name}> COMPONENT ${name}) endif() endif() endif() + # Hack: only some LLDB libraries depend on the clang autogenerated headers, # but it is simple enough to make all of LLDB depend on some of those # headers without negatively impacting much of anything. @@ -86,59 +98,35 @@ endfunction(add_lldb_library) function(add_lldb_executable name) cmake_parse_arguments(ARG - "INCLUDE_IN_SUITE;GENERATE_INSTALL" - "" + "GENERATE_INSTALL" + "ENTITLEMENTS" "LINK_LIBS;LINK_COMPONENTS" ${ARGN} ) + if(LLDB_NO_INSTALL_DEFAULT_RPATH) + set(pass_NO_INSTALL_RPATH NO_INSTALL_RPATH) + endif() + list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS}) - add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS}) + add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS} + ENTITLEMENTS ${ARG_ENTITLEMENTS} + ${pass_NO_INSTALL_RPATH} + ) target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS}) - set_target_properties(${name} PROPERTIES - FOLDER "lldb executables") - - if(ARG_INCLUDE_IN_SUITE) - add_dependencies(lldb-suite ${name}) - if(LLDB_BUILD_FRAMEWORK) - if(NOT IOS) - set(resource_dir "/Resources") - set(resource_dots "../") - endif() - string(REGEX REPLACE "[^/]+" ".." _dots ${LLDB_FRAMEWORK_INSTALL_DIR}) - set_target_properties(${name} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:liblldb>${resource_dir} - BUILD_WITH_INSTALL_RPATH On - INSTALL_RPATH "@loader_path/../../../${resource_dots}${_dots}/${LLDB_FRAMEWORK_INSTALL_DIR}") - endif() - endif() - - if(LLDB_BUILD_FRAMEWORK AND NOT ARG_INCLUDE_IN_SUITE) - set_target_properties(${name} PROPERTIES - BUILD_WITH_INSTALL_RPATH On - INSTALL_RPATH "@loader_path/../${LLDB_FRAMEWORK_INSTALL_DIR}") - endif() + set_target_properties(${name} PROPERTIES FOLDER "lldb executables") if(ARG_GENERATE_INSTALL) - set(out_dir "bin") - if (LLDB_BUILD_FRAMEWORK AND ARG_INCLUDE_IN_SUITE) - set(out_dir ${LLDB_FRAMEWORK_INSTALL_DIR}/${LLDB_FRAMEWORK_RESOURCE_DIR}) - endif() install(TARGETS ${name} - COMPONENT ${name} - RUNTIME DESTINATION ${out_dir}) + COMPONENT ${name} + RUNTIME DESTINATION bin) if (NOT CMAKE_CONFIGURATION_TYPES) add_llvm_install_targets(install-${name} DEPENDS ${name} COMPONENT ${name}) endif() endif() - - if(ARG_INCLUDE_IN_SUITE AND LLDB_BUILD_FRAMEWORK) - add_llvm_tool_symlink(${name} ${name} ALWAYS_GENERATE SKIP_INSTALL - OUTPUT_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) - endif() endfunction(add_lldb_executable) function(add_lldb_tool name) @@ -160,3 +148,40 @@ function(lldb_append_link_flags target_name new_link_flags) # Now set them onto the target. set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags}) endfunction() + +# For tools that depend on liblldb, account for varying directory structures in +# which LLDB.framework can be used and distributed: In the build-tree we find it +# by its absolute target path. This is only relevant for running the test suite. +# In the install step CMake will remove this entry and insert the final RPATHs. +# These are relative to the file path from where the tool will be loaded on the +# enduser system. +# +# Note that the LLVM install-tree doesn't match the enduser system structure +# for LLDB.framework, so by default dependent tools will not be functional in +# their install location. The LLDB_FRAMEWORK_INSTALL_DIR variable allows to fix +# this. If specified, it causes the install-tree location of the framework to be +# added as an extra RPATH below. +# +function(lldb_setup_framework_rpaths_in_tool name) + # In the build-tree, we know the exact path to the binary in the framework. + set(rpath_build_tree "$<TARGET_FILE:liblldb>") + + # The installed framework is relocatable and can be in different locations. + set(rpaths_install_tree "@loader_path/../../../SharedFrameworks") + list(APPEND rpaths_install_tree "@loader_path/../../System/Library/PrivateFrameworks") + list(APPEND rpaths_install_tree "@loader_path/../../Library/PrivateFrameworks") + + if(LLDB_FRAMEWORK_INSTALL_DIR) + set(rpaths_install_tree "@loader_path/../${LLDB_FRAMEWORK_INSTALL_DIR}") + endif() + + # If LLDB_NO_INSTALL_DEFAULT_RPATH was NOT enabled (default), this overwrites + # the default settings from llvm_setup_rpath(). + set_target_properties(${name} PROPERTIES + BUILD_WITH_INSTALL_RPATH OFF + BUILD_RPATH "${rpath_build_tree}" + INSTALL_RPATH "${rpaths_install_tree}" + ) + + add_dependencies(${name} lldb-framework) +endfunction() diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake index dae6e365da38..109c5132d3be 100644 --- a/cmake/modules/LLDBConfig.cmake +++ b/cmake/modules/LLDBConfig.cmake @@ -4,34 +4,74 @@ set(LLDB_PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) set(LLDB_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/source") set(LLDB_INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include") +set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + message(FATAL_ERROR + "In-source builds are not allowed. CMake would overwrite the makefiles " + "distributed with LLDB. Please create a directory and run cmake from " + "there, passing the path to this source directory as the last argument. " + "This process created the file `CMakeCache.txt' and the directory " + "`CMakeFiles'. Please delete them.") +endif() + set(LLDB_LINKER_SUPPORTS_GROUPS OFF) if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") # The Darwin linker doesn't understand --start-group/--end-group. set(LLDB_LINKER_SUPPORTS_GROUPS ON) endif() -set(LLDB_DEFAULT_DISABLE_PYTHON 0) -set(LLDB_DEFAULT_DISABLE_CURSES 0) +set(default_disable_python OFF) +set(default_disable_curses OFF) +set(default_disable_libedit OFF) -if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) - set(LLDB_DEFAULT_DISABLE_CURSES 1) -elseif (CMAKE_SYSTEM_NAME MATCHES "Android" ) - set(LLDB_DEFAULT_DISABLE_PYTHON 1) - set(LLDB_DEFAULT_DISABLE_CURSES 1) -elseif(IOS) - set(LLDB_DEFAULT_DISABLE_PYTHON 1) +if(DEFINED LLVM_ENABLE_LIBEDIT AND NOT LLVM_ENABLE_LIBEDIT) + set(default_disable_libedit ON) endif() -set(LLDB_DISABLE_PYTHON ${LLDB_DEFAULT_DISABLE_PYTHON} CACHE BOOL - "Disables the Python scripting integration.") -set(LLDB_DISABLE_CURSES ${LLDB_DEFAULT_DISABLE_CURSES} CACHE BOOL - "Disables the Curses integration.") +if(CMAKE_SYSTEM_NAME MATCHES "Windows") + set(default_disable_curses ON) + set(default_disable_libedit ON) +elseif(CMAKE_SYSTEM_NAME MATCHES "Android") + set(default_disable_python ON) + set(default_disable_curses ON) + set(default_disable_libedit ON) +elseif(IOS) + set(default_disable_python ON) +endif() -set(LLDB_RELOCATABLE_PYTHON 0 CACHE BOOL - "Causes LLDB to use the PYTHONHOME environment variable to locate Python.") +option(LLDB_DISABLE_PYTHON "Disable Python scripting integration." ${default_disable_python}) +option(LLDB_DISABLE_CURSES "Disable Curses integration." ${default_disable_curses}) +option(LLDB_DISABLE_LIBEDIT "Disable the use of editline." ${default_disable_libedit}) +option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to locate Python." OFF) +option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install a copy of it" OFF) +option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON) +option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF) +option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF) + +if(LLDB_BUILD_FRAMEWORK) + if(NOT APPLE) + message(FATAL_ERROR "LLDB.framework can only be generated when targeting Apple platforms") + endif() + # CMake 3.6 did not correctly emit POST_BUILD commands for Apple Framework targets + if(CMAKE_VERSION VERSION_LESS 3.7) + message(FATAL_ERROR "LLDB_BUILD_FRAMEWORK is not supported on CMake < 3.7") + endif() -set(LLDB_USE_SYSTEM_SIX 0 CACHE BOOL - "Use six.py shipped with system and do not install a copy of it") + set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)") + set(LLDB_FRAMEWORK_BUILD_DIR bin CACHE STRING "Output directory for LLDB.framework") + set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Install directory for LLDB.framework") + set(LLDB_FRAMEWORK_TOOLS darwin-debug;debugserver;lldb-argdumper;lldb-server CACHE INTERNAL + "List of tools to include in LLDB.framework/Resources") + + # Set designated directory for all dSYMs. Essentially, this emits the + # framework's dSYM outside of the framework directory. + if(LLVM_EXTERNALIZE_DEBUGINFO) + set(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING + "Directory to emit dSYM files stripped from executables and libraries (Darwin Only)") + endif() +endif() if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL @@ -243,6 +283,7 @@ if( MSVC ) -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch' -wd4068 # Suppress 'warning C4068: unknown pragma' -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type' + -wd4201 # Suppress 'warning C4201: nonstandard extension used: nameless struct/union' -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.' -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified' -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.' @@ -254,20 +295,20 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows") add_definitions( -D_UNICODE -DUNICODE ) endif() -set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) - -if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) - message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " -"the makefiles distributed with LLDB. Please create a directory and run cmake " -"from there, passing the path to this source directory as the last argument. " -"This process created the file `CMakeCache.txt' and the directory " -"`CMakeFiles'. Please delete them.") +# If LLDB_VERSION_* is specified, use it, if not use LLVM_VERSION_*. +if(NOT DEFINED LLDB_VERSION_MAJOR) + set(LLDB_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) endif() - -# Compute the LLDB version from the LLVM version. -string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLDB_VERSION - ${PACKAGE_VERSION}) +if(NOT DEFINED LLDB_VERSION_MINOR) + set(LLDB_VERSION_MINOR ${LLVM_VERSION_MINOR}) +endif() +if(NOT DEFINED LLDB_VERSION_PATCH) + set(LLDB_VERSION_PATCH ${LLVM_VERSION_PATCH}) +endif() +if(NOT DEFINED LLDB_VERSION_SUFFIX) + set(LLDB_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX}) +endif() +set(LLDB_VERSION "${LLDB_VERSION_MAJOR}.${LLDB_VERSION_MINOR}.${LLDB_VERSION_PATCH}${LLDB_VERSION_SUFFIX}") message(STATUS "LLDB version: ${LLDB_VERSION}") include_directories(BEFORE @@ -304,11 +345,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) endif() endif() -if (NOT LIBXML2_FOUND AND NOT (CMAKE_SYSTEM_NAME MATCHES "Windows")) - # Skip Libxml2 on Windows. In CMake 3.4 and higher, the algorithm for - # finding libxml2 got "smarter", and it can now locate the version which is - # in gnuwin32, even though that version does not contain the headers that - # LLDB uses. +if (NOT LIBXML2_FOUND) find_package(LibXml2) endif() @@ -323,11 +360,6 @@ if (APPLE) find_library(CORE_FOUNDATION_LIBRARY CoreFoundation) find_library(SECURITY_LIBRARY Security) - set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Output directory for LLDB.framework") - set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)") - set(LLDB_FRAMEWORK_RESOURCE_DIR - LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources) - add_definitions( -DLIBXML2_DEFINED ) list(APPEND system_libs xml2 ${CURSES_LIBRARIES} @@ -336,14 +368,11 @@ if (APPLE) ${CORE_SERVICES_LIBRARY} ${SECURITY_LIBRARY} ${DEBUG_SYMBOLS_LIBRARY}) - -else() - if (LIBXML2_FOUND) - add_definitions( -DLIBXML2_DEFINED ) - list(APPEND system_libs ${LIBXML2_LIBRARIES}) - include_directories(${LIBXML2_INCLUDE_DIR}) - endif() - + include_directories(${LIBXML2_INCLUDE_DIR}) +elseif(LIBXML2_FOUND AND LIBXML2_VERSION_STRING VERSION_GREATER 2.8) + add_definitions( -DLIBXML2_DEFINED ) + list(APPEND system_libs ${LIBXML2_LIBRARIES}) + include_directories(${LIBXML2_INCLUDE_DIR}) endif() if( WIN32 AND NOT CYGWIN ) @@ -358,6 +387,8 @@ endif() list(APPEND system_libs ${CMAKE_DL_LIBS}) +SET(SKIP_LLDB_SERVER_BUILD OFF CACHE BOOL "Skip building lldb-server") + # Figure out if lldb could use lldb-server. If so, then we'll # ensure we build lldb-server when an lldb target is being built. if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD") diff --git a/cmake/modules/LLDBFramework.cmake b/cmake/modules/LLDBFramework.cmake index abacee89d9ac..0ccabd12a010 100644 --- a/cmake/modules/LLDBFramework.cmake +++ b/cmake/modules/LLDBFramework.cmake @@ -1,44 +1,107 @@ +# Path relative to the root binary directory +get_filename_component( + framework_target_dir ${LLDB_FRAMEWORK_BUILD_DIR} ABSOLUTE + BASE_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR} +) + +message(STATUS "LLDB.framework: build path is '${framework_target_dir}'") +message(STATUS "LLDB.framework: install path is '${LLDB_FRAMEWORK_INSTALL_DIR}'") +message(STATUS "LLDB.framework: resources subdirectory is 'Versions/${LLDB_FRAMEWORK_VERSION}/Resources'") + +# Configure liblldb as a framework bundle +set_target_properties(liblldb PROPERTIES + FRAMEWORK ON + FRAMEWORK_VERSION ${LLDB_FRAMEWORK_VERSION} + + OUTPUT_NAME LLDB + VERSION ${LLDB_VERSION} + LIBRARY_OUTPUT_DIRECTORY ${framework_target_dir} + + # Compatibility version + SOVERSION "1.0.0" + + MACOSX_FRAMEWORK_IDENTIFIER com.apple.LLDB.framework + MACOSX_FRAMEWORK_BUNDLE_VERSION ${LLDB_VERSION} + MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LLDB_VERSION} + MACOSX_FRAMEWORK_INFO_PLIST ${LLDB_SOURCE_DIR}/resources/LLDB-Info.plist.in +) + +# Affects the layout of the framework bundle (default is macOS layout). +if(IOS) + set_target_properties(liblldb PROPERTIES + XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IPHONEOS_DEPLOYMENT_TARGET}") +else() + set_target_properties(liblldb PROPERTIES + XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET "${MACOSX_DEPLOYMENT_TARGET}") +endif() + +# Target to capture extra steps for a fully functional framework bundle. +add_custom_target(lldb-framework) +add_dependencies(lldb-framework liblldb) + +# Dependencies are defined once tools are added (see AddLLDB.cmake) +if(LLDB_FRAMEWORK_TOOLS) + foreach(tool ${LLDB_FRAMEWORK_TOOLS}) + add_custom_command(TARGET lldb-framework POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${tool}> $<TARGET_FILE_DIR:liblldb>/Resources + COMMENT "LLDB.framework: copy additional tool ${tool}" + ) + endforeach() +else() + message(WARNING "LLDB.framework: no additional tools configured (set via LLDB_FRAMEWORK_TOOLS)") +endif() + +# Apart from this one, CMake creates all required symlinks in the framework bundle. +add_custom_command(TARGET lldb-framework POST_BUILD + COMMAND ${CMAKE_COMMAND} -E create_symlink + Versions/Current/Headers + ${framework_target_dir}/LLDB.framework/Headers + COMMENT "LLDB.framework: create Headers symlink" +) + +# At configuration time, collect headers for the framework bundle and copy them +# into a staging directory. Later we can copy over the entire folder. file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) list(REMOVE_ITEM root_public_headers ${root_private_headers}) + +set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders) foreach(header ${public_headers} ${root_public_headers} ${LLDB_SOURCE_DIR}/include/lldb/Utility/SharingPtr.h) + get_filename_component(basename ${header} NAME) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders/${basename} - DEPENDS ${header} - COMMAND ${CMAKE_COMMAND} -E copy ${header} ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders/${basename}) - list(APPEND framework_headers ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders/${basename}) + set(staged_header ${lldb_header_staging}/${basename}) + + add_custom_command( + DEPENDS ${header} OUTPUT ${staged_header} + COMMAND ${CMAKE_COMMAND} -E copy ${header} ${staged_header} + COMMENT "LLDB.framework: collect framework header") + + list(APPEND lldb_staged_headers ${staged_header}) endforeach() -add_custom_target(lldb-framework-headers DEPENDS ${framework_headers}) +# Wrap output in a target, so lldb-framework can depend on it. +add_custom_target(lldb-framework-headers DEPENDS ${lldb_staged_headers}) +add_dependencies(lldb-framework lldb-framework-headers) -add_custom_command(TARGET lldb-framework POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders $<TARGET_FILE_DIR:liblldb>/Headers +# At build time, copy the staged headers into the framework bundle (and do +# some post-processing in-place). +add_custom_command(TARGET lldb-framework-headers POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${lldb_header_staging} $<TARGET_FILE_DIR:liblldb>/Headers COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.sh $<TARGET_FILE_DIR:liblldb>/Headers ${LLDB_VERSION} + COMMENT "LLDB.framework: copy framework headers" ) -if (NOT IOS) - if (NOT LLDB_BUILT_STANDALONE) - add_dependencies(lldb-framework clang-headers) - endif() +# Copy vendor-specific headers from clang (without staging). +if(NOT IOS AND NOT LLDB_BUILT_STANDALONE) + add_dependencies(lldb-framework clang-headers) add_custom_command(TARGET lldb-framework POST_BUILD - COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Headers ${LLDB_FRAMEWORK_DIR}/LLDB.framework/Headers - COMMAND ${CMAKE_COMMAND} -E create_symlink ${LLDB_FRAMEWORK_VERSION} ${LLDB_FRAMEWORK_DIR}/LLDB.framework/Versions/Current - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/clang/${LLDB_VERSION} $<TARGET_FILE_DIR:liblldb>/Resources/Clang + COMMAND ${CMAKE_COMMAND} -E copy_directory + $<TARGET_PROPERTY:clang-headers,RUNTIME_OUTPUT_DIRECTORY> + $<TARGET_FILE_DIR:liblldb>/Resources/Clang/include + COMMENT "LLDB.framework: copy clang vendor-specific headers" ) endif() - -set_target_properties(liblldb PROPERTIES - OUTPUT_NAME LLDB - FRAMEWORK On - FRAMEWORK_VERSION ${LLDB_FRAMEWORK_VERSION} - MACOSX_FRAMEWORK_INFO_PLIST ${LLDB_SOURCE_DIR}/resources/LLDB-Info.plist - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${LLDB_FRAMEWORK_INSTALL_DIR} - PUBLIC_HEADER "${framework_headers}") - -add_dependencies(lldb-framework - lldb-framework-headers - lldb-suite) diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake index 742c464036a4..e63b2694e6a4 100644 --- a/cmake/modules/LLDBStandalone.cmake +++ b/cmake/modules/LLDBStandalone.cmake @@ -83,6 +83,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) endif() include(AddLLVM) + include(TableGen) include(HandleLLVMOptions) include(CheckAtomic) @@ -100,17 +101,15 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) # Import CMake library targets from LLVM and Clang. include("${LLVM_OBJ_ROOT}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm/LLVMConfig.cmake") - # cmake/clang/ClangConfig.cmake is not created when LLVM and Clang are built together. if (EXISTS "${LLVM_OBJ_ROOT}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang/ClangConfig.cmake") include("${LLVM_OBJ_ROOT}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang/ClangConfig.cmake") endif() set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") - - set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR}) + set(LLVM_INCLUDE_TESTS ON CACHE INTERNAL "") set(CMAKE_INCLUDE_CURRENT_DIR ON) - include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}") + include_directories("${CMAKE_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}") # Next three include directories are needed when llvm-config is located in build directory. # LLVM and Clang are assumed to be built together if (EXISTS "${LLVM_OBJ_ROOT}/include") diff --git a/cmake/modules/debugserverConfig.cmake b/cmake/modules/debugserverConfig.cmake new file mode 100644 index 000000000000..3b716ca87716 --- /dev/null +++ b/cmake/modules/debugserverConfig.cmake @@ -0,0 +1,3 @@ +# Duplicate options from LLDBConfig that are relevant for debugserver Standalone builds. + +option(LLDB_USE_ENTITLEMENTS "When code signing, use entitlements if available" ON) diff --git a/docs/building-with-debug-llvm.txt b/docs/building-with-debug-llvm.txt index f59ca410edb0..af1bcf8856b2 100644 --- a/docs/building-with-debug-llvm.txt +++ b/docs/building-with-debug-llvm.txt @@ -48,3 +48,4 @@ currently at a shell prompt in a checked-out LLDB repository. the top left of the Xcode window. 6. Build lldb.xcodeproj. + diff --git a/docs/lldb-platform-packets.txt b/docs/lldb-platform-packets.txt new file mode 100644 index 000000000000..3258e4c0dd88 --- /dev/null +++ b/docs/lldb-platform-packets.txt @@ -0,0 +1,404 @@ +Here is a brief overview of the packets that an lldb platform server +needs to implement for the lldb testsuite to be run on a remote +target device/system. + +These are almost all lldb extensions to the gdb-remote serial +protocol. Many of the vFile: packets are described to the "Host +I/O Packets" detailed in the gdb-remote protocol documentation, +although the lldb platform extensions include packets that are not +defined there (vFile:size:, vFile:mode:, vFile:symlink, vFile:chmod:). +Most importantly, the flags that lldb passes to vFile:open: are +incompatible with the flags that gdb specifies. + + +//---------------------------------------------------------------------- +// QStartNoAckMode +// +// BRIEF +// A request to stop sending ACK packets for each properly formatted packet. +// +// EXAMPLE +// A platform session will typically start like this: +// +// receive: +$QStartNoAckMode#b0 +// send: + <-- ACKing the properly formatted QStartNoAckMode packet +// send: $OK#9a +// receive: + <-- Our OK packet getting ACKed +// +// ACK mode is now disabled. + +//---------------------------------------------------------------------- +// qHostInfo +// +// BRIEF +// Describe the hardware and OS of the target system +// +// EXAMPLE +// +// receive: qHostInfo +// send: cputype:16777228;cpusubtype:1;ostype:ios;watchpoint_exceptions_received:before;os_version:12.1;vendor:apple;default_packet_timeout:5; +// +// All numbers are base 10, os_version is a string that will be parsed as major.minor.patch. + +//---------------------------------------------------------------------- +// qModuleInfo +// +// BRIEF +// Report information about a binary on the target system +// +// EXAMPLE +// receive: qModuleInfo:2f62696e2f6c73; +// +// FIXME finish this packet description, v. GDBRemoteCommunicationServerCommon::Handle_qModuleInfo + + +//---------------------------------------------------------------------- +// qGetWorkingDir +// +// BRIEF +// Get the current working directory of the platform stub in +// ASCII hex encoding. +// +// EXAMPLE +// +// receive: qGetWorkingDir +// send: 2f4170706c65496e7465726e616c2f6c6c64622f73657474696e67732f342f5465737453657474696e67732e746573745f646973617373656d626c65725f73657474696e6773 + + + +//---------------------------------------------------------------------- +// QSetWorkingDir: +// +// BRIEF +// Set the current working directory of the platform stub in +// ASCII hex encoding. +// +// EXAMPLE +// +// receive: QSetWorkingDir:2f4170706c65496e7465726e616c2f6c6c64622f73657474696e67732f342f5465737453657474696e67732e746573745f646973617373656d626c65725f73657474696e6773 +// send: OK + +//---------------------------------------------------------------------- +// qPlatform_mkdir: +// +// BRIEF +// Create a directory on the target system. +// +// EXAMPLE +// +// receive: qPlatform_mkdir:000001fd,2f746d702f6131 +// send: F0 +// +// request packet has the fields: +// 1. mode bits in base 16 +// 2. file path in ascii-hex encoding +// +// response is F followed by the return value of the mkdir() call, +// base 10 encoded. + +//---------------------------------------------------------------------- +// qPlatform_shell: +// +// BRIEF +// Run a shell command on the target system, return the output. +// +// EXAMPLE +// +// receive: qPlatform_shell:6c73202f746d702f,0000000a +// send: F,0,0,<OUTPUT> +// +// request packet has the fields: +// 1. shell command ascii-hex encoded +// 2. timeout +// 3. {optional} working directory ascii-hex encoded +// +// Response is F followed by the return value of the command (base 16), +// followed by a another number, followed by the output of the command +/ in binary-escaped-data encoding. + +//---------------------------------------------------------------------- +// qLaunchGDBServer +// +// BRIEF +// Start a gdbserver process (gdbserver, debugserver, lldb-server) +// on the target system. +// +// EXAMPLE +// +// receive: qLaunchGDBServer;host:<HOSTNAME_LLDB_IS_ON>; +// send: pid:1337;port:43001; +// +// request packet hostname field is not ascii-hex encoded. Hostnames +// don't have $ or # characters in them. +// +// response to the packet is the pid of the newly launched gdbserver, +// and the port it is listening for a connection on. +// +// When the testsuite is running, lldb may use the pid to kill off a +// debugserver that doesn't seem to be responding, etc. + +//---------------------------------------------------------------------- +// qKillSpawnedProcess: +// +// BRIEF +// Kill a process running on the target system. +// +// EXAMPLE +// +// receive: qKillSpawnedProcess:1337 +// send: OK +// +// The request packet has the process ID in base 10. + +//---------------------------------------------------------------------- +// qProcessInfoPID: +// +// BRIEF +// Gather information about a process running on the target +// +// EXAMPLE +// +// receive: qProcessInfoPID:71964 +// send: pid:71964;name:612e6f7574; +// +// The request packet has the pid encoded in base 10. +// +// The reply has semicolon-separated name:value fields, two are +// shown here. pid is base 10 encoded. name is ascii hex encoded. +// lldb-server can reply with many additional fields, but I think +// this is enough for the testsuite. + +//---------------------------------------------------------------------- +// qfProcessInfo: +// +// BRIEF +// Search the process table for processes matching criteria, +// respond with them in multiple packets. +// +// EXAMPLE +// +// receive: qfProcessInfo:name_match:equals;name:6e6f70726f6365737365786973747377697468746869736e616d65; +// send: pid:3500;name:612e6f7574; +// +// The request packet has a criteria to search for, followed by +// a specific name. Other name_match: values include +// starts_with, ends_with, contains, regex. You can specify a pid +// to search for, a uid, all_users, triple, etc etc. The testsuite +// only ever searches for name_match:equals. +// +// The response should include any information about the process that +// can be retrieved in semicolon-separated name:value fields. +// In this example, pid is base 10, name is ascii-hex encoded. +// The testsuite seems to only require these two. +// +// This packet only responds with one process. To get further matches to +// the search, qsProcessInfo should be sent. +// +// If no process match is found, Exx should be returned. + +//---------------------------------------------------------------------- +// qsProcessInfo +// +// BRIEF +// Return the next process info found by the most recent qfProcessInfo: +// packet. +// +// EXAMPLE +// +// Continues to return the results of the qfProcessInfo. Once all matches +// have been sent, Exx is returned to indicate end of matches. + +//---------------------------------------------------------------------- +// vFile:size: +// +// BRIEF +// Get the size of a file on the target system, filename in ASCII hex. +// +// EXAMPLE +// +// receive: vFile:size:2f746d702f61 +// send: Fc008 +// +// response is "F" followed by the file size in base 16. +// "F-1,errno" with the errno if an error occurs. + + +//---------------------------------------------------------------------- +// vFile:mode: +// +// BRIEF +// Get the mode bits of a file on the target system, filename in ASCII hex. +// +// EXAMPLE +// +// receive: vFile:mode:2f746d702f61 +// send: F1ed +// +// response is "F" followed by the mode bits in base 16, this 0x1ed would +// correspond to 0755 in octal. +// "F-1,errno" with the errno if an error occurs. + +//---------------------------------------------------------------------- +// vFile:unlink: +// +// BRIEF +// Remove a file on the target system. +// +// EXAMPLE +// +// receive: vFile:unlink:2f746d702f61 +// send: F0 +// +// Argument is a file path in ascii-hex encoding. +// Response is "F" plus the return value of unlink(), base 10 encoding. + +//---------------------------------------------------------------------- +// vFile:symlink: +// +// BRIEF +// Create a symbolic link (symlink, soft-link) on the target system. +// +// EXAMPLE +// +// receive: vFile:symlink:<SRC-FILE>,<DST-NAME> +// send: F0,0 +// +// Argument file paths are in ascii-hex encoding. +// Response is "F" plus the return value of symlink(), base 10 encoding, twice. + +//---------------------------------------------------------------------- +// vFile:chmod: +// qPlatform_chmod: +// +// BRIEF +// Change the permission mode bits on a file on the target +// +// EXAMPLE +// +// receive: vFile:chmod:180,2f746d702f61 +// send: F0 +// +// Arguments are the mode bits to set, base 16, and a file path in +// ascii-hex encoding. +// Response is "F" plus the return value of chmod(), base 10 encoding. +// +// I don't know why there are two packets for the same thing, v. +// vFile:chmod:. + +//---------------------------------------------------------------------- |