StateMachineHoistedLocalScopes rows are not aligned with the hoisted slots

未关闭
#4,121 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
csharp
领域
devtools

调研方向

从第 330 行的 PortablePdbWriter.BuildStateMachineHoistedLocalScopes 开始,然后检查第 186-192 行附近的调用方,以及调试器如何从状态机字段名称中解析 slot 编号。重现 MixedAsync 示例,并将生成的行与最高 slot 进行比较;完成的标准是行按 slot 对齐,在需要时包含占位符,并且超出当前行数的 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 小时
30 天内合并 PR
44

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

icsharpcode/ILSpy 的其他 Issue

查看 icsharpcode/ILSpy 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。