31#ifndef WIN32_LEAN_AND_MEAN
32#define WIN32_LEAN_AND_MEAN
46#include <sys/resource.h>
61#define KNRM "\x1B[1;0m"
62#define KRED "\x1B[1;31m"
63#define KGRN "\x1B[1;32m"
64#define KYEL "\x1B[1;33m"
65#define KBLU "\x1B[1;34m"
66#define KPUR "\x1B[1;35m"
67#define KCYA "\x1B[1;36m"
68#define KWHT "\x1B[1;37m"
131 outs() <<
"node " << node <<
" points-to: {";
147 for (PointsToList::const_iterator ii = ptl.begin(), ie = ptl.end();
161 outs() <<
"node " << node <<
" alias set: {";
174 O <<
" " << *ii <<
" ";
182 o <<
" " <<
n <<
" ";
193 O << infor <<
"\tVmRSS: " << vmrss <<
"\tVmSize: " << vmsize <<
"\n";
203 FILE* procfile = fopen(
"/proc/self/status",
"r");
206 u32_t result = fread(
buffer,
sizeof(
char), 8192, procfile);
209 fputs (
"Reading error\n",stderr);
220 char delims[] =
"\n";
223 bool found_vmrss =
false;
224 bool found_vmsize =
false;
226 while (line !=
nullptr && (found_vmrss ==
false || found_vmsize ==
false))
228 if (
strstr(line,
"VmRSS:") !=
nullptr)
230 sscanf(line,
"%*s %u", vmrss_kb);
234 if (
strstr(line,
"VmSize:") !=
nullptr)
236 sscanf(line,
"%*s %u", vmsize_kb);
240 line =
strtok(
nullptr, delims);
243 return (found_vmrss && found_vmsize);
255 const rlim_t kStackSize = 256L * 1024L * 1024L;
257 int result = getrlimit(RLIMIT_STACK, &rl);
260 if (rl.rlim_cur < kStackSize)
262 rl.rlim_cur = kStackSize;
263 result = setrlimit(RLIMIT_STACK, &rl);
274 return !path.empty() && (stat(path.c_str(), &statbuf) == 0);
282 FILE* pipe = popen(command.c_str(),
"r");
291 int status = pclose(pipe);
296 result.erase(std::remove(result.begin(), result.end(),
'\n'), result.end());
297 result.erase(std::remove(result.begin(), result.end(),
'\r'), result.end());
307 if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
308 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
311 GetModuleFileNameA(hm, path,
sizeof(path));
313 for (
size_t i = 0; i < s.length(); ++i)
327 return std::string(info.dli_fname);
350 assert(
false &&
"SVFUtil::hclustMethodToString: unknown method");
370 assert(timeLimit > 0 &&
"startAnalysisTimer: given non-0 time-limit.");
374 unsigned remainingSeconds = alarm(0);
375 assert(remainingSeconds != 0 &&
"startAnalysisTimer: attempt to set a second alarm.");
414 const FunObjVar* func = call->getCalledFunction();
468 return intraNode->isRetInst();
475 return fun && (fun->
getName() ==
"exit" ||
476 fun->
getName() ==
"__assert_rtn" ||
477 fun->
getName() ==
"__assert_fail");
489 for (
const auto&
item: *svfirCallGraph)
502 for (
const auto&
item: *svfirCallGraph)
515 return arg->isArgOfUncalledFunction();
534 return funObjVar && funObjVar->
getName() == main_name;
#define KNRM
Color for output format.
Class representing a function argument variable in the SVFIR.
const FunObjVar * getFunction() const
Get function of this call node.
const std::string & getName() const
const FunObjVar * getCalledFunction() const
static ExtAPI * getExtAPI()
bool is_ext(const FunObjVar *funObjVar)
const GEdgeSetTy & getInEdges() const
static const Option< bool > DisableWarn
static Option< bool > SVFMain
const CallGraph * getCallGraph()
Get CG.
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
const ValVar * getBaseValVar(NodeID id) const
NodeID getId() const
Get ID.
virtual const SVFType * getType() const
virtual const std::string & getName() const
SparseBitVectorIterator iterator
static ThreadAPI * getThreadAPI()
Return a static reference.
char * fgets(char *str, int n, void *stream)
char * strtok(char *str, const char *delim)
char * strstr(const char *haystack, const char *needle)
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.
const ObjVar * getObjVarOfValVar(const ValVar *valVar)
std::string bugMsg1(const std::string &msg)
bool isProgEntryFunction(const FunObjVar *)
Program entry function e.g. main.
std::string hclustMethodToString(hclust_fast_methods method)
Returns a string representation of a hclust method.
bool isIntrinsicInst(const ICFGNode *inst)
Return true if it is an llvm intrinsic instruction.
u32_t getHeapAllocHoldingArgPosition(const FunObjVar *fun)
Get the position of argument that holds an allocated heap object.
const FunObjVar * getProgEntryFunction()
Get program entry function.
bool isHeapAllocExtFunViaRet(const FunObjVar *fun)
Return true if the call is a heap allocator/reallocator.
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 isHeapAllocExtFunViaArg(const FunObjVar *fun)
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
LLVM_NODISCARD bool isa(const Y &Val)
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.
void stopAnalysisLimitTimer(void)
Stops analysis timer.
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)
bool isArgOfUncalledFunction(const SVFVar *svfvar)
bool isExtCall(const FunObjVar *fun)
bool matchArgs(const CallICFGNode *cs, const FunObjVar *callee)
void startAnalysisLimitTimer(unsigned timeLimit)
Starts analysis timer. timeLimit must be non-0. Timer must not be already set.
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
void dumpSparseSet(const NodeBS &To)
void dumpPointsToSet(unsigned node, NodeBS To)
Dump points-to set.
bool fileExists(const std::string &path)
Check whether a file exists at the given path.
std::string getCurrentSOPath()
Return the absolute path of the current module/executable.
std::string bugMsg2(const std::string &msg)
bool isProgExitCall(const CallICFGNode *cs)
bool isCallSite(const ICFGNode *inst)
std::string wrnMsg(const std::string &msg)
Returns warning message by converting a string into yellow string output.
bool isReallocExtFun(const FunObjVar *fun)
Return true if the call is a heap reallocator.
bool isRetInstNode(const ICFGNode *node)
std::ostream & outs()
Overwrite llvm::outs().
void timeLimitReached(int signum)
Function to call when alarm for time limit hits.
std::string getStdoutFromCommand(const std::string &command)
Execute a shell command and capture its stdout output.
bool isHeapAllocExtCallViaRet(const CallICFGNode *cs)
interfaces to be used externally
void dumpSet(NodeBS To, OutStream &O=SVFUtil::outs())
Dump sparse bitvector set.
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
void dumpPointsToList(const PointsToList &ptl)
bool isProgExitFunction(const FunObjVar *fun)
Return true if this is a program exit function call.
const FunObjVar * getProgFunction(const std::string &funName)
Get program entry function from function name.