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

Function findsetreg

third-party/lua-5.3.5/src/ldebug.c:385–428  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

383** try to find last instruction before 'lastpc' that modified register 'reg'
384*/
385static int findsetreg (Proto *p, int lastpc, int reg) {
386 int pc;
387 int setreg = -1; /* keep last instruction that changed 'reg' */
388 int jmptarget = 0; /* any code before this address is conditional */
389 for (pc = 0; pc < lastpc; pc++) {
390 Instruction i = p->code[pc];
391 OpCode op = GET_OPCODE(i);
392 int a = GETARG_A(i);
393 switch (op) {
394 case OP_LOADNIL: {
395 int b = GETARG_B(i);
396 if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
397 setreg = filterpc(pc, jmptarget);
398 break;
399 }
400 case OP_TFORCALL: {
401 if (reg >= a + 2) /* affect all regs above its base */
402 setreg = filterpc(pc, jmptarget);
403 break;
404 }
405 case OP_CALL:
406 case OP_TAILCALL: {
407 if (reg >= a) /* affect all registers above base */
408 setreg = filterpc(pc, jmptarget);
409 break;
410 }
411 case OP_JMP: {
412 int b = GETARG_sBx(i);
413 int dest = pc + 1 + b;
414 /* jump is forward and do not skip 'lastpc'? */
415 if (pc < dest && dest <= lastpc) {
416 if (dest > jmptarget)
417 jmptarget = dest; /* update 'jmptarget' */
418 }
419 break;
420 }
421 default:
422 if (testAMode(op) && reg == a) /* any instruction that set A */
423 setreg = filterpc(pc, jmptarget);
424 break;
425 }
426 }
427 return setreg;
428}
429
430
431static 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