7 * Copyright (C) 2006-2010 Oracle Corporation
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.
18 /*******************************************************************************
20 *******************************************************************************/
21 #define LOG_GROUP LOG_GROUP_DBGG
22 #define VBOX_COM_NO_ATL
23 #include <VBox/dbggui.h>
24 #include <VBox/vmm/vm.h>
26 #include <iprt/assert.h>
27 #include <iprt/alloc.h>
29 #include "VBoxDbgGui.h"
32 /*******************************************************************************
33 * Structures and Typedefs *
34 *******************************************************************************/
36 * Debugger GUI instance data.
40 /** Magic number (DBGGUI_MAGIC). */
42 /** Pointer to the Debugger GUI manager object. */
43 VBoxDbgGui
*pVBoxDbgGui
;
46 /** DBGGUI magic value (Werner Heisenberg). */
47 #define DBGGUI_MAGIC 0x19011205
48 /** Invalid DBGGUI magic value. */
49 #define DBGGUI_MAGIC_DEAD 0x19760201
52 /*******************************************************************************
54 *******************************************************************************/
55 /** Virtual method table for simplifying dynamic linking. */
56 static const DBGGUIVT g_dbgGuiVT
=
60 DBGGuiAdjustRelativePos
,
62 DBGGuiShowCommandLine
,
70 * Internal worker for DBGGuiCreate and DBGGuiCreateForVM.
72 * @returns VBox status code.
73 * @param pSession The ISession interface. (DBGGuiCreate)
74 * @param pVM The VM handle. (DBGGuiCreateForVM)
75 * @param ppGui See DBGGuiCreate.
76 * @param ppGuiVT See DBGGuiCreate.
78 static int dbgGuiCreate(ISession
*pSession
, PVM pVM
, PDBGGUI
*ppGui
, PCDBGGUIVT
*ppGuiVT
)
81 * Allocate and initialize the Debugger GUI handle.
83 PDBGGUI pGui
= (PDBGGUI
)RTMemAlloc(sizeof(*pGui
));
85 return VERR_NO_MEMORY
;
86 pGui
->u32Magic
= DBGGUI_MAGIC
;
87 pGui
->pVBoxDbgGui
= new VBoxDbgGui();
91 rc
= pGui
->pVBoxDbgGui
->init(pSession
);
93 rc
= pGui
->pVBoxDbgGui
->init(pVM
);
97 * Successfully initialized.
101 *ppGuiVT
= &g_dbgGuiVT
;
108 delete pGui
->pVBoxDbgGui
;
118 * Creates the debugger GUI.
120 * @returns VBox status code.
121 * @param pSession The VirtualBox session.
122 * @param ppGui Where to store the pointer to the debugger instance.
123 * @param ppGuiVT Where to store the virtual method table pointer.
126 DBGDECL(int) DBGGuiCreate(ISession
*pSession
, PDBGGUI
*ppGui
, PCDBGGUIVT
*ppGuiVT
)
128 AssertPtrReturn(pSession
, VERR_INVALID_POINTER
);
129 return dbgGuiCreate(pSession
, NULL
, ppGui
, ppGuiVT
);
134 * Creates the debugger GUI given a VM handle.
136 * @returns VBox status code.
137 * @param pVM The VM handle.
138 * @param ppGui Where to store the pointer to the debugger instance.
139 * @param ppGuiVT Where to store the virtual method table pointer.
142 DBGDECL(int) DBGGuiCreateForVM(PVM pVM
, PDBGGUI
*ppGui
, PCDBGGUIVT
*ppGuiVT
)
144 AssertPtrReturn(pVM
, VERR_INVALID_POINTER
);
145 return dbgGuiCreate(NULL
, pVM
, ppGui
, ppGuiVT
);
150 * Destroys the debugger GUI.
152 * @returns VBox status code.
153 * @param pGui The instance returned by DBGGuiCreate().
155 DBGDECL(int) DBGGuiDestroy(PDBGGUI pGui
)
161 return VERR_INVALID_PARAMETER
;
162 AssertMsgReturn(pGui
->u32Magic
== DBGGUI_MAGIC
, ("u32Magic=%#x\n", pGui
->u32Magic
), VERR_INVALID_PARAMETER
);
167 pGui
->u32Magic
= DBGGUI_MAGIC_DEAD
;
168 delete pGui
->pVBoxDbgGui
;
176 * Notifies the debugger GUI that the console window (or whatever) has changed
179 * @param pGui The instance returned by DBGGuiCreate().
180 * @param x The x-coordinate of the window the debugger is relative to.
181 * @param y The y-coordinate of the window the debugger is relative to.
182 * @param cx The width of the window the debugger is relative to.
183 * @param cy The height of the window the debugger is relative to.
185 DBGDECL(void) DBGGuiAdjustRelativePos(PDBGGUI pGui
, int x
, int y
, unsigned cx
, unsigned cy
)
187 AssertReturn(pGui
, (void)VERR_INVALID_PARAMETER
);
188 AssertMsgReturn(pGui
->u32Magic
== DBGGUI_MAGIC
, ("u32Magic=%#x\n", pGui
->u32Magic
), (void)VERR_INVALID_PARAMETER
);
189 pGui
->pVBoxDbgGui
->adjustRelativePos(x
, y
, cx
, cy
);
194 * Shows the default statistics window.
196 * @returns VBox status code.
197 * @param pGui The instance returned by DBGGuiCreate().
199 DBGDECL(int) DBGGuiShowStatistics(PDBGGUI pGui
)
201 AssertReturn(pGui
, VERR_INVALID_PARAMETER
);
202 AssertMsgReturn(pGui
->u32Magic
== DBGGUI_MAGIC
, ("u32Magic=%#x\n", pGui
->u32Magic
), VERR_INVALID_PARAMETER
);
203 return pGui
->pVBoxDbgGui
->showStatistics();
208 * Shows the default command line window.
210 * @returns VBox status code.
211 * @param pGui The instance returned by DBGGuiCreate().
213 DBGDECL(int) DBGGuiShowCommandLine(PDBGGUI pGui
)
215 AssertReturn(pGui
, VERR_INVALID_PARAMETER
);
216 AssertMsgReturn(pGui
->u32Magic
== DBGGUI_MAGIC
, ("u32Magic=%#x\n", pGui
->u32Magic
), VERR_INVALID_PARAMETER
);
217 return pGui
->pVBoxDbgGui
->showConsole();
222 * Sets the parent windows.
224 * @param pGui The instance returned by DBGGuiCreate().
225 * @param pvParent Pointer to a QWidget object.
227 * @remarks This will no affect any existing windows, so call it right after
228 * creating the thing.
230 DBGDECL(void) DBGGuiSetParent(PDBGGUI pGui
, void *pvParent
)
232 return pGui
->pVBoxDbgGui
->setParent((QWidget
*)pvParent
);
237 * Sets the debug menu object.
239 * @param pGui The instance returned by DBGGuiCreate().
240 * @param pvMenu Pointer to a QMenu object.
242 * @remarks Call right after creation or risk losing menu item.
244 DBGDECL(void) DBGGuiSetMenu(PDBGGUI pGui
, void *pvMenu
)
246 return pGui
->pVBoxDbgGui
->setMenu((QMenu
*)pvMenu
);