StateMachineHoistedLocalScopes rows are not aligned with the hoisted slots

オープン
#4,121 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
devtools

調査の方向性

330 行目の PortablePdbWriter.BuildStateMachineHoistedLocalScopes から開始し、次に 186-192 行目付近の呼び出し元と、デバッガーがステートマシンのフィールド名からスロット番号を解析する方法を調べます。MixedAsync の例を再現し、生成された行を最も大きいスロットと比較します。完了条件は、行がスロット単位で整列され、必要に応じてプレースホルダーが含まれ、現在の行数を超える hoisted locals も表示されることです。

索引モデルが issue の本文から書いたものです。

説明

Bug PDBGen
Summary

StateMachineHoistedLocalScopes is indexed by slot number: a debugger parses N out of a state machine field name (<name>5__N, <>8__N) and reads row N-1 of the blob. PortablePdbWriter.BuildStateMachineHoistedLocalScopes (line 330) instead emits one row per surviving ILVariable that has a StateMachineField, ordered by field token, and gives every row the extent (0, CodeSize). That sequence has no relation to the slot numbering, so rows are misaligned, and where it is shorter than the highest slot the hoisted locals above the row count are dropped by the expression evaluator.

Reproduction
public static async Task<int> MixedAsync(IEnumerable<int> source)
{
	List<int> chunks = new List<int>();
	foreach (int value in source)
		chunks.Add(value);
	await Task.Yield();
	int total = 0;
	try
	{
		foreach (int chunk in chunks)
		{
			total += chunk;
			await Task.Yield();
		}
	}
	catch (InvalidOperationException e)
	{
		Console.WriteLine(e.Message);
	}
	return total;
}

State machine fields of <MixedAsync>d__0 (slots 1-7):

<>1__state, <>t__builder, source, <chunks>5__1, <total>5__2, <>s__3,
<value>5__4, <>s__5, <chunk>5__6, <e>5__7, <>u__1

Blob rows for <MixedAsync>d__0.MoveNext, start+length:

compiler:  0+24e, 0+24e, 0+0, 3c+25, 0+0, 124+8c, 1e8+1f
ILSpy:     0+24e, 0+24e, 0+24e, 0+24e, 0+24e, 0+24e, 0+24e

The compiler emits exactly one row per slot, in slot order, with an empty 0+0 placeholder for the synthesized <>s__N slots and the real live range for each user local. ILSpy's rows happen to number seven here, but they enumerate a different set (the hoisted parameter source is included, the <>s__N slots are not), so row N-1 does not describe slot N.

The counts diverge on real code: checking the PDB ILSpy generates against the highest user-visible slot in the binary reports a shortfall in 227 state machines of Newtonsoft.Json 13.0.4 and 2 of Microsoft.Extensions.Http 10.0.11. A shortfall means the hoisted locals whose slot exceeds the row count disappear from the Locals window entirely.

Note

#1230 lists StateMachineHoistedLocalScopes as unimplemented. It is emitted (PortablePdbWriter.cs lines 186-192), just not in the shape a consumer reads.

Posted by an AI agent (Claude) on Siegfried's behalf.

主要言語
C#
スター
27.1k
フォーク
3.8k
平均マージ
1日 23時間
マージ済み PR(30日)
44

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

icsharpcode/ILSpy のほかの issue

icsharpcode/ILSpy の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。