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

View file

@ -36,7 +36,7 @@ If you have questions concerning this license or the applicable additional terms
#include "framework/FileSystem.h" #include "framework/FileSystem.h"
// HvG: Debugger support // 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; 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; varEval_t reg;
idVarDef* d; idVarDef *d;
char funcObject[1024]; char funcObject[ 1024 ];
char* funcName; char *funcName;
const idVarDef* scope = NULL; const idVarDef *scope = NULL;
const idVarDef* scopeObj; const idVarDef *scopeObj;
const idTypeDef* field; const idTypeDef *field;
const function_t* func; const function_t *func;
out.Empty(); out.Empty();
if (scopeDepth == -1) { if ( scopeDepth == -1 ) {
scopeDepth = callStackDepth; scopeDepth = callStackDepth;
} }
if (scopeDepth == callStackDepth) { if ( scopeDepth == callStackDepth ) {
func = currentFunction; func = currentFunction;
} else {
func = callStack[ scopeDepth ].f;
} }
else { if ( !func ) {
func = callStack[scopeDepth].f;
}
if (!func) {
return false; return false;
} }
idStr::Copynz(funcObject, func->Name(), sizeof(funcObject)); idStr::Copynz( funcObject, func->Name(), sizeof( funcObject ) );
funcName = strstr(funcObject, "::"); funcName = strstr( funcObject, "::" );
if (funcName) { if ( funcName ) {
*funcName = '\0'; *funcName = '\0';
scopeObj = gameLocal.program.GetDef(NULL, funcObject, &def_namespace); scopeObj = gameLocal.program.GetDef( NULL, funcObject, &def_namespace );
funcName += 2; funcName += 2;
if (scopeObj) if ( scopeObj )
{ {
scope = gameLocal.program.GetDef(NULL, funcName, scopeObj); scope = gameLocal.program.GetDef( NULL, funcName, scopeObj );
} }
} } else {
else {
funcName = funcObject; funcName = funcObject;
scope = gameLocal.program.GetDef(NULL, func->Name(), &def_namespace); scope = gameLocal.program.GetDef( NULL, func->Name(), &def_namespace );
scopeObj = NULL; scopeObj = NULL;
} }
if (!scope) if ( !scope )
{ {
return false; 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 // 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); d = gameLocal.program.GetDef( NULL, name, scopeObj );
if (d) if ( d )
{ {
break; break;
} }
} }
} }
if (!d) if ( !d )
{ {
out = "???"; out = "???";
return false; return false;
} }
reg = GetVariable(d); reg = GetVariable( d );
switch (d->Type()) { switch( d->Type() ) {
case ev_float: case ev_float:
if (reg.floatPtr) { if ( reg.floatPtr ) {
out = va("%g", *reg.floatPtr); out = va("%g", *reg.floatPtr );
} } else {
else {
out = "0"; out = "0";
} }
return true; return true;
break; break;
case ev_vector: case ev_vector:
if (reg.vectorPtr) { if ( reg.vectorPtr ) {
out = va("%g,%g,%g", reg.vectorPtr->x, reg.vectorPtr->y, reg.vectorPtr->z); out = va( "%g,%g,%g", reg.vectorPtr->x, reg.vectorPtr->y, reg.vectorPtr->z );
} } else {
else {
out = "0,0,0"; out = "0,0,0";
} }
return true; return true;
break; break;
case ev_boolean: case ev_boolean:
if (reg.intPtr) { if ( reg.intPtr ) {
out = va("%d", *reg.intPtr); out = va( "%d", *reg.intPtr );
} } else {
else {
out = "0"; out = "0";
} }
return true; return true;
@ -287,39 +291,38 @@ bool idInterpreter::GetRegisterValue(const char* name, idStr& out, int scopeDept
idEntity* entity; idEntity* entity;
idScriptObject* obj; idScriptObject* obj;
if (scope == &def_namespace) { if ( scope == &def_namespace ) {
// should never happen, but handle it safely anyway // should never happen, but handle it safely anyway
return false; return false;
} }
field = d->TypeDef()->FieldType(); field = d->TypeDef()->FieldType();
entity = GetEntity(*((int*)&localstack[localstackBase])); entity = GetEntity ( *((int*)&localstack[ localstackBase ]) );
if (!entity || !field) if ( !entity || !field )
{ {
return false; return false;
} }
obj = &entity->scriptObject; obj = &entity->scriptObject;
if (!obj) { if ( !obj ) {
return false; return false;
} }
switch (field->Type()) { switch ( field->Type() ) {
case ev_boolean: case ev_boolean:
out = va("%d", *(reinterpret_cast<int*>(&obj->data[reg.ptrOffset]))); out = va( "%d", *( reinterpret_cast<int *>( &obj->data[ reg.ptrOffset ] ) ) );
return true; return true;
case ev_float: case ev_float:
out = va("%g", *(reinterpret_cast<float*>(&obj->data[reg.ptrOffset]))); out = va( "%g", *( reinterpret_cast<float *>( &obj->data[ reg.ptrOffset ] ) ) );
return true; return true;
case ev_string: { case ev_string: {
const char* str; const char* str;
str = reinterpret_cast<const char*>(&obj->data[reg.ptrOffset]); str = reinterpret_cast<const char*>( &obj->data[ reg.ptrOffset ] );
if (!str) { if ( !str ) {
out = "\"\""; out = "\"\"";
} } else {
else {
out = "\""; out = "\"";
out += str; out += str;
out += "\""; out += "\"";
@ -335,12 +338,11 @@ bool idInterpreter::GetRegisterValue(const char* name, idStr& out, int scopeDept
} }
case ev_string: case ev_string:
if (reg.stringPtr) { if ( reg.stringPtr ) {
out = "\""; out = "\"";
out += reg.stringPtr; out += reg.stringPtr;
out += "\""; out += "\"";
} } else {
else {
out = "\"\""; out = "\"\"";
} }
return true; return true;
@ -1004,7 +1006,7 @@ bool idInterpreter::Execute( void ) {
// next statement // next statement
st = &gameLocal.program.GetStatement( instructionPointer ); st = &gameLocal.program.GetStatement( instructionPointer );
if ( !IsGameDebuggerActive( this, &gameLocal.program, instructionPointer ) if ( !updateGameDebugger( this, &gameLocal.program, instructionPointer )
&& g_debugScript.GetBool( ) ) && g_debugScript.GetBool( ) )
{ {
static int lastLineNumber = -1; static int lastLineNumber = -1;

View file

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

View file

@ -117,12 +117,6 @@ class idLangDict;
class idInterpreter; class idInterpreter;
class idProgram; class idProgram;
struct DebuggerArgs_t {
idInterpreter *interpreter;
idProgram *program;
int instructionPointer;
};
class idCommon { class idCommon {
public: public:
virtual ~idCommon( void ) {} virtual ~idCommon( void ) {}
@ -277,6 +271,14 @@ public:
// it returns true if we're currently running the doom3 demo // it returns true if we're currently running the doom3 demo
// not relevant for mods, only for game/ aka base.dll/base.so/... // not relevant for mods, only for game/ aka base.dll/base.so/...
FT_IsDemo = 1, 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, FT_CheckDebuggerBreakpoint,
}; };

View file

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

View file

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

View file

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

View file

@ -36,7 +36,7 @@ If you have questions concerning this license or the applicable additional terms
#include "framework/FileSystem.h" #include "framework/FileSystem.h"
// HvG: Debugger support // 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 // next statement
st = &gameLocal.program.GetStatement( instructionPointer ); st = &gameLocal.program.GetStatement( instructionPointer );
if ( !IsGameDebuggerActive( this, &gameLocal.program, instructionPointer ) if ( !updateGameDebugger( this, &gameLocal.program, instructionPointer )
&& g_debugScript.GetBool( ) ) && g_debugScript.GetBool( ) )
{ {
static int lastLineNumber = -1; static int lastLineNumber = -1;

View file

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