VirtualBox

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

Last change on this file since 106579 was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

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