enhanced debug information of lua opcodes
This commit is contained in:
parent
91676c68dc
commit
671e2be1c4
5 changed files with 151 additions and 456 deletions
|
@ -37,7 +37,7 @@ enum enDebugLevels {
|
|||
DEBUG_NORMAL,
|
||||
DEBUG_WARN,
|
||||
DEBUG_ERROR,
|
||||
DEBUG_FUNC,
|
||||
DEBUG_LUA,
|
||||
DEBUG_BITMAPS,
|
||||
DEBUG_MODEL,
|
||||
DEBUG_STUB,
|
||||
|
|
511
engine/lua.cpp
511
engine/lua.cpp
File diff suppressed because it is too large
Load diff
|
@ -138,11 +138,13 @@ static StkId callC(lua_CFunction f, StkId base) {
|
|||
CS->num = numarg;
|
||||
CS->lua2C = base;
|
||||
CS->base = base + numarg; // == top - stack
|
||||
if (lua_callhook)
|
||||
luaD_callHook(base, NULL, 0);
|
||||
if (lua_callhook) {
|
||||
TObject *f = L->stack.stack + base - 1;
|
||||
(*lua_callhook)(Ref(f), "(C)", -1);
|
||||
}
|
||||
(*f)(); // do the actual call
|
||||
if (lua_callhook) // func may have changed lua_callhook
|
||||
luaD_callHook(base, NULL, 1);
|
||||
// if (lua_callhook) // func may have changed lua_callhook
|
||||
// (*lua_callhook)(LUA_NOOBJECT, "(return)", 0);
|
||||
firstResult = CS->base;
|
||||
*CS = oldCLS;
|
||||
return firstResult;
|
||||
|
@ -206,8 +208,10 @@ void luaD_precall(TObject *f, StkId base, int32 nResults) {
|
|||
L->ci->pc = NULL;
|
||||
} else {
|
||||
byte *pc = tfvalue(f)->code;
|
||||
if (lua_callhook)
|
||||
luaD_callHook(base, tfvalue(f), 0);
|
||||
if (lua_callhook) {
|
||||
TObject *f = L->stack.stack + base - 1;
|
||||
(*lua_callhook)(Ref(f), tfvalue(f)->fileName->str, tfvalue(f)->lineDefined);
|
||||
}
|
||||
luaD_checkstack((*pc++) + EXTRA_STACK);
|
||||
if (*pc < ZEROVARARG) {
|
||||
luaD_adjusttop(base + *(pc++));
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#include "common/endian.h"
|
||||
|
||||
#include "engine/actor.h"
|
||||
|
||||
#include "engine/lua/lbuiltin.h"
|
||||
#include "engine/lua/ldo.h"
|
||||
|
@ -18,6 +21,7 @@
|
|||
#include "engine/lua/ltask.h"
|
||||
#include "engine/lua/ltm.h"
|
||||
#include "engine/lua/lualib.h"
|
||||
#include "engine/lua/luadebug.h"
|
||||
|
||||
LState *lua_state = NULL;
|
||||
|
||||
|
@ -67,6 +71,68 @@ void lua_resetglobals() {
|
|||
luaX_init();
|
||||
}
|
||||
|
||||
Actor *check_actor(int num);
|
||||
Color *check_color(int num);
|
||||
|
||||
void callHook(lua_Function func, const char *filename, int line) {
|
||||
const char *name, *type;
|
||||
FILE *output = stdout;
|
||||
int i;
|
||||
|
||||
type = lua_getobjname(func, &name);
|
||||
if (func == LUA_NOOBJECT) {
|
||||
fprintf(output, "%s\n", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (*type) {
|
||||
case 'g':
|
||||
fprintf(output, "function: %s(", name);
|
||||
for (i = 1; ; i++) {
|
||||
if (lua_getparam(i) == LUA_NOOBJECT)
|
||||
break;
|
||||
if (lua_isnil(lua_getparam(i)))
|
||||
fprintf(output, "nil");
|
||||
else if (lua_istable(lua_getparam(i)))
|
||||
fprintf(output, "{...}");
|
||||
else if (lua_isuserdata(lua_getparam(i))) {
|
||||
if (lua_tag(lua_getparam(i)) == MKID_BE('ACTR')) {
|
||||
Actor *a = check_actor(i);
|
||||
fprintf(output, "<actor \"%s\">", a->name());
|
||||
} else if (lua_tag(lua_getparam(i)) == MKID_BE('COLR')) {
|
||||
Color *c = check_color(i);
|
||||
fprintf(output, "<color #%02x%02x%02x>", c->red(), c->green(), c->blue());
|
||||
} else
|
||||
fprintf(output, "<userdata %p>", lua_getuserdata(lua_getparam(i)));
|
||||
} else if (lua_isfunction(lua_getparam(i))) {
|
||||
fprintf(output, "<function>");
|
||||
} else if (lua_isnumber(lua_getparam(i)))
|
||||
fprintf(output, "%g", lua_getnumber(lua_getparam(i)));
|
||||
else if (lua_isstring(lua_getparam(i)))
|
||||
fprintf(output, "\"%s\"", lua_getstring(lua_getparam(i)));
|
||||
else
|
||||
fprintf(output, "<unknown>");
|
||||
if (lua_getparam(i + 1) != LUA_NOOBJECT)
|
||||
fprintf(output, ", ");
|
||||
}
|
||||
fprintf(output, ")");
|
||||
break;
|
||||
case 't':
|
||||
fprintf(output, "`%s' tag method", name);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (line == 0)
|
||||
fprintf(output, "{START SCRIPT: %s}", filename);
|
||||
else if (line < 0) {
|
||||
fprintf(output, "%s", filename);
|
||||
} else
|
||||
fprintf(output, "function (%s:%d)", filename, line);
|
||||
}
|
||||
}
|
||||
fprintf(output, "\n");
|
||||
}
|
||||
|
||||
void lua_open() {
|
||||
if (lua_state)
|
||||
return;
|
||||
|
@ -75,6 +141,8 @@ void lua_open() {
|
|||
luaT_init();
|
||||
luaB_predefine();
|
||||
luaL_addlibtolist(stdErrorRimFunc, (sizeof(stdErrorRimFunc) / sizeof(stdErrorRimFunc[0])));
|
||||
if (gDebugLevel == DEBUG_LUA || gDebugLevel == DEBUG_ALL)
|
||||
lua_callhook = callHook;
|
||||
}
|
||||
|
||||
void lua_close() {
|
||||
|
|
|
@ -678,8 +678,8 @@ callfunc:
|
|||
case RETCODE:
|
||||
{
|
||||
StkId firstResult = (base + ((aux == RETCODE) ? *pc : 0));
|
||||
if (lua_callhook)
|
||||
luaD_callHook(base, NULL, 1);
|
||||
// if (lua_callhook)
|
||||
// (*lua_callhook)(LUA_NOOBJECT, "(END OF SCRIPT}", 0);
|
||||
// If returning from the original stack frame, terminate
|
||||
if (L->ci == L->base_ci + ci_index)
|
||||
return firstResult;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue