[Lldb-commits] [lldb] 6f84ec3 - [lldb-dap] Split lldb-dap into library and tool (NFC) (#139402)
via lldb-commits
lldb-commits at lists.llvm.org
Sun May 11 14:48:43 PDT 2025
Author: Jonas Devlieghere
Date: 2025-05-11T14:48:40-07:00
New Revision: 6f84ec3496f5ec9038a59c11d2ea495f1e601049
URL: https://github.com/llvm/llvm-project/commit/6f84ec3496f5ec9038a59c11d2ea495f1e601049
DIFF: https://github.com/llvm/llvm-project/commit/6f84ec3496f5ec9038a59c11d2ea495f1e601049.diff
LOG: [lldb-dap] Split lldb-dap into library and tool (NFC) (#139402)
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 fuzzing.
Added:
lldb/tools/lldb-dap/tool/CMakeLists.txt
lldb/tools/lldb-dap/tool/lldb-dap-Info.plist.in
lldb/tools/lldb-dap/tool/lldb-dap.cpp
lldb/unittests/DAP/CMakeLists.txt
lldb/unittests/DAP/JSONUtilsTest.cpp
Modified:
lldb/tools/lldb-dap/CMakeLists.txt
lldb/unittests/CMakeLists.txt
Removed:
lldb/tools/lldb-dap/lldb-dap-Info.plist.in
lldb/tools/lldb-dap/lldb-dap.cpp
################################################################################
diff --git a/lldb/tools/lldb-dap/CMakeLists.txt b/lldb/tools/lldb-dap/CMakeLists.txt
index a9dc19006293b..608166bf0e0dd 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -1,20 +1,11 @@
-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
+
+add_lldb_library(lldbDAP
Breakpoint.cpp
BreakpointBase.cpp
DAP.cpp
@@ -85,10 +76,11 @@ add_lldb_tool(lldb-dap
Support
)
-target_include_directories(lldb-dap PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
+target_include_directories(lldbDAP
+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_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..b39a4ed9c40e7
--- /dev/null
+++ b/lldb/tools/lldb-dap/tool/CMakeLists.txt
@@ -0,0 +1,28 @@
+add_lldb_tool(lldb-dap
+ lldb-dap.cpp
+
+ LINK_LIBS
+ 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
diff erent 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
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);
+}
More information about the lldb-commits
mailing list