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

The sos "ClrStack" command now works #437

Merged
merged 11 commits into from
Mar 14, 2015
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: 4 additions & 0 deletions src/ToolBox/SOS/Strike/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ else(WIN32)
add_compile_options(-fPIC)

set(SOS_SOURCES
disasm.cpp
datatarget.cpp
eeheap.cpp
exts.cpp
gcroot.cpp
metadata.cpp
strike.cpp
sos.cpp
util.cpp
)

Expand Down
13 changes: 10 additions & 3 deletions src/ToolBox/SOS/Strike/datatarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ HRESULT STDMETHODCALLTYPE
DataTarget::GetCurrentThreadID(
/* [out] */ ULONG32* threadID)
{
*threadID = 0;
return E_NOTIMPL;
if (g_ExtSystem == NULL)
{
return E_UNEXPECTED;
}
return g_ExtSystem->GetCurrentThreadSystemId(threadID);
}

HRESULT STDMETHODCALLTYPE
Expand All @@ -155,7 +158,11 @@ DataTarget::GetThreadContext(
/* [in] */ ULONG32 contextSize,
/* [out, size_is(contextSize)] */ PBYTE context)
{
return E_NOTIMPL;
if (g_ExtClient == NULL)
{
return E_UNEXPECTED;
}
return g_ExtClient->GetThreadContextById(threadID, contextFlags, contextSize, context);
}

HRESULT STDMETHODCALLTYPE
Expand Down
45 changes: 45 additions & 0 deletions src/ToolBox/SOS/Strike/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace X86GCDump
#endif // SOS_TARGET_X86

#ifdef SOS_TARGET_AMD64
#ifndef FEATURE_PAL
#include "gcdump.h"
#define DAC_ARG(x)
#define SUPPORTS_DAC
Expand All @@ -56,6 +57,7 @@ namespace X86GCDump
#endif
#define LOG(x) ((void)0)
#include "gcdumpnonx86.cpp"
#endif // FEATURE_PAL
#endif // SOS_TARGET_AMD64

#include "disasm.h"
Expand All @@ -64,6 +66,8 @@ namespace X86GCDump
#define ERANGE 34
#endif

#ifndef FEATURE_PAL

PVOID
GenOpenMapping(
PCSTR FilePath,
Expand Down Expand Up @@ -1024,6 +1028,8 @@ void DumpStackWorker (DumpStackFlag &DSFlag)
}
}

#endif // !FEATURE_PAL


#ifdef SOS_TARGET_X86
///
Expand Down Expand Up @@ -1093,6 +1099,9 @@ LPCSTR AMD64Machine::s_SPName = "RSP";
///
void AMD64Machine::DumpGCInfo(BYTE* pTable, unsigned methodSize, printfFtn gcPrintf, bool encBytes, bool bPrintHeader) const
{
#ifdef FEATURE_PAL
ExtErr("AMD64Machine::DumpGCInfo not implemented\n");
#else
if (bPrintHeader)
{
ExtOut("Pointer table:\n");
Expand All @@ -1102,7 +1111,43 @@ void AMD64Machine::DumpGCInfo(BYTE* pTable, unsigned methodSize, printfFtn gcPri
gcDump.gcPrintf = gcPrintf;

gcDump.DumpGCTable(pTable, methodSize, 0);
#endif // FEATURE_PAL
}

#ifdef FEATURE_PAL
void AMD64Machine::Unassembly(
TADDR IPBegin,
TADDR IPEnd,
TADDR IPAskedFor,
TADDR GCStressCodeCopy,
GCEncodingInfo *pGCEncodingInfo,
SOSEHInfo *pEHInfo,
BOOL bSuppressLines,
BOOL bDisplayOffsets) const
{
ExtErr("AMD64Machine::Unassembly not implemented\n");
}

void AMD64Machine::IsReturnAddress(
TADDR retAddr,
TADDR* whereCalled) const
{
ExtErr("AMD64Machine::IsReturnAddress not implemented\n");
}

BOOL AMD64Machine::GetExceptionContext(
TADDR stack,
TADDR PC,
TADDR *cxrAddr,
CROSS_PLATFORM_CONTEXT * cxr,
TADDR *exrAddr,
PEXCEPTION_RECORD exr) const
{
ExtErr("AMD64Machine::GetExceptionContext not implemented\n");
return FALSE;
}
#endif // FEATURE_PAL

#endif // SOS_TARGET_AMD64

#ifdef SOS_TARGET_ARM64
Expand Down
1 change: 0 additions & 1 deletion src/ToolBox/SOS/Strike/disasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ class AMD64Machine : public IMachine
CROSS_PLATFORM_CONTEXT * cxr,
TADDR *exrAddr,
PEXCEPTION_RECORD exr) const;

// retrieve stack pointer, frame pointer, and instruction pointer from the target context
virtual TADDR GetSP(const CROSS_PLATFORM_CONTEXT & ctx) const { return ctx.Amd64Context.Rsp; }
virtual TADDR GetBP(const CROSS_PLATFORM_CONTEXT & ctx) const { return ctx.Amd64Context.Rbp; }
Expand Down
14 changes: 13 additions & 1 deletion src/ToolBox/SOS/Strike/eeheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "sos.h"
#include "safemath.h"

#ifndef FEATURE_PAL

// This is the increment for the segment lookup data
const int nSegLookupStgIncrement = 100;

Expand Down Expand Up @@ -337,6 +339,8 @@ void HeapStat::Delete()
fLinear = FALSE;
}

#endif // !FEATURE_PAL

// -----------------------------------------------------------------------
//
// MethodTableCache implementation
Expand Down Expand Up @@ -421,6 +425,8 @@ void MethodTableCache::Clear()
ReverseLeftMost (root);
}

MethodTableCache g_special_mtCache;

size_t Align (size_t nbytes)
{
return (nbytes + ALIGNCONST) & ~ALIGNCONST;
Expand All @@ -431,6 +437,8 @@ size_t AlignLarge(size_t nbytes)
return (nbytes + ALIGNCONSTLARGE) & ~ALIGNCONSTLARGE;
}

#ifndef FEATURE_PAL

/**********************************************************************\
* Routine Description: *
* *
Expand Down Expand Up @@ -846,7 +854,7 @@ BOOL GCHeapUsageStats(const DacpGcHeapDetails& heap, BOOL bIncUnreachable, HeapU
return TRUE;
}

MethodTableCache g_special_mtCache;
#endif // FEATURE_PAL

DWORD GetNumComponents(TADDR obj)
{
Expand Down Expand Up @@ -910,6 +918,8 @@ BOOL GetSizeEfficient(DWORD_PTR dwAddrCurrObj,
return TRUE;
}

#ifndef FEATURE_PAL

// This function expects stat to be valid, and ready to get statistics.
void GatherOneHeapFinalization(DacpGcHeapDetails& heapDetails, HeapStat *stat, BOOL bAllReady, BOOL bShort)
{
Expand Down Expand Up @@ -1909,3 +1919,5 @@ DWORD_PTR PrintModuleHeapInfo(__out_ecount(count) DWORD_PTR *moduleList, int cou

return toReturn;
}

#endif // !FEATURE_PAL
16 changes: 9 additions & 7 deletions src/ToolBox/SOS/Strike/exts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//
// ==--==
#include "exts.h"
#ifndef FEATURE_PAL
#include "disasm.h"
#ifndef FEATURE_PAL
#include "EventCallbacks.h"

#define VER_PRODUCTVERSION_W (0x0100)
Expand Down Expand Up @@ -84,6 +84,8 @@ ExtQuery(PDEBUG_CLIENT Client)
return Status;
}

#endif // FEATURE_PAL

extern "C" HRESULT
ArchQuery(void)
{
Expand Down Expand Up @@ -128,6 +130,8 @@ ArchQuery(void)
return S_OK;
}

#ifndef FEATURE_PAL

// Cleans up all debugger interfaces.
void
ExtRelease(void)
Expand Down Expand Up @@ -356,11 +360,13 @@ BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
#else // FEATURE_PAL

BOOL g_bDacBroken = FALSE;
IMachine* g_targetMachine = NULL;

PDEBUG_CLIENT g_ExtClient;
PDEBUG_DATA_SPACES g_ExtData;
PDEBUG_CONTROL2 g_ExtControl;
PDEBUG_SYMBOLS g_ExtSymbols;
PDEBUG_SYSTEM_OBJECTS g_ExtSystem;

extern "C" HRESULT
ExtQuery(PDEBUG_CLIENT Client)
Expand All @@ -369,12 +375,7 @@ ExtQuery(PDEBUG_CLIENT Client)
g_ExtControl = (PDEBUG_CONTROL2)Client;
g_ExtData = (PDEBUG_DATA_SPACES)Client;
g_ExtSymbols = (PDEBUG_SYMBOLS)Client;
return S_OK;
}

extern "C" HRESULT
ArchQuery(void)
{
g_ExtSystem = (PDEBUG_SYSTEM_OBJECTS)Client;
return S_OK;
}

Expand All @@ -385,6 +386,7 @@ ExtRelease(void)
g_ExtControl = NULL;
g_ExtData = NULL;
g_ExtSymbols = NULL;
g_ExtSystem = NULL;
}

#endif // FEATURE_PAL
2 changes: 1 addition & 1 deletion src/ToolBox/SOS/Strike/exts.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ extern PDEBUG_CLIENT g_ExtClient;
extern PDEBUG_CONTROL2 g_ExtControl;
extern PDEBUG_DATA_SPACES g_ExtData;
extern PDEBUG_SYMBOLS g_ExtSymbols;
extern PDEBUG_SYSTEM_OBJECTS g_ExtSystem;

#ifndef FEATURE_PAL

// Global variables initialized by query.
extern PDEBUG_DATA_SPACES2 g_ExtData2;
extern PDEBUG_REGISTERS g_ExtRegisters;
extern PDEBUG_SYMBOLS2 g_ExtSymbols2;
extern PDEBUG_SYSTEM_OBJECTS g_ExtSystem;
extern PDEBUG_ADVANCED3 g_ExtAdvanced3;

#endif // !FEATURE_PAL
Expand Down
21 changes: 11 additions & 10 deletions src/ToolBox/SOS/Strike/gcroot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void GCRootImpl::ReportSizeInfo(const SOSHandleData &handle, TADDR obj)
TADDR mt = ReadPointer(obj);
MTInfo *mtInfo = GetMTInfo(mt);

const wchar_t *type = mtInfo ? mtInfo->GetTypeName() : L"unknown type";
const wchar_t *type = mtInfo ? mtInfo->GetTypeName() : W("unknown type");

size_t size = mSizes[obj];
ExtOut("Handle (%s): %p -> %p: %d (0x%x) bytes (%S)\n", NameForHandle(handle.Type), SOS_PTR(handle.Handle),
Expand All @@ -410,7 +410,7 @@ void GCRootImpl::ReportSizeInfo(DWORD thread, const SOSStackRefData &stackRef, T

TADDR mt = ReadPointer(obj);
MTInfo *mtInfo = GetMTInfo(mt);
const wchar_t *type = mtInfo ? mtInfo->GetTypeName() : L"unknown type";
const wchar_t *type = mtInfo ? mtInfo->GetTypeName() : W("unknown type");

size_t size = mSizes[obj];
ExtOut("Thread %x (%S): %S: %d (0x%x) bytes (%S)\n", thread, frame.c_str(), regOutput.c_str(), size, size, type);
Expand Down Expand Up @@ -1299,7 +1299,6 @@ void PrintNotReachableInRange(TADDR rngStart, TADDR rngEnd, BOOL bExcludeReadyFo
}


#endif // !FEATURE_PAL

////////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -1919,11 +1918,11 @@ void HeapTraverser::PrintType(size_t ID,LPCWSTR name)
#ifndef FEATURE_PAL
// Sanitize name based on XML spec.
std::wstring wname = name;
replace(wname, L"&", L"&");
replace(wname, L"\"", L""");
replace(wname, L"'", L"'");
replace(wname, L"<", L"&lt;");
replace(wname, L">", L"&gt;");
replace(wname, W("&"), W("&amp;"));
replace(wname, W("\""), W("&quot;"));
replace(wname, W("'"), W("&apos;"));
replace(wname, W("<"), W("&lt;"));
replace(wname, W(">"), W("&gt;"));
name = wname.c_str();
#endif
fprintf(m_file,
Expand Down Expand Up @@ -2087,7 +2086,7 @@ void HeapTraverser::FindGCRootOnStacks()

for (unsigned int i = 0; i < refCount; ++i)
if (refs[i].Object)
PrintRoot(L"stack", TO_TADDR(refs[i].Object));
PrintRoot(W("stack"), TO_TADDR(refs[i].Object));
}
}

Expand Down Expand Up @@ -2142,7 +2141,7 @@ void HeapTraverser::TraceHandles()
break;

for (unsigned int i = 0; i < fetched; ++i)
PrintRoot(L"handle", (size_t)data[i].Handle);
PrintRoot(W("handle"), (size_t)data[i].Handle);
} while (fetched == _countof(data));
}

Expand Down Expand Up @@ -2501,3 +2500,5 @@ bool sos::ObjectIterator::Verify() const
char *c = NULL;
return Verify(c, 0);
}

#endif // !FEATURE_PAL
Loading