VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgBase.h@ 103068

Last change on this file since 103068 was 101107, checked in by vboxsync, 15 months ago

VBoxDbg: Rewrote the automatic window positioning to make it more flexible and to try keep the console window wide enough for at least 80 columns of text.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: VBoxDbgBase.h 101107 2023-09-13 14:01:58Z vboxsync $ */
2/** @file
3 * VBox Debugger GUI - Base classes.
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#ifndef DEBUGGER_INCLUDED_SRC_VBoxDbgBase_h
29#define DEBUGGER_INCLUDED_SRC_VBoxDbgBase_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34
35#include <VBox/vmm/stam.h>
36#include <VBox/vmm/vmapi.h>
37#include <VBox/vmm/vmmr3vtable.h>
38#include <VBox/dbg.h>
39#include <iprt/thread.h>
40#include <QString>
41#include <QWidget>
42
43class VBoxDbgGui;
44
45
46/**
47 * VBox Debugger GUI Base Class.
48 *
49 * The purpose of this class is to hide the VM handle, abstract VM
50 * operations, and finally to make sure the GUI won't crash when
51 * the VM dies.
52 */
53class VBoxDbgBase
54{
55public:
56 /**
57 * Construct the object.
58 *
59 * @param a_pDbgGui Pointer to the debugger gui object.
60 */
61 VBoxDbgBase(VBoxDbgGui *a_pDbgGui);
62
63 /**
64 * Destructor.
65 */
66 virtual ~VBoxDbgBase();
67
68
69 /**
70 * Checks if the VM is OK for normal operations.
71 * @returns true if ok, false if not.
72 */
73 bool isVMOk() const
74 {
75 return m_pUVM != NULL;
76 }
77
78 /**
79 * Checks if the current thread is the GUI thread or not.
80 * @return true/false accordingly.
81 */
82 bool isGUIThread() const
83 {
84 return m_hGUIThread == RTThreadNativeSelf();
85 }
86
87 /** @name Operations
88 * @{ */
89 /**
90 * Wrapper for STAMR3Reset().
91 */
92 int stamReset(const QString &rPat);
93 /**
94 * Wrapper for STAMR3Enum().
95 */
96 int stamEnum(const QString &rPat, PFNSTAMR3ENUM pfnEnum, void *pvUser);
97 /**
98 * Wrapper for DBGCCreate().
99 */
100 int dbgcCreate(PCDBGCIO pIo, unsigned fFlags);
101 /** @} */
102
103
104protected:
105 /** @name Signals
106 * @{ */
107 /**
108 * Called when the VM is being destroyed.
109 */
110 virtual void sigDestroying();
111 /**
112 * Called when the VM has been terminated.
113 */
114 virtual void sigTerminated();
115 /** @} */
116
117
118private:
119 /** @callback_method_impl{FNVMATSTATE} */
120 static DECLCALLBACK(void) atStateChange(PUVM pUVM, PCVMMR3VTABLE pVMM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
121
122private:
123 /** Pointer to the debugger GUI object. */
124 VBoxDbgGui *m_pDbgGui;
125 /** The user mode VM handle. */
126 PUVM volatile m_pUVM;
127 /** The VMM function table. */
128 PCVMMR3VTABLE volatile m_pVMM;
129 /** The handle of the GUI thread. */
130 RTNATIVETHREAD m_hGUIThread;
131};
132
133
134/**
135 * VBox Debugger GUI Base Window Class.
136 *
137 * This is just a combination of QWidget and VBoxDbgBase with some additional
138 * functionality for window management. This class is not intended for control
139 * widgets, only normal top-level windows.
140 */
141class VBoxDbgBaseWindow : public QWidget, public VBoxDbgBase
142{
143public:
144 /**
145 * Construct the object.
146 *
147 * @param a_pDbgGui Pointer to the debugger gui object.
148 * @param a_pParent Pointer to the parent object.
149 * @param a_pszTitle The window title string (persistent, not copied).
150 */
151 VBoxDbgBaseWindow(VBoxDbgGui *a_pDbgGui, QWidget *a_pParent, const char *a_pszTitle);
152
153 /**
154 * Destructor.
155 */
156 virtual ~VBoxDbgBaseWindow();
157
158 /**
159 * Shows the window and gives it focus.
160 */
161 void vShow();
162
163 /**
164 * Repositions the window, taking the frame decoration into account.
165 *
166 * @param a_x The new x coordinate.
167 * @param a_y The new x coordinate.
168 * @param a_cx The total width.
169 * @param a_cy The total height.
170 * @param a_fResize Whether to resize it as well.
171 */
172 void vReposition(int a_x, int a_y, unsigned a_cx, unsigned a_cy, bool a_fResize);
173
174 /**
175 * Gets the minimum client area width hint.
176 */
177 unsigned vGetMinWidthHint(void) const RT_NOEXCEPT
178 {
179 return m_cxMinHint;
180 }
181
182protected:
183 /**
184 * Sets the minimum client area width hint (without frame).
185 */
186 void vSetMinWidthHint(unsigned a_cxMin)
187 {
188 m_cxMinHint = a_cxMin;
189 }
190
191
192public:
193 /** VM window magnetic attraction. */
194 typedef enum
195 { kAttractionVmLeft, kAttractionVmRight, kAttractionVmTop, kAttractionVmBottom, kAttractionVmNone } VBoxDbgAttractionType;
196
197 /**
198 * Gets the window attraction.
199 */
200 VBoxDbgAttractionType vGetWindowAttraction(void) const RT_NOEXCEPT
201 {
202 return m_enmAttraction;
203 }
204
205 /**
206 * Sets the window attraction.
207 */
208 void vSetWindowAttraction(VBoxDbgAttractionType a_enmAttraction) RT_NOEXCEPT
209 {
210 m_enmAttraction = a_enmAttraction;
211 }
212
213 /**
214 * Get the border size for the window.
215 *
216 * This may return different values after the window has been shown,
217 * at least on X11.
218 */
219 QSize vGetBorderSize();
220
221protected:
222 /**
223 * For polishing the window size (X11 mess).
224 *
225 * @returns true / false.
226 * @param a_pEvt The event.
227 */
228 virtual bool event(QEvent *a_pEvt);
229
230 /**
231 * Event filter for various purposes (mainly title bar).
232 *
233 * @param pWatched The object event came to.
234 * @param pEvent The event being handled.
235 */
236 virtual bool eventFilter(QObject *pWatched, QEvent *pEvent);
237
238 /**
239 * Internal worker for polishing the size and position (X11 hacks).
240 */
241 void vPolishSizeAndPos();
242
243private:
244 /** The Window title string (inflexible, read only). */
245 const char *m_pszTitle;
246 /** Whether we've done the size polishing in showEvent or not. */
247 bool m_fPolished;
248 /** The desired x coordinate. */
249 int m_x;
250 /** The desired y coordinate. */
251 int m_y;
252 /** The desired width. */
253 unsigned m_cx;
254 /** The desired height. */
255 unsigned m_cy;
256 /** Minimum client area width hint (for the console window, etc). */
257 unsigned m_cxMinHint;
258 /** The window attraction. */
259 VBoxDbgAttractionType m_enmAttraction;
260
261 /** Best effort x border size (for X11). */
262 static unsigned m_cxBorder;
263 /** Best effort y border size (for X11). */
264 static unsigned m_cyBorder;
265};
266
267#endif /* !DEBUGGER_INCLUDED_SRC_VBoxDbgBase_h */
268
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