-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb][RPC] Upstream RPC server interface emitters #138032
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
Open
chelcassanova
wants to merge
1
commit into
llvm:main
Choose a base branch
from
chelcassanova:upstream-lldb-rpc/add-lldb-rpc-server-emitters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
6 changes: 6 additions & 0 deletions
6
lldb/test/Shell/RPC/Generator/Inputs/Server/CheckBasicIncludesEmit.h
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,6 @@ | ||
// This ia a basic header file used to check that the server-side emitter | ||
// for rpc-gen emits an expected set of includes in a generated source file. | ||
#ifndef LLDB_API_SBRPC_CHECKBASICINCLUDE_H | ||
#define LLDB_API_SBRPC_CHECKBASICINCLUDE_H | ||
|
||
#endif // LLDB_API_SBRPC_CHECKBASICINCLUDE_H |
14 changes: 14 additions & 0 deletions
14
lldb/test/Shell/RPC/Generator/Inputs/Server/CheckConstCharPointer.h
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,14 @@ | ||
#ifndef LLDB_API_SBRPC_CHECKCONSTCHARPOINTER_H | ||
#define LLDB_API_SBRPC_CHECKCONSTCHARPOINTER_H | ||
|
||
namespace lldb { | ||
class LLDB_API SBRPC_CHECKCONSTCHARPOINTER { | ||
public: | ||
// const char * parameters must decoded as rpc_common::ConstCharPointer in server side | ||
// source files. | ||
int CheckConstCharPointer(char *string); | ||
|
||
}; // class SBRPC_CHECKCONSTCHARPOINTER | ||
} // namespace lldb | ||
|
||
#endif // LLDB_API_SBRPC_CHECKCONSTCHARPOINTER_H |
15 changes: 15 additions & 0 deletions
15
lldb/test/Shell/RPC/Generator/Tests/Server/CheckBasicIncludesEmit.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,15 @@ | ||
# Disabling until the lldb-rpc-gen tool lands. | ||
UNSUPPORTED: system-windows, system-linux, system-darwin | ||
RUN: mkdir -p %t/server | ||
RUN: mkdir -p %t/lib | ||
RUN: %lldb-rpc-gen --output-dir=%t %S/../../Inputs/CheckBasicIncludesEmit.h | ||
|
||
RUN: cat %t/lib/CheckBasicIncludesEmit.cpp | FileCheck %s | ||
|
||
# All server-side source files must have these includes at the top of their files. | ||
CHECK: #include "RPCUserServer.h" | ||
CHECK: #include "SBAPI.h" | ||
CHECK: #include <lldb-rpc/common/RPCArgument.h> | ||
CHECK: #include <lldb-rpc/common/RPCCommon.h> | ||
CHECK: #include <lldb-rpc/common/RPCFunction.h> | ||
CHECK: #include <lldb/API/LLDB.h> |
11 changes: 11 additions & 0 deletions
11
lldb/test/Shell/RPC/Generator/Tests/Server/CheckConstCharPointer.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,11 @@ | ||
# Disabling until the lldb-rpc-gen tool lands. | ||
UNSUPPORTED: system-windows, system-linux, system-darwin | ||
RUN: mkdir -p %t/server | ||
RUN: mkdir -p %t/lib | ||
RUN: %lldb-rpc-gen --output-dir=%t %S/../../Inputs/CheckConstCharPointer.h | ||
|
||
RUN: cat %t/lib/CheckConstCharPointer.cpp | FileCheck %s | ||
|
||
# const char * pointers must be decoded as rpc_common::ConstCharPointer objects | ||
# in server side source files. | ||
CHECK: rpc_common::ConstCharPointer string |
75 changes: 75 additions & 0 deletions
75
lldb/tools/lldb-rpc/lldb-rpc-gen/server/RPCServerHeaderEmitter.cpp
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,75 @@ | ||
//===-- RPCServerHeaderEmitter.cpp ----------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "RPCServerHeaderEmitter.h" | ||
#include "RPCCommon.h" | ||
|
||
#include "clang/AST/AST.h" | ||
#include "clang/AST/Mangle.h" | ||
#include "clang/Frontend/CompilerInstance.h" | ||
|
||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/ToolOutputFile.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
using namespace clang; | ||
using namespace lldb_rpc_gen; | ||
|
||
void RPCServerHeaderEmitter::EmitMethod(const Method &method) { | ||
// We'll be using the mangled name in order to disambiguate | ||
// overloaded methods. | ||
const std::string &MangledName = method.MangledName; | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
EmitLine("class " + MangledName + | ||
" : public rpc_common::RPCFunctionInstance {"); | ||
EmitLine("public:"); | ||
IndentLevel++; | ||
EmitConstructor(MangledName); | ||
EmitDestructor(MangledName); | ||
EmitHandleRPCCall(); | ||
IndentLevel--; | ||
EmitLine("};"); | ||
} | ||
|
||
void RPCServerHeaderEmitter::EmitHandleRPCCall() { | ||
EmitLine("bool HandleRPCCall(rpc_common::Connection &connection, " | ||
"rpc_common::RPCStream &send, rpc_common::RPCStream &response) " | ||
"override;"); | ||
} | ||
|
||
void RPCServerHeaderEmitter::EmitConstructor(const std::string &MangledName) { | ||
EmitLine(MangledName + "() : RPCFunctionInstance(\"" + MangledName + | ||
"\") {}"); | ||
} | ||
|
||
void RPCServerHeaderEmitter::EmitDestructor(const std::string &MangledName) { | ||
EmitLine("~" + MangledName + "() override {}"); | ||
} | ||
|
||
std::string RPCServerHeaderEmitter::GetHeaderGuard() { | ||
const std::string UpperFilenameNoExt = | ||
llvm::sys::path::stem( | ||
llvm::sys::path::filename(OutputFile->getFilename())) | ||
.upper(); | ||
return "GENERATED_LLDB_RPC_SERVER_" + UpperFilenameNoExt + "_H"; | ||
} | ||
|
||
void RPCServerHeaderEmitter::Begin() { | ||
const std::string HeaderGuard = GetHeaderGuard(); | ||
EmitLine("#ifndef " + HeaderGuard); | ||
EmitLine("#define " + HeaderGuard); | ||
EmitLine(""); | ||
EmitLine("#include <lldb-rpc/common/RPCFunction.h>"); | ||
EmitLine(""); | ||
EmitLine("namespace rpc_server {"); | ||
} | ||
|
||
void RPCServerHeaderEmitter::End() { | ||
EmitLine("} // namespace rpc_server"); | ||
EmitLine("#endif // " + GetHeaderGuard()); | ||
} |
47 changes: 47 additions & 0 deletions
47
lldb/tools/lldb-rpc/lldb-rpc-gen/server/RPCServerHeaderEmitter.h
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,47 @@ | ||
//===-- RPCServerHeaderEmitter.h ----------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLDB_RPC_GEN_RPCSERVERHEADEREMITTER_H | ||
#define LLDB_RPC_GEN_RPCSERVERHEADEREMITTER_H | ||
|
||
#include "RPCCommon.h" | ||
|
||
#include "clang/AST/AST.h" | ||
#include "llvm/Support/ToolOutputFile.h" | ||
|
||
using namespace clang; | ||
|
||
namespace lldb_rpc_gen { | ||
/// Emit the source code for server-side *.h files. | ||
class RPCServerHeaderEmitter : public FileEmitter { | ||
public: | ||
RPCServerHeaderEmitter(std::unique_ptr<llvm::ToolOutputFile> &&OutputFile) | ||
: FileEmitter(std::move(OutputFile)) { | ||
Begin(); | ||
} | ||
|
||
~RPCServerHeaderEmitter() { End(); } | ||
|
||
void EmitMethod(const Method &method); | ||
|
||
private: | ||
void EmitHandleRPCCall(); | ||
|
||
void EmitConstructor(const std::string &MangledName); | ||
|
||
void EmitDestructor(const std::string &MangledName); | ||
|
||
std::string GetHeaderGuard(); | ||
|
||
void Begin(); | ||
|
||
void End(); | ||
}; | ||
} // namespace lldb_rpc_gen | ||
|
||
#endif // LLDB_RPC_GEN_RPCSERVERHEADEREMITTER_H |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UNSUPPORTED: *
should disable it everywhere.Saves someone on FreeBSD getting an unpleasant surprise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do that for the rest of the tests as well.