VirtualBox

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

Last change on this file since 56296 was 56296, checked in by vboxsync, 9 years ago

Debugger: Updated (C) year.

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