Skip to content

Commit 00ca73a

Browse files
committed
Reland "[lldb][RPC] Upstream lldb-rpc-gen tool" (#146969)" Attempt 2
Second attempt at relanding the lldb-rpc-gen tool. This should fix 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. 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//pull/138031
1 parent bb7cea0 commit 00ca73a

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
@@ -323,4 +323,23 @@ else()
323323
set(LLDB_CAN_USE_DEBUGSERVER OFF)
324324
endif()
325325

326+
# In a cross-compile build, we need to skip building the generated
327+
# lldb-rpc sources in the first phase of host build so that they can
328+
# get built using the just-built Clang toolchain in the second phase.
329+
if (NOT DEFINED LLDB_CAN_USE_LLDB_RPC_SERVER)
330+
if ((CMAKE_CROSSCOMPILING OR LLVM_HOST_TRIPLE MATCHES "${LLVM_DEFAULT_TARGET_TRIPLE}") AND
331+
CMAKE_SYSTEM_NAME MATCHES "AIX|Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows")
332+
set(LLDB_CAN_USE_LLDB_RPC_SERVER ON)
333+
else()
334+
set(LLDB_CAN_USE_LLDB_RPC_SERVER OFF)
335+
endif()
336+
endif()
337+
338+
if (CMAKE_CROSSCOMPILING)
339+
set(LLDB_BUILD_LLDBRPC OFF CACHE BOOL "")
340+
get_host_tool_path(lldb-rpc-gen LLDB_RPC_GEN_EXE lldb_rpc_gen_exe lldb_rpc_gen_target)
341+
else()
342+
set(LLDB_BUILD_LLDBRPC ON CACHE BOOL "")
343+
endif()
344+
326345
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_CAN_USE_LLDB_RPC_SERVER)
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: 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)