VBoxDbg.cpp revision 31b8243819a7f5929b0906395203af985a85b6f4
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync/* $Id$ */
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync/** @file
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * VBox Debugger GUI.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync */
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync/*
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync *
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * available from http://www.virtualbox.org. This file is free software;
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * General Public License (GPL) as published by the Free Software
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync *
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * additional information or have any questions.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync */
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync/*******************************************************************************
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync* Header Files *
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync*******************************************************************************/
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync#define VBOX_COM_NO_ATL
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync#include <VBox/dbggui.h>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync#include <VBox/vm.h>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync#include <VBox/err.h>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync#include <iprt/assert.h>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync#include <iprt/alloc.h>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync#include "VBoxDbgGui.h"
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync/*******************************************************************************
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync* Structures and Typedefs *
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync*******************************************************************************/
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync/**
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * Debugger GUI instance data.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync */
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsynctypedef struct DBGGUI
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync{
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync /** Magic number (DBGGUI_MAGIC). */
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync uint32_t u32Magic;
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync /** Pointer to the Debugger GUI manager object. */
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync VBoxDbgGui *pVBoxDbgGui;
} DBGGUI;
/** DBGGUI magic value (Werner Heisenberg). */
#define DBGGUI_MAGIC 0x19011205
/** Invalid DBGGUI magic value. */
#define DBGGUI_MAGIC_DEAD 0x19760201
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Virtual method table for simplifying dynamic linking. */
static const DBGGUIVT g_dbgGuiVT =
{
DBGGUIVT_VERSION,
DBGGuiDestroy,
DBGGuiAdjustRelativePos,
DBGGuiShowStatistics,
DBGGuiShowCommandLine,
DBGGUIVT_VERSION
};
/**
* Internal worker for DBGGuiCreate and DBGGuiCreateForVM.
*
* @returns VBox status code.
* @param pSession The ISession interface. (DBGGuiCreate)
* @param pVM The VM handle. (DBGGuiCreateForVM)
* @param ppGui See DBGGuiCreate.
* @param ppGuiVT See DBGGuiCreate.
*/
static int dbgGuiCreate(ISession *pSession, PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
{
/*
* Allocate and initialize the Debugger GUI handle.
*/
PDBGGUI pGui = (PDBGGUI)RTMemAlloc(sizeof(*pGui));
if (!pGui)
return VERR_NO_MEMORY;
pGui->u32Magic = DBGGUI_MAGIC;
pGui->pVBoxDbgGui = new VBoxDbgGui();
int rc;
if (pSession)
rc = pGui->pVBoxDbgGui->init(pSession);
else
rc = pGui->pVBoxDbgGui->init(pVM);
if (VBOX_SUCCESS(rc))
{
/*
* Successfully initialized.
*/
*ppGui = pGui;
if (ppGuiVT)
*ppGuiVT = &g_dbgGuiVT;
return rc;
}
/*
* Failed, cleanup.
*/
delete pGui->pVBoxDbgGui;
RTMemFree(pGui);
*ppGui = NULL;
if (ppGuiVT)
*ppGuiVT = NULL;
return rc;
}
/**
* Creates the debugger GUI.
*
* @returns VBox status code.
* @param pSession The Virtual Box session.
* @param ppGui Where to store the pointer to the debugger instance.
* @param ppGuiVT Where to store the virtual method table pointer.
* Optional.
*/
DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
{
AssertPtrReturn(pSession, VERR_INVALID_POINTER);
return dbgGuiCreate(pSession, NULL, ppGui, ppGuiVT);
}
/**
* Creates the debugger GUI given a VM handle.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param ppGui Where to store the pointer to the debugger instance.
* @param ppGuiVT Where to store the virtual method table pointer.
* Optional.
*/
DBGDECL(int) DBGGuiCreateForVM(PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
{
AssertPtrReturn(pVM, VERR_INVALID_POINTER);
return dbgGuiCreate(NULL, pVM, ppGui, ppGuiVT);
}
/**
* Destroys the debugger GUI.
*
* @returns VBox status code.
* @param pGui The instance returned by DBGGuiCreate().
*/
DBGDECL(int) DBGGuiDestroy(PDBGGUI pGui)
{
/*
* Validate.
*/
if (!pGui)
return VERR_INVALID_PARAMETER;
AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
/*
* Do the job.
*/
pGui->u32Magic = DBGGUI_MAGIC_DEAD;
delete pGui->pVBoxDbgGui;
RTMemFree(pGui);
return VINF_SUCCESS;
}
/**
* Notifies the debugger GUI that the console window (or whatever) has changed
* size or position.
*
* @param pGui The instance returned by DBGGuiCreate().
* @param x The x-coordinate of the window the debugger is relative to.
* @param y The y-coordinate of the window the debugger is relative to.
* @param cx The width of the window the debugger is relative to.
* @param cy The height of the window the debugger is relative to.
*/
DBGDECL(void) DBGGuiAdjustRelativePos(PDBGGUI pGui, int x, int y, unsigned cx, unsigned cy)
{
AssertReturn(pGui, (void)VERR_INVALID_PARAMETER);
AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), (void)VERR_INVALID_PARAMETER);
pGui->pVBoxDbgGui->adjustRelativePos(x, y, cx, cy);
}
/**
* Shows the default statistics window.
*
* @returns VBox status code.
* @param pGui The instance returned by DBGGuiCreate().
*/
DBGDECL(int) DBGGuiShowStatistics(PDBGGUI pGui)
{
AssertReturn(pGui, VERR_INVALID_PARAMETER);
AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
return pGui->pVBoxDbgGui->showStatistics();
}
/**
* Shows the default command line window.
*
* @returns VBox status code.
* @param pGui The instance returned by DBGGuiCreate().
*/
DBGDECL(int) DBGGuiShowCommandLine(PDBGGUI pGui)
{
AssertReturn(pGui, VERR_INVALID_PARAMETER);
AssertMsgReturn(pGui->u32Magic == DBGGUI_MAGIC, ("u32Magic=%#x\n", pGui->u32Magic), VERR_INVALID_PARAMETER);
return pGui->pVBoxDbgGui->showConsole();
}