stackwalk.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/stackwalk.h
  3. // Purpose: wxStackWalker for MSW
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 2005-01-08
  7. // Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MSW_STACKWALK_H_
  11. #define _WX_MSW_STACKWALK_H_
  12. #include "wx/arrstr.h"
  13. // these structs are declared in windows headers
  14. struct _CONTEXT;
  15. struct _EXCEPTION_POINTERS;
  16. // and these in dbghelp.h
  17. struct _SYMBOL_INFO;
  18. // ----------------------------------------------------------------------------
  19. // wxStackFrame
  20. // ----------------------------------------------------------------------------
  21. class WXDLLIMPEXP_BASE wxStackFrame : public wxStackFrameBase
  22. {
  23. private:
  24. wxStackFrame *ConstCast() const
  25. { return const_cast<wxStackFrame *>(this); }
  26. size_t DoGetParamCount() const { return m_paramTypes.GetCount(); }
  27. public:
  28. wxStackFrame(size_t level, void *address, size_t addrFrame)
  29. : wxStackFrameBase(level, address)
  30. {
  31. m_hasName =
  32. m_hasLocation = false;
  33. m_addrFrame = addrFrame;
  34. }
  35. virtual size_t GetParamCount() const
  36. {
  37. ConstCast()->OnGetParam();
  38. return DoGetParamCount();
  39. }
  40. virtual bool
  41. GetParam(size_t n, wxString *type, wxString *name, wxString *value) const;
  42. // callback used by OnGetParam(), don't call directly
  43. void OnParam(_SYMBOL_INFO *pSymInfo);
  44. protected:
  45. virtual void OnGetName();
  46. virtual void OnGetLocation();
  47. void OnGetParam();
  48. // helper for debug API: it wants to have addresses as DWORDs
  49. size_t GetSymAddr() const
  50. {
  51. return reinterpret_cast<size_t>(m_address);
  52. }
  53. private:
  54. bool m_hasName,
  55. m_hasLocation;
  56. size_t m_addrFrame;
  57. wxArrayString m_paramTypes,
  58. m_paramNames,
  59. m_paramValues;
  60. };
  61. // ----------------------------------------------------------------------------
  62. // wxStackWalker
  63. // ----------------------------------------------------------------------------
  64. class WXDLLIMPEXP_BASE wxStackWalker : public wxStackWalkerBase
  65. {
  66. public:
  67. // we don't use ctor argument, it is for compatibility with Unix version
  68. // only
  69. wxStackWalker(const char * WXUNUSED(argv0) = NULL) { }
  70. virtual void Walk(size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH);
  71. #if wxUSE_ON_FATAL_EXCEPTION
  72. virtual void WalkFromException(size_t maxDepth = wxSTACKWALKER_MAX_DEPTH);
  73. #endif // wxUSE_ON_FATAL_EXCEPTION
  74. // enumerate stack frames from the given context
  75. void WalkFrom(const _CONTEXT *ctx, size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH);
  76. void WalkFrom(const _EXCEPTION_POINTERS *ep, size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH);
  77. };
  78. #endif // _WX_MSW_STACKWALK_H_