From d220cf3abd1f5577bbd95d8133a4cae6be4c18aa Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 29 Jun 2024 20:06:23 -0600 Subject: [PATCH] CMake: Add a command for codesigning with the get-task-allow entitlement This allows developers on macOS to open Ladybird.app in Instruments. Add some documentation for how to use the command as well. It is enabled automatically when CMAKE_BUILD_TYPE is not Release or RelWithDebInfo. --- Documentation/BuildInstructionsLadybird.md | 16 +++++++++++++++- Ladybird/CMakeLists.txt | 11 +++++++++++ Meta/debug.plist | 8 ++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 Meta/debug.plist diff --git a/Documentation/BuildInstructionsLadybird.md b/Documentation/BuildInstructionsLadybird.md index fd14ba42277..c731ce9b2dc 100644 --- a/Documentation/BuildInstructionsLadybird.md +++ b/Documentation/BuildInstructionsLadybird.md @@ -204,8 +204,22 @@ After running Ladybird as suggested above with `./Meta/ladybird.sh run ladybird` Now breakpoints, stepping and variable inspection will work. -### Debugging with Xcode on macOS +### Debugging with Xcode or Instruments on macOS +If all you want to do is use Instruments, then an Xcode project is not required. + +Simply run the `ladybird.sh` script as normal, and then make sure to codesign the Ladybird binary with the proper entitlements to allow Instruments to attach to it. + +``` +./Meta/ladybird.sh build + ninja -C build/ladybird apply-debug-entitlements + # or + codesign -s - -v -f --entitlements Meta/debug.plist Build/ladybird/bin/Ladybird.app +``` + +Now you can open the Instruments app and point it to the Ladybird app bundle. + +If you want to use Xcode itself for debugging, you will need to generate an Xcode project. The `ladybird.sh` build script does not know how to generate Xcode projects, so creating the project must be done manually. ``` diff --git a/Ladybird/CMakeLists.txt b/Ladybird/CMakeLists.txt index c4a6790359d..8514e5b4aa1 100644 --- a/Ladybird/CMakeLists.txt +++ b/Ladybird/CMakeLists.txt @@ -34,6 +34,17 @@ function(create_ladybird_bundle target_name) add_custom_command(TARGET ${target_name} POST_BUILD COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" "${bundle_dir}/Contents/lib" ) + + if (NOT CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo") + add_custom_command(TARGET ${target_name} POST_BUILD + COMMAND codesign -s - -v -f --entitlements "${LADYBIRD_SOURCE_DIR}/Meta/debug.plist" "${bundle_dir}" + ) + else() + add_custom_target(apply-debug-entitlements + COMMAND codesign -s - -v -f --entitlements "${LADYBIRD_SOURCE_DIR}/Meta/debug.plist" "${bundle_dir}" + USES_TERMINAL + ) + endif() endif() if (APPLE) diff --git a/Meta/debug.plist b/Meta/debug.plist new file mode 100644 index 00000000000..3842541b7b0 --- /dev/null +++ b/Meta/debug.plist @@ -0,0 +1,8 @@ + + + + + com.apple.security.get-task-allow + + +