哪里可以了解 VS 调试器的“神奇名称" [英] Where to learn about VS debugger 'magic names'

查看:24
本文介绍了哪里可以了解 VS 调试器的“神奇名称"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您曾经使用过 Reflector,您可能会注意到 C# 编译器生成的类型、方法、字段和局部变量值得调试器进行特殊"显示.例如,以CS$"开头的局部变量不会显示给用户.对于匿名方法的闭包类型、自动属性的支持字段等,还有其他特殊的命名约定.

If you've ever used Reflector, you probably noticed that the C# compiler generates types, methods, fields, and local variables, that deserve 'special' display by the debugger. For instance, local variables beginning with 'CS$' are not displayed to the user. There are other special naming conventions for closure types of anonymous methods, backing fields of automatic properties, and so on.

我的问题:从哪里了解这些命名约定?有人知道一些文档吗?

My question: where to learn about these naming conventions? Does anyone know about some documentation?

我的目标是让 PostSharp 2.0 使用相同的约定.

My objective is to make PostSharp 2.0 use the same conventions.

推荐答案

这些是编译器未记录的实现细节,随时可能更改.(更新:见 GeneratedNames.cs在 C# 源代码中获取当前详细信息;下面的描述有点过时了.)

These are undocumented implementation details of the compiler, and subject to change at any time. (UPDATE: See GeneratedNames.cs in the C# sources for the current details; the description below is somewhat out-of-date.)

但是,由于我是一个好人,这里有一些细节:

However, since I'm a nice guy, here are some of those details:

如果优化器删除了一个未使用的局部变量,我们无论如何都会将它的调试信息发送到 PDB 中.我们将后缀 __Deleted$ 粘贴到这些变量上,以便调试器知道它们在源代码中,但未在二进制文件中表示.

If you have an unused local variable that the optimizer removes, we emit debug info for it anyway into the PDB. We stuck the suffix __Deleted$ onto such variables so that the debugger knows that they were in source code but not represented in the binary.

由编译器分配的临时变量槽以模式 CS$X$Y 命名,其中 X 是临时类型",Y 是到目前为止分配的临时变量的数量.临时类型是:

Temporary variable slots allocated by the compiler are given names with the pattern CS$X$Y, where X is the "temporary kind" and Y is the number of temporaries allocated so far. The temporary kinds are:

0 --> short lived temporaries
1 --> return value temporaries
2 --> temporaries generated for lock statements
3 --> temporaries generated for using statements
4 --> durable temporaries
5 --> the result of get enumerator in a foreach
6 --> the array storage in a foreach
7 --> the array index storage in a foreach.  

8 到 264 之间的临时种类是多维数组的附加数组索引存储.

Temporary kinds between 8 and 264 are additional array index storages for multidimensional arrays.

264 以上的临时类型用于涉及固定字符串的临时类型.

Temporary kinds above 264 are used for temporaries involving the fixed statement fixing a string.

特殊的编译器生成的名称是为:

Special compiler-generated names are generated for:

1 --> the iterator state ("state")
2 --> the value of current in an iterator ("current")
3 --> a saved parameter in an iterator
4 --> a hoisted 'this' in an iterator ("this")
5 --> a hoisted local in an iterator
6 --> the hoisted locals from an outer scope
7 --> a hoisted wrapped value ("wrap")
8 --> the closure class instance ("locals")
9 --> the cached delegate instance ("CachedAnonymousMethodDelegate")
a --> the iterator instance ("iterator")
b --> an anonymous method
c --> anonymous method closure class ("DisplayClass")
d --> iterator class
e --> fixed buffer struct ("FixedBuffer")
f --> anonymous type ("AnonymousType")
g --> initializer local ("initLocal")
h --> query expression temporary ("TransparentIdentifier")
i --> anonymous type field ("Field")
j --> anonymous type type parameter ("TPar")
k --> auto prop field ("BackingField")
l --> iterator thread id
m --> iterator finally ("Finally")
n --> fabricated method ("FabricatedMethod")
o --> dynamic container class ("SiteContainer")
p --> dynamic call site ("Site")
q --> dynamic delegate ("SiteDelegate")
r --> com ref call local ("ComRefCallLocal")
s --> lock taken local ("LockTaken")

生成魔法名字的模式是:P<N>C__SI 其中:

The pattern for generating magical names is: P<N>C__SI where:

  • P 是缓存委托和显示类实例的 CS$,否则为空.
  • N 是与事物关联的原始名称(如果有)
  • C 是上面列出的字符 1 到 s
  • S 是一个描述性后缀(当前"、状态"等),因此您在阅读元数据时不必记住上面的表格.
  • I 是可选的唯一编号

这篇关于哪里可以了解 VS 调试器的“神奇名称"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆