34 #include <sys/resource.h>
39 #define KNRM "\x1B[1;0m"
40 #define KRED "\x1B[1;31m"
41 #define KGRN "\x1B[1;32m"
42 #define KYEL "\x1B[1;33m"
43 #define KBLU "\x1B[1;34m"
44 #define KPUR "\x1B[1;35m"
45 #define KCYA "\x1B[1;36m"
46 #define KWHT "\x1B[1;37m"
109 outs() <<
"node " << node <<
" points-to: {";
125 for (PointsToList::const_iterator ii = ptl.begin(), ie = ptl.end();
139 outs() <<
"node " << node <<
" alias set: {";
152 O <<
" " << *ii <<
" ";
160 o <<
" " <<
n <<
" ";
171 O << infor <<
"\tVmRSS: " << vmrss <<
"\tVmSize: " << vmsize <<
"\n";
181 FILE* procfile = fopen(
"/proc/self/status",
"r");
184 u32_t result = fread(
buffer,
sizeof(
char), 8192, procfile);
187 fputs (
"Reading error\n",stderr);
198 char delims[] =
"\n";
201 bool found_vmrss =
false;
202 bool found_vmsize =
false;
204 while (line !=
nullptr && (found_vmrss ==
false || found_vmsize ==
false))
206 if (
strstr(line,
"VmRSS:") !=
nullptr)
208 sscanf(line,
"%*s %u", vmrss_kb);
212 if (
strstr(line,
"VmSize:") !=
nullptr)
214 sscanf(line,
"%*s %u", vmsize_kb);
218 line =
strtok(
nullptr, delims);
221 return (found_vmrss && found_vmsize);
229 const rlim_t kStackSize = 256L * 1024L * 1024L;
231 int result = getrlimit(RLIMIT_STACK, &rl);
234 if (rl.rlim_cur < kStackSize)
236 rl.rlim_cur = kStackSize;
237 result = setrlimit(RLIMIT_STACK, &rl);
249 if (
const SVFCallInst* call = SVFUtil::dyn_cast<SVFCallInst>(inst))
251 const SVFFunction* func = call->getCalledFunction();
275 assert(
false &&
"SVFUtil::hclustMethodToString: unknown method");
291 if (timeLimit == 0)
return false;
295 unsigned remainingSeconds = alarm(0);
296 if (remainingSeconds != 0)
299 alarm(remainingSeconds);
312 if (limitTimerSet) alarm(0);
330 return SVFUtil::isa<CallICFGNode>(inst);
335 if (
const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(inst))
337 const SVFFunction* func = call->getCalledFunction();
366 return isExtCall(cast<CallICFGNode>(node)->getCalledFunction());
390 if (
const auto& intraNode = dyn_cast<IntraICFGNode>(node))
391 return intraNode->isRetInst();
405 for (
const auto&
item: *svfirCallGraph)
418 for (
const auto&
item: *svfirCallGraph)
#define KNRM
Color for output format.
const SVFFunction * getCalledFunction() const
static const Option< bool > DisableWarn
const std::string & getName() const
const SVFFunction * getFunction() const
Get function of this call node.
virtual const SVFType * getType() const
PTACallGraph * getCallGraph()
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
bool isTDFork(const CallICFGNode *inst) const
Return true if this call create a new thread.
static ThreadAPI * getThreadAPI()
Return a static reference.
char * strstr(const char *haystack, const char *needle)
char * strtok(char *str, const char *delim)
bool isHeapAllocExtCallViaRet(const Instruction *inst)
bool isCallSite(const Instruction *inst)
Whether an instruction is a call or invoke instruction.
bool isHeapAllocExtCallViaArg(const Instruction *inst)
bool isProgEntryFunction(const Function *fun)
Check whether a function is an entry function (i.e., main)
bool isReallocExtCall(const CallICFGNode *cs)
std::string sucMsg(const std::string &msg)
Returns successful message by converting a string into green string output.
void increaseStackSize()
Increase the stack size limit.
std::string bugMsg1(const std::string &msg)
std::string hclustMethodToString(hclust_fast_methods method)
Returns a string representation of a hclust method.
void stopAnalysisLimitTimer(bool limitTimerSet)
bool isHeapAllocExtFunViaRet(const SVFFunction *fun)
Return true if the call is a heap allocator/reallocator.
bool isExtCall(const SVFFunction *fun)
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
OrderedSet< PointsTo, equalPointsTo > PointsToList
void dumpAliasSet(unsigned node, NodeBS To)
Dump alias set.
bool getMemoryUsageKB(u32_t *vmrss_kb, u32_t *vmsize_kb)
Get memory usage from system file. Return TRUE if succeed.
void reportMemoryUsageKB(const std::string &infor, OutStream &O=SVFUtil::outs())
Print memory usage in KB.
bool startAnalysisLimitTimer(unsigned timeLimit)
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
std::string bugMsg3(const std::string &msg)
bool isHeapAllocExtCallViaArg(const CallICFGNode *cs)
bool isHeapAllocExtCall(const ICFGNode *cs)
u32_t getHeapAllocHoldingArgPosition(const SVFFunction *fun)
Get the position of argument that holds an allocated heap object.
bool isCallSite(const SVFValue *val)
Whether an instruction is a call or invoke instruction.
bool isReallocExtFun(const SVFFunction *fun)
Return true if the call is a heap reallocator.
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
void dumpSparseSet(const NodeBS &To)
bool isHeapAllocExtFunViaArg(const SVFFunction *fun)
bool isIntrinsicInst(const SVFInstruction *inst)
Return true if it is an llvm intrinsic instruction.
void dumpPointsToSet(unsigned node, NodeBS To)
Dump points-to set.
std::string bugMsg2(const std::string &msg)
bool isProgExitCall(const CallICFGNode *cs)
std::string wrnMsg(const std::string &msg)
Returns warning message by converting a string into yellow string output.
bool isRetInstNode(const ICFGNode *node)
bool matchArgs(const CallICFGNode *cs, const SVFFunction *callee)
void timeLimitReached(int signum)
Function to call when alarm for time limit hits.
const SVFFunction * getProgFunction(const std::string &funName)
Get program entry function from function name.
bool isHeapAllocExtCallViaRet(const CallICFGNode *cs)
interfaces to be used externally
void dumpSet(NodeBS To, OutStream &O=SVFUtil::outs())
Dump sparse bitvector set.
bool isProgExitFunction(const SVFFunction *fun)
Return true if this is a program exit function call.
std::ostream & outs()
Overwrite llvm::outs()
const SVFFunction * getProgEntryFunction()
Get program entry function.
void dumpPointsToList(const PointsToList &ptl)