Skip to content

Commit 6f84ec3

Browse files
authored
[lldb-dap] Split lldb-dap into library and tool (NFC) (llvm#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.
1 parent 2ccfb99 commit 6f84ec3

File tree

7 files changed

+77
-13
lines changed

7 files changed

+77
-13
lines changed

lldb/tools/lldb-dap/CMakeLists.txt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
if(APPLE)
2-
configure_file(
3-
${CMAKE_CURRENT_SOURCE_DIR}/lldb-dap-Info.plist.in
4-
${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist
5-
)
6-
# Inline info plist in binary (use target_link_options for this as soon as CMake 3.13 is available)
7-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist")
8-
endif()
9-
101
# We need to include the llvm components we depend on manually, as liblldb does
112
# not re-export those.
123
set(LLVM_LINK_COMPONENTS Support)
134
set(LLVM_TARGET_DEFINITIONS Options.td)
145
tablegen(LLVM Options.inc -gen-opt-parser-defs)
156
add_public_tablegen_target(LLDBDAPOptionsTableGen)
16-
add_lldb_tool(lldb-dap
17-
lldb-dap.cpp
7+
8+
add_lldb_library(lldbDAP
189
Breakpoint.cpp
1910
BreakpointBase.cpp
2011
DAP.cpp
@@ -85,10 +76,11 @@ add_lldb_tool(lldb-dap
8576
Support
8677
)
8778

88-
target_include_directories(lldb-dap PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
79+
target_include_directories(lldbDAP
80+
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
8981

9082
if(LLDB_DAP_WELCOME_MESSAGE)
91-
target_compile_definitions(lldb-dap
83+
target_compile_definitions(lldbDAP
9284
PRIVATE
9385
-DLLDB_DAP_WELCOME_MESSAGE=\"${LLDB_DAP_WELCOME_MESSAGE}\")
9486
endif()
@@ -105,3 +97,5 @@ if(LLDB_BUILD_FRAMEWORK)
10597
"@loader_path/../../Library/PrivateFrameworks"
10698
)
10799
endif()
100+
101+
add_subdirectory(tool)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
add_lldb_tool(lldb-dap
2+
lldb-dap.cpp
3+
4+
LINK_LIBS
5+
lldbDAP
6+
)
7+
8+
if(APPLE)
9+
configure_file(
10+
${CMAKE_CURRENT_SOURCE_DIR}/lldb-dap-Info.plist.in
11+
${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist
12+
)
13+
target_link_options(lldb-dap
14+
PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_BINARY_DIR}/lldb-dap-Info.plist)
15+
endif()
16+
17+
if(LLDB_BUILD_FRAMEWORK)
18+
# In the build-tree, we know the exact path to the framework directory.
19+
# The installed framework can be in different locations.
20+
lldb_setup_rpaths(lldb-dap
21+
BUILD_RPATH
22+
"${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}"
23+
INSTALL_RPATH
24+
"@loader_path/../../../SharedFrameworks"
25+
"@loader_path/../../System/Library/PrivateFrameworks"
26+
"@loader_path/../../Library/PrivateFrameworks"
27+
)
28+
endif()

lldb/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ endif()
5454
add_subdirectory(Breakpoint)
5555
add_subdirectory(Callback)
5656
add_subdirectory(Core)
57+
add_subdirectory(DAP)
5758
add_subdirectory(DataFormatter)
5859
add_subdirectory(Disassembler)
5960
add_subdirectory(Editline)

lldb/unittests/DAP/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_lldb_unittest(DAPTests
2+
JSONUtilsTest.cpp
3+
4+
LINK_LIBS
5+
lldbDAP
6+
LINK_COMPONENTS
7+
Support
8+
)

lldb/unittests/DAP/JSONUtilsTest.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- JSONUtilsTest.cpp -------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "JSONUtils.h"
10+
#include "lldb/API/SBModule.h"
11+
#include "lldb/API/SBTarget.h"
12+
#include "gtest/gtest.h"
13+
14+
using namespace llvm;
15+
using namespace lldb;
16+
using namespace lldb_dap;
17+
18+
TEST(JSONUtilsTest, GetAsString) {
19+
StringRef str = "foo";
20+
json::Value value("foo");
21+
EXPECT_EQ(str, GetAsString(value));
22+
}
23+
24+
TEST(JSONUtilsTest, CreateModule) {
25+
SBTarget target;
26+
SBModule module;
27+
28+
json::Value value = CreateModule(target, module);
29+
json::Object *object = value.getAsObject();
30+
31+
ASSERT_NE(object, nullptr);
32+
EXPECT_EQ(object->size(), 0UL);
33+
}

0 commit comments

Comments
 (0)