Fix #2315 - Individual register printing is broken

This commit is contained in:
pancake 2015-04-05 18:48:36 -04:00
parent 679a1d2531
commit b55b573cef
2 changed files with 106 additions and 90 deletions

View File

@ -866,7 +866,8 @@ free (rf);
}
break;
case 'm': // "drm"
r_debug_reg_sync (core->dbg, R_REG_TYPE_FPU, R_FALSE);
/* Note, that negative type forces sync to print the regs from the backend */
r_debug_reg_sync (core->dbg, -R_REG_TYPE_FPU, R_FALSE);
//r_debug_drx_list (core->dbg);
break;
case 'p': // "drp"

View File

@ -898,10 +898,15 @@ static RList *r_debug_native_threads(RDebug *dbg, int pid) {
// TODO: what about float and hardware regs here ???
// TODO: add flag for type
static int r_debug_native_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
int showfpu = R_FALSE;
int pid = dbg->pid;
int tid = dbg->tid;
if (size<1)
return R_FALSE;
if (type<0) {
showfpu = R_TRUE; // hack for debugging
type = -type;
}
#if __WINDOWS__ && !__CYGWIN__
CONTEXT ctx __attribute__ ((aligned (16)));
ctx.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
@ -911,9 +916,10 @@ static int r_debug_native_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
}
if (type==R_REG_TYPE_FPU || type==R_REG_TYPE_MMX || type==R_REG_TYPE_XMM) {
#if __MINGW64__
eprintf("working on this ....");
eprintf ("TODO: r_debug_native_reg_read fpu/mmx/xmm\n");
#else
int i;
if (showfpu) {
eprintf ("cwd = 0x%08x ; control ", (ut32)ctx.FloatSave.ControlWord);
eprintf ("swd = 0x%08x ; status\n", (ut32)ctx.FloatSave.StatusWord);
eprintf ("twd = 0x%08x ", (ut32)ctx.FloatSave.TagWord);
@ -930,6 +936,7 @@ static int r_debug_native_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
ut64 *b = (ut64 *)&ctx.FloatSave.RegisterArea[i*10];
eprintf ("st%d = %lg (0x%08llx)\n", i, (double)*((double*)&ctx.FloatSave.RegisterArea[i*10]), *b);
}
}
#endif
}
if (sizeof (CONTEXT) < size)
@ -1078,6 +1085,7 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
#if __x86_64__
#if !__ANDROID__
ret1 = ptrace (PTRACE_GETFPREGS, pid, NULL, &fpregs);
if (showfpu) {
eprintf ("---- x86-64 ----\n ");
eprintf ("cwd = 0x%04x ; control ", fpregs.cwd);
eprintf ("swd = 0x%04x ; status\n", fpregs.swd);
@ -1108,9 +1116,8 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
,(float) f[1]
,c[1]
);
} else eprintf ("\n");
}
else
eprintf("\n");
}
if (ret1 != 0) {
return R_FALSE;
@ -1122,6 +1129,7 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
return sizeof (fpregs);
#else
ret1 = ptrace (PTRACE_GETFPREGS, pid, NULL, &fpregs);
if (showfpu) {
eprintf ("cwd = 0x%04x ; control ", fpregs.cwd);
eprintf ("swd = 0x%04x ; status\n", fpregs.swd);
eprintf ("ftw = 0x%04x ", fpregs.ftw);
@ -1146,6 +1154,7 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
,c[1]
);
}
}
if (ret1 != 0)
return R_FALSE;
if (sizeof (fpregs) < size)
@ -1158,6 +1167,7 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
struct user_fpxregs_struct fpxregs;
ret1 = ptrace (PTRACE_GETFPXREGS, pid, NULL, &fpxregs);
if (ret1==0) {
if (showfpu) {
eprintf ("---- x86-32 ----\n ");
eprintf ("cwd = 0x%04x ; control ", fpxregs.cwd);
eprintf ("swd = 0x%04x ; status\n", fpxregs.swd);
@ -1188,12 +1198,14 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
,c[1]
);
}
}
if (sizeof (fpxregs) < size)
size = sizeof (fpxregs);
memcpy (buf, &fpxregs, size);
return sizeof (fpxregs);
} else {
ret1 = ptrace (PTRACE_GETFPREGS, pid, NULL, &fpregs);
if (showfpu) {
eprintf ("---- x86-32-noxmm ----\n ");
eprintf ("cwd = 0x%04lx ; control ", fpregs.cwd);
eprintf ("swd = 0x%04lx ; status\n", fpregs.swd);
@ -1218,6 +1230,7 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
,c[1]
);
}
}
if (ret1 != 0)
return R_FALSE;
if (sizeof (fpregs) < size)
@ -1227,6 +1240,7 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
}
#else
ret1 = ptrace (PTRACE_GETFPREGS, pid, NULL, &fpregs);
if (showfpu) {
eprintf ("---- x86-32-noxmm ----\n ");
eprintf ("cwd = 0x%04lx ; control ", fpregs.cwd);
eprintf ("swd = 0x%04lx ; status\n", fpregs.swd);
@ -1246,6 +1260,7 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
eprintf ("st%d =%0.3lg (0x%016"PFMT64x") | %0.3f (0x%08x) | %0.3f (0x%08x)\n"
,i ,d[0] ,b[0] ,f[0] ,c[0] ,f[1] ,c[1]);
}
}
if (ret1 != 0)
return R_FALSE;
if (sizeof (fpregs) < size)