From 7db1410246036922664ea9b994ac9d34518e235f Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Wed, 2 Jan 2019 14:59:13 -0500
Subject: [PATCH] more permissive switch detection for arm.

Former-commit-id: ee9fd233519e8352be75cb8cc1f830352e8dc9fe
---
 libIRDB/test/fill_in_indtargs.cpp | 32 ++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/libIRDB/test/fill_in_indtargs.cpp b/libIRDB/test/fill_in_indtargs.cpp
index 8189e9501..5065a9d6f 100644
--- a/libIRDB/test/fill_in_indtargs.cpp
+++ b/libIRDB/test/fill_in_indtargs.cpp
@@ -802,22 +802,48 @@ notes:
 
 		cout << "\tEntry #"<<dec<<target_count<<"= ent-addr="<<hex<<entry_address
 	   	     << " ent="<<hex<<+table_entry	 // print as int, not char.
-		     << " ibta="<<candidate_ibta<<endl;
+		     << " ibta="<<candidate_ibta;
 
 		// stop if we failed to find an instruction,
 		// or find an instruction outside the function
-		if( ibtarget == nullptr || ibtarget->GetFunction()!=i10_func )
+		if( ibtarget == nullptr )
+		{
+			cout<<" -- no target insn!"<<endl;
 			break;
+		}
+		const auto ibtarget_func=ibtarget->GetFunction();
+		if( i10_func == nullptr )
+		{
+			// finding switch in non-function is OK.
+		}
+		else if(ibtarget_func == nullptr )
+		{
+			// finding target in non-function is OK
+		}
+		else if( i10_func != ibtarget_func )
+		{
+			// finding switch in function to different function, not ok.
+			cout<<" -- switch to diff func? No."<<endl;
+			
+		}
 
 		// record that we found something that looks valid-enough to try to pin
 		// stop if we couldn't pin.
 		if(!possible_target(candidate_ibta,entry_address,prov))
+		{
+			cout<<" -- not possible target!"<<endl;
 			break;
+		}
+		cout<<" -- valid target!"<<endl;
 		targets.insert(candidate_ibta);
 
 		// this was running away when looking for byte-entries.  occasionally there is no 
 		// byte offset that's not a valid instructoin, and we run until the end of the section.
-		if(target_count> 1024) break;
+		if(target_count> 1024) 
+		{
+			cout<<"Caution, exiting loop after 1024 valid entries."<<endl;
+			break;
+		}
 	}
 	cout << "\tUnique target count="<<dec<<targets.size()<<endl;
 	return target_count>1;
-- 
GitLab