Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug an isapi extension using the delphi debugger?

Tags:

delphi

I am trying to debug an ISAPI extension written in Delphi. The extension works just fine, however I can't seem to debug it (ie set a breakpoint and singe-step the code).

Here is what I have done:

  • Launched Delphi Rad Studio as administrator.
  • Made sure the extension is loaded by accessing it in browser.
  • Selected run->attach to process.
  • Selected the w3wp.exe process (with "pause after attach" unchecked)
  • Set a breakpoint at the start of my default handler's action
  • Tried to access again the extension

However the breakpoint is never triggered in my handler (see pic below):

enter image description here

like image 750
BigONotation Avatar asked May 25 '17 22:05

BigONotation


People also ask

How do I debug an Isapi filter?

To debug an ISAPI extension using Visual StudioLaunch Visual Studio. In the Build menu, click Start Debug and click Attach to Process. Select the Show System Process check box. If your ISAPI extension is running in the IIS process, select the Inetinfo.exe process from the list and click OK.

How do I debug in Delphi?

Debugging delphi source files You need to go to "project->options->compiler" on this tab you need to check the "use debug DCUs". After that you need to build your project again and you can run your application. From now on breakpoints also stop in Delphi source files.


1 Answers

Your approach has a limited utility because you can only start debugging AFTER your application has started. If you need to debug it from the first request, this is useless. This is how you should do:

IIS Setup:

1) On IIS, create a new web application under Default Web Site.

2) Every application under Default Web Site should be using the same application pool, DefaultAppPool. Make sure that this application pool is able to run an ISAPI application without debugging. If you can't run an ISAPI application using it, you won't be able to debug it either.

Application Setup (Delphi IDE):

Setting up the application in Delphi (any XE+ IDE has similar settings)

1) Run Delphi as administrator. Not absolutely required but makes lots of things easier and avoids lots of issues.

2) In Delphi Ide, choose Run -> Parameters. Inform Host application and Parameters as you can see in the following picture:

Delphi App setup for ISAPI debugging W3WP.exe is the IIS Worker Process executable, and we will run it interactively to debug the ISAPI app. Remember that 2 versions of w3wp.exe exist: one 32-bit under C:\Windows\SysWow64 and another 64-bit under C:\Windows\System32. You must use the correct version that matches your application.

3) Stop World Wide Web Publishing Service. You may use "net stop W3SVC" from an elevated command prompt, or use the Windows services console.

Once the W3SVC is stopped, just run the application from Delphi IDE and call it from your browser. When the application should load and all your breakpoints will be activated. You can debug like any other Delphi application.

like image 78
Alexandre M Avatar answered Oct 09 '22 15:10

Alexandre M