From 8275e31d5312b407a6d13cce31d0ac02369fd696 Mon Sep 17 00:00:00 2001 From: Clark Coleman <clc@zephyr-software.com> Date: Mon, 22 Jul 2019 13:50:59 -0400 Subject: [PATCH] Add GetFuncID() method, use func IDs in *.STARSloops annotations. --- include/base/SMPFunction.h | 1 + include/interfaces/abstract/STARSFunction.h | 1 + include/interfaces/idapro/STARSFunction.h | 5 +++-- include/interfaces/irdb/STARSFunction.h | 8 +++++--- src/base/SMPFunction.cpp | 8 ++++---- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/base/SMPFunction.h b/include/base/SMPFunction.h index 9fa4d324..80786f03 100644 --- a/include/base/SMPFunction.h +++ b/include/base/SMPFunction.h @@ -258,6 +258,7 @@ public: }; STARS_Function_t *GetFuncInfo(void) const; inline STARS_ea_t GetFirstFuncAddr(void) const { return FirstEA; }; + inline STARS_ea_t GetFuncID(void) const { return FuncInfo->getFuncID(); }; uint16_t GetJumpToFollowNodeCounter(STARS_ea_t InstAddr) const; inline long GetTypedDefs(void) const { return TypedDefs; }; inline long GetUntypedDefs(void) const { return UntypedDefs; }; diff --git a/include/interfaces/abstract/STARSFunction.h b/include/interfaces/abstract/STARSFunction.h index 175b3557..82c95c64 100644 --- a/include/interfaces/abstract/STARSFunction.h +++ b/include/interfaces/abstract/STARSFunction.h @@ -12,6 +12,7 @@ class STARS_Function_t virtual char* GetFunctionName(char* name, const int len) const = 0; virtual STARS_ea_t get_startEA() = 0; virtual STARS_ea_t get_endEA() = 0; + virtual STARS_ea_t getFuncID(void) const = 0; virtual std::size_t GetFuncSize() = 0; virtual std::size_t GetFrameSize() = 0; virtual void SetFrameSize(std::size_t size) = 0; diff --git a/include/interfaces/idapro/STARSFunction.h b/include/interfaces/idapro/STARSFunction.h index 8453ad72..b3a54465 100644 --- a/include/interfaces/idapro/STARSFunction.h +++ b/include/interfaces/idapro/STARSFunction.h @@ -27,9 +27,10 @@ public: virtual STARS_ea_t get_startEA() { return the_func->startEA; } virtual STARS_ea_t get_endEA() { return the_func->endEA; } #else - virtual STARS_ea_t get_startEA() { return the_func->start_ea; } - virtual STARS_ea_t get_endEA() { return the_func->end_ea; } + virtual STARS_ea_t get_startEA() { return the_func->start_ea; } + virtual STARS_ea_t get_endEA() { return the_func->end_ea; } #endif + virtual STARS_ea_t getFuncID(void) const { return the_func->start_ea; }; virtual std::size_t GetFuncSize() { return (std::size_t) (get_endEA() - get_startEA()); } virtual char* GetFunctionName(char* name, const int len) const { qstring TempName; diff --git a/include/interfaces/irdb/STARSFunction.h b/include/interfaces/irdb/STARSFunction.h index 67162dca..2de04cef 100644 --- a/include/interfaces/irdb/STARSFunction.h +++ b/include/interfaces/irdb/STARSFunction.h @@ -21,10 +21,12 @@ public: { strncpy((char*)name,the_func->getName().c_str(),len); return (char*)name; } // get entry point of function - virtual STARS_ea_t get_startEA() { return the_func->getEntryPoint()->getBaseID(); } + virtual STARS_ea_t get_startEA() { return the_func->getEntryPoint()->getBaseID(); } // clc needs to review and get back to me. - virtual STARS_ea_t get_endEA() { assert(0); } + virtual STARS_ea_t get_endEA() { assert(0); } + + virtual STARS_ea_t getFuncID(void) const { return (STARS_ea_t) the_func->getBaseID(); }; // return # of instructions. virtual std::size_t GetFuncSize() { return the_func->getInstructions().size(); } @@ -34,7 +36,7 @@ public: //This chunk of things is going away? // init class-local variable with IRDB value // and these are accessors to that. - virtual std::size_t GetFrameSize(){ return the_func -> getStackFrameSize(); } + virtual std::size_t GetFrameSize(){ return the_func->getStackFrameSize(); } // should go away. diff --git a/src/base/SMPFunction.cpp b/src/base/SMPFunction.cpp index ddffb941..569094c2 100644 --- a/src/base/SMPFunction.cpp +++ b/src/base/SMPFunction.cpp @@ -7008,11 +7008,11 @@ void SMPFunction::ComputeLoopNests(void) { // Emit info on loop nesting and preheader blocks. // Annotations look like: -// LOOP [loop #] FIRSTINST [hex inst ID at beginning of loop header] PREHEADER [hex inst ID] BLOCKLIST [hex inst IDs] ZZ INNERLOOPS [loop #'s] ZZ +// [hex func ID] [func size] LOOP [loop #] FIRSTINST [hex inst ID at beginning of loop header] PREHEADER [hex inst ID] BLOCKLIST [hex inst IDs] ZZ INNERLOOPS [loop #'s] ZZ void SMPFunction::EmitLoopNestAnnotations(void) { if (0 < this->LoopCount) { FILE *LoopAnnotFile = global_STARS_program->GetLoopsAnnotFile(); - SMP_fprintf(LoopAnnotFile, "FUNC %18llx LOOPCOUNT %zu \n", (uint64_t) this->GetFirstFuncAddr(), this->LoopCount); + SMP_fprintf(LoopAnnotFile, "%18llx %6zu LOOPCOUNT %zu \n", (uint64_t) this->GetFuncID(), this->FuncInfo->GetFuncSize(), this->LoopCount); for (size_t LoopIndex = 0; LoopIndex < this->LoopCount; ++LoopIndex) { int HeaderBlockNum = this->LoopHeadBlockNumbers[LoopIndex]; SMPBasicBlock *HeaderBlock = this->GetBlockByNum((size_t) HeaderBlockNum); @@ -7022,8 +7022,8 @@ void SMPFunction::EmitLoopNestAnnotations(void) { if (PreheaderBlockNum >= 0) { PreheaderFirstInstAddr = this->GetBlockByNum(PreheaderBlockNum)->GetFirstNonMarkerAddr(); } - SMP_fprintf(LoopAnnotFile, "LOOP %zu FIRSTINST %18llx PREHEADER %18llx BLOCKLIST ", - LoopIndex, (uint64_t) FirstHeaderInstAddr, PreheaderFirstInstAddr); + SMP_fprintf(LoopAnnotFile, "%18llx %6zu LOOP %zu FIRSTINST %18llx PREHEADER %18llx BLOCKLIST ", + (uint64_t) this->GetFuncID(), this->FuncInfo->GetFuncSize(), LoopIndex, (uint64_t) FirstHeaderInstAddr, (uint64_t) PreheaderFirstInstAddr); // Emit the first inst ID for each block in the loop. list<size_t> LoopBlockList; -- GitLab