static void getlocal (void) { lua_Object func = lua_stackedfunction(luaL_check_int(1)); lua_Object val; char *name; if (func == LUA_NOOBJECT) /* level out of range? */ return; /* return nil */ else if (lua_getparam(2) != LUA_NOOBJECT) { /* 2nd argument? */ if ((val = lua_getlocal(func, findlocal(func, 2), &name)) != LUA_NOOBJECT) { lua_pushobject(val); lua_pushstring(name); } /* else return nil */ } else { /* collect all locals in a table */ lua_Object result = lua_createtable(); int i; for (i=1; ;i++) { if ((val = lua_getlocal(func, i, &name)) == LUA_NOOBJECT) break; lua_pushobject(result); lua_pushstring(name); lua_pushobject(val); lua_settable(); /* result[name] = value */ } lua_pushobject(result); } }
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { CallInfo *ci = L->base_ci + ar->i_ci; const char *name = findlocal(L, ci, n); lua_lock(L); if (name) luaA_pushobject(L, ci->base + (n - 1)); lua_unlock(L); return name; }
static void setlocal (void) { lua_Object func = lua_stackedfunction(luaL_check_int(1)); int numvar; luaL_arg_check(func != LUA_NOOBJECT, 1, "level out of range"); numvar = findlocal(func, 2); lua_pushobject(luaL_nonnullarg(3)); if (!lua_setlocal(func, numvar)) lua_error("no such local variable"); }
const char *lua_setlocal (LuaThread *L, const LuaDebug *ar, int n) { THREAD_CHECK(L); StkId pos = 0; /* to avoid warnings */ const char *name = findlocal(L, ar->i_ci, n, &pos); if (name) { pos[0] = L->stack_.top_[-1]; } L->stack_.pop(); /* pop value */ return name; }
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { StkId pos = 0; /* to avoid warnings */ const char *name = findlocal(L, ar->i_ci, n, &pos); lua_lock(L); if (name) setobjs2s(L, pos, L->top - 1); L->top--; /* pop value */ lua_unlock(L); return name; }
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { CallInfo *ci = L->base_ci + ar->i_ci; const char *name = findlocal(L, ci, n); lua_lock(L); if (name) setobjs2s(L, ci->base + (n - 1), L->top - 1); L->top--; /* pop value */ lua_unlock(L); return name; }
static int i386trace(uvlong pc, uvlong sp, uvlong link) { int i; uvlong osp; Symbol s, f; char buf[128]; USED(link); i = 0; osp = 0; while(findsym(pc, CTEXT, &s)) { symoff(buf, sizeof buf, pc, CANY); fmt(buf, pc); //XXX s.value &= ~(uintptr)0; if(pc != s.value) { /* not at first instruction */ if(findlocal(&s, FRAMENAME, &f) == 0) break; sp += f.value-mach->szaddr; }else if(strcmp(s.name, "forkret") == 0){ //XXX print("//passing interrupt frame; last pc found at sp=%#llux\n", osp); sp += 15 * mach->szaddr; /* pop interrupt frame */ } pc = getval(sp); //XXX if(pc == 0 && strcmp(s.name, "forkret") == 0){ sp += 3 * mach->szaddr; /* pop iret eip, cs, eflags */ print("//guessing call through invalid pointer, try again at sp=%#llux\n", sp); s.name = ""; pc = getval(sp); } if(pc == 0) { print("//didn't find pc at sp=%#llux, last pc found at sp=%#llux\n", sp, osp); break; } osp = sp; sp += mach->szaddr; //XXX if(strcmp(s.name, "forkret") == 0) sp += 2 * mach->szaddr; /* pop iret cs, eflags */ if(++i > 40) break; } return i; }
static void emitlocal(JF, int oploc, int opvar, const char *name) { int i; if (F->lightweight) { i = findlocal(J, F, name); if (i >= 0) { emit(J, F, oploc); emitraw(J, F, i); return; } } emitstring(J, F, opvar, name); }
/* * Return the type of a variable name. * This is either local, parameter, global, static, or undefined. * * given: * name variable name to find */ int symboltype(char *name) { GLOBAL *sp; if (findparam(name) >= 0) return SYM_PARAM; if (findlocal(name) >= 0) return SYM_LOCAL; sp = findglobal(name); if (sp) { if (sp->g_filescope == SCOPE_GLOBAL) return SYM_GLOBAL; return SYM_STATIC; } return SYM_UNDEFINED; }
const char *lua_getlocal (LuaThread *L, const LuaDebug *ar, int n) { THREAD_CHECK(L); const char *name; if (ar == NULL) { /* information about non-active function? */ if (!L->stack_.top_[-1].isLClosure()) /* not a Lua function? */ name = NULL; else /* consider live variables at function start (parameters) */ name = L->stack_.top_[-1].getLClosure()->proto_->getLocalName(n, 0); } else { /* active function; get information through 'ar' */ StkId pos = 0; /* to avoid warnings */ name = findlocal(L, ar->i_ci, n, &pos); if (name) { L->stack_.push(pos[0]); } } return name; }
static void emitlocal(JF, int oploc, int opvar, js_Ast *ident) { int i; if (J->strict && oploc == OP_SETLOCAL) { if (!strcmp(ident->string, "arguments")) jsC_error(J, ident, "'arguments' is read-only in strict mode"); if (!strcmp(ident->string, "eval")) jsC_error(J, ident, "'eval' is read-only in strict mode"); } if (F->lightweight) { i = findlocal(J, F, ident->string); if (i >= 0) { emit(J, F, oploc); emitraw(J, F, i); return; } } emitstring(J, F, opvar, ident->string); }
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { const char *name; lua_lock(L); if (ar == NULL) { /* information about non-active function? */ if (!isLfunction(L->top - 1)) /* not a Lua function? */ name = NULL; else /* consider live variables at function start (parameters) */ name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0); } else { /* active function; get information through 'ar' */ StkId pos = 0; /* to avoid warnings */ name = findlocal(L, ar->i_ci, n, &pos); if (name) { setobj2s(L, L->top, pos); api_incr_top(L); } } lua_unlock(L); return name; }
static void cfunbody(JF, js_Ast *name, js_Ast *params, js_Ast *body) { F->lightweight = 1; F->arguments = 0; if (F->script) F->lightweight = 0; if (body) analyze(J, F, body); cparams(J, F, params); if (name) { emit(J, F, OP_CURRENT); if (F->lightweight) { addlocal(J, F, name, 0); emit(J, F, OP_INITLOCAL); emitraw(J, F, findlocal(J, F, name->string)); } else { emitstring(J, F, OP_INITVAR, name->string); } } if (body) { cvardecs(J, F, body); cfundecs(J, F, body); } if (F->script) { emit(J, F, OP_UNDEF); cstmlist(J, F, body); emit(J, F, OP_RETURN); } else { cstmlist(J, F, body); emit(J, F, OP_UNDEF); emit(J, F, OP_RETURN); } }
int getto(const stralloc *sa) /* find list address in line. If found, return 1, else return 0. */ { unsigned int pos = 0; unsigned int pos1; if (!sa->len) return 0; /* no To: or Cc: line */ while ((pos += 1 + byte_chr(sa->s+pos+1,sa->len-pos-1,'@')) != sa->len) { pos1 = findhost(sa,pos); if (pos1 == pos) break; if (pos1 + outhost.len <= sa->len) if (!case_diffb(sa->s+pos1,outhost.len,outhost.s)) { /* got host */ pos1 = findlocal(sa,pos); if (pos1 == pos) break; ++pos1; /* avoids 1 x 2 below */ if (pos1 >= outlocal.len) if (!case_diffb(sa->s+pos1-outlocal.len,outlocal.len,outlocal.s)) return 1; /* got local as well */ } } return 0; }
static int rtrace(uvlong pc, uvlong sp, uvlong link) { Symbol s, f; char buf[128]; uvlong oldpc; int i; i = 0; while(findsym(pc, CTEXT, &s)) { if(pc == s.value) /* at first instruction */ f.value = 0; else if(findlocal(&s, FRAMENAME, &f) == 0) break; symoff(buf, sizeof buf, pc, CANY); fmt(buf, pc); oldpc = pc; if(s.type == 'L' || s.type == 'l' || pc <= s.value+mach->pcquant){ if(link == 0) fprint(2, "%s: need to supply a valid link register\n", argv0); pc = link; }else{ pc = getval(sp); if(pc == 0) break; } if(pc == 0 || (pc == oldpc && f.value == 0)) break; sp += f.value; if(++i > 40) break; } return i; }
static int plocal(Instr *i) { char *reg; Symbol s; char *fn; int class; int offset; if(!findsym(i->addr, CTEXT, &s)) { if(debug)fprint(2,"fn not found @%lux: %r\n", i->addr); return 0; } fn = s.name; if (!findlocal(&s, FRAMENAME, &s)) { if(debug)fprint(2,"%s.%s not found @%s: %r\n", fn, FRAMENAME, s.name); return 0; } if(s.value > i->imm) { class = CAUTO; offset = s.value-i->imm; reg = "(SP)"; } else {
static int amd64trace(uvlong pc, uvlong sp, uvlong link) { int i, isintrr; uvlong osp; Symbol s, f; char buf[128]; USED(link); i = 0; osp = 0; while(findsym(pc, CTEXT, &s)) { symoff(buf, sizeof buf, pc, CANY); fmt(buf, pc); if(strcmp(s.name, "_intrr") == 0) isintrr = 1; else isintrr = 0; if(pc != s.value) { /* not at first instruction */ if(findlocal(&s, FRAMENAME, &f) == 0) break; sp += f.value-mach->szaddr; } else if(isintrr){ print("//passing interrupt frame; last pc found at sp=%#llux\n", osp); /* * Pop interrupt frame (ureg.h) up to the IP value. */ sp += 19 * mach->szaddr; } pc = getval(sp); if(pc == 0 && isintrr){ /* * Pop IP, CS and FLAGS to get to the SP. * The AMD64 aligns the interrupt stack on * a 16-byte boundary so have the get the * SP from the saved frame. */ sp += 3 * mach->szaddr; print("//guessing call through invalid pointer; try again at sp=%#llux\n", sp); s.name = ""; sp = getval(sp); pc = getval(sp); } if(pc == 0) { print("//didn't find pc at sp=%#llux, last pc found at sp=%#llux\n", sp, osp); break; } osp = sp; if(!isintrr) sp += mach->szaddr; if(++i > 40) break; } return i; }