Skip to content

Commit ba10840

Browse files
committed
[lldb/Reproducers] Make static methods go through the invoke wrapper.
They don't actually have to, but it makes it easier to unify the corresponding code and macros. NFC.
1 parent 8fc7e6d commit ba10840

File tree

1 file changed

+51
-35
lines changed

1 file changed

+51
-35
lines changed

lldb/include/lldb/Utility/ReproducerInstrumentation.h

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,45 +77,42 @@ template <typename... Ts> inline std::string stringify_args(const Ts &... ts) {
7777
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature) \
7878
R.Register<Class * Signature>(&construct<Class Signature>::doit, "", #Class, \
7979
#Class, #Signature)
80+
8081
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature) \
8182
R.Register( \
8283
&invoke<Result(Class::*) Signature>::method<(&Class::Method)>::doit, \
8384
#Result, #Class, #Method, #Signature)
85+
8486
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature) \
8587
R.Register(&invoke<Result(Class::*) Signature const>::method_const<( \
8688
&Class::Method)>::doit, \
8789
#Result, #Class, #Method, #Signature)
90+
8891
#define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature) \
89-
R.Register<Result Signature>( \
90-
static_cast<Result(*) Signature>(&Class::Method), #Result, #Class, \
91-
#Method, #Signature)
92+
R.Register( \
93+
&invoke<Result(*) Signature>::method_static<(&Class::Method)>::doit, \
94+
#Result, #Class, #Method, #Signature)
9295

9396
#define LLDB_REGISTER_CHAR_PTR_REDIRECT_STATIC(Result, Class, Method) \
94-
{ \
95-
static auto _redirect = [](char *s, size_t l) -> Result { \
96-
return char_ptr_redirect_static<Result>(Class::Method, s, l); \
97-
}; \
98-
R.Register<Result(char *, size_t)>( \
99-
static_cast<Result (*)(char *, size_t)>(&Class::Method), _redirect, \
100-
#Result, #Class, #Method, "(char*, size_t"); \
101-
}
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");
102+
102103
#define LLDB_REGISTER_CHAR_PTR_REDIRECT(Result, Class, Method) \
103-
{ \
104-
R.Register(&invoke<Result (Class::*)(char *, size_t)>::method<( \
105-
&Class::Method)>::doit, \
106-
&char_ptr_redirect<Result (Class::*)(char *, size_t)>::method<( \
107-
&Class::Method)>::doit, \
108-
#Result, #Class, #Method, "(char*, size_t"); \
109-
}
104+
R.Register(&invoke<Result (Class::*)(char *, size_t)>::method<( \
105+
&Class::Method)>::doit, \
106+
&char_ptr_redirect<Result (Class::*)(char *, size_t)>::method<( \
107+
&Class::Method)>::doit, \
108+
#Result, #Class, #Method, "(char*, size_t");
109+
110110
#define LLDB_REGISTER_CHAR_PTR_REDIRECT_CONST(Result, Class, Method) \
111-
{ \
112-
R.Register( \
113-
&invoke<Result (Class::*)(char *, size_t) \
114-
const>::method_const<(&Class::Method)>::doit, \
115-
&char_ptr_redirect<Result (Class::*)(char *, size_t) \
116-
const>::method_const<(&Class::Method)>::doit, \
117-
#Result, #Class, #Method, "(char*, size_t"); \
118-
}
111+
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, \
115+
#Result, #Class, #Method, "(char*, size_t");
119116

120117
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature, ...) \
121118
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION, \
@@ -188,17 +185,20 @@ template <typename... Ts> inline std::string stringify_args(const Ts &... ts) {
188185
stringify_args(__VA_ARGS__)); \
189186
if (lldb_private::repro::InstrumentationData _data = \
190187
LLDB_GET_INSTRUMENTATION_DATA()) { \
191-
_recorder.Record(_data.GetSerializer(), _data.GetRegistry(), \
192-
static_cast<Result(*) Signature>(&Class::Method), \
193-
__VA_ARGS__); \
188+
_recorder.Record( \
189+
_data.GetSerializer(), _data.GetRegistry(), \
190+
lldb_private::repro::invoke<Result(*) Signature>::method_static<( \
191+
&Class::Method)>::doit, \
192+
__VA_ARGS__); \
194193
}
195194

196195
#define LLDB_RECORD_STATIC_METHOD_NO_ARGS(Result, Class, Method) \
197196
lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION); \
198197
if (lldb_private::repro::InstrumentationData _data = \
199198
LLDB_GET_INSTRUMENTATION_DATA()) { \
200199
_recorder.Record(_data.GetSerializer(), _data.GetRegistry(), \
201-
static_cast<Result (*)()>(&Class::Method)); \
200+
lldb_private::repro::invoke<Result (*)()>::method_static< \
201+
(&Class::Method)>::doit); \
202202
}
203203

204204
#define LLDB_RECORD_RESULT(Result) _recorder.RecordResult(Result, true);
@@ -566,6 +566,19 @@ struct invoke<Result (Class::*)(Args...) const> {
566566
};
567567
};
568568

569+
template <typename Result, typename... Args>
570+
struct invoke<Result (*)(Args...)> {
571+
template <Result (*m)(Args...)> struct method_static {
572+
static Result doit(Args... args) { return (*m)(args...); }
573+
};
574+
};
575+
576+
template <typename... Args> struct invoke<void (*)(Args...)> {
577+
template <void (*m)(Args...)> struct method_static {
578+
static void doit(Args... args) { return (*m)(args...); }
579+
};
580+
};
581+
569582
template <typename Class, typename... Args>
570583
struct invoke<void (Class::*)(Args...)> {
571584
template <void (Class::*m)(Args...)> struct method {
@@ -835,11 +848,14 @@ struct char_ptr_redirect<Result (Class::*)(char *, size_t)> {
835848
};
836849

837850
template <typename Result>
838-
Result char_ptr_redirect_static(Result (*f)(char *, size_t), char *s,
839-
size_t l) {
840-
char *buffer = reinterpret_cast<char *>(calloc(l, sizeof(char)));
841-
return f(buffer, l);
842-
}
851+
struct char_ptr_redirect<Result (*)(char *, size_t)> {
852+
template <Result (*m)(char *, size_t)> struct method_static {
853+
static Result doit(char *s, size_t l) {
854+
char *buffer = reinterpret_cast<char *>(calloc(l, sizeof(char)));
855+
return (*m)(buffer, l);
856+
}
857+
};
858+
};
843859

844860
} // namespace repro
845861
} // namespace lldb_private

0 commit comments

Comments
 (0)