mirror of https://github.com/rusefi/lua.git
errors may happen before function start running (with pc=-1)
This commit is contained in:
parent
2d3ebba537
commit
21dc77b2af
18
ldebug.c
18
ldebug.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ldebug.c,v 1.37 2000/08/28 17:57:04 roberto Exp roberto $
|
** $Id: ldebug.c,v 1.38 2000/08/28 20:22:21 roberto Exp roberto $
|
||||||
** Debug Interface
|
** Debug Interface
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -93,7 +93,10 @@ static int lua_nups (StkId f) {
|
||||||
|
|
||||||
|
|
||||||
int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) {
|
int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) {
|
||||||
int refi = prefi ? *prefi : 0;
|
int refi;
|
||||||
|
if (lineinfo == NULL) return -1; /* no line info */
|
||||||
|
else if (pc == -1) return refline; /* function preamble */
|
||||||
|
refi = prefi ? *prefi : 0;
|
||||||
if (lineinfo[refi] < 0)
|
if (lineinfo[refi] < 0)
|
||||||
refline += -lineinfo[refi++];
|
refline += -lineinfo[refi++];
|
||||||
LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info");
|
LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info");
|
||||||
|
@ -123,7 +126,7 @@ int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) {
|
||||||
static int lua_currentpc (StkId f) {
|
static int lua_currentpc (StkId f) {
|
||||||
CallInfo *ci = infovalue(f);
|
CallInfo *ci = infovalue(f);
|
||||||
LUA_ASSERT(ttype(f) == TAG_LMARK, "function has no pc");
|
LUA_ASSERT(ttype(f) == TAG_LMARK, "function has no pc");
|
||||||
return (*ci->pc - 1) - ci->func->f.l->code;
|
return (*ci->pc - ci->func->f.l->code) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,10 +163,11 @@ const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int localnum) {
|
||||||
const char *name;
|
const char *name;
|
||||||
StkId f = ar->_func;
|
StkId f = ar->_func;
|
||||||
Proto *fp = getluaproto(f);
|
Proto *fp = getluaproto(f);
|
||||||
|
L->top--; /* pop new value */
|
||||||
if (!fp) return NULL; /* `f' is not a Lua function? */
|
if (!fp) return NULL; /* `f' is not a Lua function? */
|
||||||
name = luaF_getlocalname(fp, localnum, lua_currentpc(f));
|
name = luaF_getlocalname(fp, localnum, lua_currentpc(f));
|
||||||
if (!name || name[0] == '*') return NULL; /* `*' starts private locals */
|
if (!name || name[0] == '*') return NULL; /* `*' starts private locals */
|
||||||
*((f+1)+(localnum-1)) = *(--L->top);
|
*((f+1)+(localnum-1)) = *L->top;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,6 +380,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) {
|
||||||
int pc = lua_currentpc(func);
|
int pc = lua_currentpc(func);
|
||||||
int stackpos = obj - (func+1); /* func+1 == function base */
|
int stackpos = obj - (func+1); /* func+1 == function base */
|
||||||
Instruction i = luaG_symbexec(p, pc, stackpos);
|
Instruction i = luaG_symbexec(p, pc, stackpos);
|
||||||
|
LUA_ASSERT(pc != -1, "function must be active");
|
||||||
switch (GET_OPCODE(i)) {
|
switch (GET_OPCODE(i)) {
|
||||||
case OP_GETGLOBAL: {
|
case OP_GETGLOBAL: {
|
||||||
*name = p->kstr[GETARG_U(i)]->str;
|
*name = p->kstr[GETARG_U(i)]->str;
|
||||||
|
@ -404,7 +409,10 @@ static const char *getfuncname (lua_State *L, StkId f, const char **name) {
|
||||||
return NULL; /* not a Lua function */
|
return NULL; /* not a Lua function */
|
||||||
else {
|
else {
|
||||||
Proto *p = infovalue(func)->func->f.l;
|
Proto *p = infovalue(func)->func->f.l;
|
||||||
Instruction i = p->code[lua_currentpc(func)];
|
int pc = lua_currentpc(func);
|
||||||
|
Instruction i;
|
||||||
|
if (pc == -1) return NULL; /* function is not activated */
|
||||||
|
i = p->code[pc];
|
||||||
switch (GET_OPCODE(i)) {
|
switch (GET_OPCODE(i)) {
|
||||||
case OP_CALL: case OP_TAILCALL:
|
case OP_CALL: case OP_TAILCALL:
|
||||||
return getobjname(L, (func+1)+GETARG_A(i), name);
|
return getobjname(L, (func+1)+GETARG_A(i), name);
|
||||||
|
|
Loading…
Reference in New Issue