From 70167935fc3299af0397c2269a990f15666a1bde Mon Sep 17 00:00:00 2001 From: William Cohen Date: Wed, 22 Sep 2021 17:34:25 -0400 Subject: [PATCH] Do liveness analysis after location information set and use regno info Initially the call to the liveness analysis was being done before the location information was setup. Relocated the call after the location information has been setup. Corrected liveness analysis code to use the register number. Also added print out the function the liveness analysis is being run on. Note that for probes on inlined functions this name will be different than the probe point function name, it will be the actual function that the code was inlined into. --- analysis.cxx | 9 +++------ tapsets.cxx | 14 +++++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/analysis.cxx b/analysis.cxx index 60962f245..2c0da978a 100644 --- a/analysis.cxx +++ b/analysis.cxx @@ -199,7 +199,6 @@ int liveness(const char *executable, // 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 (); @@ -207,10 +206,7 @@ int liveness(const char *executable, 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; @@ -248,7 +244,8 @@ int liveness(const char *executable, // 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); } diff --git a/tapsets.cxx b/tapsets.cxx index 348d9c613..f4876cc5f 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -4721,13 +4721,6 @@ dwarf_var_expanding_visitor::visit_target_symbol (target_symbol *e) 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; @@ -4737,6 +4730,13 @@ dwarf_var_expanding_visitor::visit_target_symbol (target_symbol *e) 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()); -- 2.43.5