tools/*: remove bcc and as86 as they are no longer required to compile the system...
[virtualbox.git] / src / VBox / Debugger / VBoxDbg.cpp
blob84b8832d7b74972bff5b86e1c0f944ccaff4aa98
1 /* $Id$ */
2 /** @file
3 * VBox Debugger GUI.
4 */
6 /*
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 /*******************************************************************************
19 * Header Files *
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>
25 #include <VBox/err.h>
26 #include <iprt/assert.h>
27 #include <iprt/alloc.h>
29 #include "VBoxDbgGui.h"
32 /*******************************************************************************
33 * Structures and Typedefs *
34 *******************************************************************************/
35 /**
36 * Debugger GUI instance data.
38 typedef struct DBGGUI
40 /** Magic number (DBGGUI_MAGIC). */
41 uint32_t u32Magic;
42 /** Pointer to the Debugger GUI manager object. */
43 VBoxDbgGui *pVBoxDbgGui;
44 } DBGGUI;
46 /** DBGGUI magic value (Werner Heisenberg). */
47 #define DBGGUI_MAGIC 0x19011205
48 /** Invalid DBGGUI magic value. */
49 #define DBGGUI_MAGIC_DEAD 0x19760201
52 /*******************************************************************************
53 * Global Variables *
54 *******************************************************************************/
55 /** Virtual method table for simplifying dynamic linking. */
56 static const DBGGUIVT g_dbgGuiVT =
58 DBGGUIVT_VERSION,
59 DBGGuiDestroy,
60 DBGGuiAdjustRelativePos,
61 DBGGuiShowStatistics,
62 DBGGuiShowCommandLine,
63 DBGGuiSetParent,
64 DBGGuiSetMenu,
65 DBGGUIVT_VERSION
69 /**
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));
84 if (!pGui)
85 return VERR_NO_MEMORY;
86 pGui->u32Magic = DBGGUI_MAGIC;
87 pGui->pVBoxDbgGui = new VBoxDbgGui();
89 int rc;
90 if (pSession)
91 rc = pGui->pVBoxDbgGui->init(pSession);
92 else
93 rc = pGui->pVBoxDbgGui->init(pVM);
94 if (RT_SUCCESS(rc))
97 * Successfully initialized.
99 *ppGui = pGui;
100 if (ppGuiVT)
101 *ppGuiVT = &g_dbgGuiVT;
102 return rc;
106 * Failed, cleanup.
108 delete pGui->pVBoxDbgGui;
109 RTMemFree(pGui);
110 *ppGui = NULL;
111 if (ppGuiVT)
112 *ppGuiVT = NULL;
113 return rc;
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.
124 * Optional.
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.
140 * Optional.
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)
158 * Validate.
160 if (!pGui)
161 return VERR_INVALID_PARAMETER;
162 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
165 * Do the job.
167 pGui->u32Magic = DBGGUI_MAGIC_DEAD;
168 delete pGui->pVBoxDbgGui;
169 RTMemFree(pGui);
171 return VINF_SUCCESS;
176 * Notifies the debugger GUI that the console window (or whatever) has changed
177 * size or position.
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);