VirtualBox

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

Last change on this file since 12884 was 12884, checked in by vboxsync, 17 years ago

Debugger: parenting, menu, destroy on close

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette