IDebugCallStack.h 2.4 KB

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