Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
Add a no-cache backed CLRConfig lookup mechanism#59513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
455f493749728de058c3692ad1d66994a174aab957deff52e950246e471ec62File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // | ||
| // -------------------------------------------------------------------------------------------------- | ||
| // clrconfignocache.h | ||
| // | ||
| // Logic for resolving configuration names. | ||
| // | ||
| #ifndef StrLen | ||
| #define StrLen(STR) ((sizeof(STR) / sizeof(STR[0])) - 1) | ||
| #endif // !StrLen | ||
| // Config prefixes | ||
| #define COMPLUS_PREFIX_A "COMPlus_" | ||
| #define COMPLUS_PREFIX W("COMPlus_") | ||
| #define LEN_OF_COMPLUS_PREFIX StrLen(COMPLUS_PREFIX_A) | ||
| #define DOTNET_PREFIX_A "DOTNET_" | ||
| #define DOTNET_PREFIX W("DOTNET_") | ||
| #define LEN_OF_DOTNET_PREFIX StrLen(DOTNET_PREFIX_A) | ||
| class CLRConfigNoCache | ||
| { | ||
| const char* _value; | ||
| CLRConfigNoCache() = default; | ||
| CLRConfigNoCache(LPCSTR cfg) : _value { cfg } | ||
| { } | ||
| public: | ||
| bool IsSet() const { return _value != NULL; } | ||
| LPCSTR AsString() const | ||
| { | ||
| _ASSERTE(IsSet()); | ||
| return _value; | ||
| } | ||
| bool TryAsInteger(int radix, DWORD& result) const | ||
| { | ||
| _ASSERTE(IsSet()); | ||
| errno = 0; | ||
| LPSTR endPtr; | ||
| result = strtoul(_value, &endPtr, radix); | ||
| bool fSuccess = (errno != ERANGE) && (endPtr != _value); | ||
| return fSuccess; | ||
| } | ||
| static CLRConfigNoCache Get(LPCSTR cfg, bool noPrefix = false, char*(*getEnvFptr)(const char*) = nullptr) | ||
| { | ||
| char nameBuffer[64]; | ||
| const char* fallbackPrefix = NULL; | ||
| const size_t namelen = strlen(cfg); | ||
| if (noPrefix) | ||
| { | ||
| if (namelen >= _countof(nameBuffer)) | ||
| { | ||
| _ASSERTE(!"Environment variable name too long."); | ||
| return {}; | ||
| } | ||
| *nameBuffer = W('\0'); | ||
| } | ||
| else | ||
| { | ||
| bool dotnetValid = namelen < (size_t)(_countof(nameBuffer) - 1 - LEN_OF_DOTNET_PREFIX); | ||
| bool complusValid = namelen < (size_t)(_countof(nameBuffer) - 1 - LEN_OF_COMPLUS_PREFIX); | ||
| if (!dotnetValid || !complusValid) | ||
| { | ||
| _ASSERTE(!"Environment variable name too long."); | ||
| return {}; | ||
| } | ||
| // Priority order is DOTNET_ and then COMPlus_. | ||
| strcpy_s(nameBuffer, _countof(nameBuffer), DOTNET_PREFIX_A); | ||
| fallbackPrefix = COMPLUS_PREFIX_A; | ||
| } | ||
| strcat_s(nameBuffer, _countof(nameBuffer), cfg); | ||
| LPCSTR val = getEnvFptr != NULL ? getEnvFptr(nameBuffer) : getenv(nameBuffer); | ||
| if (val == NULL && fallbackPrefix != NULL) | ||
| { | ||
| strcpy_s(nameBuffer, _countof(nameBuffer), fallbackPrefix); | ||
| strcat_s(nameBuffer, _countof(nameBuffer), cfg); | ||
| val = getEnvFptr != NULL ? getEnvFptr(nameBuffer) : getenv(nameBuffer); | ||
| } | ||
| return { val }; | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -30,6 +30,10 @@ Revision History: | ||
| SET_DEFAULT_DEBUG_CHANNEL(MISC); | ||
| // clrconfignocache.h uses macro _ASSERTE, which needd to use variable | ||
| // defdbgchan defined by SET_DEFAULT_DEBUG_CHANNEL. | ||
| #include <clrconfignocache.h> | ||
| /*++ | ||
| Initialization logic for LTTng tracepoint providers. | ||
| @@ -62,10 +66,12 @@ PAL_InitializeTracing(void) | ||
| // Check if loading the LTTng providers should be disabled. | ||
| // Note: this env var is formally declared in clrconfigvalues.h, but | ||
| // this code is executed too early to use the mechanics that come with that definition. | ||
| char *disableValue = getenv("COMPlus_LTTng"); | ||
| if (disableValue != NULL) | ||
| CLRConfigNoCache cfgLTTng = CLRConfigNoCache::Get("LTTng", /*noprefix*/ false, &getenv); | ||
| if (cfgLTTng.IsSet()) | ||
| { | ||
| fShouldLoad = strtol(disableValue, NULL, 10); | ||
| DWORD value; | ||
| if (cfgLTTng.TryAsInteger(10, value)) | ||
AaronRobinsonMSFT marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| fShouldLoad = (int)value; | ||
| } | ||
| // Get the path to the currently executing shared object (libcoreclr.so). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -37,6 +37,8 @@ SET_DEFAULT_DEBUG_CHANNEL(PROCESS); // some headers have code with asserts, so d | ||
| #include "pal/stackstring.hpp" | ||
| #include "pal/signal.hpp" | ||
| #include <clrconfignocache.h> | ||
| #include <errno.h> | ||
| #if HAVE_POLL | ||
| #include <poll.h> | ||
| @@ -3108,6 +3110,8 @@ PROCFormatInt(ULONG32 value) | ||
| return buffer; | ||
| } | ||
| static const INT UndefinedDumpType = 0; | ||
| /*++ | ||
| Function | ||
| PROCBuildCreateDumpCommandLine | ||
| @@ -3124,8 +3128,8 @@ PROCBuildCreateDumpCommandLine( | ||
| std::vector<const char*>& argv, | ||
| char** pprogram, | ||
| char** ppidarg, | ||
| char* dumpName, | ||
| char* dumpType, | ||
| const char* dumpName, | ||
| INT dumpType, | ||
| BOOL diag, | ||
| BOOL crashReport) | ||
| { | ||
| @@ -3170,24 +3174,19 @@ PROCBuildCreateDumpCommandLine( | ||
| argv.push_back(dumpName); | ||
| } | ||
| if (dumpType != nullptr) | ||
| switch (dumpType) | ||
| { | ||
| if (strcmp(dumpType, "1") == 0) | ||
| { | ||
| argv.push_back("--normal"); | ||
| } | ||
| else if (strcmp(dumpType, "2") == 0) | ||
| { | ||
| argv.push_back("--withheap"); | ||
| } | ||
| else if (strcmp(dumpType, "3") == 0) | ||
| { | ||
| argv.push_back("--triage"); | ||
| } | ||
| else if (strcmp(dumpType, "4") == 0) | ||
| { | ||
| argv.push_back("--full"); | ||
| } | ||
| case 1: argv.push_back("--normal"); | ||
AaronRobinsonMSFT marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| break; | ||
| case 2: argv.push_back("--withheap"); | ||
| break; | ||
| case 3: argv.push_back("--triage"); | ||
| break; | ||
| case 4: argv.push_back("--full"); | ||
| break; | ||
| case UndefinedDumpType: | ||
| default: | ||
| break; | ||
| } | ||
| if (diag) | ||
| @@ -3277,19 +3276,37 @@ Return | ||
| BOOL | ||
| PROCAbortInitialize() | ||
| { | ||
| char* enabled = getenv("COMPlus_DbgEnableMiniDump"); | ||
| if (enabled != nullptr && _stricmp(enabled, "1") == 0) | ||
| CLRConfigNoCache enabledCfg= CLRConfigNoCache::Get("DbgEnableMiniDump", /*noprefix*/ false, &getenv); | ||
| DWORD enabled = 0; | ||
| if (enabledCfg.IsSet() | ||
| && enabledCfg.TryAsInteger(10, enabled) | ||
hoyosjs marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| && enabled) | ||
| { | ||
| char* dumpName = getenv("COMPlus_DbgMiniDumpName"); | ||
| char* dumpType = getenv("COMPlus_DbgMiniDumpType"); | ||
| char* diagStr = getenv("COMPlus_CreateDumpDiagnostics"); | ||
| BOOL diag = diagStr != nullptr && strcmp(diagStr, "1") == 0; | ||
| char* crashReportStr = getenv("COMPlus_EnableCrashReport"); | ||
| BOOL crashReport = crashReportStr != nullptr && strcmp(crashReportStr, "1") == 0; | ||
| CLRConfigNoCache dmpNameCfg = CLRConfigNoCache::Get("DbgMiniDumpName", /*noprefix*/ false, &getenv); | ||
| CLRConfigNoCache dmpTypeCfg = CLRConfigNoCache::Get("DbgMiniDumpType", /*noprefix*/ false, &getenv); | ||
| DWORD dumpType = UndefinedDumpType; | ||
| if (dmpTypeCfg.IsSet()) | ||
| { | ||
| (void)dmpTypeCfg.TryAsInteger(10, dumpType); | ||
| if (dumpType < 1 || dumpType > 4) | ||
| { | ||
| dumpType = UndefinedDumpType; | ||
| } | ||
| } | ||
| CLRConfigNoCache createDumpCfg = CLRConfigNoCache::Get("CreateDumpDiagnostics", /*noprefix*/ false, &getenv); | ||
| DWORD val = 0; | ||
| BOOL diag = createDumpCfg.IsSet() && createDumpCfg.TryAsInteger(10, val) && val == 1; | ||
| CLRConfigNoCache enabldReportCfg = CLRConfigNoCache::Get("EnableCrashReport", /*noprefix*/ false, &getenv); | ||
| val = 0; | ||
| BOOL crashReport = enabldReportCfg.IsSet() && enabldReportCfg.TryAsInteger(10, val) && val == 1; | ||
| char* program = nullptr; | ||
| char* pidarg = nullptr; | ||
| if (!PROCBuildCreateDumpCommandLine(g_argvCreateDump, &program, &pidarg, dumpName, dumpType, diag, crashReport)) | ||
| if (!PROCBuildCreateDumpCommandLine(g_argvCreateDump, &program, &pidarg, dmpNameCfg.AsString(), dumpType, diag, crashReport)) | ||
| { | ||
| return FALSE; | ||
| } | ||
| @@ -3325,23 +3342,18 @@ PAL_GenerateCoreDump( | ||
| BOOL diag) | ||
| { | ||
| std::vector<const char*> argvCreateDump; | ||
| char dumpTypeStr[16]; | ||
| if (dumpType < 1 || dumpType > 4) | ||
| { | ||
| return FALSE; | ||
| } | ||
| if (_itoa_s(dumpType, dumpTypeStr, sizeof(dumpTypeStr), 10) != 0) | ||
| { | ||
| return FALSE; | ||
| } | ||
| if (dumpName != nullptr && dumpName[0] == '\0') | ||
| { | ||
| dumpName = nullptr; | ||
| } | ||
| char* program = nullptr; | ||
| char* pidarg = nullptr; | ||
| BOOL result = PROCBuildCreateDumpCommandLine(argvCreateDump, &program, &pidarg, (char*)dumpName, dumpTypeStr, diag, false); | ||
| BOOL result = PROCBuildCreateDumpCommandLine(argvCreateDump, &program, &pidarg, dumpName, dumpType, diag, false); | ||
| if (result) | ||
| { | ||
| result = PROCCreateCrashDump(argvCreateDump); | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.