You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

backtrace.cxx 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2023 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "config.h"
  17. #ifdef BACKWARD_ENABLE
  18. #include "contrib/backward-cpp/backward.hpp"
  19. #include "fmt/core.h"
  20. #include "logger.h"
  21. namespace rspamd {
  22. void log_backtrace(void)
  23. {
  24. using namespace backward;
  25. StackTrace st;
  26. st.load_here(128);
  27. TraceResolver tr;
  28. tr.load_stacktrace(st);
  29. for (auto i = 0ul; i < st.size(); ++i) {
  30. auto trace = tr.resolve(st[i]);
  31. auto trace_line = fmt::format("#{}: [{}]: ", i, trace.addr);
  32. if (!trace.source.filename.empty()) {
  33. trace_line += fmt::format("{}:{} in {}", trace.source.filename, trace.source.line, trace.source.function);
  34. }
  35. else {
  36. trace_line += fmt::format("{} in {}", trace.object_filename, trace.object_function);
  37. }
  38. msg_err("%s", trace_line.c_str());
  39. }
  40. }
  41. }// namespace rspamd
  42. #endif
  43. extern "C" void rspamd_print_crash(void);
  44. void rspamd_print_crash(void)
  45. {
  46. #ifdef BACKWARD_ENABLE
  47. rspamd::log_backtrace();
  48. #endif
  49. }