ROSE 0.11.145.192
Function.h
1#ifndef ROSE_BinaryAnalysis_Partitioner2_Function_H
2#define ROSE_BinaryAnalysis_Partitioner2_Function_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/CallingConvention/Analysis.h>
8#include <Rose/BinaryAnalysis/CallingConvention/Definition.h>
9#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
10#include <Rose/BinaryAnalysis/StackDelta.h>
11#include <Rose/SourceLocation.h>
12
13#include <Sawyer/Attribute.h>
14#include <Sawyer/Cached.h>
15#include <Sawyer/Map.h>
16#include <Sawyer/Set.h>
17#include <Sawyer/SharedPointer.h>
18
19#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
20#include <boost/serialization/access.hpp>
21#endif
22
23namespace Rose {
24namespace BinaryAnalysis {
25namespace Partitioner2 {
26
29
42public:
47 };
48
51
52private:
53 rose_addr_t entryVa_; // entry address; destination for calls to this function
54 std::string name_; // optional function name
55 std::string demangledName_; // optional demangled name
56 std::string comment_; // optional multi-line, plain-text, commment
57 unsigned reasons_; // reason bits from SgAsmFunction::FunctionReason
58 std::string reasonComment_; // additional commentary about reasons_
59 std::set<rose_addr_t> bblockVas_; // addresses of basic blocks
60 std::vector<DataBlockPtr> dblocks_; // data blocks owned by this function, sorted by starting address
61 bool isFrozen_; // true if function is represented by the CFG
62 CallingConvention::Analysis ccAnalysis_; // analysis computing how registers etc. are used
63 CallingConvention::DefinitionPtr ccDefinition_; // best definition or null
64 StackDelta::Analysis stackDeltaAnalysis_; // analysis computing stack deltas for each block and whole function
65 InstructionSemantics::BaseSemantics::SValuePtr stackDeltaOverride_; // special value to override stack delta analysis
66 SourceLocation sourceLocation_; // corresponding location of function in source code if known
67
68 // The following members are caches either because their value is seldom needed and expensive to compute, or because the
69 // value is best computed at a higher layer (e.g., in the partitioner) yet it makes the most sense to store it here. Make
70 // sure clearCache() resets these to initial values.
72
73 void clearCache() {
74 isNoop_.clear();
75 }
76
77#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
78private:
79 friend class boost::serialization::access;
80 template<class S> void serialize(S&, unsigned version);
81#endif
82
83public:
84 ~Function();
85
86protected:
87 // Needed for serialization
88 Function();
89
90 // Use instance() instead
91 explicit Function(rose_addr_t entryVa, const std::string &name, unsigned reasons);
92
93public:
97 static Ptr instance(rose_addr_t entryVa, const std::string &name="", unsigned reasons=0);
98 static Ptr instance(rose_addr_t entryVa, unsigned reasons);
105 rose_addr_t address() const;
106
112 const std::string& name() const;
113 void name(const std::string&);
122 const std::string& demangledName() const;
123 void demangledName(const std::string&);
131 const std::string& comment() const;
132 void comment(const std::string&);
145 unsigned reasons() const;
146 void reasons(unsigned);
153 void insertReasons(unsigned reasons);
154
159 void eraseReasons(unsigned reasons);
160
164 const std::string& reasonComment() const;
165 void reasonComment(const std::string&);
173 const std::set<rose_addr_t>& basicBlockAddresses() const;
174
176 bool ownsBasicBlock(rose_addr_t bblockVa) const;
177
186 bool insertBasicBlock(rose_addr_t bblockVa);
187
193 void eraseBasicBlock(rose_addr_t bblockVa); // no-op if not existing
194
197 const std::vector<DataBlockPtr>& dataBlocks() const;
198
207
216
224
231
235 bool isFrozen() const;
236
244 bool isThunk() const;
245
247 size_t nBasicBlocks() const;
248
250 size_t nDataBlocks() const;
251
261 int64_t stackDeltaConcrete() const;
323 std::string printableName() const;
324
330
331private:
332 friend class Partitioner;
333 void freeze();
334 void thaw();
335
336 // Find an equivalent data block and replace it with the specified data block, or insert the specified data block
337 void replaceOrInsertDataBlock(const DataBlockPtr&);
338};
339
340} // namespace
341} // namespace
342} // namespace
343
344#endif
345#endif
void comment(const std::string &)
Property: Optional function comment.
void eraseBasicBlock(rose_addr_t bblockVa)
Remove a basic block from this function.
std::string printableName() const
A printable name for the function.
void reasonComment(const std::string &)
Property: Additional comment for why function was detected.
void sourceLocation(const SourceLocation &)
Property: Location of function definition in source code, if known.
FunctionPtr Ptr
Shared-ownership pointer for function.
Definition Function.h:50
AddressIntervalSet dataAddresses() const
Addresses that are part of static data.
rose_addr_t address() const
Read-only property: Entry address.
Ownership
Manner in which a function owns a block.
Definition Function.h:44
@ OWN_UNOWNED
Function does not own the block.
Definition Function.h:44
@ OWN_EXPLICIT
Function owns the block explicitly, the normal ownership.
Definition Function.h:45
@ OWN_PROVISIONAL
Function might own the block in the future.
Definition Function.h:46
bool insertDataBlock(const DataBlockPtr &)
Add a data block to this function.
void stackDeltaOverride(const InstructionSemantics::BaseSemantics::SValuePtr &delta)
Property: Stack delta override.
const std::string & reasonComment() const
Property: Additional comment for why function was detected.
bool isThunk() const
True if function is a thunk.
static Ptr instance(rose_addr_t entryVa, unsigned reasons)
Static allocating constructor.
const SourceLocation & sourceLocation() const
Property: Location of function definition in source code, if known.
const Sawyer::Cached< bool > & isNoop() const
Cached results of function no-op analysis.
const std::string & name() const
Property: Optional function name.
void insertReasons(unsigned reasons)
Insert additional function reason bits.
void demangledName(const std::string &)
Property: Optional demangled name.
void callingConventionDefinition(const CallingConvention::DefinitionPtr &)
Property: Best calling convention definition.
size_t nDataBlocks() const
Number of data blocks in the function.
CallingConvention::Analysis & callingConventionAnalysis()
Property: Calling convention analysis results.
size_t nBasicBlocks() const
Number of basic blocks in the function.
void reasons(unsigned)
Property: Bit vector of function reasons.
const std::string & demangledName() const
Property: Optional demangled name.
void eraseReasons(unsigned reasons)
Remove function reason bits.
const std::vector< DataBlockPtr > & dataBlocks() const
Returns data blocks owned by this function.
DataBlockPtr eraseDataBlock(const DataBlockPtr &)
Remove specified or equivalent data block from this function.
const std::string & comment() const
Property: Optional function comment.
CallingConvention::DefinitionPtr callingConventionDefinition()
Property: Best calling convention definition.
const std::set< rose_addr_t > & basicBlockAddresses() const
Returns basic block addresses.
unsigned reasons() const
Property: Bit vector of function reasons.
static Ptr instance(rose_addr_t entryVa, const std::string &name="", unsigned reasons=0)
Static allocating constructor.
DataBlockPtr dataBlockExists(const DataBlockPtr &) const
Determine if this function contains the specified data block, or equivalent.
bool ownsBasicBlock(rose_addr_t bblockVa) const
Predicate to test whether a function owns a basic block address.
StackDelta::Analysis & stackDeltaAnalysis()
Property: Stack delta analysis results.
InstructionSemantics::BaseSemantics::SValuePtr stackDelta() const
Property: Stack delta.
int64_t stackDeltaConcrete() const
Property: Stack delta.
InstructionSemantics::BaseSemantics::SValuePtr stackDeltaOverride() const
Property: Stack delta override.
bool isFrozen() const
Determines whether a function is frozen.
void name(const std::string &)
Property: Optional function name.
const StackDelta::Analysis & stackDeltaAnalysis() const
Property: Stack delta analysis results.
bool insertBasicBlock(rose_addr_t bblockVa)
Add a basic block to this function.
const CallingConvention::Analysis & callingConventionAnalysis() const
Property: Calling convention analysis results.
Partitions instructions into basic blocks and functions.
Information about a source location.
API and storage for attributes.
Definition Attribute.h:215
Implements cache data members.
Definition Cached.h:40
void clear() const
Remove cached value.
Definition Cached.h:82
Base class for reference counted objects.
Reference-counting intrusive smart pointer.
Sawyer::SharedPointer< Function > FunctionPtr
Shared-ownership pointer for Function.
The ROSE library.