SVF
Functions | Variables
CPPUtil.cpp File Reference
#include "SVF-FE/CPPUtil.h"
#include "Util/SVFUtil.h"
#include "SVF-FE/LLVMUtil.h"
#include <cxxabi.h>

Go to the source code of this file.

Functions

static bool isOperOverload (const string name)
 
static string getBeforeParenthesis (const string &name)
 
static void handleThunkFunction (cppUtil::DemangledName &dname)
 

Variables

const string vtblLabelBeforeDemangle = "_ZTV"
 
const string vtblLabelAfterDemangle = "vtable for "
 
const string vfunPreLabel = "_Z"
 
const string NVThunkFunLabel = "non-virtual thunk to "
 
const string VThunkFuncLabel = "virtual thunk to "
 
const string clsName = "class."
 
const string structName = "struct."
 

Function Documentation

◆ getBeforeParenthesis()

static string getBeforeParenthesis ( const string &  name)
static

Definition at line 86 of file CPPUtil.cpp.

87 {
88  size_t lastRightParen = name.rfind(")");
89  assert(lastRightParen > 0);
90 
91  s32_t paren_num = 1, pos;
92  for (pos = lastRightParen - 1; pos >= 0; pos--)
93  {
94  if (name[pos] == ')')
95  paren_num++;
96  if (name[pos] == '(')
97  paren_num--;
98  if (paren_num == 0)
99  break;
100  }
101  return name.substr(0, pos);
102 }
#define assert(ex)
Definition: util.h:141
signed s32_t
Definition: SVFBasicTypes.h:77

◆ handleThunkFunction()

static void handleThunkFunction ( cppUtil::DemangledName dname)
static

Definition at line 135 of file CPPUtil.cpp.

135  {
136  // when handling multi-inheritance,
137  // the compiler may generate thunk functions
138  // to perform `this` pointer adjustment
139  // they are indicated with `virtual thunk to `
140  // and `nun-virtual thunk to`.
141  // if the classname starts with part of a
142  // demangled name starts with
143  // these prefixes, we need to remove the prefix
144  // to get the real class name
145 
146  static vector<string> thunkPrefixes = {VThunkFuncLabel, NVThunkFunLabel};
147  for (unsigned i = 0; i < thunkPrefixes.size(); i++) {
148  auto prefix = thunkPrefixes[i];
149  if (dname.className.size() > prefix.size() &&
150  dname.className.compare(0, prefix.size(), prefix) == 0)
151  {
152  dname.className = dname.className.substr(prefix.size());
153  dname.isThunkFunc = true;
154  return;
155 
156  }
157  }
158 }
const string NVThunkFunLabel
Definition: CPPUtil.cpp:50
const string VThunkFuncLabel
Definition: CPPUtil.cpp:51

◆ isOperOverload()

static bool isOperOverload ( const string  name)
static

Definition at line 56 of file CPPUtil.cpp.

57 {
58  s32_t leftnum = 0, rightnum = 0;
59  string subname = name;
60  size_t leftpos, rightpos;
61  leftpos = subname.find("<");
62  while (leftpos != string::npos)
63  {
64  subname = subname.substr(leftpos+1);
65  leftpos = subname.find("<");
66  leftnum++;
67  }
68  subname = name;
69  rightpos = subname.find(">");
70  while (rightpos != string::npos)
71  {
72  subname = subname.substr(rightpos+1);
73  rightpos = subname.find(">");
74  rightnum++;
75  }
76  if (leftnum != rightnum)
77  {
78  return true;
79  }
80  else
81  {
82  return false;
83  }
84 }
signed s32_t
Definition: SVFBasicTypes.h:77

Variable Documentation

◆ clsName

const string clsName = "class."

Definition at line 53 of file CPPUtil.cpp.

◆ NVThunkFunLabel

const string NVThunkFunLabel = "non-virtual thunk to "

Definition at line 50 of file CPPUtil.cpp.

◆ structName

const string structName = "struct."

Definition at line 54 of file CPPUtil.cpp.

◆ vfunPreLabel

const string vfunPreLabel = "_Z"

Definition at line 47 of file CPPUtil.cpp.

◆ vtblLabelAfterDemangle

const string vtblLabelAfterDemangle = "vtable for "

Definition at line 44 of file CPPUtil.cpp.

◆ vtblLabelBeforeDemangle

const string vtblLabelBeforeDemangle = "_ZTV"

Definition at line 41 of file CPPUtil.cpp.

◆ VThunkFuncLabel

const string VThunkFuncLabel = "virtual thunk to "

Definition at line 51 of file CPPUtil.cpp.