1 | /* $Id: VBoxDbgBase.h 98103 2023-01-17 14:15:46Z 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 |
|
---|
43 | class 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 | */
|
---|
53 | class VBoxDbgBase
|
---|
54 | {
|
---|
55 | public:
|
---|
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 |
|
---|
104 | protected:
|
---|
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 |
|
---|
118 | private:
|
---|
119 | /** @callback_method_impl{FNVMATSTATE} */
|
---|
120 | static DECLCALLBACK(void) atStateChange(PUVM pUVM, PCVMMR3VTABLE pVMM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
|
---|
121 |
|
---|
122 | private:
|
---|
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 | */
|
---|
141 | class VBoxDbgBaseWindow : public QWidget, public VBoxDbgBase
|
---|
142 | {
|
---|
143 | public:
|
---|
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 | protected:
|
---|
175 | /**
|
---|
176 | * For polishing the window size (X11 mess).
|
---|
177 | *
|
---|
178 | * @returns true / false.
|
---|
179 | * @param a_pEvt The event.
|
---|
180 | */
|
---|
181 | virtual bool event(QEvent *a_pEvt);
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Event filter for various purposes (mainly title bar).
|
---|
185 | *
|
---|
186 | * @param pWatched The object event came to.
|
---|
187 | * @param pEvent The event being handled.
|
---|
188 | */
|
---|
189 | virtual bool eventFilter(QObject *pWatched, QEvent *pEvent);
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Internal worker for polishing the size and position (X11 hacks).
|
---|
193 | */
|
---|
194 | void vPolishSizeAndPos();
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Internal worker that guesses the border sizes.
|
---|
198 | */
|
---|
199 | QSize vGuessBorderSizes();
|
---|
200 |
|
---|
201 | private:
|
---|
202 | /** The Window title string (inflexible, read only). */
|
---|
203 | const char *m_pszTitle;
|
---|
204 | /** Whether we've done the size polishing in showEvent or not. */
|
---|
205 | bool m_fPolished;
|
---|
206 | /** The desired x coordinate. */
|
---|
207 | int m_x;
|
---|
208 | /** The desired y coordinate. */
|
---|
209 | int m_y;
|
---|
210 | /** The desired width. */
|
---|
211 | unsigned m_cx;
|
---|
212 | /** The desired height. */
|
---|
213 | unsigned m_cy;
|
---|
214 |
|
---|
215 | /** Best effort x border size (for X11). */
|
---|
216 | static unsigned m_cxBorder;
|
---|
217 | /** Best effort y border size (for X11). */
|
---|
218 | static unsigned m_cyBorder;
|
---|
219 | };
|
---|
220 |
|
---|
221 | #endif /* !DEBUGGER_INCLUDED_SRC_VBoxDbgBase_h */
|
---|
222 |
|
---|