VirtualBox

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

Last change on this file since 68155 was 62480, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: VBoxDbg.cpp 62480 2016-07-22 18:29:41Z vboxsync $ */
2/** @file
3 * VBox Debugger GUI.
4 */
5
6/*
7 * Copyright (C) 2006-2016 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 <VirtualBox.h>
26#else /* !RT_OS_WINDOWS */
27# include <VirtualBox_XPCOM.h>
28#endif /* !RT_OS_WINDOWS */
29#include <VBox/dbggui.h>
30#include <VBox/vmm/vm.h>
31#include <VBox/err.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 */
44typedef 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. */
62static 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 */
84static 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 */
132DBGDECL(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 */
148DBGDECL(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 */
166DBGDECL(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 */
196DBGDECL(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 */
210DBGDECL(int) DBGGuiShowStatistics(PDBGGUI pGui)
211{
212 AssertReturn(pGui, VERR_INVALID_PARAMETER);
213 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
214 return pGui->pVBoxDbgGui->showStatistics();
215}
216
217
218/**
219 * Shows the default command line window.
220 *
221 * @returns VBox status code.
222 * @param pGui The instance returned by DBGGuiCreate().
223 */
224DBGDECL(int) DBGGuiShowCommandLine(PDBGGUI pGui)
225{
226 AssertReturn(pGui, VERR_INVALID_PARAMETER);
227 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
228 return pGui->pVBoxDbgGui->showConsole();
229}
230
231
232/**
233 * Sets the parent windows.
234 *
235 * @param pGui The instance returned by DBGGuiCreate().
236 * @param pvParent Pointer to a QWidget object.
237 *
238 * @remarks This will no affect any existing windows, so call it right after
239 * creating the thing.
240 */
241DBGDECL(void) DBGGuiSetParent(PDBGGUI pGui, void *pvParent)
242{
243 return pGui->pVBoxDbgGui->setParent((QWidget *)pvParent);
244}
245
246
247/**
248 * Sets the debug menu object.
249 *
250 * @param pGui The instance returned by DBGGuiCreate().
251 * @param pvMenu Pointer to a QMenu object.
252 *
253 * @remarks Call right after creation or risk losing menu item.
254 */
255DBGDECL(void) DBGGuiSetMenu(PDBGGUI pGui, void *pvMenu)
256{
257 return pGui->pVBoxDbgGui->setMenu((QMenu *)pvMenu);
258}
259
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