Advertisement

debugging context

Started by May 15, 2006 01:26 PM
15 comments, last by kunitoki 18 years, 5 months ago
i have copy and pasted your code and i'm still getting a zero pointer when casting the void* to a asString* passing through asString**. but not only with strings, i've tried with all the other objects that i have registered and seems that i can't get a properly casted object out of that void*, apart from the basic types.
ah, i'm using 2.6.0 and working with unsafe_references... maybe that could modify how variables are stored on the stack ? i don't know, just guessing...
also i've tried calling your exception callback (from test_debug.cpp) directly in my main executeFunction code, just after the script have executed line by line:

while (!abortScript)
{
timeOut = Time::getMillisecondCounter() + 100; // 100
r = context->Execute();

switch(r)
{
case asEXECUTION_SUSPENDED:
if (debugMode)
ExceptionCallback (context, (void*) this);
break;
// ...


anyway i get always a bad cast with the variable void* pointer (but only with
user object types, not basic ones, that works straight with no errors).

further i've discovered that in my case, calling your PrintVariables from the context ExceptionCallback (making the script do a division by zero) all is fine, the cast succeed as in the test_debug.cpp that you've tried (so i can see the value of the string correctly), but if i call the same function from the LineCallback or on the main script execute function i get a zero pointer out of the same cast. dunnow if this could be my fault or not, but actually the code is the same as yours... ah and i've updated to the svn trunk in case this was working only with the code you are using.

i don't know what to do next, i'm stuck.



Advertisement
i've discovered why ! if you try to get out the variables from the current function (and so not passing a specific stack level to context GetXXX functions, leaving the default -1) it crashes. isn't that possible ?
modify the debug test and replace the line callback like this. isn't -1 the current stackLevel (so the current function) ?

void LineCallback(asIScriptContext *ctx, void *param){	asIScriptEngine *engine = ctx->GetEngine();	int funcID = ctx->GetCurrentFunction();	int col;	int line = ctx->GetCurrentLineNumber(&col);	int indent = ctx->GetCallstackSize();	for( int n = 0; n < indent; n++ )		print(" ");	print("%s:%s:%d,%d\n", engine->GetFunctionModule(funcID),	                    engine->GetFunctionDeclaration(funcID),	                    line, col);	PrintVariables(ctx, -1);	print("--- call stack ---\n");	for( int n = 0; n < ctx->GetCallstackSize(); n++ )	{		funcID = ctx->GetCallstackFunction(n);		line = ctx->GetCallstackLineNumber(n,&col);		print("%s:%s:%d,%d\n", engine->GetFunctionModule(funcID),		                       engine->GetFunctionDeclaration(funcID),							   line, col);		PrintVariables(ctx, n);	}}


in fact the script like this works for basic types (casting correctly), but it leaks when casting the string. now the question changes, how can i get out the variables from the current function (not only from current callstack) and cast it correctly ?

[Edited by - kunitoki on June 3, 2006 7:27:50 AM]
Yes, passing the stack level as -1 get the variables for the current function.

I saw that my test_debug.cpp, didn't use that call so I changed it again, and I got the same problem as you. Fortunately this is not a bug in AngelScript, it's just that the string object hasn't been instanciated yet. That's why you're receiving a null pointer. Here's the new code that I wrote:

void LineCallback(asIScriptContext *ctx, void *param){	asIScriptEngine *engine = ctx->GetEngine();	int funcID = ctx->GetCurrentFunction();	int col;	int line = ctx->GetCurrentLineNumber(&col);	int indent = ctx->GetCallstackSize();	for( int n = 0; n < indent; n++ )		print(" ");	print("%s:%s:%d,%d\n", engine->GetFunctionModule(funcID),	                    engine->GetFunctionDeclaration(funcID),	                    line, col);	PrintVariables(ctx, -1);}void PrintVariables(asIScriptContext *ctx, int stackLevel){	int numVars = ctx->GetVarCount(stackLevel);	asIScriptEngine *engine = ctx->GetEngine();	for( int n = 0; n < numVars; n++ )	{		int typeId = ctx->GetVarTypeId(n, stackLevel); 		void *varPointer = ctx->GetVarPointer(n, stackLevel);		if( typeId == engine->GetTypeIdByDecl(0, "int") )		{			print(" %s = %d\n", ctx->GetVarDeclaration(n, 0, stackLevel), *(int*)varPointer);		}		else if( typeId == engine->GetTypeIdByDecl(0, "string") )		{			asCScriptString *str = *(asCScriptString**)varPointer;			if( str )				print(" %s = '%s'\n", ctx->GetVarDeclaration(n, 0, stackLevel), str->buffer.c_str());			else				print(" %s = <null>\n", ctx->GetVarDeclaration(n, 0, stackLevel));		}	}}void ExceptionCallback(asIScriptContext *ctx, void *param){	asIScriptEngine *engine = ctx->GetEngine();	int funcID = ctx->GetExceptionFunction();	print("--- exception ---\n");	print("desc: %s\n", ctx->GetExceptionString());	print("func: %s\n", engine->GetFunctionDeclaration(funcID));	print("modl: %s\n", engine->GetFunctionModule(funcID));	print("sect: %s\n", engine->GetFunctionSection(funcID));	int col, line = ctx->GetExceptionLineNumber(&col);	print("line: %d,%d\n", line, col);	// Print the variables in the current function	PrintVariables(ctx, -1);	// Show the call stack with the variables	print("--- call stack ---\n");	for( int n = 0; n < ctx->GetCallstackSize(); n++ )	{		funcID = ctx->GetCallstackFunction(n);		line = ctx->GetCallstackLineNumber(n,&col);		print("%s:%s:%d,%d\n", engine->GetFunctionModule(funcID),		                       engine->GetFunctionDeclaration(funcID),							   line, col);		PrintVariables(ctx, n);	}}


Note the new method GetVarTypeId() that I added yesterday when testing this. :)

I'll update the manual with these explanations so that the confusion can be avoided in the future.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

cool. i didn't mind that could be the problem. i'm a poor programmer that don't like too much check for pointer zeroness ;) sorry for bothering, took me hours to understand a simple pointer validity check tho, but i think you better clarify this somewhere... now the ide is on the line ! thanx !
Don't worry about it. All this was for the good, as I've now added this clarification to the manual, so that the next developer may avoid this confusion. :)

I'm glad you're moving along with the IDE. When will we be able to download it and try it out?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
yeah i don't worry too much now that i have understood how to make it work ;) thanx a lot man...
for the ide i would like to implement at least half of things i want to be there before releasing it, and not leave anything to the fate. anyway it is comin in a few weeks, be patient as i'm patient waiting new features in angelscript (inheritance? pointers? static members and functions?) :D

[Edited by - kunitoki on June 4, 2006 5:27:58 PM]

This topic is closed to new replies.

Advertisement