Skip to content

Commit b126b9a

Browse files
authored
Store entry assembly path for easy access for diagnostics (#95045)
- Add `g_EntryAssemblyPath` global variable holding the full path to the entry assembly - Set right before loading the entry assembly (so also before startup hooks are run) - NULL if there is no entry assembly - Ensure value is included dumps - For triage dumps, the dumped value is updated to only be the assembly file name instead of the full path
1 parent 7dc2e67 commit b126b9a

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

src/coreclr/debug/daccess/enummem.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,34 @@ HRESULT ClrDataAccess::EnumMemCLRStatic(IN CLRDataEnumMemoryFlags flags)
224224

225225
ReportMem(g_gcDacGlobals.GetAddr(), sizeof(GcDacVars));
226226

227+
PTR_WSTR entryAssemblyPath = (PTR_WSTR)g_EntryAssemblyPath;
228+
entryAssemblyPath.EnumMem();
229+
230+
// Triage dumps must not include full paths (PII data). Replace entry assembly path with file name only.
231+
if (flags == CLRDATA_ENUM_MEM_TRIAGE)
232+
{
233+
WCHAR* path = entryAssemblyPath;
234+
if (path != NULL)
235+
{
236+
size_t pathLen = u16_strlen(path) + 1;
237+
238+
// Get the file name based on the last directory separator
239+
const WCHAR* name = u16_strrchr(path, DIRECTORY_SEPARATOR_CHAR_W);
240+
if (name != NULL)
241+
{
242+
name += 1;
243+
size_t len = u16_strlen(name) + 1;
244+
wcscpy_s(path, len, name);
245+
246+
// Null out the rest of the buffer
247+
for (size_t i = len; i < pathLen; ++i)
248+
path[i] = W('\0');
249+
250+
DacUpdateMemoryRegion(entryAssemblyPath.GetAddr(), pathLen, (BYTE*)path);
251+
}
252+
}
253+
}
254+
227255
// We need all of the dac variables referenced by the GC DAC global struct.
228256
// This struct contains pointers to pointers, so we first dereference the pointers
229257
// to obtain the location of the variable that's reported.

src/coreclr/inc/daccess.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@
574574
#include "crosscomp.h"
575575
#endif
576576

577+
#include <dn-u16.h>
578+
577579
// Information stored in the DAC table of interest to the DAC implementation
578580
// Note that this information is shared between all instantiations of ClrDataAccess, so initialize
579581
// it just once in code:ClrDataAccess.GetDacGlobals (rather than use fields in ClrDataAccess);
@@ -1493,10 +1495,10 @@ class __Str16Ptr : public __DPtr<WCHAR>
14931495
}
14941496
void EnumMem(void) const
14951497
{
1496-
char* str = DacInstantiateStringW(m_addr, maxChars, false);
1498+
WCHAR* str = DacInstantiateStringW(m_addr, maxChars, false);
14971499
if (str)
14981500
{
1499-
DacEnumMemoryRegion(m_addr, strlen(str) + 1);
1501+
DacEnumMemoryRegion(m_addr, u16_strlen(str) + 1);
15001502
}
15011503
}
15021504
};

src/coreclr/inc/dacvars.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,7 @@ DEFINE_DACVAR(SIZE_T, dac__g_clrNotificationArguments, ::g_clrNotificationArgume
231231
DEFINE_DACVAR(bool, dac__g_metadataUpdatesApplied, ::g_metadataUpdatesApplied)
232232
#endif
233233

234+
DEFINE_DACVAR(PTR_WSTR, dac__g_EntryAssemblyPath, ::g_EntryAssemblyPath)
235+
234236
#undef DEFINE_DACVAR
235237
#undef DEFINE_DACVAR_NO_DUMP

src/coreclr/vm/corhost.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@ HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId,
310310

311311
_ASSERTE (!pThread->PreemptiveGCDisabled());
312312

313+
if (g_EntryAssemblyPath == NULL)
314+
{
315+
// Store the entry assembly path for diagnostic purposes (for example, dumps)
316+
size_t len = u16_strlen(pwzAssemblyPath) + 1;
317+
NewArrayHolder<WCHAR> path { new WCHAR[len] };
318+
wcscpy_s(path, len, pwzAssemblyPath);
319+
g_EntryAssemblyPath = path.Extract();
320+
}
321+
313322
Assembly *pAssembly = AssemblySpec::LoadAssembly(pwzAssemblyPath);
314323

315324
#if defined(FEATURE_MULTICOREJIT)

src/coreclr/vm/vars.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ GVAL_IMPL_INIT(DWORD, g_debuggerWordTLSIndex, TLS_OUT_OF_INDEXES);
106106
#endif
107107
GVAL_IMPL_INIT(DWORD, g_TlsIndex, TLS_OUT_OF_INDEXES);
108108

109+
GVAL_IMPL_INIT(PTR_WSTR, g_EntryAssemblyPath, NULL);
110+
109111
#ifndef DACCESS_COMPILE
110112

111113
// <TODO> @TODO - PROMOTE. </TODO>

src/coreclr/vm/vars.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ GVAL_DECL(DWORD, g_debuggerWordTLSIndex);
389389
#endif
390390
GVAL_DECL(DWORD, g_TlsIndex);
391391

392+
// Full path to the managed entry assembly - stored for ease of identifying the entry asssembly for diagnostics
393+
GVAL_DECL(PTR_WSTR, g_EntryAssemblyPath);
394+
392395
// Global System Information
393396
extern SYSTEM_INFO g_SystemInfo;
394397

0 commit comments

Comments
 (0)