debugrpt.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/debugrpt.h
  3. // Purpose: declaration of wxDebugReport class
  4. // Author: Vadim Zeitlin
  5. // Created: 2005-01-17
  6. // Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_DEBUGRPT_H_
  10. #define _WX_DEBUGRPT_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_DEBUGREPORT && wxUSE_XML
  13. #include "wx/string.h"
  14. #include "wx/arrstr.h"
  15. class WXDLLIMPEXP_FWD_XML wxXmlNode;
  16. // ----------------------------------------------------------------------------
  17. // wxDebugReport: generate a debug report, processing is done in derived class
  18. // ----------------------------------------------------------------------------
  19. class WXDLLIMPEXP_QA wxDebugReport
  20. {
  21. public:
  22. // this is used for the functions which may report either the current state
  23. // or the state during the last (fatal) exception
  24. enum Context { Context_Current, Context_Exception };
  25. // ctor creates a temporary directory where we create the files which will
  26. // be included in the report, use IsOk() to check for errors
  27. wxDebugReport();
  28. // dtor normally destroys the temporary directory created in the ctor (with
  29. // all the files it contains), call Reset() to prevent this from happening
  30. virtual ~wxDebugReport();
  31. // return the name of the directory used for this report
  32. const wxString& GetDirectory() const { return m_dir; }
  33. // return true if the object was successfully initialized
  34. bool IsOk() const { return !GetDirectory().empty(); }
  35. // reset the directory name we use, the object can't be used any more after
  36. // this as it becomes invalid/uninitialized
  37. void Reset() { m_dir.clear(); }
  38. // add another file to the report: the file must already exist, its name
  39. // can be either absolute in which case it is copied to the debug report
  40. // directory or relative to GetDirectory()
  41. //
  42. // description is shown to the user in the report summary
  43. virtual void AddFile(const wxString& filename, const wxString& description);
  44. // convenience function: write the given text to a file with the given name
  45. // and then add it to the report (the difference with AddFile() is that the
  46. // file will be created by this function and doesn't have to already exist)
  47. bool AddText(const wxString& filename,
  48. const wxString& text,
  49. const wxString& description);
  50. #if wxUSE_STACKWALKER
  51. // add an XML file containing the current or exception context and the
  52. // stack trace
  53. bool AddCurrentContext() { return AddContext(Context_Current); }
  54. bool AddExceptionContext() { return AddContext(Context_Exception); }
  55. virtual bool AddContext(Context ctx);
  56. #endif
  57. #if wxUSE_CRASHREPORT
  58. // add a file with crash report
  59. bool AddCurrentDump() { return AddDump(Context_Current); }
  60. bool AddExceptionDump() { return AddDump(Context_Exception); }
  61. virtual bool AddDump(Context ctx);
  62. #endif // wxUSE_CRASHREPORT
  63. // add all available information to the report
  64. void AddAll(Context context = Context_Exception);
  65. // process this report: the base class simply notifies the user that the
  66. // report has been generated, this is usually not enough -- instead you
  67. // should override this method to do something more useful to you
  68. bool Process();
  69. // get the name used as base name for various files, by default
  70. // wxApp::GetName()
  71. virtual wxString GetReportName() const;
  72. // get the files in this report
  73. size_t GetFilesCount() const { return m_files.GetCount(); }
  74. bool GetFile(size_t n, wxString *name, wxString *desc) const;
  75. // remove the file from report: this is used by wxDebugReportPreview to
  76. // allow the user to remove files potentially containing private
  77. // information from the report
  78. void RemoveFile(const wxString& name);
  79. protected:
  80. #if wxUSE_STACKWALKER
  81. // used by AddContext()
  82. virtual bool DoAddSystemInfo(wxXmlNode *nodeSystemInfo);
  83. virtual bool DoAddLoadedModules(wxXmlNode *nodeModules);
  84. virtual bool DoAddExceptionInfo(wxXmlNode *nodeContext);
  85. virtual void DoAddCustomContext(wxXmlNode * WXUNUSED(nodeRoot)) { }
  86. #endif
  87. // used by Process()
  88. virtual bool DoProcess();
  89. private:
  90. // name of the report directory
  91. wxString m_dir;
  92. // the arrays of files in this report and their descriptions
  93. wxArrayString m_files,
  94. m_descriptions;
  95. };
  96. #if wxUSE_ZIPSTREAM
  97. // ----------------------------------------------------------------------------
  98. // wxDebugReportCompress: compress all files of this debug report in a .ZIP
  99. // ----------------------------------------------------------------------------
  100. class WXDLLIMPEXP_QA wxDebugReportCompress : public wxDebugReport
  101. {
  102. public:
  103. wxDebugReportCompress() { }
  104. // you can optionally specify the directory and/or name of the file where
  105. // the debug report should be generated, a default location under the
  106. // directory containing temporary files will be used if you don't
  107. //
  108. // both of these functions should be called before Process()ing the report
  109. // if they're called at all
  110. void SetCompressedFileDirectory(const wxString& dir);
  111. void SetCompressedFileBaseName(const wxString& name);
  112. // returns the full path of the compressed file (empty if creation failed)
  113. const wxString& GetCompressedFileName() const { return m_zipfile; }
  114. protected:
  115. virtual bool DoProcess();
  116. private:
  117. // user-specified file directory/base name, use defaults if empty
  118. wxString m_zipDir,
  119. m_zipName;
  120. // full path to the ZIP file we created
  121. wxString m_zipfile;
  122. };
  123. // ----------------------------------------------------------------------------
  124. // wxDebugReportUploader: uploads compressed file using HTTP POST request
  125. // ----------------------------------------------------------------------------
  126. class WXDLLIMPEXP_QA wxDebugReportUpload : public wxDebugReportCompress
  127. {
  128. public:
  129. // this class will upload the compressed file created by its base class to
  130. // an HTML multipart/form-data form at the specified address
  131. //
  132. // the URL is the base address, input is the name of the "type=file"
  133. // control on the form used for the file name and action is the value of
  134. // the form action field
  135. wxDebugReportUpload(const wxString& url,
  136. const wxString& input,
  137. const wxString& action,
  138. const wxString& curl = wxT("curl"));
  139. protected:
  140. virtual bool DoProcess();
  141. // this function may be overridden in a derived class to show the output
  142. // from curl: this may be an HTML page or anything else that the server
  143. // returned
  144. //
  145. // return value becomes the return value of Process()
  146. virtual bool OnServerReply(const wxArrayString& WXUNUSED(reply))
  147. {
  148. return true;
  149. }
  150. private:
  151. // the full URL to use with HTTP POST request
  152. wxString m_uploadURL;
  153. // the name of the input field containing the file name in the form at
  154. // above URL
  155. wxString m_inputField;
  156. // the curl command (by default it is just "curl" but could be full path to
  157. // curl or a wrapper script with curl-compatible syntax)
  158. wxString m_curlCmd;
  159. };
  160. #endif // wxUSE_ZIPSTREAM
  161. // ----------------------------------------------------------------------------
  162. // wxDebugReportPreview: presents the debug report to the user and allows him
  163. // to veto report entirely or remove some parts of it
  164. // ----------------------------------------------------------------------------
  165. class WXDLLIMPEXP_QA wxDebugReportPreview
  166. {
  167. public:
  168. // ctor is trivial
  169. wxDebugReportPreview() { }
  170. // present the report to the user and allow him to modify it by removing
  171. // some or all of the files and, potentially, adding some notes
  172. //
  173. // return true if the report should be processed or false if the user chose
  174. // to cancel report generation or removed all files from it
  175. virtual bool Show(wxDebugReport& dbgrpt) const = 0;
  176. // dtor is trivial as well but should be virtual for a base class
  177. virtual ~wxDebugReportPreview() { }
  178. };
  179. #if wxUSE_GUI
  180. // ----------------------------------------------------------------------------
  181. // wxDebugReportPreviewStd: standard debug report preview window
  182. // ----------------------------------------------------------------------------
  183. class WXDLLIMPEXP_QA wxDebugReportPreviewStd : public wxDebugReportPreview
  184. {
  185. public:
  186. wxDebugReportPreviewStd() { }
  187. virtual bool Show(wxDebugReport& dbgrpt) const;
  188. };
  189. #endif // wxUSE_GUI
  190. #endif // wxUSE_DEBUGREPORT && wxUSE_XML
  191. #endif // _WX_DEBUGRPT_H_