Skip to content

Commit 899439d

Browse files
committed
[lldb][rpc] Upstream RPC Client Library Emitters
This commit upstreams the client side emitters for the lldb-rpc-gen tool alongside tests for its functionality and heuristics. https://discourse.llvm.org/t/rfc-upstreaming-lldb-rpc/85804
1 parent 6b3d2b6 commit 899439d

17 files changed

+1407
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef LLDB_API_SBRPC_CHECKARRAYPTR_H
2+
#define LLDB_API_SBRPC_CHECKARRAYPTR_H
3+
4+
#include <cstddef>
5+
#include <cstdio>
6+
7+
#include "lldb/API/SBDefines.h"
8+
9+
namespace lldb {
10+
class LLDB_API SBRPC_CHECKARRAYPTR {
11+
public:
12+
// Pointers to arrays followed by length must use a
13+
// Bytes object constructed using that pointer and the sizeof()
14+
// the array object.
15+
int CheckArrayPtr(uint64_t *array, size_t array_len);
16+
17+
}; // class SBRPC_CHECKARRAYPTR
18+
} // namespace lldb
19+
20+
#endif // LLDB_API_SBRPC_CHECKARRAYPTR_H
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef LLDB_API_SBRPC_CHECKCONSTCHARPTRPTRWITHLEN_H
2+
#define LLDB_API_SBRPC_CHECKCONSTCHARPTRPTRWITHLEN_H
3+
4+
#include <cstddef>
5+
#include <cstdio>
6+
7+
#include "lldb/API/SBDefines.h"
8+
9+
namespace lldb {
10+
class LLDB_API SBRPC_CHECKCONSTCHARPTRPTRWITHLEN {
11+
public:
12+
// const char ** followed by len must use a StringList
13+
// when being encoded.
14+
int CheckConstCharPtrPtrWithLen(const char **arg1, size_t len);
15+
16+
}; // class SBRPC_CHECKCONSTCHARPTRPTRWITHLEN
17+
} // namespace lldb
18+
19+
#endif // LLDB_API_SBRPC_CHECKCONSTCHARPTRPTRWITHLEN_H
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef LLDB_API_SBRPC_CHECKCONSTSBREF_H
2+
#define LLDB_API_SBRPC_CHECKCONSTSBREF_H
3+
4+
#include <cstddef>
5+
#include <cstdio>
6+
7+
#include "lldb/API/SBDefines.h"
8+
9+
namespace lldb {
10+
class LLDB_API SBRPC_CHECKCONSTSBREF {
11+
public:
12+
// Const references to SB classes should be encoded as usual without
13+
// needing to create a new object with its own connection.
14+
int CheckConstSBRef(const SBDebugger &debugger_ref);
15+
16+
}; // class SBRPC_CHECKCONSTSBREF
17+
} // namespace lldb
18+
19+
#endif // LLDB_API_SBRPC_CHECKCONSTSBREF_H
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef LLDB_API_SBRPC_CHECKNONCONSTSBREF_H
2+
#define LLDB_API_SBRPC_CHECKNONCONSTSBREF_H
3+
4+
#include <cstddef>
5+
#include <cstdio>
6+
7+
#include "lldb/API/SBDefines.h"
8+
9+
namespace lldb {
10+
class LLDB_API SBRPC_CHECKNONCONSTSBREF {
11+
public:
12+
// Non-const references to SB classes will have new objects
13+
// of that class constructed with the connection as the first parameter
14+
// before being encoded if their existing connection is invalid.
15+
int CheckNonConstSBRef(SBDebugger &debugger_ref);
16+
17+
}; // class SBRPC_CHECKNONCONSTSBREF
18+
} // namespace lldb
19+
20+
#endif // LLDB_API_SBRPC_CHECKNONCONSTSBREF_H
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef LLDB_API_SBRPC_CHECKSBPTR_H
2+
#define LLDB_API_SBRPC_CHECKSBPTR_H
3+
4+
#include <cstddef>
5+
#include <cstdio>
6+
7+
#include "lldb/API/SBDefines.h"
8+
9+
namespace lldb {
10+
class LLDB_API SBRPC_CHECKSBPTR {
11+
public:
12+
// Pointers to SB objects must be checked to
13+
// see if they're null. If so, then a new object of the given
14+
// class must be created and encoded. Otherwise, the original
15+
// parameter will be encoded.
16+
int CheckSBPtr(SBDebugger *debugger_ptr);
17+
18+
}; // class SBRPC_CHECKSBPTR
19+
} // namespace lldb
20+
21+
#endif // LLDB_API_SBRPC_CHECKSBPTR_H
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef LLDB_API_SBRPC_CHECKVOIDPTR_H
2+
#define LLDB_API_SBRPC_CHECKVOIDPTR_H
3+
4+
#include <cstddef>
5+
#include <cstdio>
6+
7+
#include "lldb/API/SBDefines.h"
8+
9+
namespace lldb {
10+
class LLDB_API SBRPC_CHECKVOIDPTR {
11+
public:
12+
// void * followed by length must use a Bytes object
13+
// when being encoded.
14+
int CheckVoidPtr(void *buf, size_t len);
15+
16+
}; // class SBRPC_CHECKVOIDPTR
17+
} // namespace lldb
18+
19+
#endif // LLDB_API_SBRPC_CHECKVOIDPTR_H
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
RUN: mkdir -p %t/server
2+
RUN: mkdir -p %t/lib
3+
RUN: %lldb-rpc-gen --output-dir=%t %S/../../Inputs/CheckArrayPointer.h
4+
5+
RUN: cat %t/lib/CheckArrayPointer.cpp | FileCheck %s
6+
7+
# Pointers to arrays followed by length must use a
8+
# Bytes object constructed using that pointer and the sizeof()
9+
# the array object.
10+
CHECK: lldb_rpc::SBRPC_CHECKARRAYPTR::CheckArrayPtr
11+
CHECK: Bytes array_buffer(array, sizeof(uint64_t));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
RUN: mkdir -p %t/server
2+
RUN: mkdir -p %t/lib
3+
RUN: %lldb-rpc-gen --output-dir=%t %S/../../Inputs/CheckConstCharPtrPtrWithLen.h
4+
5+
RUN: cat %t/lib/CheckConstCharPtrPtrWithLen.cpp | FileCheck %s
6+
7+
# const char ** followed by len must use a StringList
8+
# when being encoded.
9+
CHECK: lldb_rpc::SBRPC_CHECKCONSTCHARPTRPTRWITHLEN::CheckConstCharPtrPtrWithLen
10+
CHECK: StringList arg1_list
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
RUN: mkdir -p %t/server
2+
RUN: mkdir -p %t/lib
3+
RUN: %lldb-rpc-gen --output-dir=%t %S/../../Inputs/CheckConstSBRef.h
4+
5+
RUN: cat %t/lib/CheckConstSBRef.cpp | FileCheck %s
6+
7+
# Const references to SB classes should be encoded as usual without
8+
# needing to create a new object with its own connection. Here
9+
# we're checking to make sure that the given SB object ref will get
10+
# encoded immediately after the previous argument gets encoded without
11+
# anything happening in between.
12+
CHECK: lldb_rpc::SBRPC_CHECKCONSTSBREF::CheckConstSBRef
13+
CHECK: RPCValueEncoder(send, rpc_common::RPCPacket::ValueType::Argument, *this);
14+
CHECK: RPCValueEncoder(send, rpc_common::RPCPacket::ValueType::Argument, debugger_ref)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
RUN: mkdir -p %t/server
2+
RUN: mkdir -p %t/lib
3+
RUN: %lldb-rpc-gen --output-dir=%t %S/../../Inputs/CheckNonConstSBRef.h
4+
5+
RUN: cat %t/lib/CheckNonConstSBRef.cpp | FileCheck %s
6+
7+
# Non-const references to SB classes will have new objects
8+
# of that class constructed with the connection as the first parameter
9+
# before being encoded if their existing connection is invalid.
10+
CHECK: lldb_rpc::SBRPC_CHECKNONCONSTSBREF::CheckNonConstSBRef
11+
CHECK: if (connection_sp && !debugger_ref.ObjectRefIsValid())
12+
CHECK: debugger_ref = lldb_rpc::SBDebugger(connection_sp);
13+
CHECK: RPCValueEncoder(send, rpc_common::RPCPacket::ValueType::Argument, debugger_ref);

0 commit comments

Comments
 (0)