From 0aa40c22361affae0ec102de0d7c14aa060479f2 Mon Sep 17 00:00:00 2001
From: clc5q <clc5q@git.zephyr-software.com>
Date: Fri, 27 Nov 2015 21:08:16 +0000
Subject: [PATCH] Debugging updates for get_root_filename() problems.

Former-commit-id: 2c9ee1a9c8b3161e2d83ff0741cddfd8261a5a4d
---
 SMP-analyze.sh                            | 3 ++-
 scripts/SMP.idc                           | 6 ++++++
 src/drivers/idapro/SMPStaticAnalyzer.cpp  | 1 +
 src/interfaces/idapro/STARSIDAProgram.cpp | 7 +++++++
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/SMP-analyze.sh b/SMP-analyze.sh
index f829463a..92c27067 100755
--- a/SMP-analyze.sh
+++ b/SMP-analyze.sh
@@ -46,6 +46,7 @@ if [ ! -f ${IDAROOT}/libida.so ]; then echo IDAROOT is set poorly, please fix.;
 
 # remove tmp files
 rm -f $1.id? $1.{nam,til,log,syms} `basename $1 .ncexe`.id?
+rm -f ${IDALOG}
 
 old_stty=`stty -g` || true
 
@@ -85,7 +86,7 @@ if [ $TVHEADLESS"X" != "X" ]; then
             	;;
         *idapro6* | *idaproCur*)
             	echo "Trying TVHEADLESS IDA"
-	    	TVHEADLESS=1 yes 
 | LD_PRELOAD=$OVERRIDE_PLUGIN time ${IDAROOT}/$myidal  -A -SSMP.idc $1 > $1.idaoutput 2>&1
+	    	TVHEADLESS=1 yes 
 | LD_PRELOAD=$OVERRIDE_PLUGIN time ${IDAROOT}/$myidal  -A -SSMP.idc -L${IDALOG} $1 > $1.idaoutput 2>&1
             	echo "Finished TVHEADLESS IDA"
             	;;
 
diff --git a/scripts/SMP.idc b/scripts/SMP.idc
index aa4d9f74..0f36cf54 100644
--- a/scripts/SMP.idc
+++ b/scripts/SMP.idc
@@ -36,6 +36,12 @@ static main()
   Wait();
 
   file = GetInputFile();
+  Message("INFO: Input file name %s \n", file);
+  auto DebugFile = "stubtest.idaoutput";
+  auto fd = fopen(DebugFile, "w");
+  fprintf(fd, "Input file name: %s \n", file);
+  fclose(fd);
+
   file = substr(file,0,strstr(file,".")) + ".asm";
   WriteTxt(file, 0, BADADDR);           // create the assembler file
   
diff --git a/src/drivers/idapro/SMPStaticAnalyzer.cpp b/src/drivers/idapro/SMPStaticAnalyzer.cpp
index 62e8b3df..1ae71718 100644
--- a/src/drivers/idapro/SMPStaticAnalyzer.cpp
+++ b/src/drivers/idapro/SMPStaticAnalyzer.cpp
@@ -41,6 +41,7 @@
 
 #include <pro.h>
 #include <ida.hpp>
+#include <idp.hpp>
 #include <ua.hpp>
 #include <bytes.hpp>
 #include <loader.hpp>
diff --git a/src/interfaces/idapro/STARSIDAProgram.cpp b/src/interfaces/idapro/STARSIDAProgram.cpp
index 7de5845f..19412aad 100644
--- a/src/interfaces/idapro/STARSIDAProgram.cpp
+++ b/src/interfaces/idapro/STARSIDAProgram.cpp
@@ -112,6 +112,13 @@ void STARS_IDA_Program_t::DetermineRootFileName(void) {
 #else
 	TempRootName[STARS_MAXSTR - 1] = '\0';
 	STARS_ssize_t FileLen = ::get_root_filename(TempRootName, sizeof(TempRootName) - 1);
+	if (0 >= FileLen) {
+		SMP_msg("FATAL ERROR on get_root_filename\n");
+		FileLen = ::get_input_file_path(TempRootName, sizeof(TempRootName) - 1);
+		if (0 < FileLen) {
+			SMP_msg("INFO: get_input_file_path returned %s\n", TempRootName);
+		}
+	}
 	assert(0 < FileLen);
 #endif
 	string TempRootString(TempRootName);
-- 
GitLab