VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgGui.cpp@ 93072

Last change on this file since 93072 was 90520, checked in by vboxsync, 3 years ago

VBoxDbg,FE/Qt: Added --statistics-expand=pat and --statistics-filter=pat command line options to VirtualBoxVM to simplify monitoring the same statistics in repeated test runs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/* $Id: VBoxDbgGui.cpp 90520 2021-08-04 21:37:54Z vboxsync $ */
2/** @file
3 * VBox Debugger GUI - The Manager.
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
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DBGG
23#define VBOX_COM_NO_ATL
24#include <VBox/com/defs.h>
25#include <iprt/errcore.h>
26
27#include "VBoxDbgGui.h"
28#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
29# include <QScreen>
30#else
31# include <QDesktopWidget>
32#endif
33#include <QApplication>
34
35
36
37VBoxDbgGui::VBoxDbgGui() :
38 m_pDbgStats(NULL), m_pDbgConsole(NULL), m_pSession(NULL), m_pConsole(NULL),
39 m_pMachineDebugger(NULL), m_pMachine(NULL), m_pUVM(NULL),
40 m_pParent(NULL), m_pMenu(NULL),
41 m_x(0), m_y(0), m_cx(0), m_cy(0), m_xDesktop(0), m_yDesktop(0), m_cxDesktop(0), m_cyDesktop(0)
42{
43
44}
45
46
47int VBoxDbgGui::init(PUVM pUVM)
48{
49 /*
50 * Set the VM handle and update the desktop size.
51 */
52 m_pUVM = pUVM; /* Note! This eats the incoming reference to the handle! */
53 updateDesktopSize();
54
55 return VINF_SUCCESS;
56}
57
58
59int VBoxDbgGui::init(ISession *pSession)
60{
61 int rc = VERR_GENERAL_FAILURE;
62
63 /*
64 * Query the VirtualBox interfaces.
65 */
66 m_pSession = pSession;
67 m_pSession->AddRef();
68
69 HRESULT hrc = m_pSession->COMGETTER(Machine)(&m_pMachine);
70 if (SUCCEEDED(hrc))
71 {
72 hrc = m_pSession->COMGETTER(Console)(&m_pConsole);
73 if (SUCCEEDED(hrc))
74 {
75 hrc = m_pConsole->COMGETTER(Debugger)(&m_pMachineDebugger);
76 if (SUCCEEDED(hrc))
77 {
78 /*
79 * Get the VM handle.
80 */
81 LONG64 llVM;
82 hrc = m_pMachineDebugger->COMGETTER(VM)(&llVM);
83 if (SUCCEEDED(hrc))
84 {
85 PUVM pUVM = (PUVM)(intptr_t)llVM;
86 rc = init(pUVM);
87 if (RT_SUCCESS(rc))
88 return rc;
89
90 VMR3ReleaseUVM(pUVM);
91 }
92
93 /* damn, failure! */
94 m_pMachineDebugger->Release();
95 m_pMachineDebugger = NULL;
96 }
97 m_pConsole->Release();
98 m_pConsole = NULL;
99 }
100 m_pMachine->Release();
101 m_pMachine = NULL;
102 }
103
104 return rc;
105}
106
107
108VBoxDbgGui::~VBoxDbgGui()
109{
110 if (m_pDbgStats)
111 {
112 delete m_pDbgStats;
113 m_pDbgStats = NULL;
114 }
115
116 if (m_pDbgConsole)
117 {
118 delete m_pDbgConsole;
119 m_pDbgConsole = NULL;
120 }
121
122 if (m_pMachineDebugger)
123 {
124 m_pMachineDebugger->Release();
125 m_pMachineDebugger = NULL;
126 }
127
128 if (m_pConsole)
129 {
130 m_pConsole->Release();
131 m_pConsole = NULL;
132 }
133
134 if (m_pMachine)
135 {
136 m_pMachine->Release();
137 m_pMachine = NULL;
138 }
139
140 if (m_pSession)
141 {
142 m_pSession->Release();
143 m_pSession = NULL;
144 }
145
146 if (m_pUVM)
147 {
148 VMR3ReleaseUVM(m_pUVM);
149 m_pUVM = NULL;
150 }
151}
152
153void
154VBoxDbgGui::setParent(QWidget *pParent)
155{
156 m_pParent = pParent;
157}
158
159
160void
161VBoxDbgGui::setMenu(QMenu *pMenu)
162{
163 m_pMenu = pMenu;
164}
165
166
167int
168VBoxDbgGui::showStatistics(const char *pszFilter, const char *pszExpand)
169{
170 if (!m_pDbgStats)
171 {
172 m_pDbgStats = new VBoxDbgStats(this,
173 pszFilter && *pszFilter ? pszFilter : "*",
174 pszExpand && *pszExpand ? pszExpand : NULL,
175 2, m_pParent);
176 connect(m_pDbgStats, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
177 repositionStatistics();
178 }
179
180 m_pDbgStats->vShow();
181 return VINF_SUCCESS;
182}
183
184
185void
186VBoxDbgGui::repositionStatistics(bool fResize/* = true*/)
187{
188 /*
189 * Move it to the right side of the VBox console,
190 * and resize it to cover all the space to the left side of the desktop.
191 */
192 if (m_pDbgStats)
193 m_pDbgStats->vReposition(m_x + m_cx, m_y,
194 m_cxDesktop - m_cx - m_x + m_xDesktop, m_cyDesktop - m_y + m_yDesktop,
195 fResize);
196}
197
198
199int
200VBoxDbgGui::showConsole()
201{
202 if (!m_pDbgConsole)
203 {
204 IVirtualBox *pVirtualBox = NULL;
205 m_pMachine->COMGETTER(Parent)(&pVirtualBox);
206 m_pDbgConsole = new VBoxDbgConsole(this, m_pParent, pVirtualBox);
207 connect(m_pDbgConsole, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
208 repositionConsole();
209 }
210
211 m_pDbgConsole->vShow();
212 return VINF_SUCCESS;
213}
214
215
216void
217VBoxDbgGui::repositionConsole(bool fResize/* = true*/)
218{
219 /*
220 * Move it to the bottom of the VBox console,
221 * and resize it to cover the space down to the bottom of the desktop.
222 */
223 if (m_pDbgConsole)
224 m_pDbgConsole->vReposition(m_x, m_y + m_cy,
225 RT_MAX(m_cx, 32), m_cyDesktop - m_cy - m_y + m_yDesktop,
226 fResize);
227}
228
229
230void
231VBoxDbgGui::updateDesktopSize()
232{
233 QRect Rct(0, 0, 1600, 1200);
234#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
235 QScreen *pScreen = QApplication::screenAt(QPoint(m_x, m_y));
236 if (pScreen)
237 Rct = pScreen->availableGeometry();
238#else
239 QDesktopWidget *pDesktop = QApplication::desktop();
240 if (pDesktop)
241 Rct = pDesktop->availableGeometry(QPoint(m_x, m_y));
242#endif
243 m_xDesktop = Rct.x();
244 m_yDesktop = Rct.y();
245 m_cxDesktop = Rct.width();
246 m_cyDesktop = Rct.height();
247}
248
249
250void
251VBoxDbgGui::adjustRelativePos(int x, int y, unsigned cx, unsigned cy)
252{
253 /* Disregard a width less than 640 since it will mess up the console,
254 * but only if previos width was already initialized.. */
255 if ((cx < 640) && (m_cx > 0))
256 cx = m_cx;
257
258 const bool fResize = cx != m_cx || cy != m_cy;
259 const bool fMoved = x != m_x || y != m_y;
260
261 m_x = x;
262 m_y = y;
263 m_cx = cx;
264 m_cy = cy;
265
266 if (fMoved)
267 updateDesktopSize();
268 repositionConsole(fResize);
269 repositionStatistics(fResize);
270}
271
272
273QString
274VBoxDbgGui::getMachineName() const
275{
276 QString strName;
277 AssertReturn(m_pMachine, strName);
278 BSTR bstr;
279 HRESULT hrc = m_pMachine->COMGETTER(Name)(&bstr);
280 if (SUCCEEDED(hrc))
281 {
282 strName = QString::fromUtf16(bstr);
283 SysFreeString(bstr);
284 }
285 return strName;
286}
287
288
289void
290VBoxDbgGui::notifyChildDestroyed(QObject *pObj)
291{
292 if (m_pDbgStats == pObj)
293 m_pDbgStats = NULL;
294 else if (m_pDbgConsole == pObj)
295 m_pDbgConsole = NULL;
296}
297
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