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