Skip to content

Commit a3237f8

Browse files
committed
[lldb/Reproducers] Simplify LLDB_RECORD macros
Redefine the LLDB_RECORD macros in terms of a common uber-macro to reduce code duplication across them. Differential revision: https://reviews.llvm.org/D78141
1 parent b1fbf43 commit a3237f8

File tree

1 file changed

+47
-79
lines changed

1 file changed

+47
-79
lines changed

lldb/include/lldb/Utility/ReproducerInstrumentation.h

Lines changed: 47 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,20 @@ template <typename... Ts> inline std::string stringify_args(const Ts &... ts) {
8484
#Result, #Class, #Method, #Signature)
8585

8686
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature) \
87-
R.Register(&invoke<Result(Class::*) Signature const>::method_const<( \
88-
&Class::Method)>::doit, \
87+
R.Register(&invoke<Result(Class::*) \
88+
Signature const>::method<(&Class::Method)>::doit, \
8989
#Result, #Class, #Method, #Signature)
9090

9191
#define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature) \
92-
R.Register( \
93-
&invoke<Result(*) Signature>::method_static<(&Class::Method)>::doit, \
94-
#Result, #Class, #Method, #Signature)
92+
R.Register(&invoke<Result(*) Signature>::method<(&Class::Method)>::doit, \
93+
#Result, #Class, #Method, #Signature)
9594

9695
#define LLDB_REGISTER_CHAR_PTR_REDIRECT_STATIC(Result, Class, Method) \
97-
R.Register(&invoke<Result (*)(char *, size_t)>::method_static<( \
98-
&Class::Method)>::doit, \
99-
&char_ptr_redirect<Result (*)(char *, size_t)>::method_static<( \
100-
&Class::Method)>::doit, \
101-
#Result, #Class, #Method, "(char*, size_t");
96+
R.Register( \
97+
&invoke<Result (*)(char *, size_t)>::method<(&Class::Method)>::doit, \
98+
&char_ptr_redirect<Result (*)(char *, \
99+
size_t)>::method<(&Class::Method)>::doit, \
100+
#Result, #Class, #Method, "(char*, size_t");
102101

103102
#define LLDB_REGISTER_CHAR_PTR_REDIRECT(Result, Class, Method) \
104103
R.Register(&invoke<Result (Class::*)(char *, size_t)>::method<( \
@@ -109,97 +108,55 @@ template <typename... Ts> inline std::string stringify_args(const Ts &... ts) {
109108

110109
#define LLDB_REGISTER_CHAR_PTR_REDIRECT_CONST(Result, Class, Method) \
111110
R.Register(&invoke<Result (Class::*)(char *, size_t) \
112-
const>::method_const<(&Class::Method)>::doit, \
113-
&char_ptr_redirect<Result (Class::*)( \
114-
char *, size_t) const>::method_const<(&Class::Method)>::doit, \
111+
const>::method<(&Class::Method)>::doit, \
112+
&char_ptr_redirect<Result (Class::*)(char *, size_t) \
113+
const>::method<(&Class::Method)>::doit, \
115114
#Result, #Class, #Method, "(char*, size_t");
116115

117-
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature, ...) \
116+
#define LLDB_CONSTRUCT_(T, ...) \
118117
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION, \
119118
stringify_args(__VA_ARGS__)); \
120119
if (lldb_private::repro::InstrumentationData _data = \
121120
LLDB_GET_INSTRUMENTATION_DATA()) { \
122121
_recorder.Record(_data.GetSerializer(), _data.GetRegistry(), \
123-
&lldb_private::repro::construct<Class Signature>::doit, \
124-
__VA_ARGS__); \
122+
&lldb_private::repro::construct<T>::doit, __VA_ARGS__); \
125123
_recorder.RecordResult(this, false); \
126124
}
127125

126+
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature, ...) \
127+
LLDB_CONSTRUCT_(Class Signature, __VA_ARGS__)
128+
128129
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class) \
129-
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION); \
130-
if (lldb_private::repro::InstrumentationData _data = \
131-
LLDB_GET_INSTRUMENTATION_DATA()) { \
132-
_recorder.Record(_data.GetSerializer(), _data.GetRegistry(), \
133-
&lldb_private::repro::construct<Class()>::doit); \
134-
_recorder.RecordResult(this, false); \
135-
}
130+
LLDB_CONSTRUCT_(Class(), lldb_private::repro::EmptyArg())
136131

137-
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature, ...) \
132+
#define LLDB_RECORD_(T1, T2, ...) \
138133
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION, \
139-
stringify_args(*this, __VA_ARGS__)); \
134+
stringify_args(__VA_ARGS__)); \
140135
if (lldb_private::repro::InstrumentationData _data = \
141136
LLDB_GET_INSTRUMENTATION_DATA()) { \
142137
_recorder.Record(_data.GetSerializer(), _data.GetRegistry(), \
143-
&lldb_private::repro::invoke<Result( \
144-
Class::*) Signature>::method<(&Class::Method)>::doit, \
145-
this, __VA_ARGS__); \
138+
&lldb_private::repro::invoke<T1>::method<T2>::doit, \
139+
__VA_ARGS__); \
146140
}
147141

142+
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature, ...) \
143+
LLDB_RECORD_(Result(Class::*) Signature, (&Class::Method), this, __VA_ARGS__)
144+
148145
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature, ...) \
149-
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION, \
150-
stringify_args(*this, __VA_ARGS__)); \
151-
if (lldb_private::repro::InstrumentationData _data = \
152-
LLDB_GET_INSTRUMENTATION_DATA()) { \
153-
_recorder.Record( \
154-
_data.GetSerializer(), _data.GetRegistry(), \
155-
&lldb_private::repro::invoke<Result( \
156-
Class::*) Signature const>::method_const<(&Class::Method)>::doit, \
157-
this, __VA_ARGS__); \
158-
}
146+
LLDB_RECORD_(Result(Class::*) Signature const, (&Class::Method), this, \
147+
__VA_ARGS__)
159148

160149
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method) \
161-
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION, \
162-
stringify_args(*this)); \
163-
if (lldb_private::repro::InstrumentationData _data = \
164-
LLDB_GET_INSTRUMENTATION_DATA()) { \
165-
_recorder.Record(_data.GetSerializer(), _data.GetRegistry(), \
166-
&lldb_private::repro::invoke<Result ( \
167-
Class::*)()>::method<(&Class::Method)>::doit, \
168-
this); \
169-
}
150+
LLDB_RECORD_(Result (Class::*)(), (&Class::Method), this)
170151

171152
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method) \
172-
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION, \
173-
stringify_args(*this)); \
174-
if (lldb_private::repro::InstrumentationData _data = \
175-
LLDB_GET_INSTRUMENTATION_DATA()) { \
176-
_recorder.Record( \
177-
_data.GetSerializer(), _data.GetRegistry(), \
178-
&lldb_private::repro::invoke<Result ( \
179-
Class::*)() const>::method_const<(&Class::Method)>::doit, \
180-
this); \
181-
}
153+
LLDB_RECORD_(Result (Class::*)() const, (&Class::Method), this)
182154

183155
#define LLDB_RECORD_STATIC_METHOD(Result, Class, Method, Signature, ...) \
184-
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION, \
185-
stringify_args(__VA_ARGS__)); \
186-
if (lldb_private::repro::InstrumentationData _data = \
187-
LLDB_GET_INSTRUMENTATION_DATA()) { \
188-
_recorder.Record( \
189-
_data.GetSerializer(), _data.GetRegistry(), \
190-
lldb_private::repro::invoke<Result(*) Signature>::method_static<( \
191-
&Class::Method)>::doit, \
192-
__VA_ARGS__); \
193-
}
156+
LLDB_RECORD_(Result(*) Signature, (&Class::Method), __VA_ARGS__)
194157

195158
#define LLDB_RECORD_STATIC_METHOD_NO_ARGS(Result, Class, Method) \
196-
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION); \
197-
if (lldb_private::repro::InstrumentationData _data = \
198-
LLDB_GET_INSTRUMENTATION_DATA()) { \
199-
_recorder.Record(_data.GetSerializer(), _data.GetRegistry(), \
200-
lldb_private::repro::invoke<Result (*)()>::method_static< \
201-
(&Class::Method)>::doit); \
202-
}
159+
LLDB_RECORD_(Result (*)(), (&Class::Method), lldb_private::repro::EmptyArg())
203160

204161
#define LLDB_RECORD_RESULT(Result) _recorder.RecordResult(Result, true);
205162

@@ -561,20 +518,20 @@ struct invoke<Result (Class::*)(Args...)> {
561518

562519
template <typename Result, typename Class, typename... Args>
563520
struct invoke<Result (Class::*)(Args...) const> {
564-
template <Result (Class::*m)(Args...) const> struct method_const {
521+
template <Result (Class::*m)(Args...) const> struct method {
565522
static Result doit(Class *c, Args... args) { return (c->*m)(args...); }
566523
};
567524
};
568525

569526
template <typename Result, typename... Args>
570527
struct invoke<Result (*)(Args...)> {
571-
template <Result (*m)(Args...)> struct method_static {
528+
template <Result (*m)(Args...)> struct method {
572529
static Result doit(Args... args) { return (*m)(args...); }
573530
};
574531
};
575532

576533
template <typename... Args> struct invoke<void (*)(Args...)> {
577-
template <void (*m)(Args...)> struct method_static {
534+
template <void (*m)(Args...)> struct method {
578535
static void doit(Args... args) { return (*m)(args...); }
579536
};
580537
};
@@ -712,6 +669,8 @@ class InstrumentationData {
712669
Registry *m_registry;
713670
};
714671

672+
struct EmptyArg {};
673+
715674
/// RAII object that records function invocations and their return value.
716675
///
717676
/// API calls are only captured when the API boundary is crossed. Once we're in
@@ -777,6 +736,15 @@ class Recorder {
777736
m_result_recorded = true;
778737
}
779738

739+
/// Specializations for the no-argument methods. These are passed an empty
740+
/// dummy argument so the same variadic macro can be used. These methods
741+
/// strip the arguments before forwarding them.
742+
template <typename Result>
743+
void Record(Serializer &serializer, Registry &registry, Result (*f)(),
744+
const EmptyArg &arg) {
745+
Record(serializer, registry, f);
746+
}
747+
780748
/// Record the result of a function call.
781749
template <typename Result>
782750
Result RecordResult(Result &&r, bool update_boundary) {
@@ -830,7 +798,7 @@ class Recorder {
830798
template <typename Signature> struct char_ptr_redirect;
831799
template <typename Result, typename Class>
832800
struct char_ptr_redirect<Result (Class::*)(char *, size_t) const> {
833-
template <Result (Class::*m)(char *, size_t) const> struct method_const {
801+
template <Result (Class::*m)(char *, size_t) const> struct method {
834802
static Result doit(Class *c, char *s, size_t l) {
835803
char *buffer = reinterpret_cast<char *>(calloc(l, sizeof(char)));
836804
return (c->*m)(buffer, l);
@@ -849,7 +817,7 @@ struct char_ptr_redirect<Result (Class::*)(char *, size_t)> {
849817

850818
template <typename Result>
851819
struct char_ptr_redirect<Result (*)(char *, size_t)> {
852-
template <Result (*m)(char *, size_t)> struct method_static {
820+
template <Result (*m)(char *, size_t)> struct method {
853821
static Result doit(char *s, size_t l) {
854822
char *buffer = reinterpret_cast<char *>(calloc(l, sizeof(char)));
855823
return (*m)(buffer, l);

0 commit comments

Comments
 (0)