Skip to content
Snippets Groups Projects
Commit 5ef867b1 authored by jdh8d's avatar jdh8d
Browse files

Updates for readability/maintainability to the annotation parser, and updates...

Updates for readability/maintainability to the annotation parser, and updates to ProblemFunc annotations to deal with more error codes from stars, and a graceful failure when error codes are unrecognized.

Former-commit-id: 24b7d34cae71583103858f73e31d8e7518fc025b
parent 6f612ff5
No related branches found
No related tags found
No related merge requests found
......@@ -45,12 +45,14 @@ class MEDS_AnnotationParser
void parseFile(const std::string &); /* pass filename */
MEDS_Annotations_t & getAnnotations() { return m_annotations; }
MEDS_FuncAnnotations_t & getFuncAnnotations() { return m_func_annotations; }
//MEDS_Annotations_t & getFuncPrototypeAnnotations() { return m_func_prototype_annotations; }
private:
// helpers
template <class type> bool add_if_valid(std::string line);
// data
MEDS_Annotations_t m_annotations;
MEDS_FuncAnnotations_t m_func_annotations;
//MEDS_Annotations_t m_func_prototype_annotations;
};
}
......
......@@ -41,27 +41,34 @@ using namespace MEDS_Annotation;
//
class MEDS_ProblemFuncAnnotation : public MEDS_FuncAnnotation
{
public:
enum ProblemType { pt_CallUnresolved, pt_JumpUnresolved, pt_BadStackAnalysis, pt_BadRTLs, pt_Unknown };
MEDS_ProblemFuncAnnotation() {};
MEDS_ProblemFuncAnnotation(const string &p_rawLine);
virtual ~MEDS_ProblemFuncAnnotation(){}
virtual const string toString() const { return "problem func: "+m_rawInputLine; }
virtual void markCallUnresolved() { m_call_unresolved = true; setValid(); }
virtual void markJumpUnresolved() { m_jump_unresolved = true; setValid(); }
virtual bool isCallUnresolved() { return m_call_unresolved; }
virtual bool isJumpUnresolved() { return m_jump_unresolved; }
virtual void markCallUnresolved() { pt = pt_CallUnresolved; setValid(); }
virtual void markJumpUnresolved() { pt = pt_JumpUnresolved; setValid(); }
virtual bool isCallUnresolved() { return pt==pt_CallUnresolved; }
virtual bool isJumpUnresolved() { return pt==pt_JumpUnresolved; }
ProblemType getProblemType() { return pt; }
void setProblemType( ProblemType _pt) { pt=_pt; }
private:
void init();
void parse();
bool matches(std::string line, string pattern, ProblemType prob_type);
private:
std::string m_rawInputLine;
bool m_call_unresolved;
bool m_jump_unresolved;
ProblemType pt;
};
}
......
......@@ -50,6 +50,37 @@ void MEDS_AnnotationParser::parseFile(const std::string &input_filename)
parseFile(infile);
}
template <class type> bool MEDS_AnnotationParser::add_if_valid(string line)
{
type * annot=new type(line);
if (annot->isValid())
{
// note that this should _NOT_ be an if/else for every possible Annotation
// this _should_ list the major categorizations of annotations
// currently we have annotations that can be looked up by VirtualOffset and looked up by Function
if(annot->isFuncAnnotation())
{
MEDS_FuncAnnotation* fannot=dynamic_cast<MEDS_FuncAnnotation*>(annot);
assert(fannot);
string nam=fannot->getFuncName();
m_func_annotations.insert(MEDS_Annotations_FuncPair_t(nam, annot));
}
else
{
VirtualOffset vo = annot->getVirtualOffset();
m_annotations.insert(MEDS_Annotations_Pair_t(vo, annot));
}
return true;
}
else
{
delete annot;
return false;
}
}
void MEDS_AnnotationParser::parseFile(istream &p_inputStream)
{
string line;
......@@ -61,38 +92,13 @@ void MEDS_AnnotationParser::parseFile(istream &p_inputStream)
//cerr << "MEDS_AnnotationParser: line: " << line << endl;
#define ADD_AND_CONTINUE_IF_VALID(type) \
{ \
type * annot=new type(line); \
if (annot->isValid()) \
{ \
if(annot->isFuncAnnotation()) \
{ \
MEDS_FuncAnnotation* fannot=dynamic_cast<MEDS_FuncAnnotation*>(annot); \
assert(fannot); \
string nam=fannot->getFuncName(); \
m_func_annotations.insert(MEDS_Annotations_FuncPair_t(nam, annot)); \
} \
else \
{ \
VirtualOffset vo = annot->getVirtualOffset(); \
m_annotations.insert(MEDS_Annotations_Pair_t(vo, annot)); \
} \
continue; \
} \
else \
{ \
delete annot; \
} \
}
ADD_AND_CONTINUE_IF_VALID(MEDS_FPTRShadowAnnotation);
ADD_AND_CONTINUE_IF_VALID(MEDS_InstructionCheckAnnotation);
ADD_AND_CONTINUE_IF_VALID(MEDS_FuncPrototypeAnnotation);
ADD_AND_CONTINUE_IF_VALID(MEDS_SafeFuncAnnotation);
ADD_AND_CONTINUE_IF_VALID(MEDS_ProblemFuncAnnotation);
ADD_AND_CONTINUE_IF_VALID(MEDS_FRSafeAnnotation);
ADD_AND_CONTINUE_IF_VALID(MEDS_FuncExitAnnotation);
if(add_if_valid<MEDS_FPTRShadowAnnotation>(line)) continue;
if(add_if_valid<MEDS_InstructionCheckAnnotation>(line)) continue;
if(add_if_valid<MEDS_FuncPrototypeAnnotation>(line)) continue;
if(add_if_valid<MEDS_SafeFuncAnnotation>(line)) continue;
if(add_if_valid<MEDS_ProblemFuncAnnotation>(line)) continue;
if(add_if_valid<MEDS_FRSafeAnnotation>(line)) continue;
if(add_if_valid<MEDS_FuncExitAnnotation>(line)) continue;
// cout<<"Found annotation: "<<annot->toString()<<endl;\
......
......@@ -79,18 +79,26 @@ void MEDS_ProblemFuncAnnotation::parse()
setFuncName(func_name);
cout<<"Found problem func name='"<<func_name<<"'"<<endl;
if (m_rawInputLine.find("JUMPUNRESOLVED")!=string::npos)
if(!isValid()) matches(m_rawInputLine,"JUMPUNRSOLVED", pt_JumpUnresolved);
if(!isValid()) matches(m_rawInputLine,"CALLUNRSOLVED", pt_CallUnresolved);
if(!isValid()) matches(m_rawInputLine,"STACKANALYSIS", pt_BadStackAnalysis);
if(!isValid()) matches(m_rawInputLine,"BADRTLS", pt_BadRTLs);
if(!isValid())
{
if(getenv("VERBOSE"))
cout<<"Found JUMPUNRESOLVED problem annotation for "<<getFuncName() << endl;
markJumpUnresolved();
pt=pt_Unknown;
setValid();
}
else if (m_rawInputLine.find("CALLUNRESOLVED")!=string::npos)
}
bool MEDS_ProblemFuncAnnotation::matches(string line, string pattern, ProblemType prob_type)
{
if (line.find(pattern)!=string::npos)
{
if(getenv("VERBOSE"))
cout<<"Found CALLUNRESOLVED annotation for "<<getFuncName() << endl;
markCallUnresolved();
cout<<"Found "<<pattern<<" problem annotation for "<<getFuncName() << endl;
pt=prob_type;
setValid();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment