IDebugCallStack.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // Description : A multiplatform base class for handling errors and collecting call stacks
  9. #ifndef CRYINCLUDE_CRYSYSTEM_IDEBUGCALLSTACK_H
  10. #define CRYINCLUDE_CRYSYSTEM_IDEBUGCALLSTACK_H
  11. #pragma once
  12. #include "System.h"
  13. #if AZ_LEGACY_CRYSYSTEM_TRAIT_FORWARD_EXCEPTION_POINTERS
  14. struct EXCEPTION_POINTERS;
  15. #endif
  16. //! Limits the maximal number of functions in call stack.
  17. enum
  18. {
  19. MAX_DEBUG_STACK_ENTRIES = 80
  20. };
  21. class IDebugCallStack
  22. {
  23. public:
  24. // Returns single instance of DebugStack
  25. static IDebugCallStack* instance();
  26. virtual int handleException([[maybe_unused]] EXCEPTION_POINTERS* exception_pointer){return 0; }
  27. // returns the module name of a given address
  28. virtual AZStd::string GetModuleNameForAddr([[maybe_unused]] void* addr) { return "[unknown]"; }
  29. // returns the function name of a given address together with source file and line number (if available) of a given address
  30. virtual void GetProcNameForAddr(void* addr, AZStd::string& procName, void*& baseAddr, AZStd::string& filename, int& line)
  31. {
  32. filename = "[unknown]";
  33. line = 0;
  34. baseAddr = addr;
  35. procName = AZStd::string::format("[%p]", addr);
  36. }
  37. // returns current filename
  38. virtual AZStd::string GetCurrentFilename() { return "[unknown]"; }
  39. //! Dumps Current Call Stack to log.
  40. virtual void LogCallstack();
  41. //triggers a fatal error, so the DebugCallstack can create the error.log and terminate the application
  42. void FatalError(const char*);
  43. //Reports a bug and continues execution
  44. virtual void ReportBug(const char*) {}
  45. virtual void FileCreationCallback(void (* postBackupProcess)());
  46. static void WriteLineToLog(const char* format, ...);
  47. virtual void StartMemLog();
  48. virtual void StopMemLog();
  49. protected:
  50. IDebugCallStack();
  51. virtual ~IDebugCallStack();
  52. static const char* TranslateExceptionCode(DWORD dwExcept);
  53. static void PutVersion(char* str, size_t length);
  54. bool m_bIsFatalError;
  55. static const char* const s_szFatalErrorCode;
  56. void (* m_postBackupProcess)();
  57. AZ::IO::HandleType m_memAllocFileHandle;
  58. };
  59. #endif // CRYINCLUDE_CRYSYSTEM_IDEBUGCALLSTACK_H