VirtualBox

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

Last change on this file since 101027 was 100068, checked in by vboxsync, 19 months ago

FE/Qt and Debugger: bugref:10450: Qt6 compatibility bits for QString::fromUtf16 calls; ushort is replaced with char16_t.

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