Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

[x86/Linux][SOS] Fix clrstack command of lldb sosplugin on x86 #13973

Merged
merged 5 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ToolBox/SOS/Strike/strike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ DECLARE_API(IP2MD)
#define DEBUG_STACK_CONTEXT AMD64_CONTEXT
#elif defined(_TARGET_ARM_) // _TARGET_WIN64_
#define DEBUG_STACK_CONTEXT ARM_CONTEXT
#endif // _TARGET_ARM_
#elif defined(_TARGET_X86_) // _TARGET_ARM_
#define DEBUG_STACK_CONTEXT X86_CONTEXT
#endif // _TARGET_X86_

#ifdef DEBUG_STACK_CONTEXT
// I use a global set of frames for stack walking on win64 because the debugger's
Expand Down
19 changes: 19 additions & 0 deletions src/ToolBox/SOS/lldbplugin/services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,25 @@ LLDBServices::GetContextFromFrame(
dtcontext->R10 = GetRegister(frame, "r10");
dtcontext->R11 = GetRegister(frame, "r11");
dtcontext->R12 = GetRegister(frame, "r12");
#elif DBG_TARGET_X86
dtcontext->Eip = frame.GetPC();
dtcontext->Esp = frame.GetSP();
dtcontext->Ebp = frame.GetFP();
dtcontext->EFlags = GetRegister(frame, "eflags");

dtcontext->Edi = GetRegister(frame, "edi");
dtcontext->Esi = GetRegister(frame, "esi");
dtcontext->Ebx = GetRegister(frame, "ebx");
dtcontext->Edx = GetRegister(frame, "edx");
dtcontext->Ecx = GetRegister(frame, "ecx");
dtcontext->Eax = GetRegister(frame, "eax");

dtcontext->SegCs = GetRegister(frame, "cs");
dtcontext->SegSs = GetRegister(frame, "ss");
dtcontext->SegDs = GetRegister(frame, "ds");
dtcontext->SegEs = GetRegister(frame, "es");
dtcontext->SegFs = GetRegister(frame, "fs");
dtcontext->SegGs = GetRegister(frame, "gs");
#endif
}

Expand Down
30 changes: 29 additions & 1 deletion src/debug/di/rsthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,15 @@ void CordbThread::Get32bitFPRegisters(CONTEXT * pContext)

FLOATING_SAVE_AREA currentFPUState;

#ifdef _MSC_VER
__asm fnsave currentFPUState // save the current FPU state.
#else
__asm__ __volatile__
(
" fnsave %0\n" \
: "=m"(currentFPUState)
);
#endif

floatarea.StatusWord &= 0xFF00; // remove any error codes.
floatarea.ControlWord |= 0x3F; // mask all exceptions.
Expand All @@ -1482,12 +1490,22 @@ void CordbThread::Get32bitFPRegisters(CONTEXT * pContext)
// @dbgtodo Microsoft crossplat: the conversion from a series of bytes to a floating
// point value will need to be done with an explicit conversion routine to unpack
// the IEEE format and compute the real number value represented.


#ifdef _MSC_VER
__asm
{
fninit
frstor floatarea ;; reload the threads FPU state.
}
#else
__asm__
(
" fninit\n" \
" frstor %0\n" \
: /* no outputs */
: "m"(floatarea)
);
#endif

unsigned int i;

Expand All @@ -1498,11 +1516,21 @@ void CordbThread::Get32bitFPRegisters(CONTEXT * pContext)
m_floatValues[i] = td;
}

#ifdef _MSC_VER
__asm
{
fninit
frstor currentFPUState ;; restore our saved FPU state.
}
#else
__asm__
(
" fninit\n" \
" frstor %0\n" \
: /* no outputs */
: "m"(currentFPUState)
);
#endif

m_fFloatStateValid = true;
m_floatStackTop = floatStackTop;
Expand Down
36 changes: 36 additions & 0 deletions src/debug/di/valuehome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,18 +481,36 @@ void FloatRegValueHome::SetEnregisteredValue(MemoryRange newValue,
// restore our original state.
DT_FLOATING_SAVE_AREA currentFPUState;

#ifdef _MSC_VER
__asm fnsave currentFPUState // save the current FPU state.
#else
__asm__ __volatile__
(
" fnsave %0\n" \
: "=m"(currentFPUState)
);
#endif

// Copy the state out of the context.
DT_FLOATING_SAVE_AREA floatarea = pContext->FloatSave;
floatarea.StatusWord &= 0xFF00; // remove any error codes.
floatarea.ControlWord |= 0x3F; // mask all exceptions.

#ifdef _MSC_VER
__asm
{
fninit
frstor floatarea ;; reload the threads FPU state.
}
#else
__asm__
(
" fninit\n" \
" frstor %0\n" \
: /* no outputs */
: "m"(floatarea)
);
#endif

double td; // temp double
double popArea[DebuggerIPCE_FloatCount];
Expand All @@ -519,17 +537,35 @@ void FloatRegValueHome::SetEnregisteredValue(MemoryRange newValue,
}

// Save out the modified float area.
#ifdef _MSC_VER
__asm fnsave floatarea
#else
__asm__ __volatile__
(
" fnsave %0\n" \
: "=m"(floatarea)
);
#endif

// Put it into the context.
pContext->FloatSave= floatarea;

// Restore our FPU state
#ifdef _MSC_VER
__asm
{
fninit
frstor currentFPUState ;; restore our saved FPU state.
}
#else
__asm__
(
" fninit\n" \
" frstor %0\n" \
: /* no outputs */
: "m"(currentFPUState)
);
#endif
#endif // DBG_TARGET_X86

// update the thread's floating point stack
Expand Down
4 changes: 2 additions & 2 deletions src/debug/shim/debugshim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
// CLRDebuggingImpl implementation (ICLRDebugging)
//*****************************************************************************

typedef HRESULT (__stdcall *OpenVirtualProcessImplFnPtr)(ULONG64 clrInstanceId,
typedef HRESULT (STDAPICALLTYPE *OpenVirtualProcessImplFnPtr)(ULONG64 clrInstanceId,
IUnknown * pDataTarget,
HMODULE hDacDll,
CLR_DEBUGGING_VERSION * pMaxDebuggerSupportedVersion,
REFIID riid,
IUnknown ** ppInstance,
CLR_DEBUGGING_PROCESS_FLAGS * pdwFlags);

typedef HRESULT (__stdcall *OpenVirtualProcess2FnPtr)(ULONG64 clrInstanceId,
typedef HRESULT (STDAPICALLTYPE *OpenVirtualProcess2FnPtr)(ULONG64 clrInstanceId,
IUnknown * pDataTarget,
HMODULE hDacDll,
REFIID riid,
Expand Down
2 changes: 1 addition & 1 deletion src/dlls/mscordbi/mscordbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//*****************************************************************************
#include "stdafx.h"

extern BOOL STDMETHODCALLTYPE DbgDllMain(HINSTANCE hInstance, DWORD dwReason,
extern BOOL WINAPI DbgDllMain(HINSTANCE hInstance, DWORD dwReason,
LPVOID lpReserved);

//*****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/inc/clrnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ RtlpGetFunctionEndAddress (
__in TADDR ImageBase
)
{
PUNWIND_INFO pUnwindInfo = (PUNWIND_INFO)(ImageBase + FunctionEntry->UnwindData);
PTR_UNWIND_INFO pUnwindInfo = (PTR_UNWIND_INFO)(ImageBase + FunctionEntry->UnwindData);

return FunctionEntry->BeginAddress + pUnwindInfo->FunctionLength;
}
Expand Down