Blame SOURCES/rhbz2047256.patch

045c8b
diff --git a/analysis.cxx b/analysis.cxx
045c8b
index a7a579e..d0d6a4f 100644
045c8b
--- a/analysis.cxx
045c8b
+++ b/analysis.cxx
045c8b
@@ -7,6 +7,7 @@
045c8b
 // later version.
045c8b
 
045c8b
 #include "config.h"
045c8b
+#include "session.h"
045c8b
 
045c8b
 #ifdef HAVE_DYNINST
045c8b
 
045c8b
@@ -46,6 +47,8 @@ analysis::analysis(string name)
045c8b
 	char *name_str = strdup(name.c_str());
045c8b
 	sts = NULL;
045c8b
 	co = NULL;
045c8b
+	SymtabAPI::Symtab *symTab;
045c8b
+	bool isParsable;
045c8b
 
045c8b
 	// Use cached information if available
045c8b
 	if (cached_info.find(name) != cached_info.end()) {
045c8b
@@ -56,6 +59,9 @@ analysis::analysis(string name)
045c8b
 
045c8b
 	// Not not seen before
045c8b
 	// Create a new binary code object from the filename argument
045c8b
+	isParsable = SymtabAPI::Symtab::openFile(symTab, name_str);
045c8b
+	if(!isParsable) goto cleanup;
045c8b
+
045c8b
 	sts = new SymtabCodeSource(name_str);
045c8b
 	if(!sts) goto cleanup;
045c8b
 
045c8b
@@ -143,39 +149,40 @@ static const MachRegister dyninst_register_64[] = {
045c8b
 static const MachRegister dyninst_register_32[1]; // No 32-bit support
045c8b
 
045c8b
 #elif defined(__powerpc__)
045c8b
+/* For ppc64 still use the ppc32 register names */
045c8b
 static const MachRegister dyninst_register_64[] = {
045c8b
-    ppc64::r0,
045c8b
-    ppc64::r1,
045c8b
-    ppc64::r2,
045c8b
-    ppc64::r3,
045c8b
-    ppc64::r4,
045c8b
-    ppc64::r5,
045c8b
-    ppc64::r6,
045c8b
-    ppc64::r7,
045c8b
-    ppc64::r8,
045c8b
-    ppc64::r9,
045c8b
-    ppc64::r10,
045c8b
-    ppc64::r11,
045c8b
-    ppc64::r12,
045c8b
-    ppc64::r13,
045c8b
-    ppc64::r14,
045c8b
-    ppc64::r15,
045c8b
-    ppc64::r16,
045c8b
-    ppc64::r17,
045c8b
-    ppc64::r18,
045c8b
-    ppc64::r19,
045c8b
-    ppc64::r20,
045c8b
-    ppc64::r21,
045c8b
-    ppc64::r22,
045c8b
-    ppc64::r23,
045c8b
-    ppc64::r24,
045c8b
-    ppc64::r25,
045c8b
-    ppc64::r26,
045c8b
-    ppc64::r27,
045c8b
-    ppc64::r28,
045c8b
-    ppc64::r29,
045c8b
-    ppc64::r30,
045c8b
-    ppc64::r31
045c8b
+    ppc32::r0,
045c8b
+    ppc32::r1,
045c8b
+    ppc32::r2,
045c8b
+    ppc32::r3,
045c8b
+    ppc32::r4,
045c8b
+    ppc32::r5,
045c8b
+    ppc32::r6,
045c8b
+    ppc32::r7,
045c8b
+    ppc32::r8,
045c8b
+    ppc32::r9,
045c8b
+    ppc32::r10,
045c8b
+    ppc32::r11,
045c8b
+    ppc32::r12,
045c8b
+    ppc32::r13,
045c8b
+    ppc32::r14,
045c8b
+    ppc32::r15,
045c8b
+    ppc32::r16,
045c8b
+    ppc32::r17,
045c8b
+    ppc32::r18,
045c8b
+    ppc32::r19,
045c8b
+    ppc32::r20,
045c8b
+    ppc32::r21,
045c8b
+    ppc32::r22,
045c8b
+    ppc32::r23,
045c8b
+    ppc32::r24,
045c8b
+    ppc32::r25,
045c8b
+    ppc32::r26,
045c8b
+    ppc32::r27,
045c8b
+    ppc32::r28,
045c8b
+    ppc32::r29,
045c8b
+    ppc32::r30,
045c8b
+    ppc32::r31
045c8b
 };
045c8b
 
045c8b
 static const MachRegister dyninst_register_32[] = {
045c8b
@@ -218,14 +225,26 @@ static const MachRegister dyninst_register_32[] = {
045c8b
 typedef map<string, LivenessAnalyzer*> precomputed_liveness;
045c8b
 static precomputed_liveness cached_liveness;
045c8b
 
045c8b
-int liveness(string executable,
045c8b
+int liveness(systemtap_session& s,
045c8b
+	     target_symbol *e,
045c8b
+	     string executable,
045c8b
 	     Dwarf_Addr addr,
045c8b
 	     location_context ctx)
045c8b
 {
045c8b
+  try{
045c8b
+	// Doing this inside a try/catch because dyninst may require
045c8b
+	// too much memory to parse the binary.
045c8b
 	// should cache the executable names like the other things
045c8b
 	analysis func_to_analyze(executable);
045c8b
 	MachRegister r;
045c8b
 
045c8b
+	// Punt if unsuccessful in parsing binary
045c8b
+	if (!func_to_analyze.co){
045c8b
+		s.print_warning(_F("liveness analysis unable to parse binary %s",
045c8b
+				   executable.c_str()), e->tok);
045c8b
+		return 0;
045c8b
+	}
045c8b
+
045c8b
 	// Determine whether 32-bit or 64-bit code as the register names are different in dyninst
045c8b
 	int reg_width = func_to_analyze.co->cs()->getAddressWidth();
045c8b
 
045c8b
@@ -282,6 +301,11 @@ int liveness(string executable,
045c8b
 	bool used;
045c8b
 	la->query(iloc, LivenessAnalyzer::Before, r, used);
045c8b
 	return (used ? 1 : -1);
045c8b
+  } catch (std::bad_alloc & ex){
045c8b
+    s.print_warning(_F("unable to allocate memory for liveness analysis of %s",
045c8b
+				   executable.c_str()), e->tok);
045c8b
+    return 0;
045c8b
+  }
045c8b
 }
045c8b
 
045c8b
 #endif // HAVE_DYNINST
045c8b
diff --git a/analysis.h b/analysis.h
045c8b
index 9b6d115..6bea675 100644
045c8b
--- a/analysis.h
045c8b
+++ b/analysis.h
045c8b
@@ -17,13 +17,15 @@
045c8b
 
045c8b
 #ifdef HAVE_DYNINST
045c8b
 
045c8b
-extern int liveness(std::string executable,
045c8b
+extern int liveness(systemtap_session& s,
045c8b
+		    target_symbol *e,
045c8b
+		    std::string executable,
045c8b
 		    Dwarf_Addr location,
045c8b
 		    location_context ctx);
045c8b
 
045c8b
 #else
045c8b
 
045c8b
-#define liveness(executable, location, var) (0)
045c8b
+#define liveness(session, target, executable, location, var) (0)
045c8b
 
045c8b
 #endif // HAVE_DYNINST
045c8b
 #endif // ANALYSIS_H
045c8b
diff --git a/tapsets.cxx b/tapsets.cxx
045c8b
index 60794bb..8fc5146 100644
045c8b
--- a/tapsets.cxx
045c8b
+++ b/tapsets.cxx
045c8b
@@ -4732,7 +4732,7 @@ dwarf_var_expanding_visitor::visit_target_symbol (target_symbol *e)
045c8b
 
045c8b
       // Now that have location information check if change to variable has any effect
045c8b
       if (lvalue) {
045c8b
-	      if (liveness(q.dw.mod_info->elf_path, addr, ctx) < 0) {
045c8b
+	      if (liveness(q.sess, e, q.dw.mod_info->elf_path, addr, ctx) < 0) {
045c8b
 		      q.sess.print_warning(_F("write at %p will have no effect",
045c8b
 					      (void *)addr), e->tok);
045c8b
 	      }