dwarfResult.h

Go to the documentation of this file.
00001 #include "dyn_regs.h"
00002 #include "dyntypes.h"
00003 #include <vector>
00004 #include <stack>
00005 #include "libdwarf.h"
00006 
00007 namespace Dyninst {
00008 
00009 struct VariableLocation;
00010 class ProcessReader;
00011 
00012 namespace Dwarf {
00013 
00014 class DwarfResult {
00015    // An interface for building representations of Dwarf expressions.
00016    // In concrete mode, we have access to process state and
00017    // can calculate a value. In symbolic mode we lack this information
00018    // and instead produce a representation. 
00019 
00020   public:
00021    
00022    typedef enum {
00023       Add,
00024       Sub,
00025       Mul,
00026       Div,
00027       Mod,
00028       Deref,
00029       Pick,
00030       Drop,
00031       And,
00032       Or,
00033       Not,
00034       Xor,
00035       Abs,
00036       GE,
00037       LE,
00038       GT,
00039       LT,
00040       Eq,
00041       Neq,
00042       Shl,
00043       Shr,
00044       ShrArith
00045    } Operator;
00046 
00047   DwarfResult(Architecture a) : arch(a), error(false) {}
00048    virtual ~DwarfResult() {};
00049    
00050    virtual void pushReg(Dyninst::MachRegister reg) = 0;
00051    virtual void readReg(Dyninst::MachRegister reg) = 0;
00052    virtual void pushUnsignedVal(Dyninst::MachRegisterVal constant) = 0;
00053    virtual void pushSignedVal(Dyninst::MachRegisterVal constant) = 0;
00054    virtual void pushOp(Operator op) = 0;
00055    virtual void pushOp(Operator op, unsigned ref) = 0;
00056 
00057    // The frame base is the logical top of the stack as reported
00058    // in the function's debug info
00059    virtual void pushFrameBase() = 0;
00060    
00061    // And the CFA is the top of the stack as reported in call frame
00062    // information. 
00063    virtual void pushCFA() = 0;
00064 
00065    bool err() const { return error; }
00066 
00067    // The conditional branch needs an immediate eval mechanism
00068    virtual bool eval(MachRegisterVal &val) = 0;
00069 
00070   protected:
00071 
00072    // Illegal
00073    Architecture arch;
00074    bool error;
00075 
00076 };
00077 
00078 class SymbolicDwarfResult : public DwarfResult {
00079 
00080   public:
00081   SymbolicDwarfResult(VariableLocation &v, Architecture a) :
00082    DwarfResult(a), var(v) {};
00083    virtual ~SymbolicDwarfResult() {};
00084    
00085    virtual void pushReg(Dyninst::MachRegister reg);
00086    virtual void readReg(Dyninst::MachRegister reg);
00087    virtual void pushUnsignedVal(Dyninst::MachRegisterVal constant);
00088    virtual void pushSignedVal(Dyninst::MachRegisterVal constant);
00089    virtual void pushOp(Operator op);
00090    virtual void pushOp(Operator op, unsigned ref);
00091 
00092    // DWARF logical "frame base", which may be the result of an expression
00093    // in itself. TODO: figure out what info we need to carry around so we
00094    // can compute it...
00095    virtual void pushFrameBase();
00096    virtual void pushCFA();
00097 
00098    VariableLocation &val();
00099 
00100    virtual bool eval(MachRegisterVal &) { return false; }
00101 
00102   private:
00103    std::stack<MachRegisterVal> operands;
00104 
00105    VariableLocation &var;
00106 };
00107 
00108 class ConcreteDwarfResult : public DwarfResult {
00109 
00110   public:
00111   ConcreteDwarfResult(ProcessReader *r, Architecture a, 
00112                      Address p, Dwarf_Debug d) :
00113    DwarfResult(a), reader(r), 
00114       pc(p), dbg(d) {};
00115    virtual ~ConcreteDwarfResult() {};
00116 
00117    virtual void pushReg(Dyninst::MachRegister reg);
00118    virtual void readReg(Dyninst::MachRegister reg);
00119    virtual void pushUnsignedVal(Dyninst::MachRegisterVal constant);
00120    virtual void pushSignedVal(Dyninst::MachRegisterVal constant);
00121    virtual void pushOp(Operator op);
00122    virtual void pushOp(Operator op, unsigned ref);
00123 
00124    // DWARF logical "frame base", which may be the result of an expression
00125    // in itself. TODO: figure out what info we need to carry around so we
00126    // can compute it...
00127    virtual void pushFrameBase();
00128    virtual void pushCFA();
00129 
00130    MachRegisterVal val();
00131 
00132    bool eval(MachRegisterVal &v);
00133 
00134   private:
00135    ProcessReader *reader;
00136 
00137    // For getting access to other expressions
00138    Address pc;
00139    Dwarf_Debug dbg;
00140      
00141    // Dwarf lets you access within the "stack", so we model 
00142    // it as a vector.
00143    std::vector<Dyninst::MachRegisterVal> operands;
00144 
00145    MachRegisterVal peek(int index);
00146    void pop(int num);
00147    void popRange(int start, int end);
00148    void push(MachRegisterVal v);
00149 
00150 };
00151 
00152 }
00153 
00154 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1