VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBugReport/VBoxBugReport.h@ 88205

Last change on this file since 88205 was 85086, checked in by vboxsync, 4 years ago

iprt/cdefs.h: Make RT*DECL, DECLCALLBACK*, and DECLINLINE imply nothrow (either attribute or declspec). Introducing DECL_INLINE_THROW for inline functions throwing stuff. Renamed RT_NO_THROW* to RT_NOTHROW*. ++ bugref:9794

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/* $Id: VBoxBugReport.h 85086 2020-07-07 17:01:10Z vboxsync $ */
2/** @file
3 * VBoxBugReport - VirtualBox command-line diagnostics tool, internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VBOX_INCLUDED_SRC_VBoxBugReport_VBoxBugReport_h
19#define VBOX_INCLUDED_SRC_VBoxBugReport_VBoxBugReport_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/*
25 * Introduction.
26 *
27 * In the most general sense a bug report is a collection of data obtained from
28 * the user's host system. It may include files common for all VMs, like the
29 * VBoxSVC.log file, as well as files related to particular machines. It may
30 * also contain the output of commands executed on the host, as well as data
31 * collected via OS APIs.
32 */
33
34/** @todo not sure if using a separate namespace would be beneficial */
35
36#include <iprt/path.h>
37#include <iprt/stream.h>
38#include <iprt/tar.h>
39#include <iprt/vfs.h>
40#include <iprt/cpp/list.h>
41
42#ifdef RT_OS_WINDOWS
43#define VBOXMANAGE "VBoxManage.exe"
44#else /* !RT_OS_WINDOWS */
45#define VBOXMANAGE "VBoxManage"
46#endif /* !RT_OS_WINDOWS */
47
48/* Base */
49
50DECL_INLINE_THROW(void) handleRtError(int rc, const char *pszMsgFmt, ...)
51{
52 if (RT_FAILURE(rc))
53 {
54 va_list va;
55 va_start(va, pszMsgFmt);
56 RTCString strMsg(pszMsgFmt, va);
57 va_end(va);
58 strMsg.appendPrintfNoThrow(". %Rrf\n", rc);
59 throw RTCError(strMsg);
60 }
61}
62
63DECL_INLINE_THROW(void) handleComError(HRESULT hr, const char *pszMsgFmt, ...)
64{
65 if (FAILED(hr))
66 {
67 va_list va;
68 va_start(va, pszMsgFmt);
69 RTCString strMsg(pszMsgFmt, va);
70 va_end(va);
71 strMsg.appendPrintfNoThrow(". (hr=0x%x %Rhrc)\n", hr, hr);
72 throw RTCError(strMsg);
73 }
74}
75
76/*
77 * An auxiliary class to facilitate in-place path joins.
78 */
79class PathJoin
80{
81public:
82 PathJoin(const char *folder, const char *file) { m_path = RTPathJoinA(folder, file); }
83 ~PathJoin() { RTStrFree(m_path); };
84 operator char*() const { return m_path; };
85private:
86 char *m_path;
87};
88
89
90/*
91 * An abstract class serving as the root of the bug report filter tree.
92 * A child provides an implementation of the 'apply' method. A child
93 * should modify the input buffer (provided via pvSource) in place, or
94 * allocate a new buffer via 'allocateBuffer'. Allocated buffers are
95 * released automatically when another buffer is allocated, which means
96 * that NEXT CALL TO 'APPLY' INVALIDATES BUFFERS RETURNED IN PREVIOUS
97 * CALLS!
98 */
99class BugReportFilter
100{
101public:
102 BugReportFilter();
103 virtual ~BugReportFilter();
104 virtual void *apply(void *pvSource, size_t *pcbInOut) = 0;
105protected:
106 void *allocateBuffer(size_t cbNeeded);
107private:
108 void *m_pvBuffer;
109 size_t m_cbBuffer;
110};
111
112
113/*
114 * An abstract class serving as the root of the bug report item tree.
115 */
116class BugReportItem
117{
118public:
119 BugReportItem(const char *pszTitle);
120 virtual ~BugReportItem();
121 virtual const char *getTitle(void);
122 virtual PRTSTREAM getStream(void) = 0;
123 void addFilter(BugReportFilter *filter);
124 void *applyFilter(void *pvSource, size_t *pcbInOut);
125private:
126 char *m_pszTitle;
127 BugReportFilter *m_filter;
128};
129
130/*
131 * An abstract class to serve as a base class for all report types.
132 */
133class BugReport
134{
135public:
136 BugReport(const char *pszFileName);
137 virtual ~BugReport();
138
139 void addItem(BugReportItem* item, BugReportFilter *filter = 0);
140 int getItemCount(void);
141 void process();
142 void *applyFilters(BugReportItem* item, void *pvSource, size_t *pcbInOut);
143
144 virtual void processItem(BugReportItem* item) = 0;
145 virtual void complete(void) = 0;
146
147protected:
148 char *m_pszFileName;
149 RTCList<BugReportItem*> m_Items;
150};
151
152/*
153 * An auxiliary class providing formatted output into a temporary file for item
154 * classes that obtain data via host OS APIs.
155 */
156class BugReportStream : public BugReportItem
157{
158public:
159 BugReportStream(const char *pszTitle);
160 virtual ~BugReportStream();
161 virtual PRTSTREAM getStream(void);
162protected:
163 int printf(const char *pszFmt, ...);
164 int putStr(const char *pszString);
165private:
166 PRTSTREAM m_Strm;
167 char m_szFileName[RTPATH_MAX];
168};
169
170
171/* Generic */
172
173/*
174 * This class reports everything into a single text file.
175 */
176class BugReportText : public BugReport
177{
178public:
179 BugReportText(const char *pszFileName);
180 virtual ~BugReportText();
181 virtual void processItem(BugReportItem* item);
182 virtual void complete(void) {};
183private:
184 PRTSTREAM m_StrmTxt;
185};
186
187/*
188 * This class reports items as individual files archived into a single compressed TAR file.
189 */
190class BugReportTarGzip : public BugReport
191{
192public:
193 BugReportTarGzip(const char *pszFileName);
194 virtual ~BugReportTarGzip();
195 virtual void processItem(BugReportItem* item);
196 virtual void complete(void);
197private:
198 /*
199 * Helper class to release handles going out of scope.
200 */
201 class VfsIoStreamHandle
202 {
203 public:
204 VfsIoStreamHandle() : m_hVfsStream(NIL_RTVFSIOSTREAM) {};
205 ~VfsIoStreamHandle() { release(); }
206 PRTVFSIOSTREAM getPtr(void) { return &m_hVfsStream; };
207 RTVFSIOSTREAM get(void) { return m_hVfsStream; };
208 void release(void)
209 {
210 if (m_hVfsStream != NIL_RTVFSIOSTREAM)
211 RTVfsIoStrmRelease(m_hVfsStream);
212 m_hVfsStream = NIL_RTVFSIOSTREAM;
213 };
214 private:
215 RTVFSIOSTREAM m_hVfsStream;
216 };
217
218 VfsIoStreamHandle m_hVfsGzip;
219
220 RTTAR m_hTar;
221 RTTARFILE m_hTarFile;
222 char m_szTarName[RTPATH_MAX];
223};
224
225
226/*
227 * BugReportFile adds a file as an item to a report.
228 */
229class BugReportFile : public BugReportItem
230{
231public:
232 BugReportFile(const char *pszPath, const char *pcszName);
233 virtual ~BugReportFile();
234 virtual PRTSTREAM getStream(void);
235
236private:
237 char *m_pszPath;
238 PRTSTREAM m_Strm;
239};
240
241/*
242 * A base class for item classes that collect CLI output.
243 */
244class BugReportCommand : public BugReportItem
245{
246public:
247 BugReportCommand(const char *pszTitle, const char *pszExec, ...);
248 virtual ~BugReportCommand();
249 virtual PRTSTREAM getStream(void);
250private:
251 PRTSTREAM m_Strm;
252 char m_szFileName[RTPATH_MAX];
253 char *m_papszArgs[32];
254};
255
256/*
257 * A base class for item classes that provide temp output file to a command.
258 */
259class BugReportCommandTemp : public BugReportItem
260{
261public:
262 BugReportCommandTemp(const char *pszTitle, const char *pszExec, ...);
263 virtual ~BugReportCommandTemp();
264 virtual PRTSTREAM getStream(void);
265private:
266 PRTSTREAM m_Strm;
267 char m_szFileName[RTPATH_MAX];
268 char m_szErrFileName[RTPATH_MAX];
269 char *m_papszArgs[32];
270};
271
272/* Platform-specific */
273
274void createBugReportOsSpecific(BugReport* report, const char *pszHome);
275
276#endif /* !VBOX_INCLUDED_SRC_VBoxBugReport_VBoxBugReport_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette