debugrpt.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: debugrpt.h
  3. // Purpose: interface of wxDebugReport*
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxDebugReportPreview
  9. This class presents the debug report to the user and allows him to veto
  10. report entirely or remove some parts of it. Although not mandatory, using
  11. this class is strongly recommended as data included in the debug report
  12. might contain sensitive private information and the user should be notified
  13. about it as well as having a possibility to examine the data which had been
  14. gathered to check whether this is effectively the case and discard the
  15. debug report if it is.
  16. wxDebugReportPreview is an abstract base class, currently the only concrete
  17. class deriving from it is wxDebugReportPreviewStd.
  18. @library{wxqa}
  19. @category{debugging}
  20. */
  21. class wxDebugReportPreview
  22. {
  23. public:
  24. /**
  25. Default constructor.
  26. */
  27. wxDebugReportPreview();
  28. /**
  29. Destructor is trivial as well but should be virtual for a base class.
  30. */
  31. virtual ~wxDebugReportPreview();
  32. /**
  33. Present the report to the user and allow him to modify it by removing
  34. some or all of the files and, potentially, adding some notes.
  35. @return @true if the report should be processed or @false if the user
  36. chose to cancel report generation or removed all files from
  37. it.
  38. */
  39. virtual bool Show(wxDebugReport& dbgrpt) const = 0;
  40. };
  41. /**
  42. @class wxDebugReportCompress
  43. wxDebugReportCompress is a wxDebugReport which compresses all the files in
  44. this debug report into a single ZIP file in its wxDebugReport::Process()
  45. function.
  46. @library{wxqa}
  47. @category{debugging}
  48. */
  49. class wxDebugReportCompress : public wxDebugReport
  50. {
  51. public:
  52. /**
  53. Default constructor does nothing special.
  54. */
  55. wxDebugReportCompress();
  56. /**
  57. Set the directory where the debug report should be generated.
  58. By default, the debug report is generated under user temporary files
  59. directory. This is usually fine if it is meant to be processed in some
  60. way (e.g. automatically uploaded to a remote server) but if the user is
  61. asked to manually upload or send the report, it may be more convenient
  62. to generate it in e.g. the users home directory and this function
  63. allows to do this.
  64. Notice that it should be called before wxDebugReport::Process() or it
  65. has no effect.
  66. @param dir
  67. The full path to an existing directory where the debug report file
  68. should be generated.
  69. @since 2.9.1
  70. */
  71. void SetCompressedFileDirectory(const wxString& dir);
  72. /**
  73. Set the base name of the generated debug report file.
  74. This function is similar to SetCompressedFileDirectory() but allows to
  75. change the base name of the file. Notice that the file extension will
  76. always be @c .zip.
  77. By default, a unique name constructed from wxApp::GetAppName(), the
  78. current process id and the current date and time is used.
  79. @param name
  80. The base name (i.e. without extension) of the file.
  81. @since 2.9.1
  82. */
  83. void SetCompressedFileBaseName(const wxString& name);
  84. /**
  85. Returns the full path of the compressed file (empty if creation
  86. failed).
  87. */
  88. const wxString& GetCompressedFileName() const;
  89. };
  90. /**
  91. @class wxDebugReport
  92. wxDebugReport is used to generate a debug report, containing information
  93. about the program current state. It is usually used from
  94. wxApp::OnFatalException() as shown in the @ref page_samples_debugrpt.
  95. A wxDebugReport object contains one or more files. A few of them can be
  96. created by the class itself but more can be created from the outside and
  97. then added to the report. Also note that several virtual functions may be
  98. overridden to further customize the class behaviour.
  99. Once a report is fully assembled, it can simply be left in the temporary
  100. directory so that the user can email it to the developers (in which case
  101. you should still use wxDebugReportCompress to compress it in a single file)
  102. or uploaded to a Web server using wxDebugReportUpload (setting up the Web
  103. server to accept uploads is your responsibility, of course). Other
  104. handlers, for example for automatically emailing the report, can be defined
  105. as well but are not currently included in wxWidgets.
  106. A typical usage example:
  107. @code
  108. wxDebugReport report;
  109. wxDebugReportPreviewStd preview;
  110. report.AddCurrentContext(); // could also use AddAll()
  111. report.AddCurrentDump(); // to do both at once
  112. if ( preview.Show(report) )
  113. report.Process();
  114. @endcode
  115. @library{wxqa}
  116. @category{debugging}
  117. */
  118. class wxDebugReport
  119. {
  120. public:
  121. /**
  122. This enum is used for functions that report either the current state or
  123. the state during the last (fatal) exception.
  124. */
  125. enum Context {
  126. Context_Current,
  127. Context_Exception
  128. };
  129. /**
  130. The constructor creates a temporary directory where the files that will
  131. be included in the report are created. Use IsOk() to check for errors.
  132. */
  133. wxDebugReport();
  134. /**
  135. The destructor normally destroys the temporary directory created in the
  136. constructor with all the files it contains. Call Reset() to prevent
  137. this from happening.
  138. */
  139. virtual ~wxDebugReport();
  140. /**
  141. Adds all available information to the report. Currently this includes a
  142. text (XML) file describing the process context and, under Win32, a
  143. minidump file.
  144. */
  145. void AddAll(Context context = Context_Exception);
  146. /**
  147. Add an XML file containing the current or exception context and the
  148. stack trace.
  149. */
  150. virtual bool AddContext(Context ctx);
  151. /**
  152. The same as calling AddContext(Context_Current).
  153. */
  154. bool AddCurrentContext();
  155. /**
  156. The same as calling AddDump(Context_Current).
  157. */
  158. bool AddCurrentDump();
  159. /**
  160. Adds the minidump file to the debug report.
  161. Minidumps are only available under recent Win32 versions
  162. (@c dbghlp32.dll can be installed under older systems to make minidumps
  163. available).
  164. */
  165. virtual bool AddDump(Context ctx);
  166. /**
  167. The same as calling AddContext(Context_Exception).
  168. */
  169. bool AddExceptionContext();
  170. /**
  171. The same as calling AddDump(Context_Exception).
  172. */
  173. bool AddExceptionDump();
  174. /**
  175. Add another file to the report. If @a filename is an absolute path, it
  176. is copied to a file in the debug report directory with the same name.
  177. Otherwise the file will be searched in the temporary directory returned
  178. by GetDirectory().
  179. The argument @a description only exists to be displayed to the user in
  180. the report summary shown by wxDebugReportPreview.
  181. @see GetDirectory(), AddText()
  182. */
  183. virtual void AddFile(const wxString& filename, const wxString& description);
  184. /**
  185. This is a convenient wrapper around AddFile(). It creates the file with
  186. the given @a name and writes @a text to it, then adds the file to the
  187. report. The @a filename shouldn't contain the path.
  188. @return @true if file could be added successfully, @false if an IO
  189. error occurred.
  190. */
  191. bool AddText(const wxString& filename, const wxString& text,
  192. const wxString& description);
  193. /**
  194. This method should be used to construct the full name of the files
  195. which you wish to add to the report using AddFile().
  196. @return The name of the temporary directory used for the files in this
  197. report.
  198. */
  199. const wxString& GetDirectory() const;
  200. /**
  201. Retrieves the name (relative to GetDirectory()) and the description of
  202. the file with the given index. If @a n is greater than or equal to the
  203. number of files, then @false is returned.
  204. */
  205. bool GetFile(size_t n, wxString* name, wxString* desc) const;
  206. /**
  207. Gets the current number files in this report.
  208. */
  209. size_t GetFilesCount() const;
  210. /**
  211. Gets the name used as a base name for various files, by default
  212. wxApp::GetAppName() is used.
  213. */
  214. virtual wxString GetReportName() const;
  215. /**
  216. Returns @true if the object was successfully initialized. If this
  217. method returns @false the report can't be used.
  218. */
  219. bool IsOk() const;
  220. /**
  221. Processes this report: the base class simply notifies the user that the
  222. report has been generated. This is usually not enough -- instead you
  223. should override this method to do something more useful to you.
  224. */
  225. bool Process();
  226. /**
  227. Removes the file from report: this is used by wxDebugReportPreview to
  228. allow the user to remove files potentially containing private
  229. information from the report.
  230. */
  231. void RemoveFile(const wxString& name);
  232. /**
  233. Resets the directory name we use. The object can't be used any more
  234. after this as it becomes uninitialized and invalid.
  235. */
  236. void Reset();
  237. protected:
  238. /**
  239. This function may be overridden to add arbitrary custom context to the
  240. XML context file created by AddContext(). By default, it does nothing.
  241. */
  242. virtual void DoAddCustomContext(wxXmlNode* nodeRoot);
  243. /**
  244. This function may be overridden to modify the contents of the exception
  245. tag in the XML context file.
  246. */
  247. virtual bool DoAddExceptionInfo(wxXmlNode* nodeContext);
  248. /**
  249. This function may be overridden to modify the contents of the modules
  250. tag in the XML context file.
  251. */
  252. virtual bool DoAddLoadedModules(wxXmlNode* nodeModules);
  253. /**
  254. This function may be overridden to modify the contents of the system
  255. tag in the XML context file.
  256. */
  257. virtual bool DoAddSystemInfo(wxXmlNode* nodeSystemInfo);
  258. };
  259. /**
  260. @class wxDebugReportPreviewStd
  261. wxDebugReportPreviewStd is a standard debug report preview window. It
  262. displays a dialog allowing the user to examine the contents of a debug
  263. report, remove files from and add notes to it.
  264. @library{wxqa}
  265. @category{debugging}
  266. */
  267. class wxDebugReportPreviewStd : public wxDebugReportPreview
  268. {
  269. public:
  270. /**
  271. Trivial default constructor.
  272. */
  273. wxDebugReportPreviewStd();
  274. /**
  275. Shows the dialog.
  276. @see wxDebugReportPreview::Show()
  277. */
  278. bool Show(wxDebugReport& dbgrpt) const;
  279. };
  280. /**
  281. @class wxDebugReportUpload
  282. This class is used to upload a compressed file using HTTP POST request. As
  283. this class derives from wxDebugReportCompress, before upload the report is
  284. compressed in a single ZIP file.
  285. @library{wxqa}
  286. @category{debugging}
  287. */
  288. class wxDebugReportUpload : public wxDebugReportCompress
  289. {
  290. public:
  291. /**
  292. This class will upload the compressed file created by its base class to
  293. an HTML multipart/form-data form at the specified address. The @a url
  294. is the upload page address, @a input is the name of the @c "type=file"
  295. control on the form used for the file name and @a action is the value
  296. of the form action field. The report is uploaded using the @e curl
  297. program which should be available, the @e curl parameter may be used to
  298. specify the full path to it.
  299. */
  300. wxDebugReportUpload(const wxString& url, const wxString& input,
  301. const wxString& action,
  302. const wxString& curl = "curl");
  303. protected:
  304. /**
  305. This function may be overridden in a derived class to show the output
  306. from curl: this may be an HTML page or anything else that the server
  307. returned. Value returned by this function becomes the return value of
  308. wxDebugReport::Process().
  309. */
  310. virtual bool OnServerReply(const wxArrayString& reply);
  311. };