2 * Copyright (c) 1996-2007 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
34 #if !defined(SymEval_h)
39 #include "Instruction.h"
40 #include "BinaryFunction.h"
41 #include "Dereference.h"
42 #include "Immediate.h"
48 #include "external/rose/rose-compat.h"
52 class SgAsmx86Instruction;
53 class SgAsmExpression;
56 namespace SymbolicEvaluation {
58 // The ROSE symbolic evaluation engine wants a data type that
59 // is template parametrized on the number of bits in the data
60 // type. However, our ASTs don't have this, and a shared_ptr
61 // to an AST _definitely_ doesn't have it. Instead, we use
62 // a wrapper class (Handle) that is parametrized appropriately
63 // and contains a shared pointer.
65 // This uses a pointer to a shared pointer. This is ordinarily a really
66 // bad idea, but stripping the pointer part makes the compiler allocate
67 // all available memory and crash. No idea why.
69 // Define the operations used by ROSE
71 struct ROSEOperation {
106 ROSEOperation(Op o) : op(o) {};
108 bool operator==(const ROSEOperation &rhs) const {
109 return (rhs.op == op);
112 const std::string format() const {
123 return "<signExtend>";
188 // Get this out of the Dyninst namespace...
189 std::ostream &operator<<(std::ostream &os, const Dyninst::SymbolicEvaluation::ROSEOperation &o);
193 namespace SymbolicEvaluation {
195 DEF_AST_LEAF_TYPE(BottomAST, bool);
196 DEF_AST_LEAF_TYPE(ConstantAST, uint64_t);
197 DEF_AST_LEAF_TYPE(AbsRegionAST, AbsRegion);
198 DEF_AST_INTERNAL_TYPE(RoseAST, ROSEOperation);
202 // Return type: mapping AbsRegions to ASTs
203 // We then can map Assignment::AbsRegions to
204 // SymEval::AbsRegions and come up with the answer
206 typedef std::map<Assignment::Ptr, AST::Ptr> Result;
207 static const AST::Ptr Placeholder;
209 // Single version: hand in an Assignment, get an AST
210 static AST::Ptr expand(const Assignment::Ptr &assignment);
212 // Hand in a set of Assignments
213 // get back a map of Assignments->ASTs
214 // We assume the assignments are prepped in the input; whatever
215 // they point to is discarded.
216 static void expand(Result &res);
218 // Hand in a Graph (of AssignNodes, natch) and get back a Result;
219 // prior results from the Graph
220 // are substituted into anything that uses them.
221 static void expand(Graph::Ptr slice, Result &res);
224 static void process(AssignNode::Ptr, SymEval::Result &res);
226 static SgAsmx86Instruction convert(const InstructionAPI::Instruction::Ptr &insn, uint64_t addr);
227 static X86InstructionKind convert(entryID opcode);
228 static SgAsmExpression *convert(const InstructionAPI::Operand &operand);
229 static SgAsmExpression *convert(const InstructionAPI::Expression::Ptr expression);
231 // Symbolically evaluate an instruction and assign
232 // an AST representation to every written absloc
233 static void expandInsn(const InstructionAPI::Instruction::Ptr insn,
237 friend class ExpressionConversionVisitor;
240 class ExpressionConversionVisitor : public InstructionAPI::Visitor {
242 ExpressionConversionVisitor() { roseExpression = NULL; }
244 SgAsmExpression *getRoseExpression() { return roseExpression; }
246 virtual void visit(InstructionAPI::BinaryFunction *binfunc);
247 virtual void visit(InstructionAPI::Immediate *immed);
248 virtual void visit(InstructionAPI::RegisterAST *regast);
249 virtual void visit(InstructionAPI::Dereference *deref);
252 SgAsmExpression *roseExpression;