调试外部程序的库? (Visual Studio 2010) [英] Debugging a library of an external program? (Visual Studio 2010)

查看:145
本文介绍了调试外部程序的库? (Visual Studio 2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对使用Visual Studio 2010调试外部应用程序有经验的程序员的一个问题。



目前,我正在为程序开发附加组件。由我工作的人制作。为了使此加载项与外部程序一起使用,我必须将.dll文件放在外部程序指定的特定文件夹中。我配置了构建设置,因此.dll文件会自动复制。我还复制了.pdb文件以启用调试选项。



由于该加载项只不过是一个类库,因此我无法像往常一样进行调试。我也没有外部应用程序的源代码。我应该如何正确调试该类库?



这是我尝试的方法:



1。附加到流程

请参阅这样正确地断点。但是,由于某种原因,这会使外部程序在遇到的第一个断点/异常处冻结 5分钟。冻结后,一切似乎按预期进行。造成冻结的原因是什么?



编辑:冻结是由外部程序引起的。查看接受的答案的评论。



5。图像文件执行选项

按照hmemcpy的建议,我还可以对自动启动调试器。这似乎与Debugger.Launch()相同,因为它显示相同的及时提示。但是,此准时化调试器根本无法调试:断点和异常将被忽略。另外,在使用发布版本时,我不能简单地禁用及时提示。



摘要

选项1加载断点,在断点/异常处中断,但花费太多时间。

选项2加载断点,在断点/异常处中断,但速度太慢。

选项3不会加载断点,并且不会在断点/异常处中断。

选项4会加载断点,但会在第一个断点/异常处冻结5分钟。

选项5不会t加载断点,并且不会在断点/异常处中断。



其他信息

外部程序和类库都是用VB.NET编写的,我使用的是Visual Studio 2010 Ultimate,目标框架是.NET Framework 4.0。



选项1和2对我有用,但是过一会儿,所有这些对话框和提示都变得令人讨厌,并拖慢了我的速度。选项3和4似乎更适合我,因此如果有人可以告诉我如何使它们工作,那将很棒。选项5似乎也没有那么有趣,我不想一直使用regedit.exe。如果还有其他选择,请告诉我。

解决方案

在以下情况下,您不能将该可执行文件设置为启动外部程序吗?调试?



Dll项目-属性-调试-启动外部程序...



编辑-对不起,我没有看到您已经在这样做:S


This is a question towards programmers who have experience with using Visual Studio 2010 for debugging external applications.

Currently, I'm developping an add-on for a program made by people I work for. In order to make this add-on work with the external program, I have to place the .dll file in a certain folder, specified by the external program. I have my build settings configurated so the .dll file is copied automatically. I also copy the .pdb file to enable debugging options.

Since this add-on is nothing but a class library, I can't debug it like I normally would. I also don't have the source code for the external application. How should I debug this class library properly?

This is what I tried:

1. Attach to Process
See Attach to a Running Process. This seems to work fine, except it takes a few seconds to set up. That's a problem, because most of the exceptions/breakpoints occur at the very first seconds of the start of the external program. It also becomes annoying to manually attach Visual Studio to a process, because I debug this class library a lot, thus taking a lot of time after a while.

2. Debugger.Launch()
Currently I use Debugger.Launch() to attach Visual Studio to the external program. This will display a Just In Time prompt, asking me which instance of Visual Studio I would like to use. I find this to be much slower than "Attach to Process", but this way I am sure that the debugger is attached before any breakpoints can occur. Placing this between #if DEBUG and #end if makes sure this popup doesn't show when I create a release build, which helps too.

3. Add as Existing Project
I've added the executable of the program as a project to my solution. By doing this I can set this executable as startup project, and pressing F5 will start it. The biggest advantage of this, is that I can now debug the executable as soon at is it is started. See: Debug an Executable Not Part of a Visual Studio Solution. With this, Visual Studio breaks at exceptions, but unfortunately it doesn't seem to load the breakpoints. The following information is shown when I try using breakpoints: The modules window displays: "Binary was not built with debug information.". Can this be solved?

4. Start Action
SilentDoc noted that I can also set an external program as start action, using Properties -> Debug -> Start Action. See: Change the Start Action for Application Debugging It appears to load the breakpoints correctly this way. However, for some reason this makes the external program freeze for 5 minutes at the first breakpoint/exception encountered. After it is done freezing, things seem to work as expected. What could cause this freeze?

Edit: the freeze was caused by the external program. See accepted answer's comments.

5. Image File Execution Options
As hmemcpy suggested, I can also use "Image File Execution Options" for Launching the Debugger Automatically. This seems to be the same as Debugger.Launch(), since it displays the same Just In Time prompt. However, this Just In Time "debugger" doesn't debug at all: breakpoints and exceptions are ignored. Also, when working with a release build, I can't simply disable the Just In Time prompt.

Summary
Option 1 loads breakpoints, breaks at breakpoints/exceptions, but takes too much time.
Option 2 loads breakpoints, breaks at breakpoints/exceptions, but is too slow.
Option 3 doesn't load breakpoints, and doesn't break at breakpoints/exceptions.
Option 4 loads breakpoints, but freezes for 5 minutes at first breakpoint/exception.
Option 5 doesn't load breakpoints, and doesn't break at breakpoints/exceptions.

Additional information
The external program and class library are both written in VB.NET, I am using Visual Studio 2010 Ultimate, and the target framework is .NET Framework 4.0.

Option 1 and 2 work for me, but after a while, all those dialogs and prompts become annoying, and slow me down. Option 3 and 4 seem more suitable for me, so if anyone can tell me how to get them to work, that would be great. Option 5 doesn't seem that interesting either, I don't want to be using regedit.exe all the time. If there are any other options, please let me know.

解决方案

Can't you set that executable as the Starting external program when debugging ?

Dll Project - Properties - Debug - Start External Program ...

EDIT - Sorry, I had not seen you're already doing that :S

这篇关于调试外部程序的库? (Visual Studio 2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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