VirtualBox

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

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

Debugger: log groups and console 'exit' fix.

  • 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 12878 2008-10-01 21:11:52Z 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 DBGGUIVT_VERSION
68};
69
70
71/**
72 * Internal worker for DBGGuiCreate and DBGGuiCreateForVM.
73 *
74 * @returns VBox status code.
75 * @param pSession The ISession interface. (DBGGuiCreate)
76 * @param pVM The VM handle. (DBGGuiCreateForVM)
77 * @param ppGui See DBGGuiCreate.
78 * @param ppGuiVT See DBGGuiCreate.
79 */
80static int dbgGuiCreate(ISession *pSession, PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
81{
82 /*
83 * Allocate and initialize the Debugger GUI handle.
84 */
85 PDBGGUI pGui = (PDBGGUI)RTMemAlloc(sizeof(*pGui));
86 if (!pGui)
87 return VERR_NO_MEMORY;
88 pGui->u32Magic = DBGGUI_MAGIC;
89 pGui->pVBoxDbgGui = new VBoxDbgGui();
90
91 int rc;
92 if (pSession)
93 rc = pGui->pVBoxDbgGui->init(pSession);
94 else
95 rc = pGui->pVBoxDbgGui->init(pVM);
96 if (VBOX_SUCCESS(rc))
97 {
98 /*
99 * Successfully initialized.
100 */
101 *ppGui = pGui;
102 if (ppGuiVT)
103 *ppGuiVT = &g_dbgGuiVT;
104 return rc;
105 }
106
107 /*
108 * Failed, cleanup.
109 */
110 delete pGui->pVBoxDbgGui;
111 RTMemFree(pGui);
112 *ppGui = NULL;
113 if (ppGuiVT)
114 *ppGuiVT = NULL;
115 return rc;
116}
117
118
119/**
120 * Creates the debugger GUI.
121 *
122 * @returns VBox status code.
123 * @param pSession The Virtual Box session.
124 * @param ppGui Where to store the pointer to the debugger instance.
125 * @param ppGuiVT Where to store the virtual method table pointer.
126 * Optional.
127 */
128DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
129{
130 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
131 return dbgGuiCreate(pSession, NULL, ppGui, ppGuiVT);
132}
133
134
135/**
136 * Creates the debugger GUI given a VM handle.
137 *
138 * @returns VBox status code.
139 * @param pVM The VM handle.
140 * @param ppGui Where to store the pointer to the debugger instance.
141 * @param ppGuiVT Where to store the virtual method table pointer.
142 * Optional.
143 */
144DBGDECL(int) DBGGuiCreateForVM(PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
145{
146 AssertPtrReturn(pVM, VERR_INVALID_POINTER);
147 return dbgGuiCreate(NULL, pVM, ppGui, ppGuiVT);
148}
149
150
151/**
152 * Destroys the debugger GUI.
153 *
154 * @returns VBox status code.
155 * @param pGui The instance returned by DBGGuiCreate().
156 */
157DBGDECL(int) DBGGuiDestroy(PDBGGUI pGui)
158{
159 /*
160 * Validate.
161 */
162 if (!pGui)
163 return VERR_INVALID_PARAMETER;
164 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
165
166 /*
167 * Do the job.
168 */
169 pGui->u32Magic = DBGGUI_MAGIC_DEAD;
170 delete pGui->pVBoxDbgGui;
171 RTMemFree(pGui);
172
173 return VINF_SUCCESS;
174}
175
176
177/**
178 * Notifies the debugger GUI that the console window (or whatever) has changed
179 * size or position.
180 *
181 * @param pGui The instance returned by DBGGuiCreate().
182 * @param x The x-coordinate of the window the debugger is relative to.
183 * @param y The y-coordinate of the window the debugger is relative to.
184 * @param cx The width of the window the debugger is relative to.
185 * @param cy The height of the window the debugger is relative to.
186 */
187DBGDECL(void) DBGGuiAdjustRelativePos(PDBGGUI pGui, int x, int y, unsigned cx, unsigned cy)
188{
189 AssertReturn(pGui, (void)VERR_INVALID_PARAMETER);
190 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), (void)VERR_INVALID_PARAMETER);
191 pGui->pVBoxDbgGui->adjustRelativePos(x, y, cx, cy);
192}
193
194
195/**
196 * Shows the default statistics window.
197 *
198 * @returns VBox status code.
199 * @param pGui The instance returned by DBGGuiCreate().
200 */
201DBGDECL(int) DBGGuiShowStatistics(PDBGGUI pGui)
202{
203 AssertReturn(pGui, VERR_INVALID_PARAMETER);
204 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
205 return pGui->pVBoxDbgGui->showStatistics();
206}
207
208
209/**
210 * Shows the default command line window.
211 *
212 * @returns VBox status code.
213 * @param pGui The instance returned by DBGGuiCreate().
214 */
215DBGDECL(int) DBGGuiShowCommandLine(PDBGGUI pGui)
216{
217 AssertReturn(pGui, VERR_INVALID_PARAMETER);
218 AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
219 return pGui->pVBoxDbgGui->showConsole();
220}
221
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