VirtualBox

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

Last change on this file since 12831 was 12462, checked in by vboxsync, 16 years ago

Debugger: made tstVBoxDbg useful again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/* $Id: VBoxDbg.cpp 12462 2008-09-15 13:22:28Z 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.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 * 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 VBOX_COM_NO_ATL
26#include <VBox/dbggui.h>
27#include <VBox/vm.h>
28#include <VBox/err.h>
29#include <iprt/assert.h>
30#include <iprt/alloc.h>
31
32#include "VBoxDbgGui.h"
33
34
35/*******************************************************************************
36* Structures and Typedefs *
37*******************************************************************************/
38/**
39 * Debugger GUI instance data.
40 */
41typedef struct DBGGUI
42{
43 /** Magic number (DBGGUI_MAGIC). */
44 uint32_t u32Magic;
45 /** Pointer to the Debugger GUI manager object. */
46 VBoxDbgGui *pVBoxDbgGui;
47} DBGGUI;
48
49/** DBGGUI magic value (Werner Heisenberg). */
50#define DBGGUI_MAGIC 0x19011205
51/** Invalid DBGGUI magic value. */
52#define DBGGUI_MAGIC_DEAD 0x19760201
53
54
55/*******************************************************************************
56* Global Variables *
57*******************************************************************************/
58/** Virtual method table for simplifying dynamic linking. */
59static const DBGGUIVT g_dbgGuiVT =
60{
61 DBGGUIVT_VERSION,
62 DBGGuiDestroy,
63 DBGGuiAdjustRelativePos,
64 DBGGuiShowStatistics,
65 DBGGuiShowCommandLine,
66 DBGGUIVT_VERSION
67};
68
69
70/**
71 * Internal worker for DBGGuiCreate and DBGGuiCreateForVM.
72 *
73 * @returns VBox status code.
74 * @param pSession The ISession interface. (DBGGuiCreate)
75 * @param pVM The VM handle. (DBGGuiCreateForVM)
76 * @param ppGui See DBGGuiCreate.
77 * @param ppGuiVT See DBGGuiCreate.
78 */
79static int dbgGuiCreate(ISession *pSession, PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
80{
81 /*
82 * Allocate and initialize the Debugger GUI handle.
83 */
84 PDBGGUI pGui = (PDBGGUI)RTMemAlloc(sizeof(*pGui));
85 if (!pGui)
86 return VERR_NO_MEMORY;
87 pGui->u32Magic = DBGGUI_MAGIC;
88 pGui->pVBoxDbgGui = new VBoxDbgGui();
89
90 int rc;
91 if (pSession)
92 rc = pGui->pVBoxDbgGui->init(pSession);
93 else
94 rc = pGui->pVBoxDbgGui->init(pVM);
95 if (VBOX_SUCCESS(rc))
96 {
97 /*
98 * Successfully initialized.
99 */
100 *ppGui = pGui;
101 if (ppGuiVT)
102 *ppGuiVT = &g_dbgGuiVT;
103 return rc;
104 }
105
106 /*
107 * Failed, cleanup.
108 */
109 delete pGui->pVBoxDbgGui;
110 RTMemFree(pGui);
111 *ppGui = NULL;
112 if (ppGuiVT)
113 *ppGuiVT = NULL;
114 return rc;
115}
116
117
118/**
119 * Creates the debugger GUI.
120 *
121 * @returns VBox status code.
122 * @param pSession The Virtual Box session.
123 * @param ppGui Where to store the pointer to the debugger instance.
124 * @param ppGuiVT Where to store the virtual method table pointer.
125 * Optional.
126 */
127DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
128{
129 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
130 return dbgGuiCreate(pSession, NULL, ppGui, ppGuiVT);
131}
132
133
134/**
135 * Creates the debugger GUI given a VM handle.
136 *
137 * @returns VBox status code.
138 * @param pVM The VM handle.
139 * @param ppGui Where to store the pointer to the debugger instance.
140 * @param ppGuiVT Where to store the virtual method table pointer.
141 * Optional.
142 */
143DBGDECL(int) DBGGuiCreateForVM(PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
144{
145 AssertPtrReturn(pVM, VERR_INVALID_POINTER);
146 return dbgGuiCreate(NULL, pVM, ppGui, ppGuiVT);
147}
148
149
150/**
151 * Destroys the debugger GUI.
152 *
153 * @returns VBox status code.
154 * @param pGui The instance returned by DBGGuiCreate().
155 */
156DBGDECL(int) DBGGuiDestroy(PDBGGUI pGui)
157{
158 /*
159 * Validate.
160 */
161 if (!pGui)
162 return VERR_INVALID_PARAMETER;
163 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
164
165 /*
166 * Do the job.
167 */
168 pGui->u32Magic = DBGGUI_MAGIC_DEAD;
169 delete pGui->pVBoxDbgGui;
170 RTMemFree(pGui);
171
172 return VINF_SUCCESS;
173}
174
175
176/**
177 * Notifies the debugger GUI that the console window (or whatever) has changed
178 * size or position.
179 *
180 * @param pGui The instance returned by DBGGuiCreate().
181 * @param x The x-coordinate of the window the debugger is relative to.
182 * @param y The y-coordinate of the window the debugger is relative to.
183 * @param cx The width of the window the debugger is relative to.
184 * @param cy The height of the window the debugger is relative to.
185 */
186DBGDECL(void) DBGGuiAdjustRelativePos(PDBGGUI pGui, int x, int y, unsigned cx, unsigned cy)
187{
188 AssertReturn(pGui, (void)VERR_INVALID_PARAMETER);
189 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), (void)VERR_INVALID_PARAMETER);
190 pGui->pVBoxDbgGui->adjustRelativePos(x, y, cx, cy);
191}
192
193
194/**
195 * Shows the default statistics window.
196 *
197 * @returns VBox status code.
198 * @param pGui The instance returned by DBGGuiCreate().
199 */
200DBGDECL(int) DBGGuiShowStatistics(PDBGGUI pGui)
201{
202 AssertReturn(pGui, VERR_INVALID_PARAMETER);
203 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
204 return pGui->pVBoxDbgGui->showStatistics();
205}
206
207
208/**
209 * Shows the default command line window.
210 *
211 * @returns VBox status code.
212 * @param pGui The instance returned by DBGGuiCreate().
213 */
214DBGDECL(int) DBGGuiShowCommandLine(PDBGGUI pGui)
215{
216 AssertReturn(pGui, VERR_INVALID_PARAMETER);
217 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
218 return pGui->pVBoxDbgGui->showConsole();
219}
220
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