CrashHandler.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // LY Crashpad Hook
  9. #pragma once
  10. #include <map>
  11. #include <string>
  12. #include <vector>
  13. namespace CrashHandler
  14. {
  15. static const char* defaultCrashFolder = "CrashDB/";
  16. static const char* O3DEProductName = "O3DE";
  17. using CrashHandlerAnnotations = std::map<std::string, std::string>;
  18. using CrashHandlerArguments = std::vector<std::string>;
  19. class CrashHandlerBase
  20. {
  21. public:
  22. CrashHandlerBase() = default;
  23. virtual ~CrashHandlerBase() = default;
  24. static void InitCrashHandler(const std::string& moduleTag, const std::string& devRoot, const std::string& crashUrl = {}, const std::string& crashToken = {}, const std::string& handlerFolder = {}, const CrashHandlerAnnotations& baseAnnotations = CrashHandlerAnnotations(), const CrashHandlerArguments& argumentVec = CrashHandlerArguments());
  25. void Initialize(const std::string& moduleTag, const std::string& devRoot);
  26. void Initialize(const std::string& moduleTag, const std::string& devRoot, const std::string& crashUrl, const std::string& crashToken, const std::string& handlerFolder = {}, const CrashHandlerAnnotations& baseAnnotations = CrashHandlerAnnotations(), const CrashHandlerArguments& argumentVec = CrashHandlerArguments());
  27. // Helper to add an annotation after initialization - must have already called InitCrashHandler
  28. static void AddAnnotation(const std::string& keyName, const std::string& valueStr);
  29. protected:
  30. virtual std::string GetCrashReportFolder(const std::string& lyAppRoot) const;
  31. virtual const char* GetDefaultCrashFolder() const { return defaultCrashFolder; }
  32. virtual std::string GetCrashHandlerPath(const std::string& lyAppRoot = {}) const;
  33. virtual const char* GetCrashHandlerExecutableName() const;
  34. virtual std::string DetermineAppPath() const;
  35. virtual const char* GetProductName() const { return O3DEProductName; }
  36. virtual bool CreateCrashHandlerDB(const std::string& reportPath) const;
  37. virtual std::string GetCrashSubmissionURL() const { return{}; }
  38. virtual std::string GetCrashSubmissionToken() const { return{}; }
  39. static void AppendSep(std::string& lyAppRoot);
  40. virtual void GetBuildAnnotations(CrashHandlerAnnotations& annotations) const;
  41. virtual void GetUserAnnotations(CrashHandlerAnnotations& ) const {};
  42. // OS Dependent
  43. virtual std::string GetAppRootFromCWD() const;
  44. virtual void GetOSAnnotations(CrashHandlerAnnotations& annotations) const;
  45. const std::string& GetConfigSubmissionToken() const;
  46. private:
  47. void ReadConfigFile();
  48. std::string m_submissionToken;
  49. };
  50. }