2 * Copyright (c) 1996-2009 Barton P. Miller
4 * We provide the Paradyn Parallel Performance Tools (below
5 * described as "Paradyn") on an AS IS basis, and do not warrant its
6 * validity or performance. We reserve the right to update, modify,
7 * or discontinue this software at any time. We shall have no
8 * obligation to supply such updates or modifications or any other
9 * form of support to you.
11 * By your use of Paradyn, you understand and agree that we (or any
12 * other person or entity with proprietary rights in Paradyn) are
13 * under no obligation to provide either maintenance services,
14 * update services, notices of latent defects, or correction of
15 * defects for Paradyn.
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 #if !defined(IA_IAPI_H)
35 #include "InstructionAdapter.h"
36 #include "Instruction.h"
37 #include "InstructionDecoder.h"
38 #include <boost/tuple/tuple.hpp>
40 class IA_IAPI : public InstructionAdapter
42 friend class image_func;
44 IA_IAPI(Dyninst::InstructionAPI::InstructionDecoder dec_,
45 Address start_, image_func* f);
46 IA_IAPI(Dyninst::InstructionAPI::InstructionDecoder dec_,
47 Address start_, image * im);
50 Dyninst::InstructionAPI::Instruction::Ptr getInstruction();
52 virtual bool hasCFT() const;
53 virtual size_t getSize() const;
54 virtual bool isFrameSetupInsn() const;
55 virtual bool isAbortOrInvalidInsn() const;
56 virtual bool isAllocInsn() const;
58 getNewEdges(pdvector<std::pair< Address, EdgeTypeEnum> >&
59 outEdges, image_basicBlock* currBlk,
60 unsigned int num_insns,
61 dictionary_hash<Address, std::string> *pltFuncs) const;
62 virtual InstrumentableLevel getInstLevel( unsigned int num_insns ) const;
63 virtual bool isDynamicCall() const;
64 virtual bool isAbsoluteCall() const;
65 virtual bool simulateJump() const;
66 virtual void advance();
67 virtual bool isNop() const;
68 virtual bool isLeave() const;
69 virtual bool isDelaySlot() const;
70 virtual bool isRelocatable(InstrumentableLevel lvl) const;
71 virtual bool isTailCall(unsigned int) const;
72 virtual bool checkEntry() const;
73 virtual Address getCFT() const;
74 virtual bool isStackFramePreamble(int& frameSize) const;
75 virtual bool savesFP() const;
76 virtual bool cleansStack() const;
77 virtual bool isConditional() const;
78 virtual bool isBranch() const;
79 virtual bool isInterruptOrSyscall() const;
80 virtual bool isSyscall() const;
81 virtual bool isInterrupt() const;
83 virtual bool isRealCall() const;
84 virtual bool isThunk() const;
85 bool parseJumpTable(image_basicBlock* currBlk,
86 pdvector<std::pair< Address, EdgeTypeEnum > >& outEdges) const;
87 bool isIPRelativeBranch() const;
88 bool isMovAPSTable(pdvector<std::pair< Address, EdgeTypeEnum > >& outEdges) const;
89 std::pair<Address, Address> findThunkAndOffset(image_basicBlock* start) const;
90 bool isTableInsn(Dyninst::InstructionAPI::Instruction::Ptr i) const;
91 std::map<Address, Dyninst::InstructionAPI::Instruction::Ptr>::const_iterator findTableInsn() const;
92 boost::tuple<Dyninst::InstructionAPI::Instruction::Ptr,
93 Dyninst::InstructionAPI::Instruction::Ptr,
94 bool> findMaxSwitchInsn(image_basicBlock *start) const;
95 Address findThunkInBlock(image_basicBlock* curBlock, Address& thunkOffset) const;
96 bool computeTableBounds(Dyninst::InstructionAPI::Instruction::Ptr maxSwitchInsn,
97 Dyninst::InstructionAPI::Instruction::Ptr branchInsn,
98 Dyninst::InstructionAPI::Instruction::Ptr tableInsn,
99 bool foundJCCAlongTaken,
101 unsigned& tableStride) const;
102 bool fillTableEntries(Address thunkOffset,
105 unsigned tableStride,
106 pdvector<std::pair< Address, EdgeTypeEnum> >& outEdges) const;
107 Address getTableAddress(Dyninst::InstructionAPI::Instruction::Ptr tableInsn,
108 Address thunkOffset) const;
109 bool isFrameSetupInsn(Dyninst::InstructionAPI::Instruction::Ptr i) const;
110 virtual bool isReturn() const;
111 virtual bool isCall() const;
116 Dyninst::InstructionAPI::InstructionDecoder dec;
117 std::map<Address, Dyninst::InstructionAPI::Instruction::Ptr> allInsns;
118 Dyninst::InstructionAPI::Instruction::Ptr curInsn() const;
119 std::map<Address, Dyninst::InstructionAPI::Instruction::Ptr>::const_iterator curInsnIter;
120 mutable bool validCFT;
121 mutable Address cachedCFT;
122 mutable std::pair<bool, bool> hascftstatus;
123 mutable std::pair<bool, bool> tailCall;
124 static std::map<Architecture, Dyninst::InstructionAPI::RegisterAST::Ptr> framePtr;
125 static std::map<Architecture, Dyninst::InstructionAPI::RegisterAST::Ptr> stackPtr;
126 static std::map<Architecture, Dyninst::InstructionAPI::RegisterAST::Ptr> thePC;
127 static std::map<Address, bool> thunkAtTarget;
131 #endif // !defined(IA_IAPI_H)