VBoxVideoWinDbg.cpp revision 40bd0fc692d21a6d579862d7ccdc20c2ccf361a5
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * Copyright (C) 2011 Oracle Corporation
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * available from http://www.virtualbox.org. This file is free software;
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * you can redistribute it and/or modify it under the terms of the GNU
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * General Public License (GPL) as published by the Free Software
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync * DLL entry point.
de6e321f351aa489a6a62bed474390a0056e8093vboxsync/* note: need to name it this way to make dprintf & other macros defined in wdbgexts.h work */
044af0d1e6474076366759db86f101778c5f20ccvboxsyncVOID WDBGAPI WinDbgExtensionDllInit(PWINDBG_EXTENSION_APIS64 lpExtensionApis, USHORT MajorVersion, USHORT MinorVersion);
044af0d1e6474076366759db86f101778c5f20ccvboxsyncVOID WDBGAPI WinDbgExtensionDllInit(PWINDBG_EXTENSION_APIS64 lpExtensionApis, USHORT MajorVersion, USHORT MinorVersion)
de6e321f351aa489a6a62bed474390a0056e8093vboxsync dprintf("**** VirtulBox Video Driver debugging extension ****\n"
de6e321f351aa489a6a62bed474390a0056e8093vboxsync " The following commands are supported: \n"
de6e321f351aa489a6a62bed474390a0056e8093vboxsync " !ms - save memory (video data) to clipboard \n"
044af0d1e6474076366759db86f101778c5f20ccvboxsync " usage: !ms <virtual memory address> <width> <height> [bitsPerPixel (default is 32)] [pitch (default is ((width * bpp + 7) >> 3) + 3) & ~3)]\n");
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* address */
de6e321f351aa489a6a62bed474390a0056e8093vboxsync if (!pExpr) { dprintf("address not specified\n"); return; }
044af0d1e6474076366759db86f101778c5f20ccvboxsync if (!GetExpressionEx(pExpr, &u64Mem, &pExpr)) { dprintf("error evaluating address\n"); return; }
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync if (!u64Mem) { dprintf("address value can not be NULL\n"); return; }
de6e321f351aa489a6a62bed474390a0056e8093vboxsync /* width */
de6e321f351aa489a6a62bed474390a0056e8093vboxsync if (!pExpr) { dprintf("width not specified\n"); return; }
de6e321f351aa489a6a62bed474390a0056e8093vboxsync if (!GetExpressionEx(pExpr, &u64Width, &pExpr)) { dprintf("error evaluating width\n"); return; }
de6e321f351aa489a6a62bed474390a0056e8093vboxsync if (!u64Width) { dprintf("width value can not be NULL\n"); return; }
de6e321f351aa489a6a62bed474390a0056e8093vboxsync /* height */
de6e321f351aa489a6a62bed474390a0056e8093vboxsync if (!pExpr) { dprintf("height not specified\n"); return; }
de6e321f351aa489a6a62bed474390a0056e8093vboxsync if (!GetExpressionEx(pExpr, &u64Height, &pExpr)) { dprintf("error evaluating height\n"); return; }
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync if (!u64Height) { dprintf("height value can not be NULL\n"); return; }
044af0d1e6474076366759db86f101778c5f20ccvboxsync if (pExpr && GetExpressionEx(pExpr, &u64NumColors, &pExpr))
044af0d1e6474076366759db86f101778c5f20ccvboxsync if (!u64NumColors) { dprintf("Num Colors value can not be NULL\n"); return; }
de6e321f351aa489a6a62bed474390a0056e8093vboxsync if (pExpr && GetExpressionEx(pExpr, &u64Bpp, &pExpr))
044af0d1e6474076366759db86f101778c5f20ccvboxsync if (!u64Bpp) { dprintf("bpp value can not be NULL\n"); return; }
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* pitch */
044af0d1e6474076366759db86f101778c5f20ccvboxsync u64DefaultPitch = (((((u64Width * u64Bpp) + 7) >> 3) + 3) & ~3ULL);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync if (pExpr && GetExpressionEx(pExpr, &u64Pitch, &pExpr))
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync if (u64Pitch < u64DefaultPitch) { dprintf("pitch value can not be less than (%d)\n", (UINT)u64DefaultPitch); return; }
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("processing data for address(0x%p), width(%d), height(%d), bpp(%d), pitch(%d)...\n",
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync u64Mem, (UINT)u64Width, (UINT)u64Height, (UINT)u64Bpp, (UINT)u64Pitch);
044af0d1e6474076366759db86f101778c5f20ccvboxsync dprintf("failed to allocate memory buffer of size(%d)\n", (UINT)cbSize);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("Failed to read the memory buffer of size(%d)\n", (UINT)cbSize);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("the actual number of bytes read(%d) no equal the requested size(%d)\n", (UINT)cbRead, (UINT)cbSize);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("reading memory by chunks since custom pitch is specified...\n");
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync for (i = 0; i < u64Height; ++i, u64Offset+=u64Pitch, pvcBuf+=u64DefaultPitch)
044af0d1e6474076366759db86f101778c5f20ccvboxsync uRc = ReadMemory(u64Offset, pvcBuf, u64DefaultPitch, &cbRead);
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync dprintf("WARNING!!! Failed to read the memory buffer of size(%d), chunk(%d)\n", (UINT)u64DefaultPitch, (UINT)i);
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync dprintf("ignoring this one and the all the rest, using height(%d)\n", (UINT)i);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("WARNING!!! the actual number of bytes read(%d) not equal the requested size(%d), chunk(%d)\n", (UINT)cbRead, (UINT)u64DefaultPitch, (UINT)i);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("ignoring this one and the all the rest, using height(%d)\n", (UINT)i);
044af0d1e6474076366759db86f101778c5f20ccvboxsync dprintf("no data to be processed since height it 0\n");
044af0d1e6474076366759db86f101778c5f20ccvboxsync dprintf("WARNING: unsupported number colors: (%d)\n", (UINT)u64NumColors);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync ULONG64 cbSize32 = u64DefaultPitch * 4 * u64Height;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("ERROR: failed to allocate memory buffer of size(%d)", cbSize32);
044af0d1e6474076366759db86f101778c5f20ccvboxsync dprintf("WARNING: unsupported number colors: (%d)\n", (UINT)u64NumColors);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("succeeded!! You can now do <ctrl>+v in your favourite image editor\n");
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("SetClipboardData failed, err(%d)\n", winEr);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync dprintf("EmptyClipboard failed, err(%d)\n", winEr);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync dprintf("CreateBitmapIndirect failed, err(%d)\n", winEr);