Skip to content

Commit

Permalink
Old API restored
Browse files Browse the repository at this point in the history
  • Loading branch information
John Detter authored and ssunny7 committed Nov 16, 2016
1 parent 08cff7b commit 7b572c5
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 31 deletions.
1 change: 0 additions & 1 deletion common/src/arch-x86.C
Expand Up @@ -596,7 +596,6 @@ static int vex3_simdop_convert[3][4] = {
#define Mf { am_M, op_f }
#define Mfd { am_M, op_dbl }
#define M14 { am_M, op_14 }
#define Nss { am_N, op_ss }
#define Ob { am_O, op_b }
#define Ov { am_O, op_v }
#define Pd { am_P, op_d }
Expand Down
15 changes: 15 additions & 0 deletions instructionAPI/h/BinaryFunction.h
Expand Up @@ -343,6 +343,21 @@ namespace Dyninst
return m_arg1->isUsed(findMe) || m_arg2->isUsed(findMe)
|| (*m_arg1 == *findMe) || (*m_arg2 == *findMe) || (*findMe == *this);
}

virtual std::string format(formatStyle how) const
{
std::stringstream retVal;
if(how == memoryAccessStyle)
{
retVal << m_arg2->format() << "(" << m_arg1->format() << ")";
}
else
{
retVal << m_arg1->format() << " " << m_funcPtr->format() << " " << m_arg2->format();
}

return retVal.str();
}

virtual std::string format(ArchSpecificFormatter *formatter, formatStyle how) const
{
Expand Down
49 changes: 49 additions & 0 deletions instructionAPI/h/Dereference.h
Expand Up @@ -105,6 +105,55 @@ namespace Dyninst
return addressToDereference->isUsed(findMe) || *findMe == *this;
}

virtual std::string format(formatStyle) const
{
std::stringstream retVal;
#if defined(DEBUG_MEMORY_ACCESS_WIDTH)
switch(Expression::userSetValue.type)
{
case u8:
retVal << "u8 @ ";
break;
case s8:
retVal << "s8 @ ";
break;
case u16:
retVal << "u16 @ ";
break;
case s16:
retVal << "s16 @ ";
break;
case u32:
retVal << "u32 @ ";
break;
case s32:
retVal << "s32 @ ";
break;
case u64:
retVal << "u64 @ ";
break;
case s64:
retVal << "s64 @ ";
break;
case sp_float:
retVal << "float @ ";
break;
case dp_float:
retVal << "double @ ";
break;
case dbl128:
retVal << "packed double @ ";
break;
default:
retVal << "UNKNOWN SIZE @ ";
break;
}
#endif
retVal << "[" << addressToDereference->format() << "]";
// retVal << addressToDereference->format(memoryAccessStyle);
return retVal.str();
}

virtual std::string format(ArchSpecificFormatter *formatter, formatStyle) const
{
#if defined(DEBUG_MEMORY_ACCESS_WIDTH)
Expand Down
1 change: 1 addition & 0 deletions instructionAPI/h/Expression.h
Expand Up @@ -179,6 +179,7 @@ namespace Dyninst
virtual void getUses(set<InstructionAST::Ptr>& ) {};
virtual bool isUsed(InstructionAST::Ptr ) const { return true;};
virtual std::string format(ArchSpecificFormatter *, formatStyle) const { return "[WILDCARD]";};
virtual std::string format(formatStyle) const { return "[WILDCARD]";};
DummyExpr() : Expression(u8) {}
protected:
virtual bool checkRegID(MachRegister, unsigned int = 0, unsigned int = 0) const;
Expand Down
3 changes: 3 additions & 0 deletions instructionAPI/h/Immediate.h
Expand Up @@ -64,6 +64,7 @@ namespace Dyninst
virtual bool isUsed(InstructionAST::Ptr findMe) const;

virtual std::string format(ArchSpecificFormatter *, formatStyle) const;
virtual std::string format(formatStyle) const;
static Immediate::Ptr makeImmediate(const Result& val);
virtual void apply(Visitor* v);

Expand All @@ -78,6 +79,7 @@ namespace Dyninst

static ArmConditionImmediate::Ptr makeArmConditionImmediate(const Result &val);
virtual std::string format(ArchSpecificFormatter *, formatStyle) const;
virtual std::string format(formatStyle) const;

private:
std::map<unsigned int, std::string> m_condLookupMap;
Expand All @@ -90,6 +92,7 @@ namespace Dyninst

static Immediate::Ptr makeArmPrfmTypeImmediate(const Result &val);
virtual std::string format(ArchSpecificFormatter *, formatStyle) const;
virtual std::string format(formatStyle) const;

private:
std::map<unsigned int, std::string> m_prfmTypeLookupMap;
Expand Down
4 changes: 4 additions & 0 deletions instructionAPI/h/InstructionAST.h
Expand Up @@ -111,6 +111,10 @@ namespace Dyninst
/// The \c format interface returns the contents of an %InstructionAST
/// object as a string. By default, \c format() produces assembly language.
virtual std::string format(ArchSpecificFormatter *, formatStyle how = defaultStyle) const = 0;

/// The \c format interface returns the contents of an %InstructionAST
/// object as a string. By default, \c format() produces assembly language.
virtual std::string format(formatStyle how = defaultStyle) const = 0;

protected:
friend class RegisterAST;
Expand Down
35 changes: 5 additions & 30 deletions instructionAPI/h/Operand.h
Expand Up @@ -125,6 +125,11 @@ namespace Dyninst
/// \return The operand in a disassembly format
INSTRUCTION_EXPORT std::string format(ArchSpecificFormatter *formatter, Architecture arch, Address addr = 0) const;


/// \brief Return a printable string representation of the operand. Please use the updated function instead.
/// \return The operand in a dissassembly format.
INSTRUCTION_EXPORT std::string format(Architecture arch, Address addr = 0) const;

/// The \c getValue method returns an %Expression::Ptr to the AST contained by the operand.
INSTRUCTION_EXPORT Expression::Ptr getValue() const;

Expand All @@ -134,36 +139,6 @@ namespace Dyninst
bool m_isWritten;
bool m_isImplicit;
};

#if 0
static inline void print_tabs(int depth)
{
for(int x = 0;x < depth;x++)
std::cout << "\t";
}
#endif

struct att_operand_arglist
{
char* base;
char* scale;
char* segment;
char* offset;
char* displacement;
};

/**
* Create the AT&T syntax for the instruction operand AST (not call or jump).
*/
INSTRUCTION_EXPORT int binary_function_att_jump(const Expression* exp,
uint64_t* imm_val);

/**
* Convert the given instruction AST into the address of the target of
* the jump/call.
*/
INSTRUCTION_EXPORT int binary_function_att(const Expression* exp,
struct att_operand_arglist* options, int depth, ArchSpecificFormatter *formatter);
};
};

Expand Down
3 changes: 3 additions & 0 deletions instructionAPI/h/Register.h
Expand Up @@ -76,6 +76,8 @@ namespace Dyninst

/// The \c format method on a %RegisterAST object returns the name associated with its ID.
virtual std::string format(ArchSpecificFormatter *, formatStyle how = defaultStyle) const;
/// The \c format method on a %RegisterAST object returns the name associated with its ID.
virtual std::string format(formatStyle how = defaultStyle) const __attribute__ ((deprecated));

/// Utility function to get a Register object that represents the program counter.
///
Expand Down Expand Up @@ -128,6 +130,7 @@ namespace Dyninst
: RegisterAST(r, lowbit, highbit, regType) {}

virtual std::string format(ArchSpecificFormatter *formatter, formatStyle how = defaultStyle) const;
virtual std::string format(formatStyle how = defaultStyle) const;
};
};
};
Expand Down
21 changes: 21 additions & 0 deletions instructionAPI/src/Immediate.C
Expand Up @@ -71,6 +71,10 @@ namespace Dyninst {
return formatter->formatImmediate(eval().format());
}

std::string Immediate::format(formatStyle) const {
return eval().format();
}

bool Immediate::isStrictEqual(const InstructionAST &rhs) const {

return (rhs.eval() == eval());
Expand Down Expand Up @@ -98,6 +102,14 @@ namespace Dyninst {
return "Error: Invalid condition code for ARM64!";
}

std::string ArmConditionImmediate::format(formatStyle) const {
unsigned int cond_val = eval().convert<unsigned int>();
if(m_condLookupMap.count(cond_val) > 0)
return m_condLookupMap.find(cond_val)->second;
else
return "Error: Invalid condition code for ARM64!";
}

ArmPrfmTypeImmediate::ArmPrfmTypeImmediate(const Result &val) : Immediate(val) {
m_prfmTypeLookupMap = boost::assign::map_list_of(0, "PLDL1KEEP")(1, "PLDL1STRM")(2, "PLDL2KEEP")(3, "PLDL2STRM")(4, "PLDL3KEEP")(5, "PLDL3STRM")(8, "PLIL1KEEP")(9, "PLIL1STRM")(10, "PLIL2KEEP")(11, "PLIL2STRM")(12, "PLIL3KEEP")(13, "PLIL3STRM")(16, "PSTL1KEEP")(17, "PSTL1STRM")(18, "PSTL2KEEP")(19, "PSTL2STRM")(20, "PSTL3KEEP")(21, "PSTL3STRM").convert_to_container<std::map<unsigned int, std::string> >();
}
Expand All @@ -115,5 +127,14 @@ namespace Dyninst {
return "Error: Invalid prefetech memory type for ARM64!";
}

std::string ArmPrfmTypeImmediate::format(formatStyle) const {
unsigned prfm_type = eval().convert<unsigned int>();
if(m_prfmTypeLookupMap.count(prfm_type) > 0)
return m_prfmTypeLookupMap.find(prfm_type)->second;
else
return "Error: Invalid prefetech memory type for ARM64!";
}


};
};
16 changes: 16 additions & 0 deletions instructionAPI/src/Operand.C
Expand Up @@ -139,6 +139,22 @@ namespace Dyninst
return op_value->format(formatter);
}

INSTRUCTION_EXPORT std::string Operand::format(Architecture arch, Address addr) const
{
if(!op_value) return "ERROR: format() called on empty operand!";
if (addr) {
Expression::Ptr thePC = Expression::Ptr(new RegisterAST(MachRegister::getPC(arch)));
op_value->bind(thePC.get(), Result(u32, addr));
Result res = op_value->eval();
if (res.defined) {
stringstream ret;
ret << hex << res.convert<uintmax_t>() << dec;
return ret.str();
}
}
return op_value->format();
}

INSTRUCTION_EXPORT Expression::Ptr Operand::getValue() const
{
return op_value;
Expand Down
32 changes: 32 additions & 0 deletions instructionAPI/src/Register.C
Expand Up @@ -98,6 +98,38 @@ namespace Dyninst
return formatter->formatRegister(m_Reg.name());
}

std::string RegisterAST::format(formatStyle) const
{
std::string name = m_Reg.name();
std::string::size_type substr = name.rfind(':');
if(substr != std::string::npos)
{
name = name.substr(substr + 1, name.length());
}

/* we have moved to AT&T syntax (lowercase registers) */
std::transform(name.begin(), name.end(), name.begin(), ::toupper);
return name;
}

std::string MaskRegisterAST::format(formatStyle) const
{
std::string name = m_Reg.name();
std::string::size_type substr = name.rfind(':');
if(substr != std::string::npos)
{
name = name.substr(substr + 1, name.length());
}

/* The syntax for a masking register is {kX} in AT&T syntax. */
std::stringstream ss;
ss << "{" << name << "}";

return ss.str();
}



RegisterAST RegisterAST::makePC(Dyninst::Architecture arch)
{
return RegisterAST(MachRegister::getPC(arch), 0, MachRegister::getPC(arch).size());
Expand Down

0 comments on commit 7b572c5

Please sign in to comment.