2 * See the dyninst/COPYRIGHT file for copyright information.
4 * We provide the Paradyn Tools (below described as "Paradyn")
5 * on an AS IS basis, and do not warrant its validity or performance.
6 * We reserve the right to update, modify, or discontinue this
7 * software at any time. We shall have no obligation to supply such
8 * updates or modifications or any other form of support to you.
10 * By your use of Paradyn, you understand and agree that we (or any
11 * other person or entity with proprietary rights in Paradyn) are
12 * under no obligation to provide either maintenance services,
13 * update services, notices of latent defects, or correction of
14 * defects for Paradyn.
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 #ifndef _BPatch_function_h_
32 #define _BPatch_function_h_
34 #include "Annotatable.h"
35 #include "BPatch_dll.h"
36 #include "BPatch_Vector.h"
37 #include "BPatch_Set.h"
38 #include "BPatch_enums.h"
39 #include "BPatch_type.h"
40 #include "BPatch_module.h"
41 #include "BPatch_memoryAccess_NP.h"
42 //#include "BPatch_dependenceGraphNode.h"
43 // class BPatch_dependenceGraphNode;
48 class BPatch_localVarCollection;
49 class BPatch_function;
51 class BPatch_flowGraph;
53 class BPatchTranslatorBase;
55 class ReturnParameterType;
56 class BPatch_function;
61 BPATCH_DLL_EXPORT Function *convert(const BPatch_function *);
65 BPATCH_DLL_EXPORT PatchFunction *convert(const BPatch_function *);
72 class BPATCH_DLL_EXPORT BPatch_function :
73 public BPatch_sourceObj,
74 public Dyninst::AnnotatableSparse
76 friend class BPatch_flowGraph;
77 friend class BPatch_basicBlock;
78 friend class BPatch_asyncEventHandler;
79 friend class BPatch_image;
80 friend class BPatch_thread;
81 friend class BPatch_process;
82 friend class BPatch_binaryEdit;
83 friend class BPatch_addressSpace;
84 friend class BPatch_point;
85 friend Dyninst::ParseAPI::Function *Dyninst::ParseAPI::convert(const BPatch_function *);
86 friend Dyninst::PatchAPI::PatchFunction *Dyninst::PatchAPI::convert(const BPatch_function *);
88 //BPatch_process *proc;
89 BPatch_addressSpace *addSpace;
90 AddressSpace *lladdSpace;
93 BPatch_flowGraph* cfg;
97 BPatch_point* createMemInstPoint(void *addr, BPatch_memoryAccess* ma);
100 bool varsAndParamsValid;
103 void constructVarsAndParams();
105 void identifyParamDependencies(BPatch_function* callee, void* calleeAddress);
107 #if defined(_MSC_VER)
108 #pragma warning(push)
109 #pragma warning(disable:4251)
111 // Disable warning that these vectors cannot be used externally,
112 // which is irrelevant since the vectors are private
113 std::map<BPatch_localVar *, BPatch_variableExpr *> local_vars;
114 BPatch_Vector<BPatch_localVar *> params;
115 #if defined(_MSC_VER)
120 //dynC internal use only
121 bool hasParamDebugInfo();
124 virtual ~BPatch_function();
126 // The following are for internal use by the library only:
127 func_instance *lowlevel_func() const { return func; }
128 BPatch_process *getProc() const;
129 BPatch_addressSpace *getAddSpace() const { return addSpace; }
131 BPatch_function(BPatch_addressSpace *_addSpace, func_instance *_func,
132 BPatch_module *mod = NULL);
133 BPatch_function(BPatch_addressSpace *_addSpace, func_instance *_func,
134 BPatch_type * _retType,
136 bool getSourceObj(BPatch_Vector<BPatch_sourceObj *> &);
137 BPatch_sourceObj *getObjParent();
138 BPatch_localVarCollection * localVariables;
139 BPatch_localVarCollection * funcParameters;
140 void setReturnType(BPatch_type * _retType){retType = _retType;}
141 void setModule(BPatch_module *module) { if (this->mod == NULL) this->mod = module;}
142 void removeCFG() { cfg = NULL; }
143 void getUnresolvedControlTransfers(BPatch_Vector<BPatch_point *> &unresolvedCF);
144 void getAbruptEndPoints(BPatch_Vector<BPatch_point *> &abruptEnds);
145 void getCallerPoints(BPatch_Vector<BPatch_point*>& callerPoints);
146 void getAllPoints(BPatch_Vector<BPatch_point*>& allPoints);
148 void getEntryPoints(BPatch_Vector<BPatch_point *> &entryPoints);
149 void getExitPoints(BPatch_Vector<BPatch_point *> &entryPoints);
150 void getCallPoints(BPatch_Vector<BPatch_point *> &entryPoints);
152 bool setHandlerFaultAddrAddr(Dyninst::Address addr, bool set);
153 bool removeInstrumentation(bool useInsertionSet);
154 bool parseNewEdge(Dyninst::Address source, Dyninst::Address target);
155 void relocateFunction();
156 bool getSharedFuncs(std::set<BPatch_function*> &funcs);
158 void addParam(Dyninst::SymtabAPI::localVar *lvar);
160 // void addParam(const char * _name, BPatch_type *_type, int _linenum,
161 // long _frameOffset, int _reg = -1,
162 // BPatch_storageClass _sc = BPatch_storageFrameOffset);
163 void fixupUnknown(BPatch_module *);
166 // This isn't so much for internal use only, but it *should*
167 // remain undocumented for now.
168 bool containsSharedBlocks();
172 // End of functions for internal use only
175 // For users of the library:
178 // BPatch_function::getName
179 // Returns <demangled> name of function
181 char * getName(char *s, int len);
183 // String interface to mangled name
184 std::string getName();
185 std::string getMangledName();
186 std::string getDemangledName();
187 std::string getTypedName();
188 bool getNames(std::vector<std::string> &names);
189 bool getDemangledNames(std::vector<std::string> &names);
190 bool getMangledNames(std::vector<std::string> &names);
191 bool getTypedNames(std::vector<std::string> &names);
193 // BPatch_function::getMangledName
194 // Returns mangled name of function, same as getName for non-c++ mutatees
196 char * getMangledName(char *s, int len);
198 // BPatch_function::getTypedName
199 // Returns demanged name of function (with type string), may be empty
201 char * getTypedName(char *s, int len);
203 // BPatch_function::getNames
204 // Adds all names of the function (inc. weak symbols) to the
205 // provided vector. Names are represented as const char *s,
206 // and do not require cleanup by the user.
208 bool getNames(BPatch_Vector<const char *> &names);
210 // BPatch_function::getMangledNames
211 // Adds all mangled names of the function (inc. weak symbols) to
212 // the provided vector. Names are represented as const char *s,
213 // and do not require cleanup by the user.
215 bool getMangledNames(BPatch_Vector<const char *> &names);
217 // BPatch_function::getBaseAddr
218 // Returns base address of function
220 void * getBaseAddr(void);
222 // BPatch_function::getReturnType
223 // Returns the <BPatch_type> return type of this function
226 BPatch_type * getReturnType();
228 // BPatch_function::getModule
229 // Returns the BPatch_module to which this function belongs
232 BPatch_module * getModule();
234 // BPatch_function::getParams
235 // Returns a vector of BPatch_localVar, representing this function's parameters
238 BPatch_Vector<BPatch_localVar *> * getParams();
240 // BPatch_function::getVars
241 // Returns a vector of local variables in this functions
244 BPatch_Vector<BPatch_localVar *> * getVars();
246 // BPatch_function::findPoint
247 // Returns a vector of inst points, corresponding to the given BPatch_procedureLocation
250 BPatch_Vector<BPatch_point *> * findPoint(const BPatch_procedureLocation loc);
252 // BPatch_function::findPoint
253 // Returns a vector of inst points, corresponding to the given set of op codes
255 BPatch_Vector<BPatch_point *> * findPoint(const BPatch_Set<BPatch_opCode>& ops);
256 BPatch_Vector<BPatch_point *> * findPoint(const std::set<BPatch_opCode>& ops);
258 // BPatch_function::findPoint
260 // Returns a BPatch_point that corresponds with the provided address. Returns NULL
261 // if the address does not correspond with an instruction.
262 BPatch_point * findPoint(Dyninst::Address addr);
265 // BPatch_function::findLocalVar
266 // Returns a BPatch_localVar, if a match for <name> is found
269 BPatch_localVar * findLocalVar(const char * name);
271 // BPatch_function::findLocalParam
272 // Returns a BPatch_localVar, if a match for <name> is found
275 BPatch_localVar * findLocalParam(const char * name);
277 // BPatch_function::findVariable
278 // Returns a set of variables matching <name> at the scope of this function
279 // -- or global scope, if nothing found in this scope
281 BPatch_Vector<BPatch_variableExpr *> * findVariable(const char *name);
283 bool findVariable(const char *name, BPatch_Vector<BPatch_variableExpr*> &vars);
285 // BPatch_function::getVariables
286 // This returns false, and should probably not exist. See getVars.
287 // is this defined, what variables should be returned??
291 bool getVariables(BPatch_Vector<BPatch_variableExpr *> &vect);
293 // BPatch_function::getModuleName
294 // Returns name of module this function belongs to
297 char * getModuleName(char *name, int maxLen);
299 // BPatch_function::isInstrumentable
301 // Returns true if the function is instrumentable.
305 bool isInstrumentable();
307 // BPatch_function::isSharedLib
308 // Returns true if this function lives in a shared library
313 // BPatch_function::getCFG
315 // method to create the control flow graph for the function
318 BPatch_flowGraph* getCFG();
320 const char * addName(const char *name, bool isPrimary = true, bool isMangled = false);
322 // Return native pointer to the function.
323 // Allocates and returns a special type of BPatch_variableExpr.
325 // Get all functions that share a block (or any code, but it will
326 // always be a block) with this function.
328 // Get the underlying ParseAPI Function
329 operator Dyninst::ParseAPI::Function *() const;
331 // Get the underlying PatchAPI Function
332 operator Dyninst::PatchAPI::PatchFunction *() const;
334 bool getAddressRange(void * &start, void * &end);
336 bool getAddressRange(Dyninst::Address &start, Dyninst::Address &end);
338 unsigned int getFootprint();
339 BPatch_variableExpr *getFunctionRef();
340 bool findOverlapping(BPatch_Vector<BPatch_function *> &funcs);
342 // Add stack modifications
343 bool addMods(std::set<StackMod*>);
346 #endif /* _BPatch_function_h_ */