Skip to content
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

Support converting embedded Pdbs to XML #235

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KirillOsenkov
Copy link
Member

No description provided.

Copy link
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use reflection?

@KirillOsenkov
Copy link
Member Author

The APIs I needed weren't public. Maybe I missed something? Feel free to push directly to the PR branch to fix.

@KirillOsenkov
Copy link
Member Author

I'm sorry, I don't quite understand how to use the link you provided to get rid of reflection here.

My task is given a MetadataReaderProvider how to obtain the uncompressed byte[] of the embedded Pdb or a Stream that I could pass to the Pdb2Xml dumper.

@tmat
Copy link
Member

tmat commented Dec 7, 2021

I see. You can use MetadataReader.MetadataPointer and MetadataReader.Length to read the data.

@KirillOsenkov
Copy link
Member Author

I'm sorry again, I'm not well-versed in pointers and unsafe code, so I really don't know how to do this.

It would be great if you could just do it yourself when you have time (not urgent).

@KirillOsenkov
Copy link
Member Author

I think PEReader should be able to read from an RVA given the position and size, and fill a byte array. Not sure if disk layout/memory layout of the PE format is relevant here.

Comment on lines +205 to +210
var embeddedProvider = reader.ReadEmbeddedPortablePdbDebugDirectoryData(entry);
var memoryBlock = embeddedProvider.GetType().GetMethod("GetMetadataBlock", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(embeddedProvider, null);
var memoryBlockType = memoryBlock.GetType();
var size = (int)memoryBlockType.GetProperty("Size").GetValue(memoryBlock);
var bytes = (ImmutableArray<byte>)memoryBlockType.GetMethod("GetContentUnchecked").Invoke(memoryBlock, new object[] { 0, size });
pdbStream = new MemoryStream(bytes.ToArray());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var pdbStream = new UnmanagedMemoryStream(reader.MetadataPointer, reader.MetadataLength, reader.MetadataLength, FileAccess.Read);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants