From ba10840eebcd2ba9df62e423c596f7a583f5e9d9 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Tue, 14 Apr 2020 10:18:50 -0700 Subject: [PATCH] [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. --- .../lldb/Utility/ReproducerInstrumentation.h | 86 +++++++++++++--------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/lldb/include/lldb/Utility/ReproducerInstrumentation.h b/lldb/include/lldb/Utility/ReproducerInstrumentation.h index 1eae930..8e02f4f 100644 --- a/lldb/include/lldb/Utility/ReproducerInstrumentation.h +++ b/lldb/include/lldb/Utility/ReproducerInstrumentation.h @@ -77,45 +77,42 @@ template inline std::string stringify_args(const Ts &... ts) { #define LLDB_REGISTER_CONSTRUCTOR(Class, Signature) \ R.Register(&construct::doit, "", #Class, \ #Class, #Signature) + #define LLDB_REGISTER_METHOD(Result, Class, Method, Signature) \ R.Register( \ &invoke::method<(&Class::Method)>::doit, \ #Result, #Class, #Method, #Signature) + #define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature) \ R.Register(&invoke::method_const<( \ &Class::Method)>::doit, \ #Result, #Class, #Method, #Signature) + #define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature) \ - R.Register( \ - static_cast(&Class::Method), #Result, #Class, \ - #Method, #Signature) + R.Register( \ + &invoke::method_static<(&Class::Method)>::doit, \ + #Result, #Class, #Method, #Signature) #define LLDB_REGISTER_CHAR_PTR_REDIRECT_STATIC(Result, Class, Method) \ - { \ - static auto _redirect = [](char *s, size_t l) -> Result { \ - return char_ptr_redirect_static(Class::Method, s, l); \ - }; \ - R.Register( \ - static_cast(&Class::Method), _redirect, \ - #Result, #Class, #Method, "(char*, size_t"); \ - } + R.Register(&invoke::method_static<( \ + &Class::Method)>::doit, \ + &char_ptr_redirect::method_static<( \ + &Class::Method)>::doit, \ + #Result, #Class, #Method, "(char*, size_t"); + #define LLDB_REGISTER_CHAR_PTR_REDIRECT(Result, Class, Method) \ - { \ - R.Register(&invoke::method<( \ - &Class::Method)>::doit, \ - &char_ptr_redirect::method<( \ - &Class::Method)>::doit, \ - #Result, #Class, #Method, "(char*, size_t"); \ - } + R.Register(&invoke::method<( \ + &Class::Method)>::doit, \ + &char_ptr_redirect::method<( \ + &Class::Method)>::doit, \ + #Result, #Class, #Method, "(char*, size_t"); + #define LLDB_REGISTER_CHAR_PTR_REDIRECT_CONST(Result, Class, Method) \ - { \ - R.Register( \ - &invoke::method_const<(&Class::Method)>::doit, \ - &char_ptr_redirect::method_const<(&Class::Method)>::doit, \ - #Result, #Class, #Method, "(char*, size_t"); \ - } + R.Register(&invoke::method_const<(&Class::Method)>::doit, \ + &char_ptr_redirect::method_const<(&Class::Method)>::doit, \ + #Result, #Class, #Method, "(char*, size_t"); #define LLDB_RECORD_CONSTRUCTOR(Class, Signature, ...) \ lldb_private::repro::Recorder _recorder(LLVM_PRETTY_FUNCTION, \ @@ -188,9 +185,11 @@ template inline std::string stringify_args(const Ts &... ts) { stringify_args(__VA_ARGS__)); \ if (lldb_private::repro::InstrumentationData _data = \ LLDB_GET_INSTRUMENTATION_DATA()) { \ - _recorder.Record(_data.GetSerializer(), _data.GetRegistry(), \ - static_cast(&Class::Method), \ - __VA_ARGS__); \ + _recorder.Record( \ + _data.GetSerializer(), _data.GetRegistry(), \ + lldb_private::repro::invoke::method_static<( \ + &Class::Method)>::doit, \ + __VA_ARGS__); \ } #define LLDB_RECORD_STATIC_METHOD_NO_ARGS(Result, Class, Method) \ @@ -198,7 +197,8 @@ template inline std::string stringify_args(const Ts &... ts) { if (lldb_private::repro::InstrumentationData _data = \ LLDB_GET_INSTRUMENTATION_DATA()) { \ _recorder.Record(_data.GetSerializer(), _data.GetRegistry(), \ - static_cast(&Class::Method)); \ + lldb_private::repro::invoke::method_static< \ + (&Class::Method)>::doit); \ } #define LLDB_RECORD_RESULT(Result) _recorder.RecordResult(Result, true); @@ -566,6 +566,19 @@ struct invoke { }; }; +template +struct invoke { + template struct method_static { + static Result doit(Args... args) { return (*m)(args...); } + }; +}; + +template struct invoke { + template struct method_static { + static void doit(Args... args) { return (*m)(args...); } + }; +}; + template struct invoke { template struct method { @@ -835,11 +848,14 @@ struct char_ptr_redirect { }; template -Result char_ptr_redirect_static(Result (*f)(char *, size_t), char *s, - size_t l) { - char *buffer = reinterpret_cast(calloc(l, sizeof(char))); - return f(buffer, l); -} +struct char_ptr_redirect { + template struct method_static { + static Result doit(char *s, size_t l) { + char *buffer = reinterpret_cast(calloc(l, sizeof(char))); + return (*m)(buffer, l); + } + }; +}; } // namespace repro } // namespace lldb_private -- 2.7.4