mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[0.1.x] fixed workitem-10850: thread context over IDebugRegisters
git-svn-id: https://pykd.svn.codeplex.com/svn@77597 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
8ee1e65535
commit
4c7944a3f1
152
pykd/context.cpp
152
pykd/context.cpp
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace pykd {
|
namespace pykd {
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Fill 32-bit register context
|
// Fill 32-bit register context
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -50,77 +51,61 @@ void FillRegistersFromContext32(
|
|||||||
regValues[CV_REG_EFLAGS] = Context.EFlags;
|
regValues[CV_REG_EFLAGS] = Context.EFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
namespace I386 {
|
struct CvRegName
|
||||||
#include "defctxi386.h"
|
{
|
||||||
}
|
CvRegName(CV_HREG_e cvValue, const std::string &name)
|
||||||
|
: m_cvValue( cvValue ), m_name( boost::to_lower_copy(name) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
CV_HREG_e m_cvValue;
|
||||||
|
std::string m_name;
|
||||||
|
};
|
||||||
|
#define _REG_NAME(prefix, regName) CvRegName(CV_##prefix##regName, #regName)
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define _REG_X86(regName) _REG_NAME(REG_, regName)
|
||||||
|
static const CvRegName g_x86Registers[] = {
|
||||||
|
_REG_X86(DR0), _REG_X86(DR1), _REG_X86(DR2), _REG_X86(DR3), _REG_X86(DR6), _REG_X86(DR7),
|
||||||
|
_REG_X86(GS), _REG_X86(FS), _REG_X86(ES), _REG_X86(DS),
|
||||||
|
_REG_X86(EDI), _REG_X86(EBX), _REG_X86(EDX), _REG_X86(ECX), _REG_X86(EAX),
|
||||||
|
_REG_X86(EBP), _REG_X86(ESP), _REG_X86(SS),
|
||||||
|
_REG_X86(EIP), _REG_X86(CS),
|
||||||
|
CvRegName(CV_REG_EFLAGS, "efl")
|
||||||
|
};
|
||||||
|
#undef _REG_X86
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define _REG_X64(regName) _REG_NAME(AMD64_, regName)
|
||||||
|
static const CvRegName g_x64Registers[] = {
|
||||||
|
_REG_X64(MXCSR),
|
||||||
|
_REG_X64(CS), _REG_X64(DS), _REG_X64(ES), _REG_X64(FS), _REG_X64(GS), _REG_X64(SS),
|
||||||
|
|
||||||
|
_REG_X64(DR0), _REG_X64(DR1), _REG_X64(DR2), _REG_X64(DR3), _REG_X64(DR6), _REG_X64(DR7),
|
||||||
|
|
||||||
|
_REG_X64(RAX), _REG_X64(RCX), _REG_X64(RDX), _REG_X64(RBX), _REG_X64(RSP), _REG_X64(RBP), _REG_X64(RSI), _REG_X64(RDI),
|
||||||
|
_REG_X64(R8), _REG_X64(R9), _REG_X64(R10), _REG_X64(R11), _REG_X64(R12), _REG_X64(R13), _REG_X64(R14), _REG_X64(R15),
|
||||||
|
|
||||||
|
_REG_X64(RIP),
|
||||||
|
CvRegName(CV_AMD64_EFLAGS, "efl")
|
||||||
|
};
|
||||||
|
#undef _REG_X64
|
||||||
|
|
||||||
|
#undef _REG_NAME
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void ThreadContext::getI386Context()
|
void ThreadContext::getI386Context()
|
||||||
{
|
{
|
||||||
I386::CONTEXT Context = {0};
|
queryRegisters(g_x86Registers, _countof(g_x86Registers));
|
||||||
|
|
||||||
HRESULT hres = m_advanced->GetThreadContext(&Context, sizeof(Context));
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DbgException( "IDebugAdvanced2::GetThreadContext", hres );
|
|
||||||
|
|
||||||
FillRegistersFromContext32(m_regValues, Context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
namespace AMD64 {
|
|
||||||
#include "defctxamd64.h"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void ThreadContext::getAmd64Context()
|
void ThreadContext::getAmd64Context()
|
||||||
{
|
{
|
||||||
AMD64::CONTEXT Context = {0};
|
queryRegisters(g_x64Registers, _countof(g_x64Registers));
|
||||||
|
|
||||||
HRESULT hres = m_advanced->GetThreadContext(&Context, sizeof(Context));
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DbgException( "IDebugAdvanced2::GetThreadContext", hres);
|
|
||||||
|
|
||||||
m_regValues[CV_AMD64_MXCSR] = Context.MxCsr;
|
|
||||||
|
|
||||||
m_regValues[CV_AMD64_CS] = Context.SegCs;
|
|
||||||
m_regValues[CV_AMD64_DS] = Context.SegDs;
|
|
||||||
m_regValues[CV_AMD64_ES] = Context.SegEs;
|
|
||||||
m_regValues[CV_AMD64_FS] = Context.SegFs;
|
|
||||||
m_regValues[CV_AMD64_GS] = Context.SegGs;
|
|
||||||
m_regValues[CV_AMD64_SS] = Context.SegSs;
|
|
||||||
|
|
||||||
m_regValues[CV_AMD64_EFLAGS] = Context.EFlags;
|
|
||||||
|
|
||||||
m_regValues[CV_AMD64_DR0] = Context.Dr0;
|
|
||||||
m_regValues[CV_AMD64_DR1] = Context.Dr1;
|
|
||||||
m_regValues[CV_AMD64_DR2] = Context.Dr2;
|
|
||||||
m_regValues[CV_AMD64_DR3] = Context.Dr3;
|
|
||||||
m_regValues[CV_AMD64_DR6] = Context.Dr6;
|
|
||||||
m_regValues[CV_AMD64_DR7] = Context.Dr7;
|
|
||||||
|
|
||||||
m_regValues[CV_AMD64_RAX] = Context.Rax;
|
|
||||||
m_regValues[CV_AMD64_RCX] = Context.Rcx;
|
|
||||||
m_regValues[CV_AMD64_RDX] = Context.Rdx;
|
|
||||||
m_regValues[CV_AMD64_RBX] = Context.Rbx;
|
|
||||||
m_regValues[CV_AMD64_RSP] = Context.Rsp;
|
|
||||||
m_regValues[CV_AMD64_RBP] = Context.Rbp;
|
|
||||||
m_regValues[CV_AMD64_RSI] = Context.Rdi;
|
|
||||||
m_regValues[CV_AMD64_RDI] = Context.Rdi;
|
|
||||||
m_regValues[CV_AMD64_R8] = Context.R8;
|
|
||||||
m_regValues[CV_AMD64_R9] = Context.R9;
|
|
||||||
m_regValues[CV_AMD64_R10] = Context.R10;
|
|
||||||
m_regValues[CV_AMD64_R11] = Context.R11;
|
|
||||||
m_regValues[CV_AMD64_R12] = Context.R12;
|
|
||||||
m_regValues[CV_AMD64_R13] = Context.R13;
|
|
||||||
m_regValues[CV_AMD64_R14] = Context.R14;
|
|
||||||
m_regValues[CV_AMD64_R15] = Context.R15;
|
|
||||||
|
|
||||||
m_regValues[CV_AMD64_RIP] = Context.Rip;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -158,6 +143,55 @@ ThreadContext::ThreadContext(
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void ThreadContext::queryRegisters(
|
||||||
|
const CvRegName *regs,
|
||||||
|
ULONG countOfRegs
|
||||||
|
)
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
std::vector<ULONG> regIndices( countOfRegs );
|
||||||
|
|
||||||
|
for (ULONG i = 0; i < countOfRegs; ++i)
|
||||||
|
{
|
||||||
|
hres = m_registers->GetIndexByName(regs[i].m_name.c_str(), ®Indices[i]);
|
||||||
|
if (S_OK != hres)
|
||||||
|
throw DbgException( "IDebugRegisters::GetIndexByName", hres);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<DEBUG_VALUE> regValues( countOfRegs );
|
||||||
|
hres =
|
||||||
|
m_registers->GetValues(
|
||||||
|
static_cast<ULONG>(countOfRegs),
|
||||||
|
®Indices[0],
|
||||||
|
0,
|
||||||
|
®Values[0]);
|
||||||
|
if (S_OK != hres)
|
||||||
|
throw DbgException( "IDebugRegisters::GetValues", hres);
|
||||||
|
|
||||||
|
for (ULONG i = 0; i < countOfRegs; ++i)
|
||||||
|
{
|
||||||
|
const DEBUG_VALUE ®Value = regValues[i];
|
||||||
|
switch (regValue.Type)
|
||||||
|
{
|
||||||
|
case DEBUG_VALUE_INT8:
|
||||||
|
m_regValues[regs[i].m_cvValue] = regValue.I8;
|
||||||
|
break;
|
||||||
|
case DEBUG_VALUE_INT16:
|
||||||
|
m_regValues[regs[i].m_cvValue] = regValue.I16;
|
||||||
|
break;
|
||||||
|
case DEBUG_VALUE_INT32:
|
||||||
|
m_regValues[regs[i].m_cvValue] = regValue.I32;
|
||||||
|
break;
|
||||||
|
case DEBUG_VALUE_INT64:
|
||||||
|
m_regValues[regs[i].m_cvValue] = regValue.I64;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ContextPtr ThreadContext::getWow64Context( IDebugClient4 *client )
|
ContextPtr ThreadContext::getWow64Context( IDebugClient4 *client )
|
||||||
{
|
{
|
||||||
ContextPtr ptrContext( new ThreadContext(client, IMAGE_FILE_MACHINE_I386) );
|
ContextPtr ptrContext( new ThreadContext(client, IMAGE_FILE_MACHINE_I386) );
|
||||||
|
@ -16,6 +16,7 @@ class ThreadContext;
|
|||||||
typedef boost::shared_ptr< ThreadContext > ContextPtr;
|
typedef boost::shared_ptr< ThreadContext > ContextPtr;
|
||||||
|
|
||||||
class StackFrame;
|
class StackFrame;
|
||||||
|
struct CvRegName;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -67,6 +68,11 @@ protected:
|
|||||||
ULONG processorType
|
ULONG processorType
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void queryRegisters(
|
||||||
|
const CvRegName *regs,
|
||||||
|
ULONG countOfRegs
|
||||||
|
);
|
||||||
|
|
||||||
// query i386 registers
|
// query i386 registers
|
||||||
void getI386Context();
|
void getI386Context();
|
||||||
|
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
|
|
||||||
struct DECLSPEC_ALIGN(16) M128A {
|
|
||||||
ULONGLONG Low;
|
|
||||||
LONGLONG High;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct XMM_SAVE_AREA32 {
|
|
||||||
USHORT ControlWord;
|
|
||||||
USHORT StatusWord;
|
|
||||||
UCHAR TagWord;
|
|
||||||
UCHAR Reserved1;
|
|
||||||
USHORT ErrorOpcode;
|
|
||||||
ULONG ErrorOffset;
|
|
||||||
USHORT ErrorSelector;
|
|
||||||
USHORT Reserved2;
|
|
||||||
ULONG DataOffset;
|
|
||||||
USHORT DataSelector;
|
|
||||||
USHORT Reserved3;
|
|
||||||
ULONG MxCsr;
|
|
||||||
ULONG MxCsr_Mask;
|
|
||||||
M128A FloatRegisters[8];
|
|
||||||
M128A XmmRegisters[16];
|
|
||||||
UCHAR Reserved4[96];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DECLSPEC_ALIGN(16) CONTEXT {
|
|
||||||
ULONG64 P1Home;
|
|
||||||
ULONG64 P2Home;
|
|
||||||
ULONG64 P3Home;
|
|
||||||
ULONG64 P4Home;
|
|
||||||
ULONG64 P5Home;
|
|
||||||
ULONG64 P6Home;
|
|
||||||
ULONG ContextFlags;
|
|
||||||
ULONG MxCsr;
|
|
||||||
USHORT SegCs;
|
|
||||||
USHORT SegDs;
|
|
||||||
USHORT SegEs;
|
|
||||||
USHORT SegFs;
|
|
||||||
USHORT SegGs;
|
|
||||||
USHORT SegSs;
|
|
||||||
ULONG EFlags;
|
|
||||||
ULONG64 Dr0;
|
|
||||||
ULONG64 Dr1;
|
|
||||||
ULONG64 Dr2;
|
|
||||||
ULONG64 Dr3;
|
|
||||||
ULONG64 Dr6;
|
|
||||||
ULONG64 Dr7;
|
|
||||||
ULONG64 Rax;
|
|
||||||
ULONG64 Rcx;
|
|
||||||
ULONG64 Rdx;
|
|
||||||
ULONG64 Rbx;
|
|
||||||
ULONG64 Rsp;
|
|
||||||
ULONG64 Rbp;
|
|
||||||
ULONG64 Rsi;
|
|
||||||
ULONG64 Rdi;
|
|
||||||
ULONG64 R8;
|
|
||||||
ULONG64 R9;
|
|
||||||
ULONG64 R10;
|
|
||||||
ULONG64 R11;
|
|
||||||
ULONG64 R12;
|
|
||||||
ULONG64 R13;
|
|
||||||
ULONG64 R14;
|
|
||||||
ULONG64 R15;
|
|
||||||
ULONG64 Rip;
|
|
||||||
union {
|
|
||||||
XMM_SAVE_AREA32 FltSave;
|
|
||||||
struct {
|
|
||||||
M128A Header[2];
|
|
||||||
M128A Legacy[8];
|
|
||||||
M128A Xmm0;
|
|
||||||
M128A Xmm1;
|
|
||||||
M128A Xmm2;
|
|
||||||
M128A Xmm3;
|
|
||||||
M128A Xmm4;
|
|
||||||
M128A Xmm5;
|
|
||||||
M128A Xmm6;
|
|
||||||
M128A Xmm7;
|
|
||||||
M128A Xmm8;
|
|
||||||
M128A Xmm9;
|
|
||||||
M128A Xmm10;
|
|
||||||
M128A Xmm11;
|
|
||||||
M128A Xmm12;
|
|
||||||
M128A Xmm13;
|
|
||||||
M128A Xmm14;
|
|
||||||
M128A Xmm15;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
M128A VectorRegister[26];
|
|
||||||
ULONG64 VectorControl;
|
|
||||||
ULONG64 DebugControl;
|
|
||||||
ULONG64 LastBranchToRip;
|
|
||||||
ULONG64 LastBranchFromRip;
|
|
||||||
ULONG64 LastExceptionToRip;
|
|
||||||
ULONG64 LastExceptionFromRip;
|
|
||||||
};
|
|
@ -1,54 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#define MAXIMUM_SUPPORTED_EXTENSION 512
|
|
||||||
|
|
||||||
#define SIZE_OF_80387_REGISTERS 80
|
|
||||||
|
|
||||||
struct FLOATING_SAVE_AREA {
|
|
||||||
ULONG ControlWord;
|
|
||||||
ULONG StatusWord;
|
|
||||||
ULONG TagWord;
|
|
||||||
ULONG ErrorOffset;
|
|
||||||
ULONG ErrorSelector;
|
|
||||||
ULONG DataOffset;
|
|
||||||
ULONG DataSelector;
|
|
||||||
UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
|
|
||||||
ULONG Cr0NpxState;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CONTEXT {
|
|
||||||
|
|
||||||
ULONG ContextFlags;
|
|
||||||
|
|
||||||
ULONG Dr0;
|
|
||||||
ULONG Dr1;
|
|
||||||
ULONG Dr2;
|
|
||||||
ULONG Dr3;
|
|
||||||
ULONG Dr6;
|
|
||||||
ULONG Dr7;
|
|
||||||
|
|
||||||
|
|
||||||
FLOATING_SAVE_AREA FloatSave;
|
|
||||||
|
|
||||||
|
|
||||||
ULONG SegGs;
|
|
||||||
ULONG SegFs;
|
|
||||||
ULONG SegEs;
|
|
||||||
ULONG SegDs;
|
|
||||||
|
|
||||||
ULONG Edi;
|
|
||||||
ULONG Esi;
|
|
||||||
ULONG Ebx;
|
|
||||||
ULONG Edx;
|
|
||||||
ULONG Ecx;
|
|
||||||
ULONG Eax;
|
|
||||||
|
|
||||||
ULONG Ebp;
|
|
||||||
ULONG Eip;
|
|
||||||
ULONG SegCs;
|
|
||||||
ULONG EFlags;
|
|
||||||
ULONG Esp;
|
|
||||||
ULONG SegSs;
|
|
||||||
|
|
||||||
UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
|
|
||||||
};
|
|
@ -547,14 +547,6 @@
|
|||||||
RelativePath=".\dbgpath.h"
|
RelativePath=".\dbgpath.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\defctxamd64.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\defctxi386.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\diacallback.h"
|
RelativePath=".\diacallback.h"
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user