crash_reports.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. namespace CrashReports {
  9. QString PlatformString();
  10. #ifndef TDESKTOP_DISABLE_CRASH_REPORTS
  11. struct dump {
  12. ~dump();
  13. };
  14. const dump &operator<<(const dump &stream, const char *str);
  15. const dump &operator<<(const dump &stream, const wchar_t *str);
  16. const dump &operator<<(const dump &stream, int num);
  17. const dump &operator<<(const dump &stream, unsigned int num);
  18. const dump &operator<<(const dump &stream, unsigned long num);
  19. const dump &operator<<(const dump &stream, unsigned long long num);
  20. const dump &operator<<(const dump &stream, double num);
  21. #endif // TDESKTOP_DISABLE_CRASH_REPORTS
  22. enum Status {
  23. CantOpen,
  24. Started
  25. };
  26. // Open status or crash report dump.
  27. using StartResult = std::variant<Status, QByteArray>;
  28. StartResult Start();
  29. Status Restart(); // can be only CantOpen or Started
  30. void Finish();
  31. void SetAnnotation(const std::string &key, const QString &value);
  32. void SetAnnotationHex(const std::string &key, const QString &value);
  33. inline void ClearAnnotation(const std::string &key) {
  34. SetAnnotation(key, QString());
  35. }
  36. // Remembers value pointer and tries to add the value to the crash report.
  37. // Attention! You should call clearCrashAnnotationRef(key) before destroying value.
  38. void SetAnnotationRef(const std::string &key, const QString *valuePtr);
  39. inline void ClearAnnotationRef(const std::string &key) {
  40. SetAnnotationRef(key, nullptr);
  41. }
  42. void StartCatching();
  43. void FinishCatching();
  44. } // namespace CrashReports