DebugCallStack.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #if defined (WIN32) || defined (WIN64)
  13. //! Limits the maximal number of functions in call stack.
  14. const int MAX_DEBUG_STACK_ENTRIES_FILE_DUMP = 12;
  15. struct ISystem;
  16. //!============================================================================
  17. //!
  18. //! DebugCallStack class, capture call stack information from symbol files.
  19. //!
  20. //!============================================================================
  21. class DebugCallStack
  22. : public IDebugCallStack
  23. {
  24. public:
  25. DebugCallStack();
  26. virtual ~DebugCallStack();
  27. ISystem* GetSystem() { return m_pSystem; };
  28. virtual AZStd::string GetModuleNameForAddr(void* addr);
  29. virtual void GetProcNameForAddr(void* addr, AZStd::string& procName, void*& baseAddr, AZStd::string& filename, int& line);
  30. virtual AZStd::string GetCurrentFilename();
  31. void installErrorHandler(ISystem* pSystem);
  32. virtual int handleException(EXCEPTION_POINTERS* exception_pointer);
  33. virtual void ReportBug(const char*);
  34. void dumpCallStack(std::vector<AZStd::string>& functions);
  35. void SetUserDialogEnable(const bool bUserDialogEnable);
  36. typedef std::map<void*, AZStd::string> TModules;
  37. protected:
  38. static void RemoveOldFiles();
  39. static void RemoveFile(const char* szFileName);
  40. static int PrintException(EXCEPTION_POINTERS* exception_pointer);
  41. static INT_PTR CALLBACK ExceptionDialogProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);
  42. static INT_PTR CALLBACK ConfirmSaveDialogProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);
  43. void LogExceptionInfo(EXCEPTION_POINTERS* exception_pointer);
  44. bool BackupCurrentLevel();
  45. bool SaveCurrentLevel();
  46. int SubmitBug(EXCEPTION_POINTERS* exception_pointer);
  47. void ResetFPU(EXCEPTION_POINTERS* pex);
  48. static const int s_iCallStackSize = 32768;
  49. char m_excLine[256];
  50. char m_excModule[128];
  51. char m_excDesc[MAX_WARNING_LENGTH];
  52. char m_excCode[MAX_WARNING_LENGTH];
  53. char m_excAddr[80];
  54. char m_excCallstack[s_iCallStackSize];
  55. void* prevExceptionHandler;
  56. bool m_bCrash;
  57. const char* m_szBugMessage;
  58. ISystem* m_pSystem;
  59. int m_nSkipNumFunctions;
  60. CONTEXT m_context;
  61. TModules m_modules;
  62. };
  63. #endif //WIN32
  64. #endif // CRYINCLUDE_CRYSYSTEM_DEBUGCALLSTACK_H