|
From: <sv...@va...> - 2012-09-21 09:12:38
|
tom 2012-09-21 10:12:30 +0100 (Fri, 21 Sep 2012)
New Revision: 13010
Log:
Implement some extra DW_OPs - more constants and some unary operators.
Patch from Mark Wielaard on BZ#307038.
Modified files:
trunk/coregrind/m_debuginfo/debuginfo.c
trunk/coregrind/m_debuginfo/priv_storage.h
trunk/coregrind/m_debuginfo/readdwarf.c
trunk/coregrind/m_debuginfo/storage.c
Modified: trunk/coregrind/m_debuginfo/storage.c (+25 -0)
===================================================================
--- trunk/coregrind/m_debuginfo/storage.c 2012-09-21 10:04:27 +01:00 (rev 13009)
+++ trunk/coregrind/m_debuginfo/storage.c 2012-09-21 10:12:30 +01:00 (rev 13010)
@@ -585,6 +585,15 @@
e.Cex.Const.con = con;
return (Int)VG_(addToXA)( dst, &e );
}
+Int ML_(CfiExpr_Unop)( XArray* dst, CfiUnop op, Int ix )
+{
+ CfiExpr e;
+ VG_(memset)( &e, 0, sizeof(e) );
+ e.tag = Cex_Unop;
+ e.Cex.Unop.op = op;
+ e.Cex.Unop.ix = ix;
+ return (Int)VG_(addToXA)( dst, &e );
+}
Int ML_(CfiExpr_Binop)( XArray* dst, CfiBinop op, Int ixL, Int ixR )
{
CfiExpr e;
@@ -612,6 +621,16 @@
return (Int)VG_(addToXA)( dst, &e );
}
+static void ppCfiUnop ( CfiUnop op )
+{
+ switch (op) {
+ case Cunop_Abs: VG_(printf)("abs"); break;
+ case Cunop_Neg: VG_(printf)("-"); break;
+ case Cunop_Not: VG_(printf)("~"); break;
+ default: vg_assert(0);
+ }
+}
+
static void ppCfiBinop ( CfiBinop op )
{
switch (op) {
@@ -664,6 +683,12 @@
case Cex_Const:
VG_(printf)("0x%lx", e->Cex.Const.con);
break;
+ case Cex_Unop:
+ ppCfiUnop(e->Cex.Unop.op);
+ VG_(printf)("(");
+ ML_(ppCfiExpr)(src, e->Cex.Unop.ix);
+ VG_(printf)(")");
+ break;
case Cex_Binop:
VG_(printf)("(");
ML_(ppCfiExpr)(src, e->Cex.Binop.ixL);
Modified: trunk/coregrind/m_debuginfo/readdwarf.c (+51 -1)
===================================================================
--- trunk/coregrind/m_debuginfo/readdwarf.c 2012-09-21 10:04:27 +01:00 (rev 13009)
+++ trunk/coregrind/m_debuginfo/readdwarf.c 2012-09-21 10:12:30 +01:00 (rev 13010)
@@ -2732,6 +2732,7 @@
UChar opcode;
Word sw;
UWord uw;
+ CfiUnop uop;
CfiBinop bop;
HChar* opname;
@@ -2778,7 +2779,7 @@
break;
}
- bop = 0; opname = NULL; /* excessively conservative */
+ uop = 0; bop = 0; opname = NULL; /* excessively conservative */
opcode = *expr++;
switch (opcode) {
@@ -2836,6 +2837,15 @@
VG_(printf)("DW_OP_const4s: %ld", sw);
break;
+ case DW_OP_const2s:
+ /* push: 16-bit signed immediate */
+ sw = read_le_s_encoded_literal( expr, 2 );
+ expr += 2;
+ PUSH( ML_(CfiExpr_Const)( dst, (UWord)sw ) );
+ if (ddump_frames)
+ VG_(printf)("DW_OP_const2s: %ld", sw);
+ break;
+
case DW_OP_const1s:
/* push: 8-bit signed immediate */
sw = read_le_s_encoded_literal( expr, 1 );
@@ -2845,6 +2855,46 @@
VG_(printf)("DW_OP_const1s: %ld", sw);
break;
+ case DW_OP_const1u:
+ /* push: 8-bit unsigned immediate */
+ uw = read_le_u_encoded_literal( expr, 1 );
+ expr += 1;
+ PUSH( ML_(CfiExpr_Const)( dst, uw ) );
+ if (ddump_frames)
+ VG_(printf)("DW_OP_const1: %lu", uw);
+ break;
+
+ case DW_OP_const2u:
+ /* push: 16-bit unsigned immediate */
+ uw = read_le_u_encoded_literal( expr, 2 );
+ expr += 2;
+ PUSH( ML_(CfiExpr_Const)( dst, uw ) );
+ if (ddump_frames)
+ VG_(printf)("DW_OP_const2: %lu", uw);
+ break;
+
+ case DW_OP_const4u:
+ /* push: 32-bit unsigned immediate */
+ uw = read_le_u_encoded_literal( expr, 4 );
+ expr += 4;
+ PUSH( ML_(CfiExpr_Const)( dst, uw ) );
+ if (ddump_frames)
+ VG_(printf)("DW_OP_const4: %lu", uw);
+ break;
+
+ case DW_OP_abs:
+ uop = Cunop_Abs; opname = "abs"; goto unop;
+ case DW_OP_neg:
+ uop = Cunop_Neg; opname = "neg"; goto unop;
+ case DW_OP_not:
+ uop = Cunop_Not; opname = "not"; goto unop;
+ unop:
+ POP( ix );
+ PUSH( ML_(CfiExpr_Unop)( dst, uop, ix ) );
+ if (ddump_frames)
+ VG_(printf)("DW_OP_%s", opname);
+ break;
+
case DW_OP_minus:
bop = Cbinop_Sub; opname = "minus"; goto binop;
case DW_OP_plus:
Modified: trunk/coregrind/m_debuginfo/priv_storage.h (+14 -0)
===================================================================
--- trunk/coregrind/m_debuginfo/priv_storage.h 2012-09-21 10:04:27 +01:00 (rev 13009)
+++ trunk/coregrind/m_debuginfo/priv_storage.h 2012-09-21 10:12:30 +01:00 (rev 13010)
@@ -279,6 +279,14 @@
typedef
enum {
+ Cunop_Abs=0x231,
+ Cunop_Neg,
+ Cunop_Not
+ }
+ CfiUnop;
+
+typedef
+ enum {
Cbinop_Add=0x321,
Cbinop_Sub,
Cbinop_And,
@@ -313,6 +321,7 @@
Cex_Undef=0x123,
Cex_Deref,
Cex_Const,
+ Cex_Unop,
Cex_Binop,
Cex_CfiReg,
Cex_DwReg
@@ -332,6 +341,10 @@
UWord con;
} Const;
struct {
+ CfiUnop op;
+ Int ix;
+ } Unop;
+ struct {
CfiBinop op;
Int ixL;
Int ixR;
@@ -350,6 +363,7 @@
extern Int ML_(CfiExpr_Undef) ( XArray* dst );
extern Int ML_(CfiExpr_Deref) ( XArray* dst, Int ixAddr );
extern Int ML_(CfiExpr_Const) ( XArray* dst, UWord con );
+extern Int ML_(CfiExpr_Unop) ( XArray* dst, CfiUnop op, Int ix );
extern Int ML_(CfiExpr_Binop) ( XArray* dst, CfiBinop op, Int ixL, Int ixR );
extern Int ML_(CfiExpr_CfiReg)( XArray* dst, CfiReg reg );
extern Int ML_(CfiExpr_DwReg) ( XArray* dst, Int reg );
Modified: trunk/coregrind/m_debuginfo/debuginfo.c (+11 -1)
===================================================================
--- trunk/coregrind/m_debuginfo/debuginfo.c 2012-09-21 10:04:27 +01:00 (rev 13009)
+++ trunk/coregrind/m_debuginfo/debuginfo.c 2012-09-21 10:12:30 +01:00 (rev 13010)
@@ -2051,12 +2051,22 @@
UWord evalCfiExpr ( XArray* exprs, Int ix,
CfiExprEvalContext* eec, Bool* ok )
{
- UWord wL, wR;
+ UWord w, wL, wR;
Addr a;
CfiExpr* e;
vg_assert(sizeof(Addr) == sizeof(UWord));
e = VG_(indexXA)( exprs, ix );
switch (e->tag) {
+ case Cex_Unop:
+ w = evalCfiExpr( exprs, e->Cex.Unop.ix, eec, ok );
+ if (!(*ok)) return 0;
+ switch (e->Cex.Unop.op) {
+ case Cunop_Abs: return (Word) w < 0 ? - w : w;
+ case Cunop_Neg: return - (Word) w;
+ case Cunop_Not: return ~ w;
+ default: goto unhandled;
+ }
+ /*NOTREACHED*/
case Cex_Binop:
wL = evalCfiExpr( exprs, e->Cex.Binop.ixL, eec, ok );
if (!(*ok)) return 0;
|