first attempt to make debug API skip JITed Lua functions - issue 16

pull/81/head
Dibyendu Majumdar 9 years ago
parent 68cfd0c3f9
commit 380dfbbd60

@ -167,8 +167,10 @@ struct Table {
struct Node *lastfree; /* any free position is before this position */
struct Table *metatable;
struct GCObject *gclist;
char *ravi_data;
enum ravitype_t ravi_array_type; /* RAVI specialization */
unsigned int ravi_array_len; /* RAVI len specialization */
unsigned int ravi_array_size; /* RAVI len specialization */
};
struct Mbuffer {
@ -214,6 +216,7 @@ struct CallInfo {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct CallInfoLua {
@ -224,6 +227,7 @@ struct CallInfoLua {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct global_State;

@ -167,8 +167,10 @@ struct Table {
struct Node *lastfree; /* any free position is before this position */
struct Table *metatable;
struct GCObject *gclist;
char *ravi_data;
enum ravitype_t ravi_array_type; /* RAVI specialization */
unsigned int ravi_array_len; /* RAVI len specialization */
unsigned int ravi_array_size; /* RAVI len specialization */
};
struct Mbuffer {
@ -214,6 +216,7 @@ struct CallInfo {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct CallInfoLua {
@ -224,6 +227,7 @@ struct CallInfoLua {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct global_State;

@ -167,8 +167,10 @@ struct Table {
struct Node *lastfree; /* any free position is before this position */
struct Table *metatable;
struct GCObject *gclist;
char *ravi_data;
enum ravitype_t ravi_array_type; /* RAVI specialization */
unsigned int ravi_array_len; /* RAVI len specialization */
unsigned int ravi_array_size; /* RAVI len specialization */
};
struct Mbuffer {
@ -214,6 +216,7 @@ struct CallInfo {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct CallInfoLua {
@ -224,6 +227,7 @@ struct CallInfoLua {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct global_State;

@ -167,8 +167,10 @@ struct Table {
struct Node *lastfree; /* any free position is before this position */
struct Table *metatable;
struct GCObject *gclist;
char *ravi_data;
enum ravitype_t ravi_array_type; /* RAVI specialization */
unsigned int ravi_array_len; /* RAVI len specialization */
unsigned int ravi_array_size; /* RAVI len specialization */
};
struct Mbuffer {
@ -214,6 +216,7 @@ struct CallInfo {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct CallInfoLua {
@ -224,6 +227,7 @@ struct CallInfoLua {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct global_State;

@ -167,8 +167,10 @@ struct Table {
struct Node *lastfree; /* any free position is before this position */
struct Table *metatable;
struct GCObject *gclist;
char *ravi_data;
enum ravitype_t ravi_array_type; /* RAVI specialization */
unsigned int ravi_array_len; /* RAVI len specialization */
unsigned int ravi_array_size; /* RAVI len specialization */
};
struct Mbuffer {
@ -214,6 +216,7 @@ struct CallInfo {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct CallInfoLua {
@ -224,6 +227,7 @@ struct CallInfoLua {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct global_State;

@ -167,8 +167,10 @@ struct Table {
struct Node *lastfree; /* any free position is before this position */
struct Table *metatable;
struct GCObject *gclist;
char *ravi_data;
enum ravitype_t ravi_array_type; /* RAVI specialization */
unsigned int ravi_array_len; /* RAVI len specialization */
unsigned int ravi_array_size; /* RAVI len specialization */
};
struct Mbuffer {
@ -214,6 +216,7 @@ struct CallInfo {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct CallInfoLua {
@ -224,6 +227,7 @@ struct CallInfoLua {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct global_State;

@ -167,8 +167,10 @@ struct Table {
struct Node *lastfree; /* any free position is before this position */
struct Table *metatable;
struct GCObject *gclist;
char *ravi_data;
enum ravitype_t ravi_array_type; /* RAVI specialization */
unsigned int ravi_array_len; /* RAVI len specialization */
unsigned int ravi_array_size; /* RAVI len specialization */
};
struct Mbuffer {
@ -214,6 +216,7 @@ struct CallInfo {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct CallInfoLua {
@ -224,6 +227,7 @@ struct CallInfoLua {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned char callstatus;
unsigned char jitstatus;
};
struct global_State;

@ -80,6 +80,7 @@ typedef struct CallInfo {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
lu_byte callstatus;
lu_byte jitstatus; /* Only valid if Lua function - if 1 means JITed - RAVI extension */
} CallInfo;
@ -96,6 +97,7 @@ typedef struct CallInfo {
#define CIST_HOOKYIELD (1<<6) /* last hook called yielded */
#define isLua(ci) ((ci)->callstatus & CIST_LUA)
#define isJITed(ci) ((ci)->jitstatus)
/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
#define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v))

@ -38,7 +38,7 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
static int currentpc (CallInfo *ci) {
lua_assert(isLua(ci));
lua_assert(isLua(ci) && !isJITed(ci));
return pcRel(ci->u.l.savedpc, ci_func(ci)->p);
}
@ -56,7 +56,7 @@ LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
mask = 0;
func = NULL;
}
if (isLua(L->ci))
if (isLua(L->ci) && !isJITed(L->ci))
L->oldpc = L->ci->u.l.savedpc;
L->hook = func;
L->basehookcount = count;
@ -119,7 +119,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
StkId *pos) {
const char *name = NULL;
StkId base;
if (isLua(ci)) {
if (isLua(ci) && !isJITed(ci)) {
if (n < 0) /* access to vararg values? */
return findvararg(ci, -n, pos);
else {
@ -223,7 +223,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
break;
}
case 'l': {
ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;
ar->currentline = (ci && isLua(ci) && !isJITed(ci)) ? currentline(ci) : -1;
break;
}
case 'u': {
@ -244,7 +244,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
}
case 'n': {
/* calling function is a known Lua function? */
if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous) && !isJITed(ci->previous))
ar->namewhat = getfuncname(L, ci->previous, &ar->name);
else
ar->namewhat = NULL;
@ -441,16 +441,16 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
TMS tm = (TMS)0; /* to avoid warnings */
Proto *p = ci_func(ci)->p; /* calling function */
if (p->ravi_jit.jit_status == 2) {
*name = "?";
return "compiled";
}
int pc = currentpc(ci); /* calling instruction index */
Instruction i = p->code[pc]; /* calling instruction */
if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
*name = "?";
return "hook";
}
if (p->ravi_jit.jit_status == 2) {
*name = "?";
return "compiled";
}
switch (GET_OPCODE(i)) {
case OP_CALL:
case OP_TAILCALL: /* get function name */
@ -526,7 +526,7 @@ static const char *varinfo (lua_State *L, const TValue *o) {
const char *name = NULL; /* to avoid warnings */
CallInfo *ci = L->ci;
const char *kind = NULL;
if (isLua(ci)) {
if (isLua(ci) && !isJITed(ci)) {
kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
if (!kind && isinstack(ci, o)) /* no? try a register */
kind = getobjname(ci_func(ci)->p, currentpc(ci),
@ -580,7 +580,7 @@ l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
static void addinfo (lua_State *L, const char *msg) {
CallInfo *ci = L->ci;
if (isLua(ci)) { /* is Lua code? */
if (isLua(ci) && !isJITed(ci)) { /* is Lua code? */
char buff[LUA_IDSIZE]; /* add file:line information */
int line = currentline(ci);
TString *src = ci_func(ci)->p->source;

@ -331,6 +331,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults, int compile) {
ci->top = L->top + LUA_MINSTACK;
lua_assert(ci->top <= L->stack_last);
ci->callstatus = 0;
ci->jitstatus = 0;
luaC_checkGC(L); /* stack grow uses memory */
if (L->hookmask & LUA_MASKCALL)
luaD_hook(L, LUA_HOOKCALL, -1);
@ -365,6 +366,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults, int compile) {
lua_assert(ci->top <= L->stack_last);
ci->u.l.savedpc = p->code; /* starting point */
ci->callstatus = CIST_LUA;
ci->jitstatus = 0;
L->top = ci->top;
luaC_checkGC(L); /* stack grow uses memory */
if (L->hookmask & LUA_MASKCALL)
@ -377,12 +379,14 @@ int luaD_precall (lua_State *L, StkId func, int nresults, int compile) {
if (p->ravi_jit.jit_status == 2) {
/* compiled */
lua_assert(p->ravi_jit.jit_function != NULL);
ci->jitstatus = 1;
if (++L->nCcalls >= LUAI_MAXCCALLS) {
if (L->nCcalls == LUAI_MAXCCALLS)
luaG_runerror(L, "C stack overflow");
else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS >> 3)))
luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
}
L->nny++;
(*p->ravi_jit.jit_function)(L);
L->nny--;
@ -390,6 +394,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults, int compile) {
lua_assert(L->ci == prevci);
ci = L->ci;
lua_assert(isLua(ci));
lua_assert(isJITed(ci));
/* Return a different value from 1 to allow luaV_execute() to distinguish between JITed function and true C function*/
return 2;
}

@ -107,6 +107,7 @@ void luaE_setdebt (global_State *g, l_mem debt) {
CallInfo *luaE_extendCI (lua_State *L) {
CallInfo *ci = luaM_new(L, CallInfo);
ci->jitstatus = 0;
lua_assert(L->ci->next == NULL);
L->ci->next = ci;
ci->previous = L->ci;
@ -158,6 +159,7 @@ static void stack_init (lua_State *L1, lua_State *L) {
ci = &L1->base_ci;
ci->next = ci->previous = NULL;
ci->callstatus = 0;
ci->jitstatus = 0; /* RAVI extension */
ci->func = L1->top;
setnilvalue(L1->top++); /* 'function' entry for this 'ci' */
ci->top = L1->top + LUA_MINSTACK;

@ -1246,6 +1246,7 @@ newframe: /* reentry point when frame changes (call/return) */
else { /* Lua function */
ci = L->ci;
ci->callstatus |= CIST_REENTRY;
lua_assert(!ci->jitstatus);
goto newframe; /* restart luaV_execute over new Lua function */
}
} break;
@ -1273,6 +1274,7 @@ newframe: /* reentry point when frame changes (call/return) */
oci->top = L->top = ofunc + (L->top - nfunc); /* correct top */
oci->u.l.savedpc = nci->u.l.savedpc;
oci->callstatus |= CIST_TAIL; /* function was tail called */
oci->jitstatus = 0;
ci = L->ci = oci; /* remove new frame */
lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize);
goto newframe; /* restart luaV_execute over new Lua function */

@ -531,6 +531,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
elements.push_back(C_ptrdiff_t); /* extra */
elements.push_back(llvm::Type::getInt16Ty(context)); /* nresults */
elements.push_back(lu_byteT); /* callstatus */
elements.push_back(lu_byteT); /* jitstatus RAVI extension*/
CallInfoT->setBody(elements);
// typedef struct ravi_State ravi_State;
@ -879,6 +880,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
nodes.push_back(std::pair<llvm::MDNode *, uint64_t>(tbaa_longlongT, 32));
nodes.push_back(std::pair<llvm::MDNode *, uint64_t>(tbaa_shortT, 40));
nodes.push_back(std::pair<llvm::MDNode *, uint64_t>(tbaa_charT, 42));
nodes.push_back(std::pair<llvm::MDNode *, uint64_t>(tbaa_charT, 43));
tbaa_CallInfoT = mdbuilder.createTBAAStructTypeNode("CallInfo", nodes);
//!7 = metadata !{metadata !"lua_State",

Loading…
Cancel
Save