Skip to content

Commit 9693eb0

Browse files
chelcassanovaJDevlieghere
authored andcommitted
Reland "[lldb][RPC] Upstream lldb-rpc-gen tool" (llvm#146969)" Attempt 2 (llvm#148996)
Second attempt at relanding the lldb-rpc-gen tool. This should fix 2 issues: - An assert that was hitting when building on Linux. The assert would hit in the server source emitter, specifically when attemping to determine the storage size for a return type is that is a pointer, but isn't a const char *, const char ** or void pointer. The assert would hit when attempting to generate SBAttachInfo::GetProcessPluginName, which returns a const char * (meaning it shouldn't have been in the code block for the assert at all). The reason that it was hitting the assert when generating this function is that lldb_rpc_gen::TypeIsConstCharPtr was returning false for this function even though it did return a const char *. This was happening because when checking the return type for a const char *, TypeIsConstCharPtr would only check that the underlying type was a signed char. This failed on Linux (but was fine on Darwin), as the underlying type also needs to be checked for being an unsigned char. - Cross compiling support The build for lldb-rpc-gen had no support for cross compiling and as such, the sources generated for lldb-rpc-gen would get compiled too early in phase 2 when cross compiling, before the Clang toolchain was built and this led to an error when trying to include stdlib files. This reland splits this build into 2 by building the tool first and then compiling the sources in the second stage of the cross-compiled build. 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: github.com/llvm/pull/138031 (cherry picked from commit 68c8c8c)
1 parent c440bec commit 9693eb0

19 files changed

+918
-15
lines changed

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,23 @@ else()
380380
set(LLDB_CAN_USE_DEBUGSERVER OFF)
381381
endif()
382382

383+
# In a cross-compile build, we need to skip building the generated
384+
# lldb-rpc sources in the first phase of host build so that they can
385+
# get built using the just-built Clang toolchain in the second phase.
386+
if (NOT DEFINED LLDB_CAN_USE_LLDB_RPC_SERVER)
387+
if ((CMAKE_CROSSCOMPILING OR LLVM_HOST_TRIPLE MATCHES "${LLVM_DEFAULT_TARGET_TRIPLE}") AND
388+
CMAKE_SYSTEM_NAME MATCHES "AIX|Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows")
389+
set(LLDB_CAN_USE_LLDB_RPC_SERVER ON)
390+
else()
391+
set(LLDB_CAN_USE_LLDB_RPC_SERVER OFF)
392+
endif()
393+
endif()
394+
395+
if (CMAKE_CROSSCOMPILING)
396+
set(LLDB_BUILD_LLDBRPC OFF CACHE BOOL "")
397+
get_host_tool_path(lldb-rpc-gen LLDB_RPC_GEN_EXE lldb_rpc_gen_exe lldb_rpc_gen_target)
398+
else()
399+
set(LLDB_BUILD_LLDBRPC ON CACHE BOOL "")
400+
endif()
401+
383402
include(LLDBGenerateConfig)

lldb/test/CMakeLists.txt

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

137+
if (LLDB_CAN_USE_LLDB_RPC_SERVER)
138+
add_lldb_test_dependency(lldb-rpc-generate-sources)
139+
endif()
140+
137141
# Add dependencies that are not exported targets when building standalone.
138142
if(NOT LLDB_BUILT_STANDALONE)
139143
add_lldb_test_dependency(
@@ -260,7 +264,8 @@ llvm_canonicalize_cmake_booleans(
260264
LLDB_TEST_SHELL_DISABLE_REMOTE
261265
LLDB_TOOL_LLDB_SERVER_BUILD
262266
LLDB_USE_SYSTEM_DEBUGSERVER
263-
LLDB_IS_64_BITS)
267+
LLDB_IS_64_BITS
268+
LLDB_BUILD_LLDBRPC)
264269

265270
# BEGIN SWIFT
266271
llvm_canonicalize_cmake_booleans(

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
@@ -36,6 +36,7 @@ config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
3636
config.have_lldb_server = @LLDB_TOOL_LLDB_SERVER_BUILD@
3737
config.lldb_system_debugserver = @LLDB_USE_SYSTEM_DEBUGSERVER@
3838
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
39+
config.lldb_has_lldbrpc = @LLDB_BUILD_LLDBRPC@
3940
# The shell tests use their own module caches.
4041
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-shell")
4142
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-shell")

lldb/tools/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ 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-gen)
15+
endif()
16+
if (LLDB_CAN_USE_LLDB_RPC_SERVER)
17+
add_subdirectory(lldb-rpc)
18+
endif()
1319

1420
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
1521
add_lldb_tool_subdirectory(darwin-debug)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
add_lldb_tool(lldb-rpc-gen
2+
RPCCommon.cpp
3+
server/RPCServerHeaderEmitter.cpp
4+
server/RPCServerSourceEmitter.cpp
5+
lldb-rpc-gen.cpp
6+
7+
CLANG_LIBS
8+
clangAST
9+
clangBasic
10+
clangCodeGen
11+
clangFrontend
12+
clangLex
13+
clangRewrite
14+
clangSerialization
15+
clangTooling
16+
17+
LINK_COMPONENTS
18+
Support
19+
)
20+
21+
if (NOT DEFINED LLDB_RPC_GEN_EXE)
22+
set(LLDB_RPC_GEN_EXE $<TARGET_FILE:lldb-rpc-gen> CACHE STRING "Executable that generates lldb-rpc-server")
23+
endif()

0 commit comments

Comments
 (0)