Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
SVF::SVFBugReport Class Reference

#include <SVFBugReport.h>

Public Types

typedef SVF::Set< const GenericBug * > BugSet
 

Public Member Functions

 SVFBugReport ()=default
 
 ~SVFBugReport ()
 
void setStat (double time, std::string mem, double coverage)
 
void addSaberBug (GenericBug::BugType bugType, const GenericBug::EventStack &eventStack)
 
void addAbsExecBug (GenericBug::BugType bugType, const GenericBug::EventStack &eventStack, s64_t allocLowerBound, s64_t allocUpperBound, s64_t accessLowerBound, s64_t accessUpperBound)
 
void dumpToJsonFile (const std::string &filePath) const
 
const BugSetgetBugSet () const
 

Protected Attributes

BugSet bugSet
 
double time
 
std::string mem
 
double coverage
 

Detailed Description

Definition at line 286 of file SVFBugReport.h.

Member Typedef Documentation

◆ BugSet

Definition at line 291 of file SVFBugReport.h.

Constructor & Destructor Documentation

◆ SVFBugReport()

SVF::SVFBugReport::SVFBugReport ( )
default

◆ ~SVFBugReport()

SVFBugReport::~SVFBugReport ( )

Definition at line 335 of file SVFBugReport.cpp.

336{
337 for(auto bugIt: bugSet)
338 {
339 delete bugIt;
340 }
341}
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

Member Function Documentation

◆ addAbsExecBug()

void SVF::SVFBugReport::addAbsExecBug ( GenericBug::BugType  bugType,
const GenericBug::EventStack eventStack,
s64_t  allocLowerBound,
s64_t  allocUpperBound,
s64_t  accessLowerBound,
s64_t  accessUpperBound 
)
inline

add bugs

Definition at line 365 of file SVFBugReport.h.

367 {
369 GenericBug *newBug = nullptr;
370 switch(bugType)
371 {
373 {
374 newBug = new FullBufferOverflowBug(eventStack, allocLowerBound, allocUpperBound, accessLowerBound, accessUpperBound);
375 bugSet.insert(newBug);
376 break;
377 }
379 {
380 newBug = new PartialBufferOverflowBug(eventStack, allocLowerBound, allocUpperBound, accessLowerBound, accessUpperBound);
381 bugSet.insert(newBug);
382 break;
383 }
385 {
386 newBug = new FullNullPtrDereferenceBug(eventStack);
387 bugSet.insert(newBug);
388 break;
389 }
391 {
392 newBug = new PartialNullPtrDereferenceBug(eventStack);
393 bugSet.insert(newBug);
394 break;
395 }
396 default:
397 {
398 assert(false && "Abstract Execution does NOT have this bug type!");
399 break;
400 }
401 }
402
403 // when add a bug, also print it to terminal
404 //newBug->printBugToTerminal();
405 }

◆ addSaberBug()

void SVF::SVFBugReport::addSaberBug ( GenericBug::BugType  bugType,
const GenericBug::EventStack eventStack 
)
inline

create and add the bug

Definition at line 313 of file SVFBugReport.h.

314 {
316 GenericBug *newBug = nullptr;
317 switch(bugType)
318 {
320 {
321 newBug = new NeverFreeBug(eventStack);
322 bugSet.insert(newBug);
323 break;
324 }
326 {
327 newBug = new PartialLeakBug(eventStack);
328 bugSet.insert(newBug);
329 break;
330 }
332 {
333 newBug = new DoubleFreeBug(eventStack);
334 bugSet.insert(newBug);
335 break;
336 }
338 {
339 newBug = new FileNeverCloseBug(eventStack);
340 bugSet.insert(newBug);
341 break;
342 }
344 {
345 newBug = new FilePartialCloseBug(eventStack);
346 bugSet.insert(newBug);
347 break;
348 }
349 default:
350 {
351 assert(false && "saber does NOT have this bug type!");
352 break;
353 }
354 }
355
356 // when add a bug, also print it to terminal
357 newBug->printBugToTerminal();
358 }

◆ dumpToJsonFile()

void SVFBugReport::dumpToJsonFile ( const std::string &  filePath) const

Add defects

Add bug information to JSON

Add event information to JSON

Dump single bug to JSON string and write to file

Destroy the cJSON object

Add program information

Definition at line 343 of file SVFBugReport.cpp.

344{
345 std::map<u32_t, std::string> eventType2Str =
346 {
347 {SVFBugEvent::CallSite, "call site"},
348 {SVFBugEvent::Caller, "caller"},
349 {SVFBugEvent::Loop, "loop"},
350 {SVFBugEvent::Branch, "branch"}
351 };
352
353 ofstream jsonFile(filePath, ios::out);
354
355 jsonFile << "{\n";
356
358 jsonFile << "\"Defects\": [\n";
359 size_t commaCounter = bugSet.size() - 1;
360 for (auto bugPtr : bugSet)
361 {
363
365 cJSON *bugType = cJSON_CreateString(
366 GenericBug::BugType2Str.at(bugPtr->getBugType()).c_str());
367 cJSON_AddItemToObject(singleDefect, "DefectType", bugType);
368
369 cJSON *bugLoc = cJSON_Parse(bugPtr->getLoc().c_str());
370 if (bugLoc == nullptr)
371 {
372 bugLoc = cJSON_CreateObject();
373 }
374 cJSON_AddItemToObject(singleDefect, "Location", bugLoc);
375
377 bugPtr->getFuncName().c_str());
379
380 cJSON_AddItemToObject(singleDefect, "Description",
381 bugPtr->getBugDescription());
382
385 const GenericBug::EventStack &bugEventStack = bugPtr->getEventStack();
387 {
388 // Add only when bug is context sensitive
389 for (const SVFBugEvent &event : bugEventStack)
390 {
391 if (event.getEventType() == SVFBugEvent::SourceInst)
392 {
393 continue;
394 }
395
397 // Event type
399 eventType2Str[event.getEventType()].c_str());
401 // Function name
403 event.getFuncName().c_str());
405 // Event loc
406 cJSON *eventLoc = cJSON_Parse(event.getEventLoc().c_str());
407 if (eventLoc == nullptr)
408 {
410 }
412 // Event description
414 event.getEventDescription().c_str());
416
418 }
419 }
421
425 if (commaCounter != 0)
426 {
427 jsonFile << ",\n";
428 }
429 commaCounter--;
430
433 }
434 jsonFile << "\n],\n";
435
437 jsonFile << "\"Time\": " << time << ",\n";
438 jsonFile << "\"Memory\": \"" << mem << "\",\n";
439 jsonFile << "\"Coverage\": " << coverage << "\n";
440
441 jsonFile << "}";
442 jsonFile.close();
443}
cJSON_Delete(null)
static bool classof(const GenericBug *bug)
ClassOf.
static const OrderedMap< GenericBug::BugType, std::string > BugType2Str
std::vector< SVFBugEvent > EventStack
Definition cJSON.h:104

◆ getBugSet()

const BugSet & SVF::SVFBugReport::getBugSet ( ) const
inline

Definition at line 417 of file SVFBugReport.h.

418 {
419 return bugSet;
420 }

◆ setStat()

void SVF::SVFBugReport::setStat ( double  time,
std::string  mem,
double  coverage 
)
inline

Definition at line 301 of file SVFBugReport.h.

302 {
303 this->time = time;
304 this->mem = mem;
305 this->coverage = coverage;
306 }

Member Data Documentation

◆ bugSet

BugSet SVF::SVFBugReport::bugSet
protected

Definition at line 294 of file SVFBugReport.h.

◆ coverage

double SVF::SVFBugReport::coverage
protected

Definition at line 297 of file SVFBugReport.h.

◆ mem

std::string SVF::SVFBugReport::mem
protected

Definition at line 296 of file SVFBugReport.h.

◆ time

double SVF::SVFBugReport::time
protected

Definition at line 295 of file SVFBugReport.h.


The documentation for this class was generated from the following files: