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