Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

ILLinker fails to load portable pdb files for crossgen'd assemblies #1620

Open

Description

@eerhardt

In order to debug a trimmed application, I need to give the untrimmed symbols to the ILLinker so it can update the symbols as necessary.

The symbols for System.* assemblies I get from the Microsoft Symbols Server when debugging an untrimmed application appear to be the portable pdb format. However, if I feed these symbols into the ILLinker when trimming an app, the ILLinker refuses to load the .pdb because of the following check:

https://github.com/mono/cecil/blob/8cf97c125748b0a2832f0420728c8fac2ae22348/Mono.Cecil.Cil/PortablePdb.cs#L86-L96

		public bool ProcessDebugHeader (ImageDebugHeader header)
		{
			if (image == module.Image)
				return true;

			var entry = header.GetCodeViewEntry ();
			if (entry == null)
				return false;

			var data = entry.Data;

			if (data.Length < 24)
				return false;

			var magic = ReadInt32 (data, 0);
			if (magic != 0x53445352)
				return false;

			var buffer = new byte [16];
			Buffer.BlockCopy (data, 4, buffer, 0, 16);

			var module_guid = new Guid (buffer);

			Buffer.BlockCopy (image.PdbHeap.Id, 0, buffer, 0, 16);

			var pdb_guid = new Guid (buffer);

			if (module_guid != pdb_guid)
				return false;

When debugging the ILLinker, module_guid and pdb_guid don't match, thus it returns false.

Building dotnet/runtime locally, I grabbed the crossgen'd .dll and the 2 pdb files (the .ni.pdb and portable .pdb) and tried each with the ILLinker. The ILLinker loaded the .ni.pdb file, but complained about the portable .pdb file.

@noahfalk @mikem8361 - is the above Cecil code for checking the image Guid's correct? Or does it need to be updated for crossgen'd assemblies? I know that Visual Studio can successfully load a portable .pdb with a crossgen'd binary. So I assume there is something wrong with the ILLinker in this case.

cc @vitek-karas

Activity

  1. noahfalk commented on Nov 12, 2020

    @noahfalk
    Member

    cc @tmat

    I think what you are seeing is that Cecil doesn't properly support binaries with multiple CodeView entries. I'm not aware of any binaries that do this other than those produced with NGEN and R2R. For example:

    >dumpbin /headers "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.0\System.Private.CoreLib.dll"
    ...
      Debug Directories
    
            Time Type        Size      RVA  Pointer
        -------- ------- -------- -------- --------
        BF1DA3D2 cv           11C 008EC7E8   8EB9E8    Format: RSDS, {8BB111C4-B66F-C747-0651-09E4DB42CA10}, 1, System.Private.CoreLib.ni.pdb
        BF1DA3D2 cv            83 008EC904   8EBB04    Format: RSDS, {F3DD31A3-D437-4D7D-9525-D887480DAE95}, 1, F:\workspace\_work\1\s\artifacts\obj\coreclr\System.Private.CoreLib\x64\Release\System.Private.CoreLib.pdb
        00000000 repro          0 00000000        0
    

    My educated guess is that if you ran your test on this binary you would see module_guid = 8BB111C4-B66F-C747-0651-09E4DB42CA10 and pdb_guid = F3DD31A3-D437-4D7D-9525-D887480DAE95. The Cecil code appears to only be reading the first CodeView entry and assumes that is the one which will correspond to the portable PDB. If Cecil continued iterating the list it would discover the 2nd entry and match it.

  2. marek-safar commented on Nov 12, 2020

    @marek-safar
    Contributor

    @eerhardt would you mind filling Cecil issue at https://github.com/jbevain/cecil/ or prepare PR?

  3. eerhardt commented on Nov 13, 2020

    @eerhardt
    MemberAuthor

    I've opened jbevain/cecil#704 to track this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions