[lldb] Upstream lldb-rpc-gen and LLDB RPC server-side emitters by chelcassanova · Pull Request #136748 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)

Changes

This commit upstreams lldb-rpc-gen, a tool that emits the client and server interfaces used for LLDB RPC. This is the initial commit in the upstreaming process for LLDB RPC. lldb-rpc-gen is a ClangTool that reads the LLDB SB API headers and uses their information to generate the interfaces for RPC. This commit specifically adds the server-side emitters for easier review. The client-side interface will be added in a later commit.

RFC: https://discourse.llvm.org/t/rfc-upstreaming-lldb-rpc/85804


Patch is 92.84 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/136748.diff

15 Files Affected:

diff --git a/lldb/scripts/convert-lldb-header-to-rpc-header.py b/lldb/scripts/convert-lldb-header-to-rpc-header.py new file mode 100755 index 0000000000000..bf1eb526e8b3a --- /dev/null +++ b/lldb/scripts/convert-lldb-header-to-rpc-header.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# Usage: convert-lldb-header-to-rpc-header.py <path/to/input-header.h> <path/to/output-header.h> + +import argparse +import os +import re +import subprocess + +def main():

+if name == "main":

diff --git a/lldb/scripts/framework-header-include-fix.py b/lldb/scripts/framework-header-include-fix.py new file mode 100755 index 0000000000000..fcca7f31b2954 --- /dev/null +++ b/lldb/scripts/framework-header-include-fix.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# Usage: framework-header-include-fix.py <path/to/input-header.h> <path/to/output-header.h> + +import argparse +import os +import re +import subprocess + +def main():

+if name == "main":

diff --git a/lldb/scripts/framework-header-version-fix.py b/lldb/scripts/framework-header-version-fix.py new file mode 100755 index 0000000000000..d2417ea4f9414 --- /dev/null +++ b/lldb/scripts/framework-header-version-fix.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# Usage: framework-header-version-fix.py <path/to/input-header.h> <path/to/output-header.h> MAJOR MINOR PATCH + +import argparse +import os +import re +import subprocess + +def main():

+if name == "main":

diff --git a/lldb/tools/CMakeLists.txt b/lldb/tools/CMakeLists.txt index 6804dc234555b..6a2859d042148 100644 --- a/lldb/tools/CMakeLists.txt +++ b/lldb/tools/CMakeLists.txt @@ -7,6 +7,8 @@ add_subdirectory(intel-features)

example is check-lldb. So, we pass EXCLUDE_FROM_ALL here.

add_subdirectory(lldb-test EXCLUDE_FROM_ALL) add_subdirectory(lldb-fuzzer EXCLUDE_FROM_ALL) +add_subdirectory(lldb-rpc EXCLUDE_FROM_ALL) +

add_lldb_tool_subdirectory(lldb-instr) add_lldb_tool_subdirectory(lldb-dap) diff --git a/lldb/tools/lldb-rpc/CMakeLists.txt b/lldb/tools/lldb-rpc/CMakeLists.txt new file mode 100644 index 0000000000000..ab1e8517b5909 --- /dev/null +++ b/lldb/tools/lldb-rpc/CMakeLists.txt @@ -0,0 +1,19 @@ +if(LLDB_CODESIGN_IDENTITY)

+# 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) diff --git a/lldb/tools/lldb-rpc/LLDBRPCGeneration.cmake b/lldb/tools/lldb-rpc/LLDBRPCGeneration.cmake new file mode 100644 index 0000000000000..c0a041f3e96b7 --- /dev/null +++ b/lldb/tools/lldb-rpc/LLDBRPCGeneration.cmake @@ -0,0 +1,95 @@ +if (NOT DEFINED LLDB_RPC_GEN_EXE)

+endif() +set(lldb_rpc_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") +set(lldb_rpc_server_generated_source_dir "${lldb_rpc_generated_dir}/server") +set(lldb_rpc_lib_generated_source_dir "${lldb_rpc_generated_dir}/lib") +set(lldb_rpc_client_generated_source_dir "${lldb_rpc_generated_dir}/client") + +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

+# fail to run. This is only needed when we do a standalone build. +set(clang_resource_dir_arg) +if (LLDB_BUILT_STANDALONE)

diff --git a/lldb/tools/lldb-rpc/LLDBRPCHeaders.cmake b/lldb/tools/lldb-rpc/LLDBRPCHeaders.cmake new file mode 100644 index 0000000000000..7a066caceb9cb --- /dev/null +++ b/lldb/tools/lldb-rpc/LLDBRPCHeaders.cmake @@ -0,0 +1,119 @@ +set(derived_headers_location "${CMAKE_CURRENT_BINARY_DIR}/DerivedHeaders") +set(original_headers_location "${LLDB_SOURCE_DIR}/include/lldb") +set(headers_to_process

+set(version_header

+foreach(source_header ${public_headers})

+# Then apply version fix and park together with all the others. +FixIncludePaths(${version_header} ".." staged_header) +FixVersions(${staged_header} Headers parked_header) +list(APPEND preprocessed_headers ${parked_header}) + +# 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) +set_target_properties(liblldbrpc-headers PROPERTIES

+#include "clang/AST/Mangle.h" +#include "clang/Lex/Lexer.h" + +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" + +using namespace clang; + +// We intentionally do not generate some classes because they are currently +// inconvenient, they aren't really used by most consumers, or we're not sure +// why they exist. +static constexpr llvm::StringRef DisallowedClasses[] = {

+}; + +// We intentionally avoid generating certain methods either because they are +// difficult to support correctly or they aren't really used much from C++. +// FIXME: We should be able to annotate these methods instead of maintaining a +// list in the generator itself. +static constexpr llvm::StringRef DisallowedMethods[] = {

+}; + +static constexpr llvm::StringRef ClassesWithoutDefaultCtor[] = {

+}; + +static constexpr llvm::StringRef ClassesWithoutCopyOperations[] = {

+}; + +static constexpr llvm::StringRef MethodsWithPointerPlusLen[] = {

[truncated]