VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgBase.cpp@ 31510

Last change on this file since 31510 was 31510, checked in by vboxsync, 15 years ago

The debugger is back in the OSE.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: VBoxDbgBase.cpp 31510 2010-08-10 08:48:11Z vboxsync $ */
2/** @file
3 * VBox Debugger GUI - Base classes.
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#include <VBox/err.h>
18#include <iprt/asm.h>
19#include <iprt/assert.h>
20#include <limits.h>
21#include "VBoxDbgBase.h"
22#include "VBoxDbgGui.h"
23
24#include <QApplication>
25#include <QWidgetList>
26
27
28
29VBoxDbgBase::VBoxDbgBase(VBoxDbgGui *a_pDbgGui)
30 : m_pDbgGui(a_pDbgGui), m_pVM(NULL), m_hGUIThread(RTThreadNativeSelf())
31{
32 /*
33 * Register
34 */
35 PVM pVM = a_pDbgGui->getVMHandle();
36 if (pVM)
37 {
38 m_pVM = pVM;
39 int rc = VMR3AtStateRegister(pVM, atStateChange, this);
40 AssertRC(rc);
41 }
42}
43
44
45VBoxDbgBase::~VBoxDbgBase()
46{
47 /*
48 * If the VM is still around.
49 */
50 /** @todo need to do some locking here? */
51 PVM pVM = ASMAtomicXchgPtrT(&m_pVM, NULL, PVM);
52 if (pVM)
53 {
54 int rc = VMR3AtStateDeregister(pVM, atStateChange, this);
55 AssertRC(rc);
56 }
57}
58
59
60int
61VBoxDbgBase::stamReset(const QString &rPat)
62{
63 QByteArray Utf8Array = rPat.toUtf8();
64 const char *pszPat = !rPat.isEmpty() ? Utf8Array.constData() : NULL;
65 PVM pVM = m_pVM;
66 if ( pVM
67 && VMR3GetState(pVM) < VMSTATE_DESTROYING)
68 return STAMR3Reset(pVM, pszPat);
69 return VERR_INVALID_HANDLE;
70}
71
72
73int
74VBoxDbgBase::stamEnum(const QString &rPat, PFNSTAMR3ENUM pfnEnum, void *pvUser)
75{
76 QByteArray Utf8Array = rPat.toUtf8();
77 const char *pszPat = !rPat.isEmpty() ? Utf8Array.constData() : NULL;
78 PVM pVM = m_pVM;
79 if ( pVM
80 && VMR3GetState(pVM) < VMSTATE_DESTROYING)
81 return STAMR3Enum(pVM, pszPat, pfnEnum, pvUser);
82 return VERR_INVALID_HANDLE;
83}
84
85
86int
87VBoxDbgBase::dbgcCreate(PDBGCBACK pBack, unsigned fFlags)
88{
89 PVM pVM = m_pVM;
90 if ( pVM
91 && VMR3GetState(pVM) < VMSTATE_DESTROYING)
92 return DBGCCreate(pVM, pBack, fFlags);
93 return VERR_INVALID_HANDLE;
94}
95
96
97/*static*/ DECLCALLBACK(void)
98VBoxDbgBase::atStateChange(PVM pVM, VMSTATE enmState, VMSTATE /*enmOldState*/, void *pvUser)
99{
100 VBoxDbgBase *pThis = (VBoxDbgBase *)pvUser;
101 switch (enmState)
102 {
103 case VMSTATE_TERMINATED:
104 /** @todo need to do some locking here? */
105 if (ASMAtomicCmpXchgPtr(&pThis->m_pVM, NULL, pVM))
106 pThis->sigTerminated();
107 break;
108
109 case VMSTATE_DESTROYING:
110 pThis->sigDestroying();
111 break;
112
113 default:
114 break;
115 }
116}
117
118
119void
120VBoxDbgBase::sigDestroying()
121{
122}
123
124
125void
126VBoxDbgBase::sigTerminated()
127{
128}
129
130
131
132
133//
134//
135//
136// V B o x D b g B a s e W i n d o w
137// V B o x D b g B a s e W i n d o w
138// V B o x D b g B a s e W i n d o w
139//
140//
141//
142
143unsigned VBoxDbgBaseWindow::m_cxBorder = 0;
144unsigned VBoxDbgBaseWindow::m_cyBorder = 0;
145
146
147VBoxDbgBaseWindow::VBoxDbgBaseWindow(VBoxDbgGui *a_pDbgGui, QWidget *a_pParent)
148 : QWidget(a_pParent, Qt::Window), VBoxDbgBase(a_pDbgGui),
149#ifdef Q_WS_X11
150 m_fPolished(false),
151#else
152 m_fPolished(true),
153#endif
154 m_x(INT_MAX), m_y(INT_MAX), m_cx(0), m_cy(0)
155{
156}
157
158
159VBoxDbgBaseWindow::~VBoxDbgBaseWindow()
160{
161
162}
163
164
165void
166VBoxDbgBaseWindow::vShow()
167{
168 show();
169 /** @todo this ain't working right. HELP! */
170 setWindowState(windowState() & ~Qt::WindowMinimized);
171 //activateWindow();
172 //setFocus();
173 vPolishSizeAndPos();
174}
175
176
177void
178VBoxDbgBaseWindow::vReposition(int a_x, int a_y, unsigned a_cx, unsigned a_cy, bool a_fResize)
179{
180 if (a_fResize)
181 {
182 m_cx = a_cx;
183 m_cy = a_cy;
184
185 QSize BorderSize = frameSize() - size();
186 if (BorderSize == QSize(0,0))
187 BorderSize = vGuessBorderSizes();
188
189 resize(a_cx - BorderSize.width(), a_cy - BorderSize.height());
190 }
191
192 m_x = a_x;
193 m_y = a_y;
194 move(a_x, a_y);
195}
196
197
198bool
199VBoxDbgBaseWindow::event(QEvent *a_pEvt)
200{
201 bool fRc = QWidget::event(a_pEvt);
202 vPolishSizeAndPos();
203 return fRc;
204}
205
206
207void
208VBoxDbgBaseWindow::vPolishSizeAndPos()
209{
210 /* Ignore if already done or no size set. */
211 if ( m_fPolished
212 || (m_x == INT_MAX && m_y == INT_MAX))
213 return;
214
215 QSize BorderSize = frameSize() - size();
216 if (BorderSize != QSize(0,0))
217 m_fPolished = true;
218
219 vReposition(m_x, m_y, m_cx, m_cy, m_cx || m_cy);
220}
221
222
223QSize
224VBoxDbgBaseWindow::vGuessBorderSizes()
225{
226#ifdef Q_WS_X11 /* (from the qt gui) */
227 /* only once. */
228 if (!m_cxBorder && !m_cyBorder)
229 {
230
231 /* On X11, there is no way to determine frame geometry (including WM
232 * decorations) before the widget is shown for the first time. Stupidly
233 * enumerate other top level widgets to find the thickest frame. The code
234 * is based on the idea taken from QDialog::adjustPositionInternal(). */
235
236 int extraw = 0, extrah = 0;
237
238 QWidgetList list = QApplication::topLevelWidgets();
239 QListIterator<QWidget*> it (list);
240 while ((extraw == 0 || extrah == 0) && it.hasNext())
241 {
242 int framew, frameh;
243 QWidget *current = it.next();
244 if (!current->isVisible())
245 continue;
246
247 framew = current->frameGeometry().width() - current->width();
248 frameh = current->frameGeometry().height() - current->height();
249
250 extraw = qMax (extraw, framew);
251 extrah = qMax (extrah, frameh);
252 }
253
254 if (extraw || extrah)
255 {
256 m_cxBorder = extraw;
257 m_cyBorder = extrah;
258 }
259 }
260#endif /* X11 */
261 return QSize(m_cxBorder, m_cyBorder);
262}
263
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