Blame SOURCES/rhbz2047256.patch

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