From 618fd0933f5fe61f04e3de200e15ead9e80a1e3b Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Fri, 20 Mar 2015 12:54:21 -0700 Subject: [PATCH] Enable DumpLog. Implemented DebugClient::GetNameByOffset for the DumpLog command. Implemented stressLogDump.cpp's getTime for Linux by just formatting the system time. Removed PAL_FormatDateW because there is no implementation. Fix expression parsing to better default to hex (without the 0x) since most of the addresses and hex values printed by the sos commands don't have the 0x. --- src/ToolBox/SOS/Strike/CMakeLists.txt | 1 + src/ToolBox/SOS/Strike/stressLogDump.cpp | 27 +++++++--- src/ToolBox/SOS/Strike/strike.cpp | 10 +++- src/ToolBox/SOS/lldbplugin/debugclient.cpp | 80 ++++++++++++++++++++++++++++-- src/ToolBox/SOS/lldbplugin/debugclient.h | 7 +++ src/ToolBox/SOS/lldbplugin/inc/dbgeng.h | 7 +++ src/pal/inc/pal.h | 14 ------ 7 files changed, 118 insertions(+), 28 deletions(-) diff --git a/src/ToolBox/SOS/Strike/CMakeLists.txt b/src/ToolBox/SOS/Strike/CMakeLists.txt index e8b4ffc..4fd06e4 100644 --- a/src/ToolBox/SOS/Strike/CMakeLists.txt +++ b/src/ToolBox/SOS/Strike/CMakeLists.txt @@ -81,6 +81,7 @@ else(WIN32) exts.cpp gcroot.cpp metadata.cpp + stressLogDump.cpp strike.cpp sos.cpp util.cpp diff --git a/src/ToolBox/SOS/Strike/stressLogDump.cpp b/src/ToolBox/SOS/Strike/stressLogDump.cpp index 07b3dd9..7165e68 100644 --- a/src/ToolBox/SOS/Strike/stressLogDump.cpp +++ b/src/ToolBox/SOS/Strike/stressLogDump.cpp @@ -21,24 +21,28 @@ #include "stresslog.h" +#ifndef FEATURE_PAL void GcHistClear(); void GcHistAddLog(LPCSTR msg, StressMsg* stressMsg); +#endif /*********************************************************************************/ static const WCHAR* getTime(const FILETIME* time, __out_ecount (buffLen) WCHAR* buff, int buffLen) { SYSTEMTIME systemTime; - static const WCHAR badTime[] = L"BAD TIME"; - static const WCHAR format[] = L"HH:mm:ss"; + static const WCHAR badTime[] = W("BAD TIME"); if (!FileTimeToSystemTime(time, &systemTime)) return badTime; #ifdef FEATURE_PAL - if (0 == PAL_FormatDateW(NULL, format, FALSE, FALSE, 0, &systemTime, buff, buffLen)) + int length = _snwprintf(buff, buffLen, W("%02d:%02d:%02d"), systemTime.wHour, systemTime.wMinute, systemTime.wSecond); + if (length <= 0) return badTime; #else // FEATURE_PAL + static const WCHAR format[] = W("HH:mm:ss"); + SYSTEMTIME localTime; SystemTimeToTzSpecificLocalTime(NULL, &systemTime, &localTime); @@ -177,7 +181,7 @@ void formatOutput(struct IDebugDataSpaces* memCallBack, __in FILE* file, __inout static WCHAR wszNameBuffer[1024]; // should be large enough if (g_sos->GetMethodDescName(arg, 1024, wszNameBuffer, NULL) != S_OK) { - wcscpy_s(wszNameBuffer, _countof(wszNameBuffer),L"UNKNOWN METHODDESC"); + wcscpy_s(wszNameBuffer, _countof(wszNameBuffer), W("UNKNOWN METHODDESC")); } wcscpy_s(buff, capacity_buff, wszNameBuffer); @@ -274,7 +278,7 @@ void formatOutput(struct IDebugDataSpaces* memCallBack, __in FILE* file, __inout hr = memCallBack->ReadVirtual(TO_CDADDR((char* )args[iArgCount]), wstrBuf, cbWstrBuf, 0); if (hr != S_OK) { - wcscpy_s(wstrBuf, cbWstrBuf/sizeof(WCHAR), L"(#Could not read address of string#)"); + wcscpy_s(wstrBuf, cbWstrBuf/sizeof(WCHAR), W("(#Could not read address of string#)")); } args[iArgCount] = wstrBuf; @@ -330,13 +334,18 @@ HRESULT StressLog::Dump(ULONG64 outProcLog, const char* fileName, struct IDebugD if (bDoGcHist) { +#ifdef FEATURE_PAL + ExtOut ("GC history not support\n"); + return S_FALSE; +#else GcHistClear(); +#endif } else { - ExtOut("Writing to file: %s\n", fileName); - ExtOut("Stress log in module 0x%p\n", SOS_PTR(g_hThisInst)); - ExtOut("Stress log address = 0x%p\n", SOS_PTR(outProcLog)); + ExtOut("Writing to file: %s\n", fileName); + ExtOut("Stress log in module 0x%p\n", SOS_PTR(g_hThisInst)); + ExtOut("Stress log address = 0x%p\n", SOS_PTR(outProcLog)); } // Fetch the circular buffers for each thread into the 'logs' list ThreadStressLog* logs = 0; @@ -486,11 +495,13 @@ HRESULT StressLog::Dump(ULONG64 outProcLog, const char* fileName, struct IDebugD double deltaTime = ((double) (latestMsg->timeStamp - inProcLog.startTimeStamp)) / inProcLog.tickFrequency; if (bDoGcHist) { +#ifndef FEATURE_PAL if (strcmp(format, ThreadStressLog::TaskSwitchMsg()) == 0) { latestLog->threadId = (unsigned)(size_t)latestMsg->args[0]; } GcHistAddLog(format, latestMsg); +#endif // FEATURE_PAL } else { diff --git a/src/ToolBox/SOS/Strike/strike.cpp b/src/ToolBox/SOS/Strike/strike.cpp index dbc54d0..397065a 100644 --- a/src/ToolBox/SOS/Strike/strike.cpp +++ b/src/ToolBox/SOS/Strike/strike.cpp @@ -8288,6 +8288,8 @@ DECLARE_API(u) return Status; } +#endif // FEATURE_PAL + /**********************************************************************\ * Routine Description: * * * @@ -8340,9 +8342,14 @@ DECLARE_API(DumpLog) { if (g_bDacBroken) { +#ifdef FEATURE_PAL + ExtOut("No stress log address. DAC is broken; can't get it\n"); + return E_FAIL; +#else // Try to find stress log symbols DWORD_PTR dwAddr = GetValueFromExpression(MAIN_CLR_MODULE_NAME_A "!StressLog::theLog"); StressLogAddress = dwAddr; +#endif } else if (g_sos->GetStressLogAddress(&StressLogAddress) != S_OK) { @@ -8938,7 +8945,6 @@ DECLARE_API(Token2EE) return Status; } - /**********************************************************************\ * Routine Description: * * * @@ -9067,6 +9073,8 @@ DECLARE_API(Name2EE) } #ifndef FEATURE_PAL + +#ifndef FEATURE_PAL DECLARE_API(PathTo) { INIT_API(); diff --git a/src/ToolBox/SOS/lldbplugin/debugclient.cpp b/src/ToolBox/SOS/lldbplugin/debugclient.cpp index a925901..704422e 100644 --- a/src/ToolBox/SOS/lldbplugin/debugclient.cpp +++ b/src/ToolBox/SOS/lldbplugin/debugclient.cpp @@ -251,6 +251,72 @@ DebugClient::GetSymbolOptions( } HRESULT +DebugClient::GetNameByOffset( + ULONG64 offset, + PSTR nameBuffer, + ULONG nameBufferSize, + PULONG nameSize, + PULONG64 displacement) +{ + HRESULT hr = E_FAIL; + ULONG64 disp = 0; + std::string str; + + lldb::SBTarget target = m_debugger.GetSelectedTarget(); + if (target.IsValid()) + { + lldb::SBAddress address = target.ResolveLoadAddress(offset); + if (address.IsValid()) + { + lldb::SBModule module = address.GetModule(); + if (module.IsValid()) + { + hr = S_OK; + + lldb::SBFileSpec file = module.GetFileSpec(); + if (file.IsValid()) + { + str.append(file.GetFilename()); + } + + lldb::SBSymbol symbol = address.GetSymbol(); + if (symbol.IsValid()) + { + lldb::SBAddress startAddress = symbol.GetStartAddress(); + disp = address.GetOffset() - startAddress.GetOffset(); + + const char *name = symbol.GetName(); + if (name) + { + if (file.IsValid()) + { + str.append("!"); + } + str.append(name); + } + } + + str.append(1, '\0'); + } + } + } + + if (nameSize) + { + *nameSize = str.length(); + } + if (nameBuffer) + { + str.copy(nameBuffer, nameBufferSize); + } + if (displacement) + { + *displacement = disp; + } + return hr; +} + +HRESULT DebugClient::GetNumberModules( PULONG loaded, PULONG unloaded) @@ -697,13 +763,17 @@ DebugClient::GetExpression( { return E_FAIL; } - HRESULT hr = GetExpression(frame, exp, result); + // To be compatible with windbg/dbgeng, we need to emulate the default + // hex radix (because sos prints addresses and other hex values without + // the 0x) by first prepending 0x and if that fails use the actual + // undecorated expression. + std::string str; + str.append("0x"); + str.append(exp); + HRESULT hr = GetExpression(frame, str.c_str(), result); if (hr != S_OK) { - std::string str; - str.append("0x"); - str.append(exp); - hr = GetExpression(frame, str.c_str(), result); + hr = GetExpression(frame, exp, result); } return hr; } \ No newline at end of file diff --git a/src/ToolBox/SOS/lldbplugin/debugclient.h b/src/ToolBox/SOS/lldbplugin/debugclient.h index 8c79064..d653656 100644 --- a/src/ToolBox/SOS/lldbplugin/debugclient.h +++ b/src/ToolBox/SOS/lldbplugin/debugclient.h @@ -74,6 +74,13 @@ public: HRESULT GetSymbolOptions( PULONG options); + HRESULT GetNameByOffset( + ULONG64 offset, + PSTR nameBuffer, + ULONG nameBufferSize, + PULONG nameSize, + PULONG64 displacement); + HRESULT GetNumberModules( PULONG loaded, PULONG unloaded); diff --git a/src/ToolBox/SOS/lldbplugin/inc/dbgeng.h b/src/ToolBox/SOS/lldbplugin/inc/dbgeng.h index 735209f..90722e5 100644 --- a/src/ToolBox/SOS/lldbplugin/inc/dbgeng.h +++ b/src/ToolBox/SOS/lldbplugin/inc/dbgeng.h @@ -191,6 +191,13 @@ public: virtual HRESULT GetSymbolOptions( PULONG options) = 0; + virtual HRESULT GetNameByOffset( + ULONG64 offset, + PSTR nameBuffer, + ULONG nameBufferSize, + PULONG nameSize, + PULONG64 displacement) = 0; + // Enumerates the engines list of modules // loaded for the current process. This may // or may not match the system module list diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index 7adfa10..8470157 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -4327,20 +4327,6 @@ PAL_NormalizeStringExW( OUT LPWSTR lpDestStr, IN int cchDest); - -PALIMPORT -int -PALAPI -PAL_FormatDateW( - IN LPCWSTR lpLocaleName, - IN LPCWSTR lpFormat, - IN BOOL fUseUTC, - IN BOOL fUseCustomTz, - IN int tzOffsetSeconds, - IN LPSYSTEMTIME lpTime, - OUT LPWSTR lpDestStr, - IN int cchDest); - PALIMPORT int PALAPI -- 2.7.4