// Determine whether 32-bit or 64-bit code as the register names are different in dyninst
int reg_width = func_to_analyze.co->cs()->getAddressWidth();
- #if 0
// Find where the variable is located
location *loc = ctx.locations.back ();
if (loc->type != loc_register) return 0;
// Map dwarf number to dyninst register name, punt if out of range
- unsigned int regno = loc->offset;
- #else
- unsigned int regno = 5; // Dummy up to arg1 of x86
- #endif
+ unsigned int regno = loc->regno;
switch (reg_width){
case 4:
if (regno >= (sizeof(dyninst_register_32)/sizeof(MachRegister))) return 0;
// Query to see if whether the register is live at that point
bool used;
la.query(iloc, LivenessAnalyzer::Before, r, used);
- cout << "liveness analysis " << executable << " " << hex << addr << endl;
+ cout << "liveness analysis " << executable << " " << func->name()
+ << " " << hex << addr << endl;
cout << r.name() << (used ? " used" : " unused") << endl;
return (used ? 1 : -1);
}
ctx.pc = addr;
ctx.userspace_p = userspace_p;
- // Check if change to variable has any effect
- if (lvalue) {
- if (liveness(q.dw.module_name.c_str(), addr, ctx) < 0) {
- // warn that the write has no effect
- }
- }
-
// NB: pass the ctx.e (copied/rewritten veraion e, not orig_e),
// so [x] index expressions have their intra-synthetic-function names
Dwarf_Die endtype;
q.dw.literal_stmt_for_local (ctx, getscopes(e), e->sym_name(),
ctx.e, lvalue, &endtype);
+ // Now that have location information check if change to variable has any effect
+ if (lvalue) {
+ if (liveness(q.dw.module_name.c_str(), addr, ctx) < 0) {
+ // FIXME: warn that the write has no effect
+ }
+ }
+
q.dw.sess.globals.insert(q.dw.sess.globals.end(),
ctx.globals.begin(),
ctx.globals.end());