]> sourceware.org Git - systemtap.git/commitdiff
Show the liveness information at points being probed
authorWilliam Cohen <wcohen@redhat.com>
Mon, 20 Sep 2021 13:46:04 +0000 (09:46 -0400)
committerWilliam Cohen <wcohen@redhat.com>
Tue, 26 Oct 2021 13:57:22 +0000 (09:57 -0400)
This code is work-in-progress and to check whether the liveness
analysis is working.  Currently, the location context information for
the variable isn't being passed in and the setup of that is disabled.

analysis.cxx
analysis.h
tapsets.cxx

index 6b114597282f984bfd931921d68c1530b5e03869..5e8701efb7ddb480cbe2fabf535daadb16661043 100644 (file)
@@ -10,7 +10,7 @@
 
 #ifdef HAVE_DYNINST
 
-#include <libdwarf/libdwarf.h>
+#include "loc2stap.h"
 #include "analysis.h"
 #include <dyninst/Symtab.h>
 #include <dyninst/Function.h>
@@ -39,25 +39,91 @@ analysis::analysis(char *name)
        // If not seen before
        // Create a new binary code object from the filename argument
        sts = new SymtabCodeSource(name);
-       return;
+       if(!sts) return;
 
        co = new CodeObject(sts);
        if(!co) return;
 }
 
+// FIXME: Currently only support x86_64 will need to set up for powerpc and aarch64
+static const MachRegister dyninst_register[] = {
+       x86_64::rax,
+       x86_64::rdx,
+       x86_64::rcx,
+       x86_64::rbx,
+       x86_64::rsi,
+       x86_64::rdi,
+       x86_64::rbp,
+       x86_64::rsp,
+       x86_64::r8,
+       x86_64::r9,
+       x86_64::r10,
+       x86_64::r11,
+       x86_64::r12,
+       x86_64::r13,
+       x86_64::r14,
+       x86_64::r15,
+       x86_64::rip
+};
+
 
-int liveness(char *executable,
-            Dwarf_Addr addr  __attribute__ ((unused))
-            /*, variable */)
+int liveness(const char *executable,
+            Dwarf_Addr addr,
+            location_context ctx __attribute__ ((unused)))
 {
-       analysis func_to_analyze(executable);
+       // should cache the executable names like the other things
+       char *exe = strdup(executable);
+       analysis func_to_analyze(exe);
+
+       #if 0
        // Find where the variable is located
+       location *loc = ctx.locations.back ();
+
        // If variable isn't in a register, punt (return 0)
+       if (loc->type != loc_register) return 0;
+
+       // Map dwarf number to dyninst number, skip if out of range
+       if (loc->offset >= sizeof(dyninst_register)/sizeof(MachRegister)) return 0;
+       MachRegister r = dyninst_register[loc->offset];
+       #endif
+
        // Find the function containing address
+       cout << "liveness analysis " << executable << " " << hex << addr << endl;
+       vector<CodeRegion *> rr = func_to_analyze.co->cs()->regions();
+       std::set<ParseAPI::Function*> ff;
+       if(func_to_analyze.co->findFuncs(rr[0], addr, ff) <= 0) return 0;
+       ParseAPI::Function *func = *ff.begin();
+       cout << "<" << func->addr() << ">:" << func->name() << "[" << addr << "]" << endl;
        // Check to see if a previous liveness information exists for function to reuse
        // Otherwise create new liveness analysis
+       LivenessAnalyzer la(func->obj()->cs()->getAddressWidth());
+       la.analyze(func);
+       // Construct a liveness query location for the function entry.
+       // Get basic block containing the instruction
+       set<Block *> bb_s;
+       if (func_to_analyze.co->findBlocks(rr[0], addr, bb_s) != 1 )
+               return 0; // problem find basic block, punt
+       Block *bb = *bb_s.begin();
+       Instruction curInsn = bb->getInsn(addr);
+
+       // Construct a liveness query location for the function entry.
+       InsnLoc i(bb,  addr, curInsn);
+       Location iloc(func, i);
+
+       #if 0
        // Query to see if whether the register is live at that point
+       bool used;
+       la.query(iloc, LivenessAnalyzer::Before, r, used);
+       cout << r <<  (used ? " used"  : "unused") << endl;
+       return (used ? 1 : -1);
+       #else
+       // Query to list out the registers that are live at that point
+       // FIXME: This is because not currently getting the actual register
+       bitArray liveRegs;
+       la.query(iloc, LivenessAnalyzer::Before, liveRegs);
+       cout << "liveRegs " << liveRegs << endl;
        return 0;
+       #endif
 }
 
 #endif // HAVE_DYNINST
index 7ddf1927b0aaeec1e45d6b0b71dc040137fe5202..470bca57d26a92bec9ed263dd6bb744aecc40ebe 100644 (file)
@@ -17,7 +17,9 @@
 
 #ifdef HAVE_DYNINST
 
-extern int liveness(char *executable, Dwarf_Addr location __attribute__ ((unused)) /*, varaccess */);
+extern int liveness(const char *executable,
+                   Dwarf_Addr location,
+                   location_context ctx);
 
 #else
 
index 1c82aaf6942082b7e3d04ec7bda6c238112382e0..348d9c613c04aeb86f3b33958d89f638416fe195 100644 (file)
@@ -23,6 +23,7 @@
 #include "dwflpp.h"
 #include "setupdwfl.h"
 #include "loc2stap.h"
+#include "analysis.h"
 #include <gelf.h>
 
 #include "sdt_types.h"
@@ -4720,6 +4721,13 @@ 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;
This page took 0.031329 seconds and 5 git commands to generate.