VirtualBox

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

Last change on this file since 41309 was 35346, checked in by vboxsync, 14 years ago

VMM reorg: Moving the public include files from include/VBox to include/VBox/vmm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/* $Id: VBoxDbg.cpp 35346 2010-12-27 16:13:13Z vboxsync $ */
2/** @file
3 * VBox Debugger GUI.
4 */
5
6/*
7 * Copyright (C) 2006-2010 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* 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>
28
29#include "VBoxDbgGui.h"
30
31
32/*******************************************************************************
33* Structures and Typedefs *
34*******************************************************************************/
35/**
36 * Debugger GUI instance data.
37 */
38typedef struct DBGGUI
39{
40 /** Magic number (DBGGUI_MAGIC). */
41 uint32_t u32Magic;
42 /** Pointer to the Debugger GUI manager object. */
43 VBoxDbgGui *pVBoxDbgGui;
44} DBGGUI;
45
46/** DBGGUI magic value (Werner Heisenberg). */
47#define DBGGUI_MAGIC 0x19011205
48/** Invalid DBGGUI magic value. */
49#define DBGGUI_MAGIC_DEAD 0x19760201
50
51
52/*******************************************************************************
53* Global Variables *
54*******************************************************************************/
55/** Virtual method table for simplifying dynamic linking. */
56static const DBGGUIVT g_dbgGuiVT =
57{
58 DBGGUIVT_VERSION,
59 DBGGuiDestroy,
60 DBGGuiAdjustRelativePos,
61 DBGGuiShowStatistics,
62 DBGGuiShowCommandLine,
63 DBGGuiSetParent,
64 DBGGuiSetMenu,
65 DBGGUIVT_VERSION
66};
67
68
69/**
70 * Internal worker for DBGGuiCreate and DBGGuiCreateForVM.
71 *
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.
77 */
78static int dbgGuiCreate(ISession *pSession, PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
79{
80 /*
81 * Allocate and initialize the Debugger GUI handle.
82 */
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();
88
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))
95 {
96 /*
97 * Successfully initialized.
98 */
99 *ppGui = pGui;
100 if (ppGuiVT)
101 *ppGuiVT = &g_dbgGuiVT;
102 return rc;
103 }
104
105 /*
106 * Failed, cleanup.
107 */
108 delete pGui->pVBoxDbgGui;
109 RTMemFree(pGui);
110 *ppGui = NULL;
111 if (ppGuiVT)
112 *ppGuiVT = NULL;
113 return rc;
114}
115
116
117/**
118 * Creates the debugger GUI.
119 *
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.
125 */
126DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
127{
128 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
129 return dbgGuiCreate(pSession, NULL, ppGui, ppGuiVT);
130}
131
132
133/**
134 * Creates the debugger GUI given a VM handle.
135 *
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.
141 */
142DBGDECL(int) DBGGuiCreateForVM(PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
143{
144 AssertPtrReturn(pVM, VERR_INVALID_POINTER);
145 return dbgGuiCreate(NULL, pVM, ppGui, ppGuiVT);
146}
147
148
149/**
150 * Destroys the debugger GUI.
151 *
152 * @returns VBox status code.
153 * @param pGui The instance returned by DBGGuiCreate().
154 */
155DBGDECL(int) DBGGuiDestroy(PDBGGUI pGui)
156{
157 /*
158 * Validate.
159 */
160 if (!pGui)
161 return VERR_INVALID_PARAMETER;
162 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
163
164 /*
165 * Do the job.
166 */
167 pGui->u32Magic = DBGGUI_MAGIC_DEAD;
168 delete pGui->pVBoxDbgGui;
169 RTMemFree(pGui);
170
171 return VINF_SUCCESS;
172}
173
174
175/**
176 * Notifies the debugger GUI that the console window (or whatever) has changed
177 * size or position.
178 *
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.
184 */
185DBGDECL(void) DBGGuiAdjustRelativePos(PDBGGUI pGui, int x, int y, unsigned cx, unsigned cy)
186{
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);
190}
191
192
193/**
194 * Shows the default statistics window.
195 *
196 * @returns VBox status code.
197 * @param pGui The instance returned by DBGGuiCreate().
198 */
199DBGDECL(int) DBGGuiShowStatistics(PDBGGUI pGui)
200{
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();
204}
205
206
207/**
208 * Shows the default command line window.
209 *
210 * @returns VBox status code.
211 * @param pGui The instance returned by DBGGuiCreate().
212 */
213DBGDECL(int) DBGGuiShowCommandLine(PDBGGUI pGui)
214{
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();
218}
219
220
221/**
222 * Sets the parent windows.
223 *
224 * @param pGui The instance returned by DBGGuiCreate().
225 * @param pvParent Pointer to a QWidget object.
226 *
227 * @remarks This will no affect any existing windows, so call it right after
228 * creating the thing.
229 */
230DBGDECL(void) DBGGuiSetParent(PDBGGUI pGui, void *pvParent)
231{
232 return pGui->pVBoxDbgGui->setParent((QWidget *)pvParent);
233}
234
235
236/**
237 * Sets the debug menu object.
238 *
239 * @param pGui The instance returned by DBGGuiCreate().
240 * @param pvMenu Pointer to a QMenu object.
241 *
242 * @remarks Call right after creation or risk losing menu item.
243 */
244DBGDECL(void) DBGGuiSetMenu(PDBGGUI pGui, void *pvMenu)
245{
246 return pGui->pVBoxDbgGui->setMenu((QMenu *)pvMenu);
247}
248
Note: See TracBrowser for help on using the repository browser.

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