VBoxVideoWinDbg.cpp revision ac7e45442a6e3b7c01faa0cdc1c48daee049ff59
/* $Id$ */
/** @file
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <windows.h>
#define KDEXT_64BIT
#include <wdbgexts.h>
#define VBOXVWD_VERSION_MAJOR 1
#define VBOXVWD_VERSION_MINOR 1
static EXT_API_VERSION g_VBoxVWDVersion = {
0
};
/**
* DLL entry point.
*/
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{
break;
}
case DLL_PROCESS_DETACH:
{
break;
}
default:
break;
}
return bOk;
}
/* note: need to name it this way to make dprintf & other macros defined in wdbgexts.h work */
#ifdef __cplusplus
extern "C"
{
#endif
VOID WDBGAPI WinDbgExtensionDllInit(PWINDBG_EXTENSION_APIS64 lpExtensionApis, USHORT MajorVersion, USHORT MinorVersion);
#ifdef __cplusplus
}
#endif
{
return &g_VBoxVWDVersion;
}
{
return;
}
VOID WDBGAPI WinDbgExtensionDllInit(PWINDBG_EXTENSION_APIS64 lpExtensionApis, USHORT MajorVersion, USHORT MinorVersion)
{
}
{
dprintf("**** VirtulBox Video Driver debugging extension ****\n"
" The following commands are supported: \n"
" !ms - save memory (video data) to clipboard \n"
" usage: !ms <virtual memory address> <width> <height> [bitsPerPixel (default is 32)] [pitch (default is ((width * bpp + 7) >> 3) + 3) & ~3)]\n");
}
{
/* address */
/* width */
/* height */
#if 0
{
}
#endif
/* bpp */
{
}
/* pitch */
{
if (u64Pitch < u64DefaultPitch) { dprintf("pitch value can not be less than (%d)\n", (UINT)u64DefaultPitch); return; }
}
else
{
}
dprintf("processing data for address(0x%p), width(%d), height(%d), bpp(%d), pitch(%d)...\n",
if (!pvBuf)
{
return;
}
if(u64DefaultPitch == u64Pitch)
{
dprintf("reading the entire memory buffer...\n");
if (!uRc)
{
}
{
dprintf("the actual number of bytes read(%d) no equal the requested size(%d)\n", (UINT)cbRead, (UINT)cbSize);
uRc = 0;
}
}
else
{
ULONG64 i;
dprintf("reading memory by chunks since custom pitch is specified...\n");
{
if (!uRc)
{
dprintf("WARNING!!! Failed to read the memory buffer of size(%d), chunk(%d)\n", (UINT)u64DefaultPitch, (UINT)i);
u64Height = i;
uRc = 1;
break;
}
else if (cbRead != u64DefaultPitch)
{
dprintf("WARNING!!! the actual number of bytes read(%d) not equal the requested size(%d), chunk(%d)\n", (UINT)cbRead, (UINT)u64DefaultPitch, (UINT)i);
u64Height = i;
break;
}
}
}
if (!uRc)
{
dprintf("read memory failed\n");
return;
}
if (!u64Height)
{
dprintf("no data to be processed since height it 0\n");
return;
}
switch (u64Bpp)
{
case 32:
case 24:
case 16:
#if 0
if (u64NumColors != 3)
{
}
#else
u64NumColors = 3;
#endif
break;
case 8:
{
#if 1
u64NumColors = 1;
#endif
if (u64NumColors == 1)
{
if (!pvBuf32)
{
return;
}
{
{
pByteBuf32[0] = pByteBuf[0];
pByteBuf32 += 4;
pByteBuf += 1;
}
}
u64DefaultPitch *= 4;
u64Bpp *= 4;
}
else
{
}
}
break;
}
dprintf("read memory succeeded..\n");
if (hBmp)
{
if (OpenClipboard(GetDesktopWindow()))
{
if (EmptyClipboard())
{
{
dprintf("succeeded!! You can now do <ctrl>+v in your favourite image editor\n");
}
else
{
}
}
else
{
}
}
else
{
}
}
else
{
}
}