24-support_for-non-abort-grpc.patch 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --- a/src/core/lib/gprpp/crash.cc (index)
  2. +++ b/src/core/lib/gprpp/crash.cc (working tree)
  3. @@ -23,12 +23,24 @@
  4. #include <grpc/support/log.h>
  5. +namespace {
  6. + grpc_core::CustomCrashFunction custom_crash;
  7. +}
  8. +
  9. namespace grpc_core {
  10. +void SetCustomCrashFunction(CustomCrashFunction fn) {
  11. + custom_crash = fn;
  12. +}
  13. +
  14. void Crash(y_absl::string_view message, SourceLocation location) {
  15. gpr_log(location.file(), location.line(), GPR_LOG_SEVERITY_ERROR, "%s",
  16. TString(message).c_str());
  17. - abort();
  18. + if (custom_crash) {
  19. + custom_crash(location.file(), location.line(), TString(message).c_str());
  20. + } else {
  21. + abort();
  22. + }
  23. }
  24. } // namespace grpc_core
  25. --- a/src/core/lib/gprpp/crash.h (index)
  26. +++ b/grpc/src/core/lib/gprpp/crash.h (working tree)
  27. @@ -15,6 +15,8 @@
  28. #ifndef GRPC_SRC_CORE_LIB_GPRPP_CRASH_H
  29. #define GRPC_SRC_CORE_LIB_GPRPP_CRASH_H
  30. +#include <functional>
  31. +
  32. #include <grpc/support/port_platform.h>
  33. #include "y_absl/strings/string_view.h"
  34. @@ -23,6 +25,9 @@
  35. namespace grpc_core {
  36. +typedef std::function<void(const char*, int, const char*)> CustomCrashFunction;
  37. +void SetCustomCrashFunction(CustomCrashFunction fn);
  38. +
  39. // Crash the program after printing `message`.
  40. // ::grpc_core:: prefix to SourceLocation is required to work around a symbol
  41. // mismatch bug on MSVC.