是否可以使用Visual Studio在Windows上调试使用Mono / XBuild编译的程序集? [英] Is it possible to debug assemblies compiled with Mono / XBuild with Visual Studio on Windows?

查看:474
本文介绍了是否可以使用Visual Studio在Windows上调试使用Mono / XBuild编译的程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XBuild为Mono编译Visual Studio解决方案。这将生成程序集+ mdb文件。是否有可能在Windows上使用Visual Studio调试此程序集?当使用附加到进程时,我无法调试,因为显示没有加载符号的错误。



我尝试为此程序集生成pdb文件Mono.Cecil(AssemblyDefinition,MdbReaderProvider,PdbWriterProvider),并通过Debug / Windows / Modules和Load Symbol From / Symbol Path手动加载它,它们实际加载了符号(显示在Modules窗口中),但不启用调试

解决方案

当比较VS2012构建和XBuild构建之间的汇编定义时,我注意到XBuild没有生成DebuggableAttribute。如果缺少此属性,则无法使用Visual Studio 2012进行调试,即使手动加载符号也是如此。需要以下步骤来调试使用具有VS2012的Mono / XBuild编译的程序集:


  1. 使用XBuild编译解决方案

  2. 为要调试的每个程序集使用Mono.Cecil来生成pdb文件并注入DebuggableAttribute(参见下面的代码)

  3. 使用XBuild编译程序启动

  4. 使用VS2012中的Debug / Attach to process ...调试正在运行的程序

代码用于生成pdb并注入DebuggableAttribute:

  string assemblyPath = @HelloWorld.exe; 

var assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath,
new ReaderParameters(){SymbolReaderProvider = new MdbReaderProvider(),ReadSymbols = true});

CustomAttribute debuggableAttribute = newCustomAttribute(
assemblyDefinition.MainModule.Import(
typeof(DebuggableAttribute).GetConstructor(new [] {typeof(bool),typeof(bool)})) );

debuggableAttribute.ConstructorArguments.Add(new CustomAttributeArgument(
assemblyDefinition.MainModule.Import(typeof(bool)),true));

debuggableAttribute.ConstructorArguments.Add(new CustomAttributeArgument(
assemblyDefinition.MainModule.Import(typeof(bool)),true));

assemblyDefinition.CustomAttributes.Add(debuggableAttribute);

assemblyDefinition.Write(assemblyPath,
new WriterParameters(){SymbolWriterProvider = new PdbWriterProvider(),WriteSymbols = true});


I'm using XBuild to compile Visual Studio solutions for Mono. This generates the assembly + mdb file. Is there a possibility to debug this assembly with Visual Studio on Windows? When using "Attach to process" i can't debug because an error is shown that the symbols aren't loaded.

I tried generating the pdb file for this assembly via Mono.Cecil (AssemblyDefinition, MdbReaderProvider, PdbWriterProvider) and loading it manually via Debug / Windows / Modules and "Load Symbol From / Symbol Path", which actually loads the symbols (shown in the Modules windows) but that doesn't enable debugging either.

解决方案

When comparing assembly definitions between VS2012 builds and XBuild builds, i noticed that XBuild is not generating the DebuggableAttribute. If this attribute is missing, debugging with Visual Studio 2012 isn't possible, even if you load the symbols manually. Following steps are needed to debug assemblies compiled with Mono / XBuild with VS2012:

  1. Use XBuild to compile the solution
  2. Use Mono.Cecil for each assembly you want to debug to generate the pdb file and to inject the DebuggableAttribute (see code below)
  3. Start your with XBuild compiled program
  4. Use "Debug / Attach to process..." from VS2012 to debug the running program

Code for generating pdb and injecting DebuggableAttribute:

string assemblyPath = @"HelloWorld.exe";

var assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath,
    new ReaderParameters() { SymbolReaderProvider = new MdbReaderProvider(), ReadSymbols = true});

CustomAttribute debuggableAttribute = newCustomAttribute(
assemblyDefinition.MainModule.Import(
    typeof(DebuggableAttribute).GetConstructor(new[] { typeof(bool), typeof(bool) })));

debuggableAttribute.ConstructorArguments.Add(new CustomAttributeArgument(
    assemblyDefinition.MainModule.Import(typeof(bool)), true));

debuggableAttribute.ConstructorArguments.Add(new CustomAttributeArgument(
    assemblyDefinition.MainModule.Import(typeof(bool)), true));

assemblyDefinition.CustomAttributes.Add(debuggableAttribute);

assemblyDefinition.Write(assemblyPath,
    new WriterParameters() { SymbolWriterProvider = new PdbWriterProvider(), WriteSymbols = true});

这篇关于是否可以使用Visual Studio在Windows上调试使用Mono / XBuild编译的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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