debugging

This commit is contained in:
Aaron Robinson 2004-03-19 06:20:58 +00:00
parent a01b8d0266
commit 550d2e96b7
6 changed files with 200 additions and 35 deletions

BIN
Cxbx.opt

Binary file not shown.

View File

@ -46,7 +46,10 @@ extern class ResourceTracker : public Mutex
ResourceTracker() : m_head(0), m_tail(0) {};
~ResourceTracker();
// insert a ptr
// clear the tracker
void clear();
// insert a ptr
void insert(void *pResource);
// remove a ptr
@ -64,7 +67,7 @@ extern class ResourceTracker : public Mutex
struct RTNode *m_tail;
}
g_VBTrackTotal, g_VBTrackDisable,
g_PBTrackTotal, g_PBTrackDisable;
g_PBTrackTotal, g_PBTrackDisable, g_PBTrackShowOnce;
struct RTNode
{

View File

@ -117,7 +117,15 @@ void DbgConsole::Reset()
}
#ifdef _DEBUG_TRACK_VB
static void EnableTracker(ResourceTracker &trackTotal, ResourceTracker &trackDisable, int a, int b, bool enable)
typedef enum _ETAction
{
ETA_ENABLE = 0,
ETA_DISABLE = 1,
ETA_SHOW = 2
}
ETAction;
static void EnableTracker(ResourceTracker &trackTotal, ResourceTracker &tracker, int a, int b, ETAction action)
{
int v=0;
@ -140,17 +148,22 @@ static void EnableTracker(ResourceTracker &trackTotal, ResourceTracker &trackDis
if((cur == NULL) || (cur->pNext == NULL))
break;
if(enable)
if(action == ETA_ENABLE)
printf("CxbxDbg: #%.02d (0x%.08X) enabled\n", a, cur->pResource);
else if(action == ETA_DISABLE)
printf("CxbxDbg: #%.02d (0x%.08X) disabled\n", a, cur->pResource);
else if(action == ETA_SHOW)
printf("CxbxDbg: #%.02d (0x%.08X) queued for show info..\n", a, cur->pResource);
if(action == ETA_ENABLE)
{
trackDisable.remove(cur->pResource);
tracker.remove(cur->pResource);
}
else
{
trackDisable.insert(cur->pResource);
tracker.insert(cur->pResource);
}
printf("CxbxDbg: %.02d (0x%.08X) %s\n", a, cur->pResource, enable ? "enabled" : "disabled");
cur = cur->pNext;
}
}
@ -194,8 +207,10 @@ void DbgConsole::ParseCommand()
#ifdef _DEBUG_TRACK_PB
printf("CxbxDbg: ListPB [LPB] : List Active Push Buffers\n");
printf("CxbxDbg: DisablePB [DPB #] : Disable Active Push Buffer(s)\n");
printf("CxbxDbg: EnablePB [EPB #] : Enable Active Push Buffer(s)\n");
printf("CxbxDbg: ShowPB [SPB #] : Show Push Buffer(s)\n");
printf("CxbxDbg: DisablePB [DPB #] : Disable Push Buffer(s)\n");
printf("CxbxDbg: EnablePB [EPB #] : Enable Push Buffer(s)\n");
printf("CxbxDbg: ClearPB [CPB] : Clear Push Buffer List\n");
#endif
#ifdef _DEBUG_ALLOC
@ -245,11 +260,11 @@ void DbgConsole::ParseCommand()
if(c == 1)
{
EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, n, false);
EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, n, ETA_DISABLE);
}
else if(c == 2)
{
EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, m, false);
EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, m, ETA_DISABLE);
}
else
{
@ -264,11 +279,11 @@ void DbgConsole::ParseCommand()
if(c == 1)
{
EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, n, true);
EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, n, ETA_ENABLE);
}
else if(c == 2)
{
EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, m, true);
EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, m, ETA_ENABLE);
}
else
{
@ -296,6 +311,25 @@ void DbgConsole::ParseCommand()
g_PBTrackTotal.Unlock();
}
else if(stricmp(szCmd, "spb") == 0 || stricmp(szCmd, "ShowPB") == 0)
{
int n=0, m=0;
int c = sscanf(m_szInput, "%*s %d-%d", &n, &m);
if(c == 1)
{
EnableTracker(g_PBTrackTotal, g_PBTrackShowOnce, n, n, ETA_SHOW);
}
else if(c == 2)
{
EnableTracker(g_PBTrackTotal, g_PBTrackShowOnce, n, m, ETA_SHOW);
}
else
{
printf("CxbxDbg: Syntax Incorrect (spb #)\n");
}
}
else if(stricmp(szCmd, "dpb") == 0 || stricmp(szCmd, "DisablePB") == 0)
{
int n=0, m=0;
@ -304,11 +338,11 @@ void DbgConsole::ParseCommand()
if(c == 1)
{
EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, n, false);
EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, n, ETA_DISABLE);
}
else if(c == 2)
{
EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, m, false);
EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, m, ETA_DISABLE);
}
else
{
@ -323,16 +357,22 @@ void DbgConsole::ParseCommand()
if(c == 1)
{
EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, n, true);
EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, n, ETA_ENABLE);
}
else if(c == 2)
{
EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, m, true);
EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, m, ETA_ENABLE);
}
else
{
printf("CxbxDbg: Syntax Incorrect (dpb #)\n");
}
}
else if(stricmp(szCmd, "cpb") == 0 || stricmp(szCmd, "ClearPB") == 0)
{
g_PBTrackTotal.clear();
printf("CxbxDbg: Push Buffer List Cleared!\n");
}
#endif
#ifdef _DEBUG_ALLOC

View File

@ -6428,7 +6428,8 @@ VOID WINAPI XTL::EmuIDirect3DDevice8_DrawIndexedVertices
g_pD3DDevice8->DrawIndexedPrimitive
(
PCPrimitiveType, 0, ((DWORD)pIndexData)/2 + VertexCount, ((DWORD)pIndexData)/2, PrimitiveCount
PCPrimitiveType, ((DWORD)pIndexData)/2, VertexCount, ((DWORD)pIndexData)/2, PrimitiveCount
// PCPrimitiveType, 0, ((DWORD)pIndexData)/2 + VertexCount, ((DWORD)pIndexData)/2, PrimitiveCount
);
#ifdef _DEBUG_TRACK_VB

View File

@ -45,9 +45,11 @@ namespace XTL
extern XTL::LPDIRECT3DDEVICE8 g_pD3DDevice8; // Direct3D8 Device
bool XTL::g_bStepPush = FALSE;
bool XTL::g_bSkipPush = FALSE;
bool XTL::g_bBrkPush = FALSE;
bool XTL::g_bStepPush = false;
bool XTL::g_bSkipPush = false;
bool XTL::g_bBrkPush = false;
bool g_bPBSkipPusher = false;
// pushbuffer execution emulation
void XTL::EmuExecutePushBuffer
@ -59,6 +61,9 @@ void XTL::EmuExecutePushBuffer
if(g_bSkipPush)
return;
if(pFixup != NULL)
EmuCleanup("PushBuffer has fixups\n");
DWORD *pdwPushData = (DWORD*)pPushBuffer->Data;
D3DPRIMITIVETYPE PCPrimitiveType = (D3DPRIMITIVETYPE)-1;
@ -71,6 +76,24 @@ void XTL::EmuExecutePushBuffer
// g_pD3DDevice8->SetRenderState(D3DRS_ZENABLE, FALSE);
// g_pD3DDevice8->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
#ifdef _DEBUG_TRACK_PB
bool bShowPB = false;
g_PBTrackTotal.insert(pdwPushData);
if(g_PBTrackShowOnce.exists(pdwPushData))
{
g_PBTrackShowOnce.remove(pdwPushData);
printf("\n");
printf("\n");
printf(" PushBuffer@0x%.08X...\n", pdwPushData);
printf("\n");
bShowPB = true;
}
#endif
// NOTE: I believe 0x1808 is actually a seperate command, but I need to verify this.
while(true)
@ -83,10 +106,32 @@ void XTL::EmuExecutePushBuffer
{
pdwPushData++;
#ifdef _DEBUG_TRACK_PB
if(bShowPB)
{
printf(" NVPB_SetBeginEnd(");
}
#endif
if(*pdwPushData == 0)
{
#ifdef _DEBUG_TRACK_PB
if(bShowPB)
{
printf("DONE)\n");
}
#endif
break; // done?
}
else
{
#ifdef _DEBUG_TRACK_PB
if(bShowPB)
{
printf("PrimitiveType := %d)\n", *pdwPushData);
}
#endif
XBPrimitiveType = *pdwPushData;
PCPrimitiveType = EmuPrimitiveType(XBPrimitiveType);
}
@ -111,7 +156,56 @@ void XTL::EmuExecutePushBuffer
pIndexData = pdwPushData;
#ifdef _DEBUG_TRACK_PB
g_PBTrackTotal.insert(pIndexData);
if(bShowPB)
{
printf(" NVPB_InlineArray(0x%.08X)...\n", pIndexData);
printf("\n");
printf(" Index Array Data...\n");
WORD *pwVal = (WORD*)pIndexData;
for(uint s=0;s<dwCount/2;s++)
{
if(s%8 == 0) printf("\n ");
printf(" %.04X", *pwVal++);
}
printf("\n");
XTL::IDirect3DVertexBuffer8 *pActiveVB = NULL;
D3DVERTEXBUFFER_DESC VBDesc;
BYTE *pVBData = 0;
UINT uiStride;
// retrieve stream data
g_pD3DDevice8->GetStreamSource(0, &pActiveVB, &uiStride);
// retrieve stream desc
pActiveVB->GetDesc(&VBDesc);
// unlock just in case
pActiveVB->Unlock();
// grab ptr
pActiveVB->Lock(0, 0, &pVBData, D3DLOCK_READONLY);
// print out stream data
{
printf("\n");
printf(" Vertex Stream Data (0x%.08X)...\n", pActiveVB);
printf("\n");
printf(" Format : %d\n", VBDesc.Format);
printf(" Size : %d bytes\n", VBDesc.Size);
printf(" FVF : 0x%.08X\n", VBDesc.FVF);
printf("\n");
}
// release ptr
pActiveVB->Unlock();
}
#endif
pdwPushData += dwCount - (bInc ? 0 : 1);
@ -141,14 +235,17 @@ void XTL::EmuExecutePushBuffer
g_pD3DDevice8->SetIndices(pIndexBuffer, 0);
#ifdef _DEBUG_TRACK_PB
if(!g_PBTrackDisable.exists(pIndexData))
if(!g_PBTrackDisable.exists((PVOID)pPushBuffer->Data))
{
#endif
g_pD3DDevice8->DrawIndexedPrimitive
(
PCPrimitiveType, 0, dwCount*2, 0, EmuD3DVertex2PrimitiveCount(XBPrimitiveType, dwCount*2)
);
if(!g_bPBSkipPusher)
{
g_pD3DDevice8->DrawIndexedPrimitive
(
PCPrimitiveType, 0, dwCount*2, 0, EmuD3DVertex2PrimitiveCount(XBPrimitiveType, dwCount*2)
);
}
#ifdef _DEBUG_TRACK_PB
}
@ -163,6 +260,15 @@ void XTL::EmuExecutePushBuffer
pdwPushData++;
}
#ifdef _DEBUG_TRACK_PB
if(bShowPB)
{
printf("\n");
printf("CxbxDbg> ");
fflush(stdout);
}
#endif
if(g_bStepPush)
{
g_pD3DDevice8->Present(0,0,0,0);

View File

@ -34,25 +34,40 @@
#include "ResourceTracker.h"
// exported globals
bool g_bVBSkipStream = false;
bool g_bVBSkipPusher = false;
bool g_bVBSkipStream = false;
bool g_bVBSkipPusher = false;
ResourceTracker g_VBTrackTotal;
ResourceTracker g_VBTrackDisable;
ResourceTracker g_PBTrackTotal;
ResourceTracker g_PBTrackDisable;
ResourceTracker g_PBTrackShowOnce;
ResourceTracker::~ResourceTracker()
{
RTNode *cur = m_head;
clear();
}
while(cur != 0)
{
void ResourceTracker::clear()
{
this->Lock();
RTNode *cur = m_head;
while(cur != 0)
{
RTNode *tmp = cur->pNext;
delete cur;
cur = tmp;
}
cur = tmp;
}
m_head = m_tail = 0;
this->Unlock();
}
void ResourceTracker::insert(void *pResource)