Skip to content

Commit d249015

Browse files
committed
[lldb][rpc] Use Clang attributes to keep track of pointer plus len
In LLDB RPC, we need to keep track of methods that have a pointer parameter followed by a lengtgh parameter as these parameters need some exceptions when they're being emitted by lldb-rpc-gen. Previously, we used an exception list to keep track of every method that fell under this category using their mangled names. This method worked, but manually maintaining an exception list this way is unwieldly and can lead to hard-to-track errors for clients that use RPC and forget to add a method that they use to said list. This commit changes this by using the Clang annotation attribute to annotate every method that uses a pointer plus length directly in the SB API, and checks that a given method has this attribute when determining if a method has a pointer plus length.
1 parent 2368be3 commit d249015

File tree

14 files changed

+68
-51
lines changed

14 files changed

+68
-51
lines changed

lldb/include/lldb/API/SBData.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class LLDB_API SBData {
6969

7070
const char *GetString(lldb::SBError &error, lldb::offset_t offset);
7171

72+
LLDB_RPC_POINTER_PLUS_LEN
7273
size_t ReadRawData(lldb::SBError &error, lldb::offset_t offset, void *buf,
7374
size_t size);
7475

@@ -80,9 +81,11 @@ class LLDB_API SBData {
8081
// DataExtractor, but having two SetData() signatures triggers a SWIG bug
8182
// where the typemap isn't applied before resolving the overload, and thus
8283
// the right function never gets called
84+
LLDB_RPC_POINTER_PLUS_LEN
8385
void SetData(lldb::SBError &error, const void *buf, size_t size,
8486
lldb::ByteOrder endian, uint8_t addr_size);
8587

88+
LLDB_RPC_POINTER_PLUS_LEN
8689
void SetDataWithOwnership(lldb::SBError &error, const void *buf, size_t size,
8790
lldb::ByteOrder endian, uint8_t addr_size);
8891

@@ -96,41 +99,51 @@ class LLDB_API SBData {
9699
// in the following CreateData*() and SetData*() prototypes, the two
97100
// parameters array and array_len should not be renamed or rearranged,
98101
// because doing so will break the SWIG typemap
102+
LLDB_RPC_POINTER_PLUS_LEN
99103
static lldb::SBData CreateDataFromUInt64Array(lldb::ByteOrder endian,
100104
uint32_t addr_byte_size,
101105
uint64_t *array,
102106
size_t array_len);
103107

108+
LLDB_RPC_POINTER_PLUS_LEN
104109
static lldb::SBData CreateDataFromUInt32Array(lldb::ByteOrder endian,
105110
uint32_t addr_byte_size,
106111
uint32_t *array,
107112
size_t array_len);
108113

114+
LLDB_RPC_POINTER_PLUS_LEN
109115
static lldb::SBData CreateDataFromSInt64Array(lldb::ByteOrder endian,
110116
uint32_t addr_byte_size,
111117
int64_t *array,
112118
size_t array_len);
113119

120+
LLDB_RPC_POINTER_PLUS_LEN
114121
static lldb::SBData CreateDataFromSInt32Array(lldb::ByteOrder endian,
115122
uint32_t addr_byte_size,
116123
int32_t *array,
117124
size_t array_len);
118125

126+
LLDB_RPC_POINTER_PLUS_LEN
119127
static lldb::SBData CreateDataFromDoubleArray(lldb::ByteOrder endian,
120128
uint32_t addr_byte_size,
121129
double *array,
122130
size_t array_len);
123131

124132
bool SetDataFromCString(const char *data);
125133

134+
LLDB_RPC_POINTER_PLUS_LEN
126135
bool SetDataFromUInt64Array(uint64_t *array, size_t array_len);
127136

137+
LLDB_RPC_POINTER_PLUS_LEN
128138
bool SetDataFromUInt32Array(uint32_t *array, size_t array_len);
129139

140+
LLDB_RPC_POINTER_PLUS_LEN
130141
bool SetDataFromSInt64Array(int64_t *array, size_t array_len);
131142

143+
LLDB_RPC_POINTER_PLUS_LEN
132144
bool SetDataFromSInt32Array(int32_t *array, size_t array_len);
133145

146+
LLDB_RPC_POINTER_PLUS_LEN
134147
bool SetDataFromDoubleArray(double *array, size_t array_len);
135148

136149
protected:

lldb/include/lldb/API/SBDebugger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class LLDB_API SBDebugger {
421421
bool GetUseSourceCache() const;
422422

423423
/// Get the default architecture.
424+
LLDB_RPC_POINTER_PLUS_LEN
424425
static bool GetDefaultArchitecture(char *arch_name, size_t arch_name_len);
425426

426427
/// Set the default architecture.
@@ -476,6 +477,7 @@ class LLDB_API SBDebugger {
476477
#endif
477478

478479
/// Dispatch input to the debugger.
480+
LLDB_RPC_POINTER_PLUS_LEN
479481
void DispatchInput(const void *data, size_t data_len);
480482

481483
/// Interrupt the current input dispatch.

lldb/include/lldb/API/SBDefines.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
#define LLDB_DEPRECATED_FIXME(MSG, FIX)
4040
#endif
4141

42+
#if defined(LLDB_RPC_GEN)
43+
#define LLDB_RPC_POINTER_PLUS_LEN \
44+
__attribute__((annotate("lldb-rpc-gen pointer plus len")))
45+
#else
46+
#define LLDB_RPC_POINTER_PLUS_LEN
47+
#endif
48+
4249
// Forward Declarations
4350
namespace lldb {
4451

lldb/include/lldb/API/SBFile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class LLDB_API SBFile {
3434

3535
SBFile &operator=(const SBFile &rhs);
3636

37+
LLDB_RPC_POINTER_PLUS_LEN
3738
SBError Read(uint8_t *buf, size_t num_bytes, size_t *OUTPUT);
39+
LLDB_RPC_POINTER_PLUS_LEN
3840
SBError Write(const uint8_t *buf, size_t num_bytes, size_t *OUTPUT);
3941
SBError Flush();
4042
bool IsValid() const;

lldb/include/lldb/API/SBFileSpec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ class LLDB_API SBFileSpec {
5151

5252
void SetDirectory(const char *directory);
5353

54+
LLDB_RPC_POINTER_PLUS_LEN
5455
uint32_t GetPath(char *dst_path, size_t dst_len) const;
5556

57+
LLDB_RPC_POINTER_PLUS_LEN
5658
static int ResolvePath(const char *src_path, char *dst_path, size_t dst_len);
5759

5860
bool GetDescription(lldb::SBStream &description) const;

lldb/include/lldb/API/SBModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ class LLDB_API SBModule {
274274
/// This function always returns the number of version numbers
275275
/// that this object file has regardless of the number of
276276
/// version numbers that were copied into \a versions.
277+
LLDB_RPC_POINTER_PLUS_LEN
277278
uint32_t GetVersion(uint32_t *versions, uint32_t num_versions);
278279

279280
/// Get accessor for the symbol file specification.

lldb/include/lldb/API/SBModuleSpec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class LLDB_API SBModuleSpec {
7171

7272
void SetTriple(const char *triple);
7373

74+
LLDB_RPC_POINTER_PLUS_LEN
7475
const uint8_t *GetUUIDBytes();
7576

7677
size_t GetUUIDLength();

lldb/include/lldb/API/SBProcess.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ class LLDB_API SBProcess {
6363

6464
size_t PutSTDIN(const char *src, size_t src_len);
6565

66+
LLDB_RPC_POINTER_PLUS_LEN
6667
size_t GetSTDOUT(char *dst, size_t dst_len) const;
6768

69+
LLDB_RPC_POINTER_PLUS_LEN
6870
size_t GetSTDERR(char *dst, size_t dst_len) const;
6971

72+
LLDB_RPC_POINTER_PLUS_LEN
7073
size_t GetAsyncProfileData(char *dst, size_t dst_len) const;
7174

7275
#ifndef SWIG
@@ -197,11 +200,14 @@ class LLDB_API SBProcess {
197200
///
198201
void ForceScriptedState(StateType new_state);
199202

203+
LLDB_RPC_POINTER_PLUS_LEN
200204
size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
201205

206+
LLDB_RPC_POINTER_PLUS_LEN
202207
size_t WriteMemory(addr_t addr, const void *buf, size_t size,
203208
lldb::SBError &error);
204209

210+
LLDB_RPC_POINTER_PLUS_LEN
205211
size_t ReadCStringFromMemory(addr_t addr, void *char_buf, size_t size,
206212
lldb::SBError &error);
207213

lldb/include/lldb/API/SBStructuredData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class SBStructuredData {
104104
/// \return
105105
/// Returns the byte size needed to completely write the string value at
106106
/// \a dst in all cases.
107+
LLDB_RPC_POINTER_PLUS_LEN
107108
size_t GetStringValue(char *dst, size_t dst_len) const;
108109

109110
/// Return the generic pointer if this data structure is a generic type.

lldb/include/lldb/API/SBTarget.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ class LLDB_API SBTarget {
607607
///
608608
/// \return
609609
/// The amount of data read in host bytes.
610+
LLDB_RPC_POINTER_PLUS_LEN
610611
size_t ReadMemory(const SBAddress addr, void *buf, size_t size,
611612
lldb::SBError &error);
612613

@@ -688,12 +689,13 @@ class LLDB_API SBTarget {
688689
const SBFileSpecList &module_list,
689690
const SBFileSpecList &comp_unit_list);
690691

692+
LLDB_RPC_POINTER_PLUS_LEN
691693
lldb::SBBreakpoint BreakpointCreateByNames(
692694
const char *symbol_name[], uint32_t num_names,
693695
uint32_t
694696
name_type_mask, // Logical OR one or more FunctionNameType enum bits
695-
lldb::LanguageType symbol_language,
696-
const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list);
697+
lldb::LanguageType symbol_language, const SBFileSpecList &module_list,
698+
const SBFileSpecList &comp_unit_list);
697699

698700
lldb::SBBreakpoint BreakpointCreateByNames(
699701
const char *symbol_name[], uint32_t num_names,
@@ -900,20 +902,24 @@ class LLDB_API SBTarget {
900902
lldb::SBAddress end_addr,
901903
const char *flavor_string);
902904

905+
LLDB_RPC_POINTER_PLUS_LEN
903906
lldb::SBInstructionList GetInstructions(lldb::SBAddress base_addr,
904907
const void *buf, size_t size);
905908

906909
// The "WithFlavor" is necessary to keep SWIG from getting confused about
907910
// overloaded arguments when using the buf + size -> Python Object magic.
908911

912+
LLDB_RPC_POINTER_PLUS_LEN
909913
lldb::SBInstructionList GetInstructionsWithFlavor(lldb::SBAddress base_addr,
910914
const char *flavor_string,
911915
const void *buf,
912916
size_t size);
913917

914918
#ifndef SWIG
919+
LLDB_RPC_POINTER_PLUS_LEN
915920
lldb::SBInstructionList GetInstructions(lldb::addr_t base_addr,
916921
const void *buf, size_t size);
922+
LLDB_RPC_POINTER_PLUS_LEN
917923
lldb::SBInstructionList GetInstructionsWithFlavor(lldb::addr_t base_addr,
918924
const char *flavor_string,
919925
const void *buf,

0 commit comments

Comments
 (0)