-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[lldb][RPC] Upstream lldb-rpc-gen tool #138031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chelcassanova
merged 1 commit into
llvm:main
from
chelcassanova:upstream-lldb-rpc/add-lldb-rpc-gen-tool
Jul 3, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
9 changes: 9 additions & 0 deletions
9
lldb/test/Shell/RPC/Generator/Tests/CheckRPCGenToolByproducts.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
RUN: %lldb-rpc-gen --output-dir=%t %S/../Inputs/SBDummy.h | ||
|
||
RUN: ls %t | FileCheck %s | ||
|
||
# We're just making sure that the tool emits the class names, | ||
# methods and skipped methods file in the output directory. | ||
CHECK: SBAPI.def | ||
CHECK: SBClasses.def | ||
CHECK: SkippedMethods.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# All tests for the tool need lldb-rpc-gen to be built. | ||
if not config.lldb_has_lldbrpc: | ||
config.unsupported = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
include(CheckCXXCompilerFlag) | ||
# Umbrella target for the entire framework is a default target. | ||
add_custom_target(lldb-rpc ALL) | ||
|
||
if(LLDB_CODESIGN_IDENTITY) | ||
# Use explicit LLDB identity | ||
set(LLVM_CODESIGNING_IDENTITY ${LLDB_CODESIGN_IDENTITY}) | ||
else() | ||
# Use explicit LLVM identity or default to ad-hoc signing if empty | ||
if(NOT LLVM_CODESIGNING_IDENTITY) | ||
set(LLVM_CODESIGNING_IDENTITY -) | ||
endif() | ||
endif() | ||
|
||
# LLDBRPCGeneration.cmake needs the LLDB_RPC_GEN_EXE variable | ||
# which gets defined in the lldb-rpc-gen folder, so we're adding | ||
# this folder before we add that file. | ||
add_lldb_tool_subdirectory(lldb-rpc-gen) | ||
include(${CMAKE_CURRENT_SOURCE_DIR}/LLDBRPCGeneration.cmake) | ||
include(${CMAKE_CURRENT_SOURCE_DIR}/LLDBRPCHeaders.cmake) | ||
|
||
add_dependencies(lldb-rpc lldb-rpc-generate-sources liblldbrpc-headers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
if (NOT DEFINED LLDB_RPC_GEN_EXE) | ||
message(FATAL_ERROR | ||
"Unable to generate lldb-rpc sources because LLDB_RPC_GEN_EXE is not | ||
defined. If you are cross-compiling, please build lldb-rpc-gen for your host | ||
platform.") | ||
endif() | ||
set(lldb_rpc_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") | ||
|
||
file(GLOB api_headers ${LLDB_SOURCE_DIR}/include/lldb/API/SB*.h) | ||
# We don't generate SBCommunication | ||
list(REMOVE_ITEM api_headers ${LLDB_SOURCE_DIR}/include/lldb/API/SBCommunication.h) | ||
# SBDefines.h is mostly definitions and forward declarations, nothing to | ||
# generate. | ||
list(REMOVE_ITEM api_headers ${LLDB_SOURCE_DIR}/include/lldb/API/SBDefines.h) | ||
|
||
# Generate the list of byproducts. Note that we cannot just glob the files in | ||
# the directory with the generated sources because BYPRODUCTS needs to be known | ||
# at configure time but the files are generated at build time. | ||
set(lldb_rpc_gen_byproducts | ||
${lldb_rpc_generated_dir}/SBClasses.def | ||
${lldb_rpc_generated_dir}/SBAPI.def | ||
${lldb_rpc_generated_dir}/lldb.py | ||
${lldb_rpc_server_generated_source_dir}/SBAPI.h | ||
) | ||
|
||
# Make sure that the clang-resource-dir is set correctly or else the tool will | ||
# fail to run. This is only needed when we do a standalone build. | ||
set(clang_resource_dir_arg) | ||
if (LLDB_BUILT_STANDALONE) | ||
if (TARGET clang-resource-headers) | ||
set(clang_resource_headers_dir | ||
$<TARGET_PROPERTY:clang-resource-headers,INTERFACE_INCLUDE_DIRECTORIES>) | ||
set(clang_resource_dir_arg --extra-arg="-resource-dir=${clang_resource_headers_dir}/..") | ||
else() | ||
set(clang_resource_dir_arg --extra-arg="-resource-dir=${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}") | ||
endif() | ||
endif() | ||
|
||
add_custom_command(OUTPUT ${lldb_rpc_gen_byproducts} | ||
COMMAND ${CMAKE_COMMAND} -E make_directory | ||
${lldb_rpc_generated_dir} | ||
|
||
COMMAND ${LLDB_RPC_GEN_EXE} | ||
-p ${CMAKE_BINARY_DIR} | ||
--output-dir=${lldb_rpc_generated_dir} | ||
${clang_resource_dir_arg} | ||
--extra-arg="-USWIG" | ||
${api_headers} | ||
|
||
DEPENDS ${LLDB_RPC_GEN_EXE} ${api_headers} | ||
COMMENT "Generating sources for lldb-rpc-server..." | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | ||
) | ||
|
||
add_custom_target(lldb-rpc-generate-sources | ||
DEPENDS | ||
${lldb_rpc_gen_byproducts} | ||
lldb-sbapi-dwarf-enums) | ||
|
||
add_dependencies(lldb-rpc-generate-sources clang-resource-headers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
set(derived_headers_location "${CMAKE_CURRENT_BINARY_DIR}/DerivedHeaders") | ||
|
||
# Obtain the original headers from their staged location in the build directory. | ||
set(original_headers_location "${CMAKE_BINARY_DIR}/include/lldb") | ||
set(headers_to_process | ||
SBDefines.h | ||
lldb-defines.h | ||
lldb-enumerations.h | ||
lldb-types.h | ||
) | ||
|
||
file(MAKE_DIRECTORY ${derived_headers_location}) | ||
|
||
# Take the original headers and convert them RPC as necessary using the conversion script. | ||
set(original_headers) | ||
set(derived_headers) | ||
foreach(header ${headers_to_process}) | ||
set(original_header "${original_headers_location}/${header}") | ||
|
||
get_filename_component(header_filename ${header} NAME) | ||
string(REPLACE "lldb-" "lldb-rpc-" rpc_header_filename "${header_filename}") | ||
set(derived_header "${derived_headers_location}/${rpc_header_filename}") | ||
|
||
list(APPEND original_headers "${original_header}") | ||
list(APPEND derived_headers "${derived_header}") | ||
add_custom_command(OUTPUT ${derived_header} | ||
COMMAND ${Python3_EXECUTABLE} ${LLDB_SOURCE_DIR}/scripts/convert-lldb-header-to-rpc-header.py | ||
${original_header} ${derived_header} | ||
DEPENDS ${original_header} | ||
|
||
COMMENT "Creating ${derived_header}" | ||
) | ||
endforeach() | ||
|
||
# Do the same thing for any header files that were autogenerated. | ||
set(generated_headers_to_process | ||
API/SBLanguages.h | ||
) | ||
foreach(header ${generated_headers_to_process}) | ||
set(original_header "${LLDB_OBJ_DIR}/include/lldb/${header}") | ||
|
||
get_filename_component(header_filename ${header} NAME) | ||
string(REPLACE "lldb-" "lldb-rpc-" rpc_header_filename "${header_filename}") | ||
set(derived_header "${derived_headers_location}/${rpc_header_filename}") | ||
|
||
list(APPEND original_headers "${original_header}") | ||
list(APPEND derived_headers "${derived_header}") | ||
add_custom_command(OUTPUT ${derived_header} | ||
COMMAND ${CMAKE_COMMAND} -E copy ${original_header} ${derived_header} | ||
COMMAND ${Python3_EXECUTABLE} ${LLDB_SOURCE_DIR}/scripts/convert-lldb-header-to-rpc-header.py | ||
${original_header} ${derived_header} | ||
DEPENDS lldb-sbapi-dwarf-enums | ||
|
||
COMMENT "Creating ${derived_header}" | ||
) | ||
endforeach() | ||
|
||
add_custom_target(copy-aux-rpc-headers DEPENDS ${derived_headers}) | ||
add_dependencies(copy-aux-rpc-headers liblldb-header-staging) | ||
|
||
list(APPEND public_headers | ||
${derived_headers_location}/SBDefines.h | ||
${derived_headers_location}/SBLanguages.h | ||
${derived_headers_location}/lldb-rpc-enumerations.h | ||
${derived_headers_location}/lldb-rpc-types.h | ||
${derived_headers_location}/lldb-rpc-defines.h | ||
) | ||
|
||
# Collect and preprocess headers for the framework bundle | ||
set(version_header | ||
${derived_headers_location}/lldb-rpc-defines.h | ||
) | ||
|
||
function(FixIncludePaths in subfolder out) | ||
get_filename_component(base_name ${in} NAME) | ||
set(parked_header ${CMAKE_CURRENT_BINARY_DIR}/ParkedHeaders/${subfolder}/${base_name}) | ||
set(${out} ${parked_header} PARENT_SCOPE) | ||
find_program(unifdef_EXECUTABLE unifdef) | ||
|
||
add_custom_command(OUTPUT ${parked_header} | ||
COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py | ||
-f lldb_rpc -i ${in} -o ${parked_header} -p ${unifdef_EXECUTABLE} USWIG | ||
DEPENDS ${in} | ||
COMMENT "Fixing includes in ${in}" | ||
) | ||
endfunction() | ||
|
||
set(preprocessed_headers) | ||
|
||
# Apply include-paths fix and any version fix on all headers and park them. | ||
foreach(source_header ${public_headers}) | ||
FixIncludePaths(${source_header} Headers parked_header) | ||
list(APPEND preprocessed_headers ${parked_header}) | ||
endforeach() | ||
|
||
# Wrap header preprocessing in a target, so liblldbrpc can depend on. | ||
add_custom_target(liblldbrpc-headers DEPENDS ${preprocessed_headers}) | ||
add_dependencies(liblldbrpc-headers copy-aux-rpc-headers liblldb-header-staging) | ||
set_target_properties(liblldbrpc-headers PROPERTIES | ||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ParkedHeaders | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
add_lldb_tool(lldb-rpc-gen | ||
RPCCommon.cpp | ||
lldb-rpc-gen.cpp | ||
|
||
CLANG_LIBS | ||
clangAST | ||
clangBasic | ||
clangCodeGen | ||
clangFrontend | ||
clangLex | ||
clangRewrite | ||
clangSerialization | ||
clangTooling | ||
|
||
LINK_COMPONENTS | ||
Support | ||
) | ||
|
||
if (NOT DEFINED LLDB_RPC_GEN_EXE) | ||
set(LLDB_RPC_GEN_EXE $<TARGET_FILE:lldb-rpc-gen> CACHE STRING "Executable that generates lldb-rpc-server") | ||
endif() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.