https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/139402
>From b0996a236d9eaf70de562ae2cf0e1900417cae93 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Sat, 10 May 2025 12:08:29 -0700 Subject: [PATCH 1/3] [lldb-dap] Split lldb-dap into library and tool (NFC) Split lldb-dap into a library (lldbDAP) and a tool (lldb-dap). The motivation is being able to link parts of lldb-dap separately, for example to support unit testing and fizzing. --- lldb/tools/lldb-dap/CMakeLists.txt | 22 ++++++--------- lldb/tools/lldb-dap/tool/CMakeLists.txt | 28 +++++++++++++++++++ .../{ => tool}/lldb-dap-Info.plist.in | 0 lldb/tools/lldb-dap/{ => tool}/lldb-dap.cpp | 0 4 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 lldb/tools/lldb-dap/tool/CMakeLists.txt rename lldb/tools/lldb-dap/{ => tool}/lldb-dap-Info.plist.in (100%) rename lldb/tools/lldb-dap/{ => tool}/lldb-dap.cpp (100%) diff --git a/lldb/tools/lldb-dap/CMakeLists.txt b/lldb/tools/lldb-dap/CMakeLists.txt index a9dc19006293b..25bacd91fe581 100644 --- a/lldb/tools/lldb-dap/CMakeLists.txt +++ b/lldb/tools/lldb-dap/CMakeLists.txt @@ -1,20 +1,14 @@ -if(APPLE) - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/lldb-dap-Info.plist.in - ${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist - ) - # Inline info plist in binary (use target_link_options for this as soon as CMake 3.13 is available) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist") -endif() - # We need to include the llvm components we depend on manually, as liblldb does # not re-export those. set(LLVM_LINK_COMPONENTS Support) set(LLVM_TARGET_DEFINITIONS Options.td) tablegen(LLVM Options.inc -gen-opt-parser-defs) add_public_tablegen_target(LLDBDAPOptionsTableGen) -add_lldb_tool(lldb-dap - lldb-dap.cpp + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +add_lldb_library(lldbDAP Breakpoint.cpp BreakpointBase.cpp DAP.cpp @@ -85,10 +79,8 @@ add_lldb_tool(lldb-dap Support ) -target_include_directories(lldb-dap PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - if(LLDB_DAP_WELCOME_MESSAGE) - target_compile_definitions(lldb-dap + target_compile_definitions(lldbDAP PRIVATE -DLLDB_DAP_WELCOME_MESSAGE=\"${LLDB_DAP_WELCOME_MESSAGE}\") endif() @@ -105,3 +97,5 @@ if(LLDB_BUILD_FRAMEWORK) "@loader_path/../../Library/PrivateFrameworks" ) endif() + +add_subdirectory(tool) diff --git a/lldb/tools/lldb-dap/tool/CMakeLists.txt b/lldb/tools/lldb-dap/tool/CMakeLists.txt new file mode 100644 index 0000000000000..e418737bc05b1 --- /dev/null +++ b/lldb/tools/lldb-dap/tool/CMakeLists.txt @@ -0,0 +1,28 @@ +if(APPLE) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/lldb-dap-Info.plist.in + ${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist + ) + # Inline info plist in binary (use target_link_options for this as soon as CMake 3.13 is available) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist") +endif() + +add_lldb_tool(lldb-dap + lldb-dap.cpp + + LINK_LIBS + lldbDAP + ) + +if(LLDB_BUILD_FRAMEWORK) + # In the build-tree, we know the exact path to the framework directory. + # The installed framework can be in different locations. + lldb_setup_rpaths(lldb-dap + BUILD_RPATH + "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}" + INSTALL_RPATH + "@loader_path/../../../SharedFrameworks" + "@loader_path/../../System/Library/PrivateFrameworks" + "@loader_path/../../Library/PrivateFrameworks" + ) +endif() diff --git a/lldb/tools/lldb-dap/lldb-dap-Info.plist.in b/lldb/tools/lldb-dap/tool/lldb-dap-Info.plist.in similarity index 100% rename from lldb/tools/lldb-dap/lldb-dap-Info.plist.in rename to lldb/tools/lldb-dap/tool/lldb-dap-Info.plist.in diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/tool/lldb-dap.cpp similarity index 100% rename from lldb/tools/lldb-dap/lldb-dap.cpp rename to lldb/tools/lldb-dap/tool/lldb-dap.cpp >From 6f0768f467b3991069ae6c35e5bb9f612340444d Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Sat, 10 May 2025 12:32:07 -0700 Subject: [PATCH 2/3] Add simple unit tests as an example --- lldb/tools/lldb-dap/CMakeLists.txt | 6 ++--- lldb/unittests/CMakeLists.txt | 1 + lldb/unittests/DAP/CMakeLists.txt | 8 +++++++ lldb/unittests/DAP/JSONUtilsTest.cpp | 33 ++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 lldb/unittests/DAP/CMakeLists.txt create mode 100644 lldb/unittests/DAP/JSONUtilsTest.cpp diff --git a/lldb/tools/lldb-dap/CMakeLists.txt b/lldb/tools/lldb-dap/CMakeLists.txt index 25bacd91fe581..cdca4a0d62e8a 100644 --- a/lldb/tools/lldb-dap/CMakeLists.txt +++ b/lldb/tools/lldb-dap/CMakeLists.txt @@ -5,9 +5,6 @@ set(LLVM_TARGET_DEFINITIONS Options.td) tablegen(LLVM Options.inc -gen-opt-parser-defs) add_public_tablegen_target(LLDBDAPOptionsTableGen) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - add_lldb_library(lldbDAP Breakpoint.cpp BreakpointBase.cpp @@ -79,6 +76,9 @@ add_lldb_library(lldbDAP Support ) +target_include_directories(lldbDAP + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR_DIR}) + if(LLDB_DAP_WELCOME_MESSAGE) target_compile_definitions(lldbDAP PRIVATE diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt index cc9d45ebf981d..fa59c00a3f0c8 100644 --- a/lldb/unittests/CMakeLists.txt +++ b/lldb/unittests/CMakeLists.txt @@ -54,6 +54,7 @@ endif() add_subdirectory(Breakpoint) add_subdirectory(Callback) add_subdirectory(Core) +add_subdirectory(DAP) add_subdirectory(DataFormatter) add_subdirectory(Disassembler) add_subdirectory(Editline) diff --git a/lldb/unittests/DAP/CMakeLists.txt b/lldb/unittests/DAP/CMakeLists.txt new file mode 100644 index 0000000000000..f61c4006072a3 --- /dev/null +++ b/lldb/unittests/DAP/CMakeLists.txt @@ -0,0 +1,8 @@ +add_lldb_unittest(DAPTests + JSONUtilsTest.cpp + + LINK_LIBS + lldbDAP + LINK_COMPONENTS + Support + ) diff --git a/lldb/unittests/DAP/JSONUtilsTest.cpp b/lldb/unittests/DAP/JSONUtilsTest.cpp new file mode 100644 index 0000000000000..0cf42a1c08870 --- /dev/null +++ b/lldb/unittests/DAP/JSONUtilsTest.cpp @@ -0,0 +1,33 @@ +//===-- JSONUtilsTest.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 "JSONUtils.h" +#include "lldb/API/SBModule.h" +#include "lldb/API/SBTarget.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace lldb; +using namespace lldb_dap; + +TEST(JSONUtilsTest, GetAsString) { + StringRef str = "foo"; + json::Value value("foo"); + EXPECT_EQ(str, GetAsString(value)); +} + +TEST(JSONUtilsTest, CreateModule) { + SBTarget target; + SBModule module; + + json::Value value = CreateModule(target, module); + json::Object *object = value.getAsObject(); + + ASSERT_NE(object, nullptr); + EXPECT_EQ(object->size(), 0UL); +} >From 53a51f96c0cf3e4bdf6743bc7da58eb0f6a62aae Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Sun, 11 May 2025 12:10:37 -0700 Subject: [PATCH 3/3] Fix typo & use target_link_options now that we're on cmake 3.20 --- lldb/tools/lldb-dap/CMakeLists.txt | 2 +- lldb/tools/lldb-dap/tool/CMakeLists.txt | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lldb/tools/lldb-dap/CMakeLists.txt b/lldb/tools/lldb-dap/CMakeLists.txt index cdca4a0d62e8a..608166bf0e0dd 100644 --- a/lldb/tools/lldb-dap/CMakeLists.txt +++ b/lldb/tools/lldb-dap/CMakeLists.txt @@ -77,7 +77,7 @@ add_lldb_library(lldbDAP ) target_include_directories(lldbDAP - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR_DIR}) + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) if(LLDB_DAP_WELCOME_MESSAGE) target_compile_definitions(lldbDAP diff --git a/lldb/tools/lldb-dap/tool/CMakeLists.txt b/lldb/tools/lldb-dap/tool/CMakeLists.txt index e418737bc05b1..b39a4ed9c40e7 100644 --- a/lldb/tools/lldb-dap/tool/CMakeLists.txt +++ b/lldb/tools/lldb-dap/tool/CMakeLists.txt @@ -1,12 +1,3 @@ -if(APPLE) - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/lldb-dap-Info.plist.in - ${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist - ) - # Inline info plist in binary (use target_link_options for this as soon as CMake 3.13 is available) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist") -endif() - add_lldb_tool(lldb-dap lldb-dap.cpp @@ -14,6 +5,15 @@ add_lldb_tool(lldb-dap lldbDAP ) +if(APPLE) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/lldb-dap-Info.plist.in + ${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist + ) + target_link_options(lldb-dap + PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist) +endif() + if(LLDB_BUILD_FRAMEWORK) # In the build-tree, we know the exact path to the framework directory. # The installed framework can be in different locations. _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits