Dennis’s Weblog

Debug-Attach to process

Posted on: March 18, 2009

1.use NUNIT

a.install NUNIT

b.Write a test class in our project, remember to import the NUNIT.core and NUNIT.framework

c.Then open the project in NUNIT UI.

d.open the project in visual studio 2005, and then set the breakpoint at the position that you want to debug.

e.in NUNIT execute the function that you want to debug.

//Attatch to process used the attached the library that will be generated by current project to the process that will call this library,

Because of the invocation, the debug code will be triggered.

 

When want to debug a webapplication with build unit test, you should follow this:

debug the program,

and leave the aspnet_webserver alive(don’t close it).

//(don’t need) and then stop the debug,after that navigate to the unit test function,

//(don’t need) Web then attach all the code the webserver.exe process,

and click debug the unit test.

 

为什么用attach to process呢?其实我们生成的都是一些DLL文件,里面只是一些供调用的函数,所以只有attach to process,在那个process中会以各种方式调用我们DLL中的函数,从而触发DLL中的函数,并定位到breakpoint.

以下的Webserver debug,调用的方法是通过因特网访问。

2.

In this tutorial we shall talk of debugging managed code using the Visual Studio .Net debugger .

To debug managed code, you need to have the Machine Debug Manager(mdm.exe) service running on your remote server. To check if MDM is installed, Click Start -> Programs -> Administrative Tools -> Services . Scroll down to see if Machine Debug Manager is running. If it is not, you need to install it. To install MDM, run Visual Studio .Net setup. Click on the Remote Components Setup.

The below screen opens up ->

Scroll down ->

For managed code debugging, you need to install full remote debug components .Click the ‘Install Full’ button ->

Once the installation is complete, verify that the MDM service is running.

Next you need to find out with what id the ASP.Net worker process is running. If this is running with the same id with which you are logged on to your client machine, then it is enough if your id is part of the debugger group on the server. If not, to debug the worker process, you need to have administrative access on the remote server. The worker process runs with the ASPNET account by default. To change the account with which the worker process runs, you need to modify the machine.config file – and that would be different topic in itself. Let us assume that you have administrative access on the remote server, that is, the id with which you are logged onto the client, is part of the administrator group on the remote server.

Open a Visual Studio Instance. Click Tools -> Debug Processes . The processes window opens up à

In the Name text box , type in the name of the remote server and press Enter.

The list of available processes is shown as below –

Select the aspnet_wp.exe, which is the ASP.Net worker process. Click Attach. The below screen pops-up. Make sure Common Language Runtime checkbox is checked. In the list below, where it shows ‘The below programs will be debugged’ you should see a list of sites on the server that are debuggable. The application that you are trying to debug

should also be listed in it. If it is not, then probably the web.config file has the debug option disabled. Open up the web.config file and check the compilation attribute à

Change the debug attribute to true. On attaching the debugger to the worker process, your application should be listed now.

Click OK on the Attach to process window. Click Close on the Process window.

On the visual studio instance, click File -> Open . Open the file(s) that you wish to debug. For example, I want to debug the webservice1 application, which runs a vb file called service1.asmx.vb. I want to debug the webmethod . I put a breakpoint in webmethod1()

Next, I need to execute the webservice so that my breakpoint gets hit and I can debug.

Open up an Internet Explorer window and type http://RemoteServer/WebService1/service1.asmx

I click the async method

Click Invoke. And Yo ! Visual Studio pops-up with the breakpoint highlighted à

Congratulations ! You are now ready to debug !!

———————————————————————————————–

Dated 25th Nov 2004

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: