rev feedback v1.

This commit is contained in:
HarrievG 2021-07-01 01:09:15 +02:00
parent d4db77b9ed
commit ebf53cdc21
9 changed files with 119 additions and 139 deletions

View file

@ -302,16 +302,11 @@ void idGameLocal::Clear( void ) {
#endif
}
static DebuggerArgs_t * userDebuggerArgs;
static bool ( *checkDebuggerBreakpointFnPtr )( void ) = NULL;
bool IsGameDebuggerActive( idInterpreter *interpreter, idProgram *program, int instructionPointer ) {
static bool ( *updateDebuggerFnPtr )( idInterpreter *interpreter, idProgram *program, int instructionPointer ) = NULL;
bool updateGameDebugger( idInterpreter *interpreter, idProgram *program, int instructionPointer ) {
bool ret = false;
if ( interpreter != nullptr && program != nullptr ) {
userDebuggerArgs->interpreter = interpreter;
userDebuggerArgs->program = program;
userDebuggerArgs->instructionPointer = instructionPointer;
ret = checkDebuggerBreakpointFnPtr ? checkDebuggerBreakpointFnPtr( ) : false;
ret = updateDebuggerFnPtr ? updateDebuggerFnPtr( interpreter , program, instructionPointer ) : false;
}
return ret;
}
@ -427,8 +422,7 @@ void idGameLocal::Init( void ) {
Printf( "...%d aas types\n", aasList.Num() );
//debugger support
common->GetAdditionalFunction( idCommon::FT_CheckDebuggerBreakpoint,
( idCommon::FunctionPointer * ) &checkDebuggerBreakpointFnPtr, ( void ** ) &userDebuggerArgs );
common->GetAdditionalFunction( idCommon::FT_CheckDebuggerBreakpoint,( idCommon::FunctionPointer * ) &updateDebuggerFnPtr,NULL);
}
@ -1370,7 +1364,7 @@ void idGameLocal::InitFromNewMap(const char* mapName, idRenderWorld* renderWorld
idGameLocal::InitFromSaveGame
=================
*/
bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, idFile *saveGameFile, int activeEditors) {
bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, idFile *saveGameFile ) {
int i;
int num;
idEntity *ent;

View file

@ -36,7 +36,7 @@ If you have questions concerning this license or the applicable additional terms
#include "framework/FileSystem.h"
// HvG: Debugger support
extern bool IsGameDebuggerActive( idInterpreter *interpreter, idProgram *program, int instructionPointer );
extern bool updateGameDebugger( idInterpreter *interpreter, idProgram *program, int instructionPointer );
/*
================
@ -181,102 +181,106 @@ void idInterpreter::Reset( void ) {
doneProcessing = true;
}
bool idInterpreter::GetRegisterValue(const char* name, idStr& out, int scopeDepth) {
/*
================
idInterpreter::GetRegisterValue
Returns a string representation of the value of the register. This is
used primarily for the debugger and debugging
================
*/
bool idInterpreter::GetRegisterValue( const char *name, idStr &out, int scopeDepth ) {
varEval_t reg;
idVarDef* d;
char funcObject[1024];
char* funcName;
const idVarDef* scope = NULL;
const idVarDef* scopeObj;
const idTypeDef* field;
const function_t* func;
idVarDef *d;
char funcObject[ 1024 ];
char *funcName;
const idVarDef *scope = NULL;
const idVarDef *scopeObj;
const idTypeDef *field;
const function_t *func;
out.Empty();
if (scopeDepth == -1) {
if ( scopeDepth == -1 ) {
scopeDepth = callStackDepth;
}
if (scopeDepth == callStackDepth) {
}
if ( scopeDepth == callStackDepth ) {
func = currentFunction;
} else {
func = callStack[ scopeDepth ].f;
}
else {
func = callStack[scopeDepth].f;
}
if (!func) {
if ( !func ) {
return false;
}
idStr::Copynz(funcObject, func->Name(), sizeof(funcObject));
funcName = strstr(funcObject, "::");
if (funcName) {
idStr::Copynz( funcObject, func->Name(), sizeof( funcObject ) );
funcName = strstr( funcObject, "::" );
if ( funcName ) {
*funcName = '\0';
scopeObj = gameLocal.program.GetDef(NULL, funcObject, &def_namespace);
funcName += 2;
if (scopeObj)
scopeObj = gameLocal.program.GetDef( NULL, funcObject, &def_namespace );
funcName += 2;
if ( scopeObj )
{
scope = gameLocal.program.GetDef(NULL, funcName, scopeObj);
scope = gameLocal.program.GetDef( NULL, funcName, scopeObj );
}
}
else {
} else {
funcName = funcObject;
scope = gameLocal.program.GetDef(NULL, func->Name(), &def_namespace);
scope = gameLocal.program.GetDef( NULL, func->Name(), &def_namespace );
scopeObj = NULL;
}
if (!scope)
if ( !scope )
{
return false;
}
d = gameLocal.program.GetDef(NULL, name, scope);
d = gameLocal.program.GetDef( NULL, name, scope );
// Check the objects for it if it wasnt local to the function
if (!d)
if ( !d )
{
for (; scopeObj && scopeObj->TypeDef()->SuperClass(); scopeObj = scopeObj->TypeDef()->SuperClass()->def)
for ( ; scopeObj && scopeObj->TypeDef()->SuperClass(); scopeObj = scopeObj->TypeDef()->SuperClass()->def )
{
d = gameLocal.program.GetDef(NULL, name, scopeObj);
if (d)
d = gameLocal.program.GetDef( NULL, name, scopeObj );
if ( d )
{
break;
}
}
}
}
if (!d)
if ( !d )
{
out = "???";
return false;
}
reg = GetVariable(d);
switch (d->Type()) {
reg = GetVariable( d );
switch( d->Type() ) {
case ev_float:
if (reg.floatPtr) {
out = va("%g", *reg.floatPtr);
}
else {
if ( reg.floatPtr ) {
out = va("%g", *reg.floatPtr );
} else {
out = "0";
}
return true;
break;
case ev_vector:
if (reg.vectorPtr) {
out = va("%g,%g,%g", reg.vectorPtr->x, reg.vectorPtr->y, reg.vectorPtr->z);
}
else {
if ( reg.vectorPtr ) {
out = va( "%g,%g,%g", reg.vectorPtr->x, reg.vectorPtr->y, reg.vectorPtr->z );
} else {
out = "0,0,0";
}
return true;
break;
case ev_boolean:
if (reg.intPtr) {
out = va("%d", *reg.intPtr);
}
else {
if ( reg.intPtr ) {
out = va( "%d", *reg.intPtr );
} else {
out = "0";
}
return true;
@ -284,63 +288,61 @@ bool idInterpreter::GetRegisterValue(const char* name, idStr& out, int scopeDept
case ev_field:
{
idEntity* entity;
idScriptObject* obj;
if (scope == &def_namespace) {
idEntity* entity;
idScriptObject* obj;
if ( scope == &def_namespace ) {
// should never happen, but handle it safely anyway
return false;
}
field = d->TypeDef()->FieldType();
entity = GetEntity(*((int*)&localstack[localstackBase]));
if (!entity || !field)
field = d->TypeDef()->FieldType();
entity = GetEntity ( *((int*)&localstack[ localstackBase ]) );
if ( !entity || !field )
{
return false;
}
obj = &entity->scriptObject;
if (!obj) {
if ( !obj ) {
return false;
}
switch ( field->Type() ) {
case ev_boolean:
out = va( "%d", *( reinterpret_cast<int *>( &obj->data[ reg.ptrOffset ] ) ) );
return true;
switch (field->Type()) {
case ev_boolean:
out = va("%d", *(reinterpret_cast<int*>(&obj->data[reg.ptrOffset])));
return true;
case ev_float:
out = va("%g", *(reinterpret_cast<float*>(&obj->data[reg.ptrOffset])));
return true;
case ev_string: {
const char* str;
str = reinterpret_cast<const char*>(&obj->data[reg.ptrOffset]);
if (!str) {
out = "\"\"";
case ev_float:
out = va( "%g", *( reinterpret_cast<float *>( &obj->data[ reg.ptrOffset ] ) ) );
return true;
case ev_string: {
const char* str;
str = reinterpret_cast<const char*>( &obj->data[ reg.ptrOffset ] );
if ( !str ) {
out = "\"\"";
} else {
out = "\"";
out += str;
out += "\"";
}
return true;
}
else {
out = "\"";
out += str;
out += "\"";
}
return true;
}
default:
return false;
default:
return false;
}
break;
}
case ev_string:
if (reg.stringPtr) {
if ( reg.stringPtr ) {
out = "\"";
out += reg.stringPtr;
out += "\"";
}
else {
} else {
out = "\"\"";
}
return true;
@ -1004,7 +1006,7 @@ bool idInterpreter::Execute( void ) {
// next statement
st = &gameLocal.program.GetStatement( instructionPointer );
if ( !IsGameDebuggerActive( this, &gameLocal.program, instructionPointer )
if ( !updateGameDebugger( this, &gameLocal.program, instructionPointer )
&& g_debugScript.GetBool( ) )
{
static int lastLineNumber = -1;

View file

@ -3290,13 +3290,11 @@ static bool isDemo( void )
return sessLocal.IsDemoVersion();
}
static DebuggerArgs_t userDebuggerArgs;
static bool checkForDebuggerBreakPoint( void )
static bool updateDebugger( idInterpreter *interpreter, idProgram *program, int instructionPointer )
{
if (com_editors & EDITOR_DEBUGGER)
{
DebuggerServerCheckBreakpoint( userDebuggerArgs.interpreter, userDebuggerArgs.program, userDebuggerArgs.instructionPointer );
DebuggerServerCheckBreakpoint( interpreter, program, instructionPointer );
return true;
}
return false;
@ -3323,9 +3321,8 @@ bool idCommonLocal::GetAdditionalFunction(idCommon::FunctionType ft, idCommon::F
return true;
case idCommon::FT_CheckDebuggerBreakpoint:
*out_fnptr = (idCommon::FunctionPointer)checkForDebuggerBreakPoint;
if (out_userArg != NULL )
*out_userArg = &userDebuggerArgs;
*out_fnptr = (idCommon::FunctionPointer)updateDebugger;
return true;
default:
@ -3339,13 +3336,10 @@ idGameCallbacks gameCallbacks;
idGameCallbacks::idGameCallbacks()
: reloadImagesCB(NULL), reloadImagesUserArg(NULL)
, checkBreakPointCB(NULL), checkBreakPointUserArg(NULL)
{}
void idGameCallbacks::Reset()
{
reloadImagesCB = NULL;
reloadImagesUserArg = NULL;
checkBreakPointCB = NULL;
checkBreakPointUserArg = NULL;
}

View file

@ -117,12 +117,6 @@ class idLangDict;
class idInterpreter;
class idProgram;
struct DebuggerArgs_t {
idInterpreter *interpreter;
idProgram *program;
int instructionPointer;
};
class idCommon {
public:
virtual ~idCommon( void ) {}
@ -277,6 +271,14 @@ public:
// it returns true if we're currently running the doom3 demo
// not relevant for mods, only for game/ aka base.dll/base.so/...
FT_IsDemo = 1,
// the function's signature is bool fn(void) - no arguments.
// it returns true if the game debugger is active
// relevant for mods.
FT_DebuggerActive,
// the function's signature is bool fn(idInterpreter,idProgram,int) with arguments:
// idInterpreter *interpreter, idProgram *program, int instructionPointer
// it returns true if the game debugger is active.
// relevant for mods.
FT_CheckDebuggerBreakpoint,
};

View file

@ -43,10 +43,6 @@ struct idGameCallbacks {
ReloadImagesCallback reloadImagesCB;
void* reloadImagesUserArg;
typedef void ( *CheckBreakpointCallback )( void *userArg, idInterpreter *interpreter, idProgram *program, int instructionPointer );
CheckBreakpointCallback checkBreakPointCB;
void* checkBreakPointUserArg;
idGameCallbacks();
// called when Game DLL is unloaded (=> the registered callbacks become invalid)

View file

@ -270,18 +270,11 @@ bool IsDoom3DemoVersion()
return ret;
}
static DebuggerArgs_t * userDebuggerArgs;
static bool ( *checkDebuggerBreakpointFnPtr )( void ) = NULL;
bool IsGameDebuggerActive( idInterpreter *interpreter, idProgram *program, int instructionPointer )
{
static bool ( *updateDebuggerFnPtr )( idInterpreter *interpreter, idProgram *program, int instructionPointer ) = NULL;
bool updateGameDebugger( idInterpreter *interpreter, idProgram *program, int instructionPointer ) {
bool ret = false;
if (interpreter != nullptr && program != nullptr )
{
userDebuggerArgs->interpreter = interpreter;
userDebuggerArgs->program = program;
userDebuggerArgs->instructionPointer = instructionPointer;
ret = checkDebuggerBreakpointFnPtr ? checkDebuggerBreakpointFnPtr( ) : false;
if ( interpreter != nullptr && program != nullptr ) {
ret = updateDebuggerFnPtr ? updateDebuggerFnPtr( interpreter, program, instructionPointer ) : false;
}
return ret;
}
@ -368,8 +361,7 @@ void idGameLocal::Init( void ) {
// DG: hack to support the Demo version of Doom3
common->GetAdditionalFunction(idCommon::FT_IsDemo, (idCommon::FunctionPointer*)&isDemoFnPtr, NULL);
//debugger support
common->GetAdditionalFunction( idCommon::FT_CheckDebuggerBreakpoint,
( idCommon::FunctionPointer * ) &checkDebuggerBreakpointFnPtr, (void**)&userDebuggerArgs );
common->GetAdditionalFunction(idCommon::FT_CheckDebuggerBreakpoint,(idCommon::FunctionPointer*) &updateDebuggerFnPtr,NULL);
}
/*

View file

@ -293,7 +293,7 @@ public:
idEntityPtr<idEntity> lastGUIEnt; // last entity with a GUI, used by Cmd_NextGUI_f
int lastGUI; // last GUI on the lastGUIEnt
int editors; // Mirrored editors flags from common to determine which editors are running
// ---------------------- Public idGame Interface -------------------
idGameLocal();

View file

@ -36,7 +36,7 @@ If you have questions concerning this license or the applicable additional terms
#include "framework/FileSystem.h"
// HvG: Debugger support
extern bool IsGameDebuggerActive( idInterpreter *interpreter, idProgram *program, int instructionPointer );
extern bool updateGameDebugger( idInterpreter *interpreter, idProgram *program, int instructionPointer );
/*
================
@ -1007,7 +1007,7 @@ bool idInterpreter::Execute( void ) {
// next statement
st = &gameLocal.program.GetStatement( instructionPointer );
if ( !IsGameDebuggerActive( this, &gameLocal.program, instructionPointer )
if ( !updateGameDebugger( this, &gameLocal.program, instructionPointer )
&& g_debugScript.GetBool( ) )
{
static int lastLineNumber = -1;

View file

@ -147,8 +147,11 @@ Starts up the debugger server
*/
bool DebuggerServerInit ( void )
{
com_enableDebuggerServer.ClearModified( );
// Dont do this if we are in the debugger already
if ( com_editors & EDITOR_DEBUGGER )
if ( gDebuggerServer != NULL
|| ( com_editors & EDITOR_DEBUGGER ) )
{
return false;
}
@ -168,8 +171,6 @@ bool DebuggerServerInit ( void )
return false;
}
com_enableDebuggerServer.ClearModified( );
// Start the debugger server thread
#if SDL_VERSION_ATLEAST(2, 0, 0)
gDebuggerServerThread = SDL_CreateThread( DebuggerServerThread, "DebuggerServer", NULL );
@ -177,7 +178,6 @@ bool DebuggerServerInit ( void )
gDebuggerServerThread = SDL_CreateThread( DebuggerServerThread, NULL );
#endif
return true;
}