MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / findsetreg

Function findsetreg

third-party/lua-5.2.4/src/ldebug.c:357–405  ·  view source on GitHub ↗

** try to find last instruction before 'lastpc' that modified register 'reg' */

Source from the content-addressed store, hash-verified

355** try to find last instruction before 'lastpc' that modified register 'reg'
356*/
357static int findsetreg (Proto *p, int lastpc, int reg) {
358 int pc;
359 int setreg = -1; /* keep last instruction that changed 'reg' */
360 int jmptarget = 0; /* any code before this address is conditional */
361 for (pc = 0; pc < lastpc; pc++) {
362 Instruction i = p->code[pc];
363 OpCode op = GET_OPCODE(i);
364 int a = GETARG_A(i);
365 switch (op) {
366 case OP_LOADNIL: {
367 int b = GETARG_B(i);
368 if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
369 setreg = filterpc(pc, jmptarget);
370 break;
371 }
372 case OP_TFORCALL: {
373 if (reg >= a + 2) /* affect all regs above its base */
374 setreg = filterpc(pc, jmptarget);
375 break;
376 }
377 case OP_CALL:
378 case OP_TAILCALL: {
379 if (reg >= a) /* affect all registers above base */
380 setreg = filterpc(pc, jmptarget);
381 break;
382 }
383 case OP_JMP: {
384 int b = GETARG_sBx(i);
385 int dest = pc + 1 + b;
386 /* jump is forward and do not skip `lastpc'? */
387 if (pc < dest && dest <= lastpc) {
388 if (dest > jmptarget)
389 jmptarget = dest; /* update 'jmptarget' */
390 }
391 break;
392 }
393 case OP_TEST: {
394 if (reg == a) /* jumped code can change 'a' */
395 setreg = filterpc(pc, jmptarget);
396 break;
397 }
398 default:
399 if (testAMode(op) && reg == a) /* any instruction that set A */
400 setreg = filterpc(pc, jmptarget);
401 break;
402 }
403 }
404 return setreg;
405}
406
407
408static const char *getobjname (Proto *p, int lastpc, int reg,

Callers 1

getobjnameFunction · 0.70

Calls 1

filterpcFunction · 0.70

Tested by

no test coverage detected