dotnet / dotnet/fsharp

Emit StateMachineMethod and StateMachineHoistedLocalScopes into portable PDB format

Open
#12,000 1 comment 2 reactions 0 assignees View on GitHub
Area-Debug Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Roslyn has a capability to emit special debug information for C#/VB async methods.

F# doesn't emit this information. This means we must, in some way, be missing out on a debug capability supported by .NET debugging.

* [ ] clarify the user-facing experience this supports and verify it is not supported by F#
* [ ] collect the information in the compiler as we generate resumable code
* [ ] implement the code to emit this information
* [ ] see if it is useful beyond F# tasks.

Portable PDB spec is here: https://github.com/dotnet/runtime/blob/main/docs/design/specs/PortablePdb-Metadata.md

Also aplies to "StateMachine Local Scopes"
https://github.com/dotnet/roslyn/blob/3d8acbd585a75e9cdb3509623bf6c39ceb46b2c2/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs

Here's an example of what they emit: https://github.com/dotnet/roslyn/blob/3d8acbd585a75e9cdb3509623bf6c39ceb46b2c2/src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs

```
private void SerializeAsyncMethodSteppingInfo(AsyncMoveNextBodyDebugInfo asyncInfo, MethodDefinitionHandle moveNextMethod, int aggregateMethodDefRid)
{
Debug.Assert(asyncInfo.ResumeOffsets.Length == asyncInfo.YieldOffsets.Length);
Debug.Assert(asyncInfo.CatchHandlerOffset >= -1);

var writer = new BlobBuilder();

writer.WriteUInt32((uint)((long)asyncInfo.CatchHandlerOffset + 1));

for (int i = 0; i < asyncInfo.ResumeOffsets.Length; i++)
{
writer.WriteUInt32((uint)asyncInfo.YieldOffsets[i]);
writer.WriteUInt32((uint)asyncInfo.ResumeOffsets[i]);
writer.WriteCompressedInteger(aggregateMethodDefRid);
}

_debugMetadataOpt.AddCustomDebugInformation(
parent: moveNextMethod,
kind: _debugMetadataOpt.GetOrAddGuid(PortableCustomDebugInfoKinds.AsyncMethodSteppingInformationBlob),
value: _debugMetadataOpt.GetOrAddBlob(writer));
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.