1 | /* $Id: VBoxDbgGui.cpp 31510 2010-08-10 08:48:11Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Debugger GUI - The Manager.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
8 | *
|
---|
9 | * Oracle Corporation confidential
|
---|
10 | * All rights reserved
|
---|
11 | */
|
---|
12 |
|
---|
13 | /*******************************************************************************
|
---|
14 | * Header Files *
|
---|
15 | *******************************************************************************/
|
---|
16 | #define LOG_GROUP LOG_GROUP_DBGG
|
---|
17 | #define VBOX_COM_NO_ATL
|
---|
18 | #include <VBox/com/defs.h>
|
---|
19 | #include <VBox/vm.h>
|
---|
20 | #include <VBox/err.h>
|
---|
21 |
|
---|
22 | #include "VBoxDbgGui.h"
|
---|
23 | #include <QDesktopWidget>
|
---|
24 | #include <QApplication>
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 | VBoxDbgGui::VBoxDbgGui() :
|
---|
29 | m_pDbgStats(NULL), m_pDbgConsole(NULL), m_pSession(NULL), m_pConsole(NULL),
|
---|
30 | m_pMachineDebugger(NULL), m_pMachine(NULL), m_pVM(NULL),
|
---|
31 | m_pParent(NULL), m_pMenu(NULL),
|
---|
32 | m_x(0), m_y(0), m_cx(0), m_cy(0), m_xDesktop(0), m_yDesktop(0), m_cxDesktop(0), m_cyDesktop(0)
|
---|
33 | {
|
---|
34 |
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | int VBoxDbgGui::init(PVM pVM)
|
---|
39 | {
|
---|
40 | /*
|
---|
41 | * Set the VM handle and update the desktop size.
|
---|
42 | */
|
---|
43 | m_pVM = pVM;
|
---|
44 | updateDesktopSize();
|
---|
45 |
|
---|
46 | return VINF_SUCCESS;
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | int VBoxDbgGui::init(ISession *pSession)
|
---|
51 | {
|
---|
52 | int rc = VERR_GENERAL_FAILURE;
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * Query the VirtualBox interfaces.
|
---|
56 | */
|
---|
57 | m_pSession = pSession;
|
---|
58 | m_pSession->AddRef();
|
---|
59 |
|
---|
60 | HRESULT hrc = m_pSession->COMGETTER(Machine)(&m_pMachine);
|
---|
61 | if (SUCCEEDED(hrc))
|
---|
62 | {
|
---|
63 | hrc = m_pSession->COMGETTER(Console)(&m_pConsole);
|
---|
64 | if (SUCCEEDED(hrc))
|
---|
65 | {
|
---|
66 | hrc = m_pConsole->COMGETTER(Debugger)(&m_pMachineDebugger);
|
---|
67 | if (SUCCEEDED(hrc))
|
---|
68 | {
|
---|
69 | /*
|
---|
70 | * Get the VM handle.
|
---|
71 | */
|
---|
72 | ULONG64 ullVM;
|
---|
73 | hrc = m_pMachineDebugger->COMGETTER(VM)(&ullVM);
|
---|
74 | if (SUCCEEDED(hrc))
|
---|
75 | {
|
---|
76 | rc = init((PVM)(uintptr_t)ullVM);
|
---|
77 | if (RT_SUCCESS(rc))
|
---|
78 | return rc;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* damn, failure! */
|
---|
82 | m_pMachineDebugger->Release();
|
---|
83 | m_pMachineDebugger = NULL;
|
---|
84 | }
|
---|
85 | m_pConsole->Release();
|
---|
86 | m_pConsole = NULL;
|
---|
87 | }
|
---|
88 | m_pMachine->Release();
|
---|
89 | m_pMachine = NULL;
|
---|
90 | }
|
---|
91 |
|
---|
92 | return rc;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | VBoxDbgGui::~VBoxDbgGui()
|
---|
97 | {
|
---|
98 | if (m_pDbgStats)
|
---|
99 | {
|
---|
100 | delete m_pDbgStats;
|
---|
101 | m_pDbgStats = NULL;
|
---|
102 | }
|
---|
103 |
|
---|
104 | if (m_pDbgConsole)
|
---|
105 | {
|
---|
106 | delete m_pDbgConsole;
|
---|
107 | m_pDbgConsole = NULL;
|
---|
108 | }
|
---|
109 |
|
---|
110 | if (m_pMachineDebugger)
|
---|
111 | {
|
---|
112 | m_pMachineDebugger->Release();
|
---|
113 | m_pMachineDebugger = NULL;
|
---|
114 | }
|
---|
115 |
|
---|
116 | if (m_pConsole)
|
---|
117 | {
|
---|
118 | m_pConsole->Release();
|
---|
119 | m_pConsole = NULL;
|
---|
120 | }
|
---|
121 |
|
---|
122 | if (m_pMachine)
|
---|
123 | {
|
---|
124 | m_pMachine->Release();
|
---|
125 | m_pMachine = NULL;
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (m_pSession)
|
---|
129 | {
|
---|
130 | m_pSession->Release();
|
---|
131 | m_pSession = NULL;
|
---|
132 | }
|
---|
133 |
|
---|
134 | m_pVM = NULL;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void
|
---|
138 | VBoxDbgGui::setParent(QWidget *pParent)
|
---|
139 | {
|
---|
140 | m_pParent = pParent;
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | void
|
---|
145 | VBoxDbgGui::setMenu(QMenu *pMenu)
|
---|
146 | {
|
---|
147 | m_pMenu = pMenu;
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | int
|
---|
152 | VBoxDbgGui::showStatistics()
|
---|
153 | {
|
---|
154 | if (!m_pDbgStats)
|
---|
155 | {
|
---|
156 | m_pDbgStats = new VBoxDbgStats(this, "*", 2, m_pParent);
|
---|
157 | connect(m_pDbgStats, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
|
---|
158 | repositionStatistics();
|
---|
159 | }
|
---|
160 |
|
---|
161 | m_pDbgStats->vShow();
|
---|
162 | return VINF_SUCCESS;
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | void
|
---|
167 | VBoxDbgGui::repositionStatistics(bool fResize/* = true*/)
|
---|
168 | {
|
---|
169 | /*
|
---|
170 | * Move it to the right side of the VBox console,
|
---|
171 | * and resize it to cover all the space to the left side of the desktop.
|
---|
172 | */
|
---|
173 | if (m_pDbgStats)
|
---|
174 | m_pDbgStats->vReposition(m_x + m_cx, m_y,
|
---|
175 | m_cxDesktop - m_cx - m_x + m_xDesktop, m_cyDesktop - m_y + m_yDesktop,
|
---|
176 | fResize);
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | int
|
---|
181 | VBoxDbgGui::showConsole()
|
---|
182 | {
|
---|
183 | if (!m_pDbgConsole)
|
---|
184 | {
|
---|
185 | m_pDbgConsole = new VBoxDbgConsole(this, m_pParent);
|
---|
186 | connect(m_pDbgConsole, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
|
---|
187 | repositionConsole();
|
---|
188 | }
|
---|
189 |
|
---|
190 | m_pDbgConsole->vShow();
|
---|
191 | return VINF_SUCCESS;
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|
195 | void
|
---|
196 | VBoxDbgGui::repositionConsole(bool fResize/* = true*/)
|
---|
197 | {
|
---|
198 | /*
|
---|
199 | * Move it to the bottom of the VBox console,
|
---|
200 | * and resize it to cover the space down to the bottom of the desktop.
|
---|
201 | */
|
---|
202 | if (m_pDbgConsole)
|
---|
203 | m_pDbgConsole->vReposition(m_x, m_y + m_cy,
|
---|
204 | RT_MAX(m_cx, 32), m_cyDesktop - m_cy - m_y + m_yDesktop,
|
---|
205 | fResize);
|
---|
206 | }
|
---|
207 |
|
---|
208 |
|
---|
209 | void
|
---|
210 | VBoxDbgGui::updateDesktopSize()
|
---|
211 | {
|
---|
212 | QRect Rct(0, 0, 1600, 1200);
|
---|
213 | QDesktopWidget *pDesktop = QApplication::desktop();
|
---|
214 | if (pDesktop)
|
---|
215 | Rct = pDesktop->availableGeometry(QPoint(m_x, m_y));
|
---|
216 | m_xDesktop = Rct.x();
|
---|
217 | m_yDesktop = Rct.y();
|
---|
218 | m_cxDesktop = Rct.width();
|
---|
219 | m_cyDesktop = Rct.height();
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | void
|
---|
224 | VBoxDbgGui::adjustRelativePos(int x, int y, unsigned cx, unsigned cy)
|
---|
225 | {
|
---|
226 | /* Disregard a width less than 640 since it will mess up the console. */
|
---|
227 | if (cx < 640)
|
---|
228 | cx = m_cx;
|
---|
229 |
|
---|
230 | const bool fResize = cx != m_cx || cy != m_cy;
|
---|
231 | const bool fMoved = x != m_x || y != m_y;
|
---|
232 |
|
---|
233 | m_x = x;
|
---|
234 | m_y = y;
|
---|
235 | m_cx = cx;
|
---|
236 | m_cy = cy;
|
---|
237 |
|
---|
238 | if (fMoved)
|
---|
239 | updateDesktopSize();
|
---|
240 | repositionConsole(fResize);
|
---|
241 | repositionStatistics(fResize);
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | void
|
---|
246 | VBoxDbgGui::notifyChildDestroyed(QObject *pObj)
|
---|
247 | {
|
---|
248 | if (m_pDbgStats == pObj)
|
---|
249 | m_pDbgStats = NULL;
|
---|
250 | else if (m_pDbgConsole == pObj)
|
---|
251 | m_pDbgConsole = NULL;
|
---|
252 | }
|
---|
253 |
|
---|