VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbg.cpp

Last change on this file was 103464, checked in by vboxsync, 3 months ago

VBoxDbg,FE/Qt: Made it possible to configure the sub-tree filtering via the command line. bugref:10376

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
1/* $Id: VBoxDbg.cpp 103464 2024-02-20 02:35:20Z vboxsync $ */
2/** @file
3 * VBox Debugger GUI.
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
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_DBGG
33#define VBOX_COM_NO_ATL
34#ifdef RT_OS_WINDOWS
35# include <iprt/win/windows.h> /* Include via cleanup wrapper before VirtualBox.h includes it via rpc.h. */
36# include <VirtualBox.h>
37#else /* !RT_OS_WINDOWS */
38# include <VirtualBox_XPCOM.h>
39#endif /* !RT_OS_WINDOWS */
40#include <VBox/dbggui.h>
41#include <iprt/errcore.h>
42#include <iprt/assert.h>
43#include <iprt/alloc.h>
44
45#include "VBoxDbgGui.h"
46
47
48/*********************************************************************************************************************************
49* Structures and Typedefs *
50*********************************************************************************************************************************/
51/**
52 * Debugger GUI instance data.
53 */
54typedef struct DBGGUI
55{
56 /** Magic number (DBGGUI_MAGIC). */
57 uint32_t u32Magic;
58 /** Pointer to the Debugger GUI manager object. */
59 VBoxDbgGui *pVBoxDbgGui;
60} DBGGUI;
61
62/** DBGGUI magic value (Werner Heisenberg). */
63#define DBGGUI_MAGIC 0x19011205
64/** Invalid DBGGUI magic value. */
65#define DBGGUI_MAGIC_DEAD 0x19760201
66
67
68/*********************************************************************************************************************************
69* Global Variables *
70*********************************************************************************************************************************/
71/** Virtual method table for simplifying dynamic linking. */
72static const DBGGUIVT g_dbgGuiVT =
73{
74 DBGGUIVT_VERSION,
75 DBGGuiDestroy,
76 DBGGuiAdjustRelativePos,
77 DBGGuiShowStatistics,
78 DBGGuiShowCommandLine,
79 DBGGuiSetParent,
80 DBGGuiSetMenu,
81 DBGGUIVT_VERSION
82};
83
84
85/**
86 * Internal worker for DBGGuiCreate and DBGGuiCreateForVM.
87 *
88 * @returns VBox status code.
89 * @param pSession The ISession interface. (DBGGuiCreate)
90 * @param pUVM The VM handle. (DBGGuiCreateForVM)
91 * @param pVMM The VMM function table.
92 * @param ppGui See DBGGuiCreate.
93 * @param ppGuiVT See DBGGuiCreate.
94 */
95static int dbgGuiCreate(ISession *pSession, PUVM pUVM, PCVMMR3VTABLE pVMM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
96{
97 /*
98 * Allocate and initialize the Debugger GUI handle.
99 */
100 PDBGGUI pGui = (PDBGGUI)RTMemAlloc(sizeof(*pGui));
101 if (!pGui)
102 return VERR_NO_MEMORY;
103 pGui->u32Magic = DBGGUI_MAGIC;
104 pGui->pVBoxDbgGui = new VBoxDbgGui();
105
106 int rc;
107 if (pSession)
108 rc = pGui->pVBoxDbgGui->init(pSession);
109 else
110 rc = pGui->pVBoxDbgGui->init(pUVM, pVMM);
111 if (RT_SUCCESS(rc))
112 {
113 /*
114 * Successfully initialized.
115 */
116 *ppGui = pGui;
117 if (ppGuiVT)
118 *ppGuiVT = &g_dbgGuiVT;
119 return rc;
120 }
121
122 /*
123 * Failed, cleanup.
124 */
125 delete pGui->pVBoxDbgGui;
126 RTMemFree(pGui);
127 *ppGui = NULL;
128 if (ppGuiVT)
129 *ppGuiVT = NULL;
130 return rc;
131}
132
133
134/**
135 * Creates the debugger GUI.
136 *
137 * @returns VBox status code.
138 * @param pSession The VirtualBox session.
139 * @param ppGui Where to store the pointer to the debugger instance.
140 * @param ppGuiVT Where to store the virtual method table pointer.
141 * Optional.
142 */
143DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
144{
145 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
146 return dbgGuiCreate(pSession, NULL, NULL, ppGui, ppGuiVT);
147}
148
149
150/**
151 * Creates the debugger GUI given a VM handle.
152 *
153 * @returns VBox status code.
154 * @param pUVM The VM handle.
155 * @param pVMM The VMM function table.
156 * @param ppGui Where to store the pointer to the debugger instance.
157 * @param ppGuiVT Where to store the virtual method table pointer.
158 * Optional.
159 */
160DBGDECL(int) DBGGuiCreateForVM(PUVM pUVM, PCVMMR3VTABLE pVMM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
161{
162 AssertPtrReturn(pUVM, VERR_INVALID_POINTER);
163 AssertPtrReturn(pVMM, VERR_INVALID_POINTER);
164 AssertReturn(VMMR3VTABLE_IS_COMPATIBLE(pVMM->uMagicVersion), VERR_VERSION_MISMATCH);
165 AssertReturn(pVMM->pfnVMR3RetainUVM(pUVM) != UINT32_MAX, VERR_INVALID_POINTER);
166
167 int rc = dbgGuiCreate(NULL, pUVM, pVMM, ppGui, ppGuiVT);
168
169 pVMM->pfnVMR3ReleaseUVM(pUVM);
170 return rc;
171}
172
173
174/**
175 * Destroys the debugger GUI.
176 *
177 * @returns VBox status code.
178 * @param pGui The instance returned by DBGGuiCreate().
179 */
180DBGDECL(int) DBGGuiDestroy(PDBGGUI pGui)
181{
182 /*
183 * Validate.
184 */
185 if (!pGui)
186 return VERR_INVALID_PARAMETER;
187 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
188
189 /*
190 * Do the job.
191 */
192 pGui->u32Magic = DBGGUI_MAGIC_DEAD;
193 delete pGui->pVBoxDbgGui;
194 RTMemFree(pGui);
195
196 return VINF_SUCCESS;
197}
198
199
200/**
201 * Notifies the debugger GUI that the console window (or whatever) has changed
202 * size or position.
203 *
204 * @param pGui The instance returned by DBGGuiCreate().
205 * @param x The x-coordinate of the window the debugger is relative to.
206 * @param y The y-coordinate of the window the debugger is relative to.
207 * @param cx The width of the window the debugger is relative to.
208 * @param cy The height of the window the debugger is relative to.
209 */
210DBGDECL(void) DBGGuiAdjustRelativePos(PDBGGUI pGui, int x, int y, unsigned cx, unsigned cy)
211{
212 AssertReturn(pGui, (void)VERR_INVALID_PARAMETER);
213 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), (void)VERR_INVALID_PARAMETER);
214 pGui->pVBoxDbgGui->adjustRelativePos(x, y, cx, cy);
215}
216
217
218/**
219 * Shows the default statistics window.
220 *
221 * @returns VBox status code.
222 * @param pGui The instance returned by DBGGuiCreate().
223 * @param pszFilter Filter pattern.
224 * @param pszExpand Expand pattern.
225 * @param pszConfig Advanced filter configuration (min/max/regexp on
226 * sub-trees) and more.
227 */
228DBGDECL(int) DBGGuiShowStatistics(PDBGGUI pGui, const char *pszFilter, const char *pszExpand, const char *pszConfig)
229{
230 AssertReturn(pGui, VERR_INVALID_PARAMETER);
231 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
232 return pGui->pVBoxDbgGui->showStatistics(pszFilter, pszExpand, pszConfig);
233}
234
235
236/**
237 * Shows the default command line window.
238 *
239 * @returns VBox status code.
240 * @param pGui The instance returned by DBGGuiCreate().
241 */
242DBGDECL(int) DBGGuiShowCommandLine(PDBGGUI pGui)
243{
244 AssertReturn(pGui, VERR_INVALID_PARAMETER);
245 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
246 return pGui->pVBoxDbgGui->showConsole();
247}
248
249
250/**
251 * Sets the parent windows.
252 *
253 * @param pGui The instance returned by DBGGuiCreate().
254 * @param pvParent Pointer to a QWidget object.
255 *
256 * @remarks This will no affect any existing windows, so call it right after
257 * creating the thing.
258 */
259DBGDECL(void) DBGGuiSetParent(PDBGGUI pGui, void *pvParent)
260{
261 return pGui->pVBoxDbgGui->setParent((QWidget *)pvParent);
262}
263
264
265/**
266 * Sets the debug menu object.
267 *
268 * @param pGui The instance returned by DBGGuiCreate().
269 * @param pvMenu Pointer to a QMenu object.
270 *
271 * @remarks Call right after creation or risk losing menu item.
272 */
273DBGDECL(void) DBGGuiSetMenu(PDBGGUI pGui, void *pvMenu)
274{
275 return pGui->pVBoxDbgGui->setMenu((QMenu *)pvMenu);
276}
277
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use