1 | /* $Id: VBoxDbg.cpp 92906 2021-12-14 22:14:27Z 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 <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 | */
|
---|
44 | typedef 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. */
|
---|
62 | static 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 ppGui See DBGGuiCreate.
|
---|
82 | * @param ppGuiVT See DBGGuiCreate.
|
---|
83 | */
|
---|
84 | static int dbgGuiCreate(ISession *pSession, PUVM pUVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
|
---|
85 | {
|
---|
86 | /*
|
---|
87 | * Allocate and initialize the Debugger GUI handle.
|
---|
88 | */
|
---|
89 | PDBGGUI pGui = (PDBGGUI)RTMemAlloc(sizeof(*pGui));
|
---|
90 | if (!pGui)
|
---|
91 | return VERR_NO_MEMORY;
|
---|
92 | pGui->u32Magic = DBGGUI_MAGIC;
|
---|
93 | pGui->pVBoxDbgGui = new VBoxDbgGui();
|
---|
94 |
|
---|
95 | int rc;
|
---|
96 | if (pSession)
|
---|
97 | rc = pGui->pVBoxDbgGui->init(pSession);
|
---|
98 | else
|
---|
99 | rc = pGui->pVBoxDbgGui->init(pUVM);
|
---|
100 | if (RT_SUCCESS(rc))
|
---|
101 | {
|
---|
102 | /*
|
---|
103 | * Successfully initialized.
|
---|
104 | */
|
---|
105 | *ppGui = pGui;
|
---|
106 | if (ppGuiVT)
|
---|
107 | *ppGuiVT = &g_dbgGuiVT;
|
---|
108 | return rc;
|
---|
109 | }
|
---|
110 |
|
---|
111 | /*
|
---|
112 | * Failed, cleanup.
|
---|
113 | */
|
---|
114 | delete pGui->pVBoxDbgGui;
|
---|
115 | RTMemFree(pGui);
|
---|
116 | *ppGui = NULL;
|
---|
117 | if (ppGuiVT)
|
---|
118 | *ppGuiVT = NULL;
|
---|
119 | return rc;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Creates the debugger GUI.
|
---|
125 | *
|
---|
126 | * @returns VBox status code.
|
---|
127 | * @param pSession The VirtualBox session.
|
---|
128 | * @param ppGui Where to store the pointer to the debugger instance.
|
---|
129 | * @param ppGuiVT Where to store the virtual method table pointer.
|
---|
130 | * Optional.
|
---|
131 | */
|
---|
132 | DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
|
---|
133 | {
|
---|
134 | AssertPtrReturn(pSession, VERR_INVALID_POINTER);
|
---|
135 | return dbgGuiCreate(pSession, NULL, ppGui, ppGuiVT);
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Creates the debugger GUI given a VM handle.
|
---|
141 | *
|
---|
142 | * @returns VBox status code.
|
---|
143 | * @param pUVM The VM handle.
|
---|
144 | * @param ppGui Where to store the pointer to the debugger instance.
|
---|
145 | * @param ppGuiVT Where to store the virtual method table pointer.
|
---|
146 | * Optional.
|
---|
147 | */
|
---|
148 | DBGDECL(int) DBGGuiCreateForVM(PUVM pUVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
|
---|
149 | {
|
---|
150 | AssertPtrReturn(pUVM, VERR_INVALID_POINTER);
|
---|
151 | AssertPtrReturn(VMR3RetainUVM(pUVM) != UINT32_MAX, VERR_INVALID_POINTER);
|
---|
152 |
|
---|
153 | int rc = dbgGuiCreate(NULL, pUVM, ppGui, ppGuiVT);
|
---|
154 |
|
---|
155 | VMR3ReleaseUVM(pUVM);
|
---|
156 | return rc;
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Destroys the debugger GUI.
|
---|
162 | *
|
---|
163 | * @returns VBox status code.
|
---|
164 | * @param pGui The instance returned by DBGGuiCreate().
|
---|
165 | */
|
---|
166 | DBGDECL(int) DBGGuiDestroy(PDBGGUI pGui)
|
---|
167 | {
|
---|
168 | /*
|
---|
169 | * Validate.
|
---|
170 | */
|
---|
171 | if (!pGui)
|
---|
172 | return VERR_INVALID_PARAMETER;
|
---|
173 | AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
|
---|
174 |
|
---|
175 | /*
|
---|
176 | * Do the job.
|
---|
177 | */
|
---|
178 | pGui->u32Magic = DBGGUI_MAGIC_DEAD;
|
---|
179 | delete pGui->pVBoxDbgGui;
|
---|
180 | RTMemFree(pGui);
|
---|
181 |
|
---|
182 | return VINF_SUCCESS;
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Notifies the debugger GUI that the console window (or whatever) has changed
|
---|
188 | * size or position.
|
---|
189 | *
|
---|
190 | * @param pGui The instance returned by DBGGuiCreate().
|
---|
191 | * @param x The x-coordinate of the window the debugger is relative to.
|
---|
192 | * @param y The y-coordinate of the window the debugger is relative to.
|
---|
193 | * @param cx The width of the window the debugger is relative to.
|
---|
194 | * @param cy The height of the window the debugger is relative to.
|
---|
195 | */
|
---|
196 | DBGDECL(void) DBGGuiAdjustRelativePos(PDBGGUI pGui, int x, int y, unsigned cx, unsigned cy)
|
---|
197 | {
|
---|
198 | AssertReturn(pGui, (void)VERR_INVALID_PARAMETER);
|
---|
199 | AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), (void)VERR_INVALID_PARAMETER);
|
---|
200 | pGui->pVBoxDbgGui->adjustRelativePos(x, y, cx, cy);
|
---|
201 | }
|
---|
202 |
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * Shows the default statistics window.
|
---|
206 | *
|
---|
207 | * @returns VBox status code.
|
---|
208 | * @param pGui The instance returned by DBGGuiCreate().
|
---|
209 | * @param pszFilter Filter pattern.
|
---|
210 | * @param pszExpand Expand pattern.
|
---|
211 | */
|
---|
212 | DBGDECL(int) DBGGuiShowStatistics(PDBGGUI pGui, const char *pszFilter, const char *pszExpand)
|
---|
213 | {
|
---|
214 | AssertReturn(pGui, VERR_INVALID_PARAMETER);
|
---|
215 | AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
|
---|
216 | return pGui->pVBoxDbgGui->showStatistics(pszFilter, pszExpand);
|
---|
217 | }
|
---|
218 |
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Shows the default command line window.
|
---|
222 | *
|
---|
223 | * @returns VBox status code.
|
---|
224 | * @param pGui The instance returned by DBGGuiCreate().
|
---|
225 | */
|
---|
226 | DBGDECL(int) DBGGuiShowCommandLine(PDBGGUI pGui)
|
---|
227 | {
|
---|
228 | AssertReturn(pGui, VERR_INVALID_PARAMETER);
|
---|
229 | AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
|
---|
230 | return pGui->pVBoxDbgGui->showConsole();
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Sets the parent windows.
|
---|
236 | *
|
---|
237 | * @param pGui The instance returned by DBGGuiCreate().
|
---|
238 | * @param pvParent Pointer to a QWidget object.
|
---|
239 | *
|
---|
240 | * @remarks This will no affect any existing windows, so call it right after
|
---|
241 | * creating the thing.
|
---|
242 | */
|
---|
243 | DBGDECL(void) DBGGuiSetParent(PDBGGUI pGui, void *pvParent)
|
---|
244 | {
|
---|
245 | return pGui->pVBoxDbgGui->setParent((QWidget *)pvParent);
|
---|
246 | }
|
---|
247 |
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * Sets the debug menu object.
|
---|
251 | *
|
---|
252 | * @param pGui The instance returned by DBGGuiCreate().
|
---|
253 | * @param pvMenu Pointer to a QMenu object.
|
---|
254 | *
|
---|
255 | * @remarks Call right after creation or risk losing menu item.
|
---|
256 | */
|
---|
257 | DBGDECL(void) DBGGuiSetMenu(PDBGGUI pGui, void *pvMenu)
|
---|
258 | {
|
---|
259 | return pGui->pVBoxDbgGui->setMenu((QMenu *)pvMenu);
|
---|
260 | }
|
---|
261 |
|
---|