Skip to content

Commit 17fc80f

Browse files
committed
Reland "[lldb][RPC] Upstream lldb-rpc-gen tool" (#146969)
Relands the commit to upstream the lldb-rpc-gen tool in order to fix a build failure on the linux remote bots. Original PR description: This commit upstreams the lldb-rpc-gen tool, a ClangTool that generates the LLDB RPC client and server interfaces. This tool, as well as LLDB RPC itself is built by default. If it needs to be disabled, put -DLLDB_BUILD_LLDBRPC=OFF in your CMake invocation. https://discourse.llvm.org/t/rfc-upstreaming-lldb-rpc/85804 Original PR Link: #138031
1 parent 0032148 commit 17fc80f

File tree

15 files changed

+886
-15
lines changed

15 files changed

+886
-15
lines changed

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,6 @@ else()
323323
set(LLDB_CAN_USE_DEBUGSERVER OFF)
324324
endif()
325325

326+
set(LLDB_BUILD_LLDBRPC ON CACHE BOOL "")
327+
326328
include(LLDBGenerateConfig)

lldb/test/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ if(TARGET lldb-framework)
132132
add_lldb_test_dependency(lldb-framework)
133133
endif()
134134

135+
if (LLDB_BUILD_LLDBRPC)
136+
add_lldb_test_dependency(lldb-rpc-generate-sources)
137+
endif()
138+
135139
# Add dependencies that are not exported targets when building standalone.
136140
if(NOT LLDB_BUILT_STANDALONE)
137141
add_lldb_test_dependency(
@@ -249,7 +253,8 @@ llvm_canonicalize_cmake_booleans(
249253
LLDB_TEST_SHELL_DISABLE_REMOTE
250254
LLDB_TOOL_LLDB_SERVER_BUILD
251255
LLDB_USE_SYSTEM_DEBUGSERVER
252-
LLDB_IS_64_BITS)
256+
LLDB_IS_64_BITS
257+
LLDB_BUILD_LLDBRPC)
253258

254259
# Configure the individual test suites.
255260
add_subdirectory(API)

lldb/test/Shell/RPC/Generator/Inputs/SBDummy.h

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
RUN: %lldb-rpc-gen --output-dir=%t %S/../Inputs/SBDummy.h
2+
3+
RUN: ls %t | FileCheck %s
4+
5+
# We're just making sure that the tool emits the class names,
6+
# methods and skipped methods file in the output directory.
7+
CHECK: SBAPI.def
8+
CHECK: SBClasses.def
9+
CHECK: SkippedMethods.txt
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# All tests for the tool need lldb-rpc-gen to be built.
2+
if not config.lldb_has_lldbrpc:
3+
config.unsupported = True

lldb/test/Shell/helper/toolchain.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ def use_lldb_substitutions(config):
156156
extra_args=["platform"],
157157
unresolved="ignore",
158158
),
159+
ToolSubst(
160+
"%lldb-rpc-gen",
161+
command=FindTool("lldb-rpc-gen"),
162+
# We need the LLDB build directory root to pass into the tool, not the test build root.
163+
extra_args=[
164+
"-p " + config.lldb_build_directory + "/..",
165+
'--extra-arg="-resource-dir=' + config.clang_resource_dir + '"',
166+
],
167+
unresolved="ignore",
168+
),
159169
"lldb-test",
160170
"lldb-dap",
161171
ToolSubst(

lldb/test/Shell/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
3333
config.have_lldb_server = @LLDB_TOOL_LLDB_SERVER_BUILD@
3434
config.lldb_system_debugserver = @LLDB_USE_SYSTEM_DEBUGSERVER@
3535
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
36+
config.lldb_has_lldbrpc = @LLDB_BUILD_LLDBRPC@
3637
# The shell tests use their own module caches.
3738
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-shell")
3839
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-shell")

lldb/tools/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ add_subdirectory(lldb-fuzzer EXCLUDE_FROM_ALL)
1010

1111
add_lldb_tool_subdirectory(lldb-instr)
1212
add_lldb_tool_subdirectory(lldb-dap)
13+
if (LLDB_BUILD_LLDBRPC)
14+
add_lldb_tool_subdirectory(lldb-rpc)
15+
endif()
1316

1417
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
1518
add_lldb_tool_subdirectory(darwin-debug)

lldb/tools/lldb-rpc/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include(CheckCXXCompilerFlag)
2+
# Umbrella target for the entire framework is a default target.
3+
add_custom_target(lldb-rpc ALL)
4+
5+
if(LLDB_CODESIGN_IDENTITY)
6+
# Use explicit LLDB identity
7+
set(LLVM_CODESIGNING_IDENTITY ${LLDB_CODESIGN_IDENTITY})
8+
else()
9+
# Use explicit LLVM identity or default to ad-hoc signing if empty
10+
if(NOT LLVM_CODESIGNING_IDENTITY)
11+
set(LLVM_CODESIGNING_IDENTITY -)
12+
endif()
13+
endif()
14+
15+
# LLDBRPCGeneration.cmake needs the LLDB_RPC_GEN_EXE variable
16+
# which gets defined in the lldb-rpc-gen folder, so we're adding
17+
# this folder before we add that file.
18+
add_lldb_tool_subdirectory(lldb-rpc-gen)
19+
include(${CMAKE_CURRENT_SOURCE_DIR}/LLDBRPCGeneration.cmake)
20+
include(${CMAKE_CURRENT_SOURCE_DIR}/LLDBRPCHeaders.cmake)
21+
22+
add_dependencies(lldb-rpc lldb-rpc-generate-sources liblldbrpc-headers)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
if (NOT DEFINED LLDB_RPC_GEN_EXE)
2+
message(FATAL_ERROR
3+
"Unable to generate lldb-rpc sources because LLDB_RPC_GEN_EXE is not
4+
defined. If you are cross-compiling, please build lldb-rpc-gen for your host
5+
platform.")
6+
endif()
7+
set(lldb_rpc_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
8+
set(lldb_rpc_server_generated_source_dir "${lldb_rpc_generated_dir}/server")
9+
10+
file(GLOB api_headers ${LLDB_SOURCE_DIR}/include/lldb/API/SB*.h)
11+
# We don't generate SBCommunication
12+
list(REMOVE_ITEM api_headers ${LLDB_SOURCE_DIR}/include/lldb/API/SBCommunication.h)
13+
# SBDefines.h is mostly definitions and forward declarations, nothing to
14+
# generate.
15+
list(REMOVE_ITEM api_headers ${LLDB_SOURCE_DIR}/include/lldb/API/SBDefines.h)
16+
17+
# Generate the list of byproducts. Note that we cannot just glob the files in
18+
# the directory with the generated sources because BYPRODUCTS needs to be known
19+
# at configure time but the files are generated at build time.
20+
set(lldb_rpc_gen_byproducts
21+
${lldb_rpc_generated_dir}/SBClasses.def
22+
${lldb_rpc_generated_dir}/SBAPI.def
23+
${lldb_rpc_generated_dir}/lldb.py
24+
${lldb_rpc_server_generated_source_dir}/SBAPI.h
25+
)
26+
27+
set(lldb_rpc_gen_server_impl_files)
28+
foreach(path ${api_headers})
29+
get_filename_component(filename_no_ext ${path} NAME_WLE)
30+
31+
set(server_header_file "Server_${filename_no_ext}.h")
32+
list(APPEND lldb_rpc_gen_byproducts "${lldb_rpc_server_generated_source_dir}/${server_header_file}")
33+
34+
set(server_impl_file "Server_${filename_no_ext}.cpp")
35+
list(APPEND lldb_rpc_gen_byproducts "${lldb_rpc_server_generated_source_dir}/${server_impl_file}")
36+
list(APPEND lldb_rpc_gen_server_impl_files "${lldb_rpc_server_generated_source_dir}/${server_impl_file}")
37+
38+
endforeach()
39+
40+
# Make sure that the clang-resource-dir is set correctly or else the tool will
41+
# fail to run. This is only needed when we do a standalone build.
42+
set(clang_resource_dir_arg)
43+
if (TARGET clang-resource-headers)
44+
set(clang_resource_headers_dir
45+
$<TARGET_PROPERTY:clang-resource-headers,INTERFACE_INCLUDE_DIRECTORIES>)
46+
set(clang_resource_dir_arg --extra-arg="-resource-dir=${clang_resource_headers_dir}/..")
47+
else()
48+
set(clang_resource_dir_arg --extra-arg="-resource-dir=${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}")
49+
endif()
50+
51+
add_custom_command(OUTPUT ${lldb_rpc_gen_byproducts}
52+
COMMAND ${CMAKE_COMMAND} -E make_directory
53+
${lldb_rpc_generated_dir}
54+
55+
COMMAND ${CMAKE_COMMAND} -E make_directory
56+
${lldb_rpc_server_generated_source_dir}
57+
58+
COMMAND ${LLDB_RPC_GEN_EXE}
59+
-p ${CMAKE_BINARY_DIR}
60+
--output-dir=${lldb_rpc_generated_dir}
61+
${clang_resource_dir_arg}
62+
--extra-arg="-USWIG"
63+
${api_headers}
64+
65+
DEPENDS ${LLDB_RPC_GEN_EXE} ${api_headers}
66+
COMMENT "Generating sources for lldb-rpc-server..."
67+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
68+
)
69+
70+
add_custom_target(lldb-rpc-generate-sources
71+
DEPENDS
72+
${lldb_rpc_gen_byproducts}
73+
lldb-sbapi-dwarf-enums)
74+
75+
add_dependencies(lldb-rpc-generate-sources clang-resource-headers)

0 commit comments

Comments
 (0)