Skip to content
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
80 changes: 40 additions & 40 deletions src/SOS/Strike/strike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4513,9 +4513,9 @@ HRESULT PrintThreadsFromThreadStore(BOOL bMiniDump, BOOL bPrintLiveThreadsOnly)
if (SafeReadMemory(taLTOH, &taMT, sizeof(taMT), NULL))
{
if (NameForMT_s(taMT, g_mdName, mdNameLen))
lastCol += WString(g_mdName) + W(" ") + ExceptionPtr(taLTOH);
lastCol += WString(g_mdName) + W(" ") + WString(ExceptionPtr(taLTOH));
else
lastCol += WString(W("<Invalid Object> (")) + Pointer(taLTOH) + W(")");
lastCol += WString(W("<Invalid Object> (")) + WString(Pointer(taLTOH)) + W(")");

// Print something if there are nested exceptions on the thread
if (Thread.firstNestedException)
Expand Down Expand Up @@ -11051,12 +11051,12 @@ class ClrStackImpl
foundPlatform = true;
String outputFormat3 = " %3s=%016llx %3s=%016llx %3s=%016llx\n";
String outputFormat2 = " %3s=%016llx %3s=%016llx\n";
ExtOut(outputFormat3, "rsp", context.Amd64Context.Rsp, "rbp", context.Amd64Context.Rbp, "rip", context.Amd64Context.Rip);
ExtOut(outputFormat3, "rax", context.Amd64Context.Rax, "rbx", context.Amd64Context.Rbx, "rcx", context.Amd64Context.Rcx);
ExtOut(outputFormat3, "rdx", context.Amd64Context.Rdx, "rsi", context.Amd64Context.Rsi, "rdi", context.Amd64Context.Rdi);
ExtOut(outputFormat3, "r8", context.Amd64Context.R8, "r9", context.Amd64Context.R9, "r10", context.Amd64Context.R10);
ExtOut(outputFormat3, "r11", context.Amd64Context.R11, "r12", context.Amd64Context.R12, "r13", context.Amd64Context.R13);
ExtOut(outputFormat2, "r14", context.Amd64Context.R14, "r15", context.Amd64Context.R15);
ExtOut(outputFormat3.c_str(), "rsp", context.Amd64Context.Rsp, "rbp", context.Amd64Context.Rbp, "rip", context.Amd64Context.Rip);
ExtOut(outputFormat3.c_str(), "rax", context.Amd64Context.Rax, "rbx", context.Amd64Context.Rbx, "rcx", context.Amd64Context.Rcx);
ExtOut(outputFormat3.c_str(), "rdx", context.Amd64Context.Rdx, "rsi", context.Amd64Context.Rsi, "rdi", context.Amd64Context.Rdi);
ExtOut(outputFormat3.c_str(), "r8", context.Amd64Context.R8, "r9", context.Amd64Context.R9, "r10", context.Amd64Context.R10);
ExtOut(outputFormat3.c_str(), "r11", context.Amd64Context.R11, "r12", context.Amd64Context.R12, "r13", context.Amd64Context.R13);
ExtOut(outputFormat2.c_str(), "r14", context.Amd64Context.R14, "r15", context.Amd64Context.R15);
}
#endif
#if defined(SOS_TARGET_X86)
Expand All @@ -11065,9 +11065,9 @@ class ClrStackImpl
foundPlatform = true;
String outputFormat3 = " %3s=%08x %3s=%08x %3s=%08x\n";
String outputFormat2 = " %3s=%08x %3s=%08x\n";
ExtOut(outputFormat3, "esp", context.X86Context.Esp, "ebp", context.X86Context.Ebp, "eip", context.X86Context.Eip);
ExtOut(outputFormat3, "eax", context.X86Context.Eax, "ebx", context.X86Context.Ebx, "ecx", context.X86Context.Ecx);
ExtOut(outputFormat3, "edx", context.X86Context.Edx, "esi", context.X86Context.Esi, "edi", context.X86Context.Edi);
ExtOut(outputFormat3.c_str(), "esp", context.X86Context.Esp, "ebp", context.X86Context.Ebp, "eip", context.X86Context.Eip);
ExtOut(outputFormat3.c_str(), "eax", context.X86Context.Eax, "ebx", context.X86Context.Ebx, "ecx", context.X86Context.Ecx);
ExtOut(outputFormat3.c_str(), "edx", context.X86Context.Edx, "esi", context.X86Context.Esi, "edi", context.X86Context.Edi);
}
#endif
#if defined(SOS_TARGET_ARM)
Expand All @@ -11077,13 +11077,13 @@ class ClrStackImpl
String outputFormat3 = " %3s=%08x %3s=%08x %3s=%08x\n";
String outputFormat2 = " %s=%08x %s=%08x\n";
String outputFormat1 = " %s=%08x\n";
ExtOut(outputFormat3, "r0", context.ArmContext.R0, "r1", context.ArmContext.R1, "r2", context.ArmContext.R2);
ExtOut(outputFormat3, "r3", context.ArmContext.R3, "r4", context.ArmContext.R4, "r5", context.ArmContext.R5);
ExtOut(outputFormat3, "r6", context.ArmContext.R6, "r7", context.ArmContext.R7, "r8", context.ArmContext.R8);
ExtOut(outputFormat3, "r9", context.ArmContext.R9, "r10", context.ArmContext.R10, "r11", context.ArmContext.R11);
ExtOut(outputFormat1, "r12", context.ArmContext.R12);
ExtOut(outputFormat3, "sp", context.ArmContext.Sp, "lr", context.ArmContext.Lr, "pc", context.ArmContext.Pc);
ExtOut(outputFormat2, "cpsr", context.ArmContext.Cpsr, "fpscr", context.ArmContext.Fpscr);
ExtOut(outputFormat3.c_str(), "r0", context.ArmContext.R0, "r1", context.ArmContext.R1, "r2", context.ArmContext.R2);
ExtOut(outputFormat3.c_str(), "r3", context.ArmContext.R3, "r4", context.ArmContext.R4, "r5", context.ArmContext.R5);
ExtOut(outputFormat3.c_str(), "r6", context.ArmContext.R6, "r7", context.ArmContext.R7, "r8", context.ArmContext.R8);
ExtOut(outputFormat3.c_str(), "r9", context.ArmContext.R9, "r10", context.ArmContext.R10, "r11", context.ArmContext.R11);
ExtOut(outputFormat1.c_str(), "r12", context.ArmContext.R12);
ExtOut(outputFormat3.c_str(), "sp", context.ArmContext.Sp, "lr", context.ArmContext.Lr, "pc", context.ArmContext.Pc);
ExtOut(outputFormat2.c_str(), "cpsr", context.ArmContext.Cpsr, "fpscr", context.ArmContext.Fpscr);
}
#endif
#if defined(SOS_TARGET_ARM64)
Expand All @@ -11109,35 +11109,35 @@ class ClrStackImpl
{
foundPlatform = true;
String outputFormat3 = " %3s=%016llx %3s=%016llx %3s=%016llx\n";
ExtOut(outputFormat3, "r0", context.RiscV64Context.R0, "ra", context.RiscV64Context.Ra, "sp", context.RiscV64Context.Sp);
ExtOut(outputFormat3, "gp", context.RiscV64Context.Gp, "tp", context.RiscV64Context.Tp, "t0", context.RiscV64Context.T0);
ExtOut(outputFormat3, "t1", context.RiscV64Context.T1, "t2", context.RiscV64Context.T2, "fp", context.RiscV64Context.Fp);
ExtOut(outputFormat3, "s1", context.RiscV64Context.S1, "a0", context.RiscV64Context.A0, "a1", context.RiscV64Context.A1);
ExtOut(outputFormat3, "a2", context.RiscV64Context.A2, "a3", context.RiscV64Context.A3, "a4", context.RiscV64Context.A4);
ExtOut(outputFormat3, "a5", context.RiscV64Context.A5, "a6", context.RiscV64Context.A6, "a7", context.RiscV64Context.A7);
ExtOut(outputFormat3, "s2", context.RiscV64Context.S2, "s3", context.RiscV64Context.S3, "s4", context.RiscV64Context.S4);
ExtOut(outputFormat3, "s5", context.RiscV64Context.S5, "s6", context.RiscV64Context.S6, "s7", context.RiscV64Context.S7);
ExtOut(outputFormat3, "s8", context.RiscV64Context.S8, "s9", context.RiscV64Context.S9, "s10", context.RiscV64Context.S10);
ExtOut(outputFormat3, "s11", context.RiscV64Context.S11, "t3", context.RiscV64Context.T3, "t4", context.RiscV64Context.T4);
ExtOut(outputFormat3, "t5", context.RiscV64Context.T5, "t6", context.RiscV64Context.T6, "pc", context.RiscV64Context.Pc);
ExtOut(outputFormat3.c_str(), "r0", context.RiscV64Context.R0, "ra", context.RiscV64Context.Ra, "sp", context.RiscV64Context.Sp);
ExtOut(outputFormat3.c_str(), "gp", context.RiscV64Context.Gp, "tp", context.RiscV64Context.Tp, "t0", context.RiscV64Context.T0);
ExtOut(outputFormat3.c_str(), "t1", context.RiscV64Context.T1, "t2", context.RiscV64Context.T2, "fp", context.RiscV64Context.Fp);
ExtOut(outputFormat3.c_str(), "s1", context.RiscV64Context.S1, "a0", context.RiscV64Context.A0, "a1", context.RiscV64Context.A1);
ExtOut(outputFormat3.c_str(), "a2", context.RiscV64Context.A2, "a3", context.RiscV64Context.A3, "a4", context.RiscV64Context.A4);
ExtOut(outputFormat3.c_str(), "a5", context.RiscV64Context.A5, "a6", context.RiscV64Context.A6, "a7", context.RiscV64Context.A7);
ExtOut(outputFormat3.c_str(), "s2", context.RiscV64Context.S2, "s3", context.RiscV64Context.S3, "s4", context.RiscV64Context.S4);
ExtOut(outputFormat3.c_str(), "s5", context.RiscV64Context.S5, "s6", context.RiscV64Context.S6, "s7", context.RiscV64Context.S7);
ExtOut(outputFormat3.c_str(), "s8", context.RiscV64Context.S8, "s9", context.RiscV64Context.S9, "s10", context.RiscV64Context.S10);
ExtOut(outputFormat3.c_str(), "s11", context.RiscV64Context.S11, "t3", context.RiscV64Context.T3, "t4", context.RiscV64Context.T4);
ExtOut(outputFormat3.c_str(), "t5", context.RiscV64Context.T5, "t6", context.RiscV64Context.T6, "pc", context.RiscV64Context.Pc);
}
#endif
#if defined(SOS_TARGET_LOONGARCH64)
if (IsDbgTargetLoongArch64())
{
foundPlatform = true;
String outputFormat3 = " %3s=%016llx %3s=%016llx %3s=%016llx\n";
ExtOut(outputFormat3, "r0", context.LoongArch64Context.R0, "ra", context.LoongArch64Context.Ra, "tp", context.LoongArch64Context.Tp);
ExtOut(outputFormat3, "sp", context.LoongArch64Context.Sp, "a0", context.LoongArch64Context.A0, "a1", context.LoongArch64Context.A1);
ExtOut(outputFormat3, "a2", context.LoongArch64Context.A2, "a3", context.LoongArch64Context.A3, "a4", context.LoongArch64Context.A4);
ExtOut(outputFormat3, "a5", context.LoongArch64Context.A5, "a6", context.LoongArch64Context.A6, "a7", context.LoongArch64Context.A7);
ExtOut(outputFormat3, "t0", context.LoongArch64Context.T0, "t1", context.LoongArch64Context.T1, "t2", context.LoongArch64Context.T2);
ExtOut(outputFormat3, "t3", context.LoongArch64Context.T3, "t4", context.LoongArch64Context.T4, "t5", context.LoongArch64Context.T5);
ExtOut(outputFormat3, "t6", context.LoongArch64Context.T6, "t7", context.LoongArch64Context.T7, "t8", context.LoongArch64Context.T8);
ExtOut(outputFormat3, "x0", context.LoongArch64Context.X0, "fp", context.LoongArch64Context.Fp, "s0", context.LoongArch64Context.S0);
ExtOut(outputFormat3, "s1", context.LoongArch64Context.S1, "s2", context.LoongArch64Context.S2, "s3", context.LoongArch64Context.S3);
ExtOut(outputFormat3, "s4", context.LoongArch64Context.S4, "s5", context.LoongArch64Context.S5, "s6", context.LoongArch64Context.S6);
ExtOut(outputFormat3, "s7", context.LoongArch64Context.S7, "s8", context.LoongArch64Context.S8, "pc", context.LoongArch64Context.Pc);
ExtOut(outputFormat3.c_str(), "r0", context.LoongArch64Context.R0, "ra", context.LoongArch64Context.Ra, "tp", context.LoongArch64Context.Tp);
ExtOut(outputFormat3.c_str(), "sp", context.LoongArch64Context.Sp, "a0", context.LoongArch64Context.A0, "a1", context.LoongArch64Context.A1);
ExtOut(outputFormat3.c_str(), "a2", context.LoongArch64Context.A2, "a3", context.LoongArch64Context.A3, "a4", context.LoongArch64Context.A4);
ExtOut(outputFormat3.c_str(), "a5", context.LoongArch64Context.A5, "a6", context.LoongArch64Context.A6, "a7", context.LoongArch64Context.A7);
ExtOut(outputFormat3.c_str(), "t0", context.LoongArch64Context.T0, "t1", context.LoongArch64Context.T1, "t2", context.LoongArch64Context.T2);
ExtOut(outputFormat3.c_str(), "t3", context.LoongArch64Context.T3, "t4", context.LoongArch64Context.T4, "t5", context.LoongArch64Context.T5);
ExtOut(outputFormat3.c_str(), "t6", context.LoongArch64Context.T6, "t7", context.LoongArch64Context.T7, "t8", context.LoongArch64Context.T8);
ExtOut(outputFormat3.c_str(), "x0", context.LoongArch64Context.X0, "fp", context.LoongArch64Context.Fp, "s0", context.LoongArch64Context.S0);
ExtOut(outputFormat3.c_str(), "s1", context.LoongArch64Context.S1, "s2", context.LoongArch64Context.S2, "s3", context.LoongArch64Context.S3);
ExtOut(outputFormat3.c_str(), "s4", context.LoongArch64Context.S4, "s5", context.LoongArch64Context.S5, "s6", context.LoongArch64Context.S6);
ExtOut(outputFormat3.c_str(), "s7", context.LoongArch64Context.S7, "s8", context.LoongArch64Context.S8, "pc", context.LoongArch64Context.Pc);
}
#endif

Expand Down
7 changes: 4 additions & 3 deletions src/SOS/Strike/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5394,7 +5394,7 @@ WString GetFrameFromAddress(TADDR frameAddr, IXCLRDataStackWalk *pStackWalk, BOO
else
frameOutput += W("Frame");

frameOutput += WString(W(": ")) + Pointer(frameAddr) + W("] ");
frameOutput += WString(W(": ")) + WString(Pointer(frameAddr)) + W("] ");

// Print the frame's associated function info, if it has any.
CLRDATA_ADDRESS mdesc = 0;
Expand Down Expand Up @@ -5511,7 +5511,8 @@ WString MethodNameFromIP(CLRDATA_ADDRESS ip, BOOL bSuppressLines, BOOL bAssembly
if (!bSuppressLines &&
SUCCEEDED(GetLineByOffset(TO_CDADDR(ip), &linenum, wszFileName, MAX_LONGPATH, bAdjustIPForLineNumber)))
{
methodOutput += WString(W(" [")) + wszFileName + W(" @ ") + Decimal(linenum) + W("]");
const WCHAR* fileNamePtr = wszFileName;
methodOutput += WString(W(" [")) + fileNamePtr + W(" @ ") + WString(Decimal(linenum)) + W("]");
}
}

Expand All @@ -5521,7 +5522,7 @@ WString MethodNameFromIP(CLRDATA_ADDRESS ip, BOOL bSuppressLines, BOOL bAssembly
WString DmlEscape(const WString &input)
{
const WCHAR *str = input.c_str();
size_t len = input.GetLength();
size_t len = input.length();
WString result;

for (size_t i = 0; i < len; i++)
Expand Down
167 changes: 9 additions & 158 deletions src/SOS/Strike/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,159 +453,8 @@ void ConvertToLower(__out_ecount(len) char *buffer, size_t len);
extern const char * const DMLFormats[];
int GetHex(CLRDATA_ADDRESS addr, __out_ecount(len) char *out, size_t len, bool fill);

// A simple string class for mutable strings. We cannot use STL, so this is a stand in replacement
// for std::string (though it doesn't use the same interface).
template <class T, size_t (__cdecl *LEN)(const T *), errno_t (__cdecl *COPY)(T *, size_t, const T * _Src)>
class BaseString
{
public:
BaseString()
: mStr(0), mSize(0), mLength(0)
{
const size_t size = 64;

mStr = new T[size];
mSize = size;
mStr[0] = 0;
}

BaseString(const T *str)
: mStr(0), mSize(0), mLength(0)
{
CopyFrom(str, LEN(str));
}

BaseString(const BaseString<T, LEN, COPY> &rhs)
: mStr(0), mSize(0), mLength(0)
{
*this = rhs;
}

~BaseString()
{
Clear();
}

const BaseString<T, LEN, COPY> &operator=(const BaseString<T, LEN, COPY> &rhs)
{
Clear();
CopyFrom(rhs.mStr, rhs.mLength);
return *this;
}

const BaseString<T, LEN, COPY> &operator=(const T *str)
{
Clear();
CopyFrom(str, LEN(str));
return *this;
}

const BaseString<T, LEN, COPY> &operator +=(const T *str)
{
size_t len = LEN(str);
CopyFrom(str, len);
return *this;
}

const BaseString<T, LEN, COPY> &operator +=(const BaseString<T, LEN, COPY> &str)
{
CopyFrom(str.mStr, str.mLength);
return *this;
}

BaseString<T, LEN, COPY> operator+(const T *str) const
{
return BaseString<T, LEN, COPY>(mStr, mLength, str, LEN(str));
}

BaseString<T, LEN, COPY> operator+(const BaseString<T, LEN, COPY> &str) const
{
return BaseString<T, LEN, COPY>(mStr, mLength, str.mStr, str.mLength);
}

operator const T *() const
{
return mStr;
}

const T *c_str() const
{
return mStr;
}

size_t GetLength() const
{
return mLength;
}

private:
BaseString(const T * str1, size_t len1, const T * str2, size_t len2)
: mStr(0), mSize(0), mLength(0)
{
const size_t size = len1 + len2 + 1 + ((len1 + len2) >> 1);
mStr = new T[size];
mSize = size;

CopyFrom(str1, len1);
CopyFrom(str2, len2);
}

void Clear()
{
mLength = 0;
mSize = 0;
if (mStr)
{
delete [] mStr;
mStr = 0;
}
}

void CopyFrom(const T *str, size_t len)
{
if (mLength + len + 1 >= mSize)
Resize(mLength + len + 1);

COPY(mStr+mLength, mSize-mLength, str);
mLength += len;
}

void Resize(size_t size)
{
/* We always resize at least one half bigger than we need. When CopyFrom requests a resize
* it asks for the exact size that's needed to concatenate strings. However in practice
* it's common to add multiple strings together in a row, e.g.:
* String foo = "One " + "Two " + "Three " + "Four " + "\n";
* Ensuring the size of the string is bigger than we need, and that the minimum size is 64,
* we will cut down on a lot of needless resizes at the cost of a few bytes wasted in some
* cases.
*/
size += size >> 1;
if (size < 64)
size = 64;

T *newStr = new T[size];

if (mStr)
{
COPY(newStr, size, mStr);
delete [] mStr;
}
else
{
newStr[0] = 0;
}

mStr = newStr;
mSize = size;
}
private:
T *mStr;
size_t mSize, mLength;
};

typedef BaseString<char, strlen, strcpy_s> String;
typedef BaseString<WCHAR, _wcslen, wcscpy_s> WString;
typedef std::string String;
typedef std::basic_string<WCHAR> WString;

template<class T>
void Flatten(__out_ecount(len) T *data, unsigned int len)
Expand Down Expand Up @@ -772,13 +621,14 @@ namespace Output
}

/* Converts this object into a Wide char string. This allows you to write the following code:
* WString foo = L"bar " + ObjectPtr(obj);
* WString foo = L"bar " + WString(ObjectPtr(obj));
* Where ObjectPtr is a subclass/typedef of this Format class.
* Note: With std::basic_string, explicit WString() wrapping is required for concatenation.
*/
operator WString() const
{
String str = *this;
const char *cstr = (const char *)str;
const char *cstr = str.c_str();

int len = MultiByteToWideChar(CP_ACP, 0, cstr, -1, NULL, 0);
WCHAR *buffer = (WCHAR *)alloca(len*sizeof(WCHAR));
Expand All @@ -789,8 +639,9 @@ namespace Output
}

/* Converts this object into a String object. This allows you to write the following code:
* String foo = "bar " + ObjectPtr(obj);
* String foo = "bar " + String(ObjectPtr(obj));
* Where ObjectPtr is a subclass/typedef of this Format class.
* Note: With std::string, explicit String() wrapping is required for concatenation.
*/
operator String() const
{
Expand Down Expand Up @@ -1281,12 +1132,12 @@ class TableOutput

void WriteColumn(int col, const String &str)
{
WriteColumn(col, Output::Format<const char *>(str));
WriteColumn(col, Output::Format<const char *>(str.c_str()));
}

void WriteColumn(int col, const WString &str)
{
WriteColumn(col, Output::Format<const WCHAR *>(str));
WriteColumn(col, Output::Format<const WCHAR *>(str.c_str()));
}

void WriteColumn(int col, __in_z WCHAR *str)
Expand Down