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