-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SVFBugRecoder and modify source loc format #1067
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #1067 +/- ##
==========================================
- Coverage 62.72% 62.39% -0.33%
==========================================
Files 218 220 +2
Lines 21620 21863 +243
==========================================
+ Hits 13561 13642 +81
- Misses 8059 8221 +162
|
svf/include/Util/SVFBugReport.h
Outdated
typedef std::vector<GenericEvent *> EventStack; | ||
|
||
public: | ||
enum BugType{BOA, NEVERFREE, PARTIALLEAK, DOUBLEFREE, FILENEVERCLOSE, FILEPARTIALCLOSE}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BOA=>BuffOverflow
svf/include/Util/SVFBugReport.h
Outdated
protected: | ||
BugType bugType; | ||
const SVFInstruction * bugInst; | ||
EventStack *bugEventStack = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not assign nullptr in the constructor?
svf/include/Util/SVFBugReport.h
Outdated
inline BugType getBugType(){ return bugType; } | ||
std::string getLoc(); | ||
std::string getFuncName(); | ||
inline void setEventStack(EventStack *eventStack) { bugEventStack = eventStack; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need setEventStack
? why not set this in the constructor?
svf/include/Util/SVFBugReport.h
Outdated
typedef std::vector<GenericEvent *> EventStack; | ||
typedef std::vector<GenericEvent *> EventSet; | ||
typedef std::vector<GenericBug *> BugVector; | ||
typedef std::vector<EventStack *> EventStackVector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have a set and a vector?
svf/lib/Util/SVFBugReport.cpp
Outdated
auto bugIt = bugVector.begin(); | ||
for(;bugIt != bugVector.end(); bugIt ++){ | ||
delete (*bugIt); | ||
} | ||
auto eventStackIt = eventStackVector.begin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For(auto event : eventSet)
delete event
enum BugType{BOA, NEVERFREE, PARTIALLEAK, DOUBLEFREE, FILENEVERCLOSE, FILEPARTIALCLOSE}; | ||
|
||
protected: | ||
BugType bugType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
classof method for each subclass.
svf/include/Util/SVFBugReport.h
Outdated
virtual ~GenericBug() = default; | ||
|
||
inline BugType getBugType(){ return bugType; } | ||
std::string getLoc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::string
svf/include/Util/SVFBugReport.h
Outdated
EventStack *bugEventStack = nullptr; | ||
|
||
public: | ||
inline GenericBug(BugType bugType, const SVFInstruction * bugInst): bugType(bugType), bugInst(bugInst){ }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenericBug(BugType bugType, eventstack)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove const SVFInstruction * bugInst,
svf/include/Util/SVFBugReport.h
Outdated
typedef std::vector<EventStack *> EventStackVector; | ||
|
||
protected: | ||
EventStack eventStack; // maintain current execution events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BugVector bugVector; and move eventStack to each Bug class
svf/include/Util/SVFBugReport.h
Outdated
|
||
class GenericEvent{ | ||
public: | ||
enum EventType{Branch, Caller, CallSite, Loop}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add "SourceInst'' event
svf/include/Util/SVFBugReport.h
Outdated
/// branch statement and branch condition true or false | ||
protected: | ||
const BranchStmt *branchStmt; | ||
std::string description; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove description and make it retrievable in getEventDescription
svf/include/Util/SVFBugReport.h
Outdated
public: | ||
SVFBugReport() = default; | ||
~SVFBugReport(); | ||
typedef std::vector<GenericBug *> BugVector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it a set.
SVFUtil::errs() << "\n"; | ||
} | ||
|
||
const std::string CallSiteEvent::getFuncName() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::string&
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may be unfeasible because getName() returns const std::string but not const std::string&.
return description; | ||
} | ||
|
||
const std::string BranchEvent::getFuncName() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::string&
svf/lib/Util/SVFBugReport.cpp
Outdated
|
||
const std::string BranchEvent::getFuncName() const | ||
{ | ||
return branchStmt->getInst()->getFunction()->getName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::string&
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may be unfeasible because getName() returns const std::string but not const std::string&.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, pls use const std::string
svf/lib/Util/SVFBugReport.cpp
Outdated
|
||
SVFBugReport::~SVFBugReport() | ||
{ | ||
auto bugIt = bugVector.begin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for( bug : bugSet)
delete bug;
svf/lib/Util/SVFBugReport.cpp
Outdated
} | ||
} | ||
|
||
std::string SVFBugReport::toString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better change the method to "void SVFBugReport::toJson()". Never return large string!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chang to void dumpToFile(const std::string filePath).
svf/include/Util/SVFBugReport.h
Outdated
/// branch statement and branch condition true or false | ||
protected: | ||
const BranchStmt *branchStmt; | ||
bool branchCondition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this book field or it can be obtained via BranchStmt?
svf/include/Util/SVFBugReport.h
Outdated
const CallICFGNode *callSite; | ||
|
||
public: | ||
inline CallSiteEvent(const CallICFGNode *callSite): GenericEvent(GenericEvent::CallSite), callSite(callSite){ } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove inline for constructor
svf/include/Util/SVFBugReport.h
Outdated
const SVFInstruction *sourceSVFInst; | ||
|
||
public: | ||
inline SourceInstructionEvent(const SVFInstruction *sourceSVFInst): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above and following constructors
svf/include/Util/SVFBugReport.h
Outdated
|
||
class BufferOverflowBug: public GenericBug{ | ||
protected: | ||
long long allocLowerBound, allocUpperBound, accessLowerBound, accessUpperBound; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use SVF’s type and DON’T use std long long
svf/include/Util/SVFBugReport.h
Outdated
|
||
public: | ||
inline BufferOverflowBug(GenericBug::BugType bugType, EventStack eventStack, | ||
long long allocLowerBound, long long allocUpperBound, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above and followings
svf/include/Util/SVFBugReport.h
Outdated
protected: | ||
Set<std::string> conditionalFreePath; | ||
public: | ||
PartialLeakBug(EventStack bugEventStack, Set<std::string> conditionalFreePath): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have an event stack, do we need a set of condfree paths? Can we put these into the event stack?
svf/include/Util/SVFBugReport.h
Outdated
|
||
class NeverFreeBug : public GenericBug{ | ||
public: | ||
NeverFreeBug(EventStack bugEventStack): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use “const EventStack& “ to avoid copy construction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that copy construction is necessary here because the EventStack created by detector is a function local variable, so it had better to be copied and saved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can use new
to dynamically create EventStack in saber's reportBug function and destroy it in the destructor of GenericBug. I am not sure if its better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that copy construction is necessary here because the EventStack created by detector is a function local variable, so it had better to be copied and saved.
It should be const reference because it will do the copy in GeneralBug’s constructor.
svf/include/Util/SVFBugReport.h
Outdated
protected: | ||
Set<std::string> conditionalFreePath; | ||
public: | ||
PartialLeakBug(EventStack bugEventStack, Set<std::string> conditionalFreePath): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use const EventStack&
same for the following constructors
svf/include/Util/SVFBugReport.h
Outdated
|
||
class DoubleFreeBug : public GenericBug{ | ||
protected: | ||
Set<std::string> doubleFreePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this or put into the event stack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you refer to doing so for DoubleFreeBug only, I think it's feasible, but may loss consistency with other bug classes like FilePartialCloseBug, ParitalLeakBug, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the strings in this vector? Can we get or extract the from the event stack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the reason for not doing so for other bug classes is that eventStack should be used to store events happening on the execution path from entry to the bug site, but not side effects like partial free paths and partial close paths.
svf/lib/Util/SVFBugReport.cpp
Outdated
SVFUtil::errs() << "\t\t Events : \n"; | ||
|
||
auto eventIt = bugEventStack.begin(); | ||
for(; eventIt != bugEventStack.end(); eventIt ++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (event : bugEventStack)
….
svf/lib/Util/SVFBugReport.cpp
Outdated
|
||
const std::string GenericBug::getLoc() const | ||
{ | ||
return bugEventStack.at(bugEventStack.size() -1)->getEventLoc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an assertion, otherwise how can you sure the size-1 is the element you want?
/// note: should be initialized with a bugEventStack | ||
inline GenericBug(BugType bugType, EventStack bugEventStack): bugType(bugType), bugEventStack(bugEventStack){ }; | ||
|
||
virtual ~GenericBug() = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the destructor? How did you release the memory of the events in EventStack?
svf/include/Util/SVFBugReport.h
Outdated
|
||
public: | ||
/// note: should be initialized with a bugEventStack | ||
inline GenericBug(BugType bugType, EventStack bugEventStack): bugType(bugType), bugEventStack(bugEventStack){ }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const EventStack&
svf/lib/Util/SVFBugReport.cpp
Outdated
} | ||
} | ||
|
||
void SVFBugReport::dumpToFile(const std::string& filePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dumpToFile => dumpToJsonFile
|
||
public: | ||
/// note: should be initialized with a bugEventStack | ||
GenericBug(BugType bugType, EventStack bugEventStack): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const EventStack& bugEventStack
svf/include/Util/SVFBugReport.h
Outdated
|
||
class GenericBug{ | ||
public: | ||
typedef std::vector<GenericEvent *> EventStack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const GenericEvent*
svf/include/Util/SVFBugReport.h
Outdated
public: | ||
SVFBugReport() = default; | ||
~SVFBugReport(); | ||
typedef SVF::Set<GenericBug *> BugSet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const GenericBug*
svf/include/Util/SVFBugReport.h
Outdated
* usage: addBug<GenericBug::BOA>(BufferOverflowBug(bugInst, 0, 10, 1, 11)) | ||
*/ | ||
template <typename T> | ||
void addBug(T bug) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void addBug(eventstack, flag){
switch (xx)
case1:
xxxx
default:
assert(false && "no such kind of bug");
}
svf/include/Util/SVFBugReport.h
Outdated
{ | ||
T *newBug = new T(bug); | ||
bugSet.insert(newBug); | ||
GenericBug *newBug; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenericBug *newBug = nullptr;
switch(bugType){ | ||
case GenericBug::NEVERFREE:{ | ||
newBug = new NeverFreeBug(eventStack); | ||
bugSet.insert(newBug); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bugSet.insert(new NeverFreeBug(eventStack));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newBug is use at line 333 newBug->printBugToTerminal()
svf/include/Util/SVFBugReport.h
Outdated
|
||
void addAbsExecBug(GenericBug::BugType bugType, const GenericBug::EventStack &eventStack, | ||
s64_t allocLowerBound, s64_t allocUpperBound, s64_t accessLowerBound, s64_t accessUpperBound){ | ||
GenericBug *newBug; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenericBug *newBug = nullptr;
svf/include/Util/SVFBugReport.h
Outdated
} | ||
}; | ||
|
||
class SourceInstructionEvent: public GenericEvent{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SourceInstructionEvent => SourceInstEvent
svf/lib/SABER/ProgSlice.cpp
Outdated
auto stmt = PAG::getPAG()->getValueEdges(tinst); | ||
assert(stmt.size() == 1 && "returned SVFStmtSet should be of size 1!"); | ||
if(pathAllocator->isNegCond(*it)) | ||
eventStack.push_back(new BranchEvent(*(stmt.begin()), false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new BranchEvent(tinst, false)
No description provided.