Index: test/CMakeLists.txt =================================================================== --- test/CMakeLists.txt +++ test/CMakeLists.txt @@ -91,7 +91,7 @@ list(APPEND LLDB_TEST_COMMON_ARGS --server ${DEBUGSERVER_PATH}) endif() -if(SKIP_DEBUGSERVER) +if(SKIP_TEST_DEBUGSERVER) list(APPEND LLDB_TEST_COMMON_ARGS --out-of-tree-debugserver) endif() Index: tools/debugserver/CMakeLists.txt =================================================================== --- tools/debugserver/CMakeLists.txt +++ tools/debugserver/CMakeLists.txt @@ -8,12 +8,18 @@ "${CMAKE_SOURCE_DIR}/../../cmake" "${CMAKE_SOURCE_DIR}/../../cmake/modules" ) - + include(LLDBStandalone) include(AddLLDB) set(LLDB_SOURCE_DIR "${CMAKE_SOURCE_DIR}/../../") include_directories(${LLDB_SOURCE_DIR}/include) + + option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON) + if(LLDB_CODESIGN_IDENTITY) + # In the future we may use LLVM_CODESIGNING_IDENTITY directly. + set(LLVM_CODESIGNING_IDENTITY ${LLDB_CODESIGN_IDENTITY}) + endif() endif() add_subdirectory(source) Index: tools/debugserver/source/CMakeLists.txt =================================================================== --- tools/debugserver/source/CMakeLists.txt +++ tools/debugserver/source/CMakeLists.txt @@ -94,32 +94,62 @@ add_library(lldbDebugserverCommon ${lldbDebugserverCommonSources}) +# TODO: The LLDB target in Xcode has a build phase that explicitly deletes the +# executable from the framework. IIUC the liblldb target could simply skip its +# copy step to achieve the same. +option(LLDB_NO_DEBUGSERVER "Delete debugserver after building it, and don't try to codesign it" OFF) +option(LLDB_USE_SYSTEM_DEBUGSERVER "Neither build nor codesign debugserver. Use the system's debugserver instead (Darwin only)." OFF) + +# Remember where our debugserver lives and whether or not we have to test it. +set(DEBUGSERVER_PATH "" CACHE FILEPATH "Path to debugserver") +set(SKIP_TEST_DEBUGSERVER OFF CACHE BOOL "Building the in-tree debugserver was skipped") + +if(LLDB_NO_DEBUGSERVER) + # No debugserver at all. + set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE) +elseif(LLDB_USE_SYSTEM_DEBUGSERVER OR NOT LLVM_CODESIGNING_IDENTITY) + # Use system debugserver (Darwin only). + set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE) + + if(CMAKE_HOST_APPLE) + execute_process( + COMMAND xcode-select -p + OUTPUT_VARIABLE xcode_dev_dir) + string(STRIP ${xcode_dev_dir} xcode_dev_dir) + + if(EXISTS "${xcode_dev_dir}/../SharedFrameworks/LLDB.framework/") + set(lldb_framework_dir "${xcode_dev_dir}/../SharedFrameworks") + elseif(EXISTS "${xcode_dev_dir}/Library/PrivateFrameworks/LLDB.framework/") + set(lldb_framework_dir "${xcode_dev_dir}/Library/PrivateFrameworks") + else() + message(SEND_ERROR "Cannot find debugserver on system.") + endif() -set(LLDB_CODESIGN_IDENTITY "lldb_codesign" - CACHE STRING "Identity used for code signing. Set to empty string to skip the signing step.") - -if(NOT LLDB_CODESIGN_IDENTITY STREQUAL "") - set(DEBUGSERVER_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/debugserver${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "Path to debugserver.") - set(SKIP_DEBUGSERVER OFF CACHE BOOL "Skip building the in-tree debug server") -else() - execute_process( - COMMAND xcode-select -p - OUTPUT_VARIABLE XCODE_DEV_DIR) - string(STRIP ${XCODE_DEV_DIR} XCODE_DEV_DIR) - if(EXISTS "${XCODE_DEV_DIR}/../SharedFrameworks/LLDB.framework/") - set(DEBUGSERVER_PATH - "${XCODE_DEV_DIR}/../SharedFrameworks/LLDB.framework/Resources/debugserver" CACHE PATH "Path to debugserver.") - elseif(EXISTS "${XCODE_DEV_DIR}/Library/PrivateFrameworks/LLDB.framework/") - set(DEBUGSERVER_PATH - "${XCODE_DEV_DIR}/Library/PrivateFrameworks/LLDB.framework/Resources/debugserver" CACHE PATH "Path to debugserver.") - else() - message(SEND_ERROR "Cannot find debugserver on system.") + # TODO: Following the old behavior, DEBUGSERVER_PATH still points to the + # original system binary, even if we copy it over. Keep this? + set(DEBUGSERVER_PATH "${lldb_framework_dir}/LLDB.framework/Resources/debugserver" CACHE FILEPATH "" FORCE) + + # If we haven't built a signed debugserver. If possible, copy the one from + # the system to make the built debugger functional on Darwin. + # + # TODO: IIUC the following condition would be the exact equivalent for the old + # behaviour, but it doesn't hurt to do it in both cases, right? + # + # if(NOT LLVM_CODESIGNING_IDENTITY AND CMAKE_HOST_APPLE) + # + add_custom_target(debugserver + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEBUGSERVER_PATH} ${LLVM_TOOLS_BINARY_DIR} + VERBATIM + COMMENT "Copying the system debugserver to LLDB's binaries directory.") endif() - set(SKIP_DEBUGSERVER ON CACHE BOOL "Skip building the in-tree debug server") +else() + # Regular case: Build debugserver from source and code sign. + set(DEBUGSERVER_PATH ${LLVM_TOOLS_BINARY_DIR}/debugserver${CMAKE_EXECUTABLE_SUFFIX} CACHE FILEPATH "" FORCE) + set(build_and_sign_debugserver ON) endif() message(STATUS "Path to the lldb debugserver: ${DEBUGSERVER_PATH}") -if (APPLE) +if(APPLE) if(IOS) find_library(BACKBOARD_LIBRARY BackBoardServices PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks) @@ -132,7 +162,7 @@ find_library(LOCKDOWN_LIBRARY lockdown) if(NOT BACKBOARD_LIBRARY) - set(SKIP_DEBUGSERVER ON CACHE BOOL "Skip building the in-tree debug server" FORCE) + set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE) endif() else() find_library(COCOA_LIBRARY Cocoa) @@ -143,7 +173,16 @@ set(LIBCOMPRESSION compression) endif() -if(NOT SKIP_DEBUGSERVER) +if(LLDB_USE_ENTITLEMENTS) + if(IOS) + set(entitlements ${CMAKE_CURRENT_SOURCE_DIR}/debugserver-entitlements.plist) + else() + # Same entitlements file as used for lldb-server + set(entitlements ${LLDB_SOURCE_DIR}/resources/debugserver-macosx-entitlements.plist) + endif() +endif() + +if(build_and_sign_debugserver) target_link_libraries(lldbDebugserverCommon INTERFACE ${COCOA_LIBRARY} ${CORE_FOUNDATION_LIBRARY} @@ -166,6 +205,9 @@ LINK_LIBS lldbDebugserverCommon + + ENTITLEMENTS + ${entitlements} ) if(IOS) set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS @@ -203,54 +245,8 @@ LINK_LIBS lldbDebugserverCommon_NonUI - ) -endif() -set(entitlements_xml ${CMAKE_CURRENT_SOURCE_DIR}/debugserver-macosx-entitlements.plist) -if(IOS) - set(entitlements_xml ${CMAKE_CURRENT_SOURCE_DIR}/debugserver-entitlements.plist) -else() - set(entitlements_xml ${CMAKE_CURRENT_SOURCE_DIR}/../../../resources/debugserver-macosx-entitlements.plist) -endif() - -set(LLDB_USE_ENTITLEMENTS_Default On) -option(LLDB_USE_ENTITLEMENTS "Use entitlements when codesigning (Defaults Off when using lldb_codesign identity, otherwise On)" ${LLDB_USE_ENTITLEMENTS_Default}) - -if (SKIP_DEBUGSERVER) - if (CMAKE_HOST_APPLE) - # If we haven't built a signed debugserver, copy the one from the system. - add_custom_target(debugserver - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEBUGSERVER_PATH} ${CMAKE_BINARY_DIR}/bin - VERBATIM - COMMENT "Copying the system debugserver to LLDB's binaries directory.") - endif() -else() - if(LLDB_USE_ENTITLEMENTS) - set(entitlements_flags --entitlements ${entitlements_xml}) - endif() - execute_process( - COMMAND xcrun -f codesign_allocate - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE CODESIGN_ALLOCATE + ENTITLEMENTS + ${entitlements} ) - add_custom_command(TARGET debugserver - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E env CODESIGN_ALLOCATE=${CODESIGN_ALLOCATE} - codesign --force --sign ${LLDB_CODESIGN_IDENTITY} - ${entitlements_flags} - $ - ) - if(IOS) - add_custom_command(TARGET debugserver-nonui - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E env CODESIGN_ALLOCATE=${CODESIGN_ALLOCATE} - codesign --force --sign ${LLDB_CODESIGN_IDENTITY} - ${entitlements_flags} - $ - ) - endif() endif() - - - - Index: unittests/tools/CMakeLists.txt =================================================================== --- unittests/tools/CMakeLists.txt +++ unittests/tools/CMakeLists.txt @@ -1,5 +1,5 @@ if(CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|Linux|NetBSD") - if ((CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_DEBUGSERVER) OR (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_LLDB_SERVER_BUILD)) + if ((CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_TEST_DEBUGSERVER) OR (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_LLDB_SERVER_BUILD)) # These tests are meant to test lldb-server/debugserver in isolation, and # don't provide any value if run against a server copied from somewhere. else()