Flush Crossgen2 R2R output stream before generating native PDB - #131607
Flush Crossgen2 R2R output stream before generating native PDB#131607elinor-fung with Copilot wants to merge 9 commits into
Conversation
|
Azure Pipelines: 16 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
The FileStream that ReadyToRunObjectWriter writes the R2R image into was kept open (via a method-scoped `using`) while SymbolFileBuilder.SavePdb read the image back from disk to generate the native PDB. Because the FileStream buffers writes until disposed, the PDB writer could observe an incomplete image with a zeroed CodeView/RSDS GUID, producing native PDBs whose PDB-info GUID did not match the DLL. Close the stream (capturing the file size for the map builder) before generating symbol files. Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
@copilot We already have |
Extend PdbChecker to optionally take the crossgen2 output image via a new `--image <file>` argument. When supplied, it reads the image's CodeView/RSDS debug record and verifies the DIA-reported PDB-info GUID/age is nonzero and matches the image identity, regressing the zero-GUID native PDB bug. Wire the crossgen2 R2R test PDB check to pass the output image. Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Avoid silently skipping validation and returning success when a PDB file argument is omitted but --image is supplied. Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Done. Note This comment was generated by GitHub Copilot. |
…taFromPdb Keep the PDB file as the first positional argument. When --image is supplied, MSDiaSymbolReader reads the image's CodeView/RSDS identity and loads the PDB via DIA's loadAndValidateDataFromPdb, which throws when the PDB-info GUID/age don't match the image (including the all-zero GUID regression), instead of comparing identities manually in Program.cs. Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: Elinor Fung <elfung@microsoft.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (2)
src/tests/Common/CLRTest.CrossGen.targets:406
__PdbFileand__OutputFileare appended to the PdbChecker command without quoting. If the test layout path contains spaces (common on Windows agents), the--imageargument (and even the PDB path) will be split and PdbChecker will validate the wrong file or fail to start. Quote both paths when composing the command.
set __CheckPdbCommand=!__DotNet!
set __CheckPdbCommand=!__CheckPdbCommand! "!CORE_ROOT!\PdbChecker\PdbChecker.dll"
set __CheckPdbCommand=!__CheckPdbCommand! !__PdbFile! --image !__OutputFile! @(CheckPdbSymbol->'%22%(Identity)%22', ' ')
echo "!__CheckPdbCommand!"
src/coreclr/tools/PdbChecker/MSDiaSymbolReader.cs:88
- The constructor now reads/validates both the PDB and (optionally) an image file, but the catch block always wraps failures as "Error opening PDB file ...". If
imageFileis missing/corrupt or has no CodeView record, the error message will misleadingly blame the PDB. Include the image path in the wrapped message whenimageFileis provided.
catch (Exception ex)
{
throw new Exception($"Error opening PDB file {pdbFile}", ex);
}
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
Crossgen2-generated native PDBs (
*.ni.pdb) had an all-zero PDB-info GUID after the migration fromR2RPEBuildertoPEObjectWriter, so the PDB could not satisfy the DLL's symbol-server lookup key andmsdlsymbol lookup failed for .NET 11 preview SDK R2R symbols.Root cause
In
ReadyToRunObjectWriter.EmitReadyToRunObjects, the outputFileStreamwas declared with a method-scopedusing, so it stayed open whileSymbolFileBuilder.SavePdbran.SavePdb→PdbWriter.WritePDBDataHelperreads the finished image back from disk (File.Copy(dllPath, ...)) to feed DIA. SinceFileStreambuffers writes until disposed, DIA read an incomplete on-disk image with a zeroed CodeView/RSDS GUID, producing a PDB whose identity didn't match the DLL.Changes
ReadyToRunObjectWriter.cs: Scope the object emission in a nestedusingblock so the stream is flushed and closed before any symbol file (PDB/PerfMap) reads the image from disk. Capturestream.Lengthinside the block for the map builder, which was the only remaining consumer of the open stream.Notes
No regression test is added here: native PDB generation goes through DIA, which is Windows-only, and there is no cross-platform crossgen2 PDB test infrastructure to extend.