DebugCallStack.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef CRYINCLUDE_CRYSYSTEM_DEBUGCALLSTACK_H
  9. #define CRYINCLUDE_CRYSYSTEM_DEBUGCALLSTACK_H
  10. #pragma once
  11. #include "IDebugCallStack.h"
  12. #include <AzCore/std/containers/vector.h>
  13. #include <AzCore/std/containers/map.h>
  14. #if defined(WIN32) || defined(WIN64)
  15. //! Limits the maximal number of functions in call stack.
  16. const int MAX_DEBUG_STACK_ENTRIES_FILE_DUMP = 12;
  17. struct ISystem;
  18. //!============================================================================
  19. //!
  20. //! DebugCallStack class, capture call stack information from symbol files.
  21. //!
  22. //!============================================================================
  23. class DebugCallStack : public IDebugCallStack
  24. {
  25. public:
  26. DebugCallStack();
  27. virtual ~DebugCallStack();
  28. ISystem* GetSystem()
  29. {
  30. return m_pSystem;
  31. };
  32. virtual AZStd::string GetModuleNameForAddr(void* addr) override;
  33. virtual void GetProcNameForAddr(void* addr, AZStd::string& procName, void*& baseAddr, AZStd::string& filename, int& line) override;
  34. virtual AZStd::string GetCurrentFilename() override;
  35. virtual int handleException(EXCEPTION_POINTERS* exception_pointer) override;
  36. virtual void ReportBug(const char*) override;
  37. void installErrorHandler(ISystem* pSystem);
  38. void dumpCallStack(AZStd::vector<AZStd::string>& functions);
  39. void SetUserDialogEnable(const bool bUserDialogEnable);
  40. typedef AZStd::map<void*, AZStd::string> TModules;
  41. protected:
  42. enum class UserPostExceptionChoice
  43. {
  44. Exit,
  45. Recover // Only available if the exception type allows it (eg: floating point exception)
  46. };
  47. static void RemoveOldFiles();
  48. static void RemoveFile(const char* szFileName);
  49. static UserPostExceptionChoice AskUserToRecoverOrCrash(EXCEPTION_POINTERS* exception_pointer);
  50. void SaveExceptionInfoAndShowUserReportDialogs(EXCEPTION_POINTERS* exception_pointer);
  51. bool BackupCurrentLevel();
  52. bool SaveCurrentLevel();
  53. UserPostExceptionChoice SubmitBugAndAskToRecoverOrCrash(EXCEPTION_POINTERS* exception_pointer);
  54. void ResetFPU(EXCEPTION_POINTERS* pex);
  55. static const int s_iCallStackSize = 32768;
  56. char m_excLine[256];
  57. char m_excModule[128];
  58. char m_excDesc[MAX_WARNING_LENGTH];
  59. char m_excCode[MAX_WARNING_LENGTH];
  60. char m_excAddr[80];
  61. char m_excCallstack[s_iCallStackSize];
  62. void* prevExceptionHandler;
  63. bool m_bCrash;
  64. const char* m_szBugMessage;
  65. ISystem* m_pSystem;
  66. int m_nSkipNumFunctions;
  67. CONTEXT m_context;
  68. TModules m_modules;
  69. };
  70. #endif // WIN32
  71. #endif // CRYINCLUDE_CRYSYSTEM_DEBUGCALLSTACK_H