VirtualBox

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

Last change on this file since 93460 was 93460, checked in by vboxsync, 3 years ago

Main/MachineDebugger,VBoxHeadless,VirtualBoxVM,VBoxSDL,VBoxDbg: Removed a few obsolete raw-mode attributes and changed the VM attribute into getUVMAndVMMFunctionTable, restricting it to calls from within the VM process. bugref:10074

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