Skip to content

Commit c507305

Browse files
Copilotsteveisoknoahfalk
authored
Defer DOTNET_DbgEnableMiniDump error message until dump creation (#122986)
# Description The error message "DOTNET_DbgEnableMiniDump is set and the createdump binary does not exist" was being printed during runtime initialization, even when no dump would be created. This prevented setting the environment variable in crossgen scenarios where createdump isn't shipped. **Changes:** - Removed file existence check (`stat()`) during initialization in `PalCreateDumpInitialize()` to avoid unnecessary file system operations - Detect missing createdump binary when `execv()` returns `ENOENT` error in `CreateCrashDump()` - Print specific error message only when actually attempting to execute the missing binary - Error now appears only when dump creation is attempted (either via crash or explicit API call), not during initialization # Customer Impact Customers using crossgen tooling cannot set `DOTNET_DbgEnableMiniDump` without spurious error messages during builds. This affects debugging workflows in environments where dump generation is conditionally needed. # Regression No. This is an existing issue with the environment variable handling. # Testing Built NativeAOT runtime successfully with changes. Verified: - No initialization errors when createdump missing - Error message appears when attempting to execute missing createdump binary - No change in behavior when createdump exists - No unnecessary file system checks during initialization # Risk Low. Changes eliminate unnecessary file system checks during initialization and defer error detection to the point where the binary is actually needed (execv call). The actual dump creation logic and all success paths remain unchanged. Error messages now appear only when dumps are actually attempted, preventing spurious warnings during initialization. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Hard to use `DOTNET_DbgEnableMiniDump` when crossgen is involved somewhere in the build</issue_title> > <issue_description>https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/src/coreclr/nativeaot/Runtime/unix/PalCreateDump.cpp#L627 > > This line runs ahead-of-time in the non failure case when setting the `DOTNET_DbgEnableMiniDump ` env var. The Crossgen2 pack currently doesn't ship createdump and therefore this line always raises an error when the env var is set. > > This isn't great as it means that you can't set `DOTNET_DbgEnableMiniDump` if crossgen is involved. I.e. when building the runtime repo. > > cc @hoyosjs </issue_description> > > <agent_instructions>Instead of having fprintf(stderr, "DOTNET_DbgEnableMiniDump is set and the createdump binary does not exist: %s\n", program); in PalCreateDumpInitialize in PalCreateDump.cpp, we should instead output it in BuildCreateDumpCommandLine inside the if (g_szCreateDumpPath == nullptr || g_ppidarg == nullptr) block</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #122982 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: steveisok <[email protected]> Co-authored-by: noahfalk <[email protected]>
1 parent 53653bd commit c507305

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/coreclr/nativeaot/Runtime/unix/PalCreateDump.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,14 @@ CreateCrashDump(
271271
// Execute the createdump program
272272
if (execv(argv[0], (char* const *)argv) == -1)
273273
{
274-
fprintf(stderr, "Problem launching createdump (may not have execute permissions): execv(%s) FAILED %s (%d)\n", argv[0], strerror(errno), errno);
274+
if (errno == ENOENT)
275+
{
276+
fprintf(stderr, "DOTNET_DbgEnableMiniDump is set and the createdump binary does not exist: %s\n", argv[0]);
277+
}
278+
else
279+
{
280+
fprintf(stderr, "Problem launching createdump (may not have execute permissions): execv(%s) FAILED %s (%d)\n", argv[0], strerror(errno), errno);
281+
}
275282
exit(-1);
276283
}
277284
}
@@ -621,12 +628,6 @@ PalCreateDumpInitialize()
621628
}
622629
strncat(program, DumpGeneratorName, programLen);
623630

624-
struct stat fileData;
625-
if (stat(program, &fileData) == -1 || !S_ISREG(fileData.st_mode))
626-
{
627-
fprintf(stderr, "DOTNET_DbgEnableMiniDump is set and the createdump binary does not exist: %s\n", program);
628-
return true;
629-
}
630631
g_szCreateDumpPath = program;
631632

632633
// Format the app pid for the createdump command line

0 commit comments

Comments
 (0)