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
33 #if !defined(SymEval_h)
46 class SgAsmx86Instruction;
47 class SgAsmExpression;
48 class SgAsmPowerpcInstruction;
49 class SgAsmOperandList;
50 class SgAsmx86RegisterReferenceExpression;
51 class SgAsmPowerpcRegisterReferenceExpression;
60 namespace DataflowAPI {
62 // The ROSE symbolic evaluation engine wants a data type that
63 // is template parametrized on the number of bits in the data
64 // type. However, our ASTs don't have this, and a shared_ptr
65 // to an AST _definitely_ doesn't have it. Instead, we use
66 // a wrapper class (Handle) that is parametrized appropriately
67 // and contains a shared pointer.
69 // This uses a pointer to a shared pointer. This is ordinarily a really
70 // bad idea, but stripping the pointer part makes the compiler allocate
71 // all available memory and crash. No idea why.
73 // Define the operations used by ROSE
76 DATAFLOW_EXPORT Variable() : reg(), addr(0) {};
77 DATAFLOW_EXPORT Variable(AbsRegion r) : reg(r), addr(0) {};
78 DATAFLOW_EXPORT Variable(AbsRegion r, Address a) : reg(r), addr(a) {};
80 DATAFLOW_EXPORT bool operator==(const Variable &rhs) const {
81 return ((rhs.addr == addr) && (rhs.reg == reg));
84 DATAFLOW_EXPORT bool operator<(const Variable &rhs) const {
85 if (addr < rhs.addr) return true;
86 if (reg < rhs.reg) return true;
90 DATAFLOW_EXPORT const std::string format() const {
91 std::stringstream ret;
93 if (addr) ret << ":" << std::hex << addr << std::dec;
103 DATAFLOW_EXPORT Constant() : val(0), size(0) {};
104 DATAFLOW_EXPORT Constant(uint64_t v) : val(v), size(0) {};
105 DATAFLOW_EXPORT Constant(uint64_t v, size_t s) : val(v), size(s) {};
107 DATAFLOW_EXPORT bool operator==(const Constant &rhs) const {
108 return ((rhs.val == val) && (rhs.size == size));
111 DATAFLOW_EXPORT bool operator<(const Constant &rhs) const {
112 if (val < rhs.val) return true;
113 if (size < rhs.size) return true;
117 DATAFLOW_EXPORT const std::string format() const {
118 std::stringstream ret;
130 // Define the operations used by ROSE
132 struct ROSEOperation {
167 DATAFLOW_EXPORT ROSEOperation(Op o) : op(o), size(0) {};
168 DATAFLOW_EXPORT ROSEOperation(Op o, size_t s) : op(o), size(s) {};
170 DATAFLOW_EXPORT bool operator==(const ROSEOperation &rhs) const {
171 return ((rhs.op == op) && (rhs.size == size));
174 DATAFLOW_EXPORT const std::string format() const {
175 std::stringstream ret;
290 // Get this out of the Dyninst namespace...
291 DATAFLOW_EXPORT std::ostream &operator<<(std::ostream &os, const Dyninst::DataflowAPI::ROSEOperation &o);
292 DATAFLOW_EXPORT std::ostream &operator<<(std::ostream &os, const Dyninst::DataflowAPI::Constant &o);
293 DATAFLOW_EXPORT std::ostream &operator<<(std::ostream &os, const Dyninst::DataflowAPI::Variable &o);
297 namespace InstructionAPI {
303 namespace DataflowAPI {
305 typedef std::map<Assignment::Ptr, AST::Ptr> Result_t;
307 DEF_AST_LEAF_TYPE(BottomAST, bool);
308 DEF_AST_LEAF_TYPE(ConstantAST, Constant);
309 DEF_AST_LEAF_TYPE(VariableAST, Variable);
310 DEF_AST_INTERNAL_TYPE(RoseAST, ROSEOperation);
316 typedef boost::shared_ptr<SliceNode> SliceNodePtr;
317 typedef boost::shared_ptr<InstructionAPI::Instruction> InstructionPtr;
326 // Return type: mapping AbsRegions to ASTs
327 // We then can map Assignment::AbsRegions to
328 // SymEval::AbsRegions and come up with the answer
329 // static const AST::Ptr Placeholder;
331 // Single version: hand in an Assignment, get an AST
332 DATAFLOW_EXPORT static std::pair<AST::Ptr, bool> expand(const Assignment::Ptr &assignment);
334 // Hand in a set of Assignments
335 // get back a map of Assignments->ASTs
336 // We assume the assignments are prepped in the input; whatever
337 // they point to is discarded.
338 DATAFLOW_EXPORT static bool expand(Result_t &res,
339 std::set<InstructionPtr> &failedInsns,
340 bool applyVisitors = true);
342 // Hand in a Graph (of SliceNodes, natch) and get back a Result;
343 // prior results from the Graph
344 // are substituted into anything that uses them.
345 DATAFLOW_EXPORT static Retval_t expand(Dyninst::Graph::Ptr slice, DataflowAPI::Result_t &res);
349 // Symbolically evaluate an instruction and assign
350 // an AST representation to every written absloc
351 static bool expandInsn(const InstructionPtr insn,
355 static Retval_t process(SliceNodePtr ptr, Result_t &dbase, std::set<Edge::Ptr> &skipEdges);
357 static AST::Ptr simplifyStack(AST::Ptr ast, Address addr, ParseAPI::Function *func, ParseAPI::Block *block);