惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - sPhinX

如何解决在Win11下卸载McgsPro失败的问题 如何离线安装WinDbg Preview 敏捷软件开发 原则、模式与实践 第9章的例子程序(C#版) Akavache简明使用指南 Oracle存储过程解析XML内容 P/Invoke继续谈 有意思的案例: 的问题 dnSpy调试IIS(w3wp进程) Xilium.CefGlue与SingleProcess rocketmq-client-cpp(2.0.1)编译指南 RocketMQ .NET客户端的那些坑 P/Invoke今日谈 .NET编译问题汇总 动态的世界 使用ProcDump自动生成Dump文件 Process.Start可能无法选中指定文件的问题 获取本地IP 将exe和dll打包为一个exe文件 .NET异步资料收集
dnSpy - 让调试镜像文件的工作变得轻松点
sPhinX · 2020-04-05 · via 博客园 - sPhinX

原文在这里:https://github.com/0xd4d/dnSpy/wiki/Making-an-Image-Easier-to-Debug

参考了这里:https://docs.microsoft.com/zh-cn/archive/blogs/sburke/how-to-disable-optimizations-when-debugging-reference-source

当你把调试器附加到任意的.NET进程时,这个进程很有可能是被优化过的。这会使得调试过程中的体验变的很差,因为调试器无法读取所有的局部变量,对表达式求值或调用方法。所以你应该尽可能让dnSpy来启动进程

如果你不得不附加进程的话,微软推荐你新建一个ini文件

如果你的文件叫myapp.exe或者something.dll,那你相应的需要新建一个叫myapp.ini或者something.ini的文件,并把这个文件放到与exe或者dll文件所在的同一个文件夹下,文件内容如下:

[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0

注意:不能用UTF8 BOM编码方式保存这个文件!

必须给每一个exe或者dll文件配备一个相应的ini文件,光是给主exe文件配ini文件是不够。

另外,为了关闭.NET的优化选项,需要告诉CLR不要加载per-JIT(也就是通常所谓的NGEN)镜像文件,你可以新建一个CMD文件,名字可以叫NoOptDevEnv.cmd,内容大致如下:

set COMPLUS_ZapDisable=1
cd /d "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\IDE"
start devenv.exe
exit

当然你也可以选择设置系统环境变量,只不过这样影响面更大,如何选择视你的需要而定。

对于老版本的Visual Studio来说,你还需要关掉项目调试选项中的承载进程选项。这下你可以看到所有的局部变量信息了。

前:

前

后:

后

顺便说下关掉承载进程有什么影响(虽然绝大多数情况下都没有什么影响):

1、不能在区域中调试(Debug In Zone),无法调试在类似“Internet”或者”Intranet”这样安全区域中的进程了。

2、类库的设计时表达式求值功能也无法使用,这意味着不能在调试器中的立即窗口里面执行代码了。