{"id":167,"date":"2007-05-12T16:31:01","date_gmt":"2007-05-12T14:31:01","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/d5-debugging-dll-on-winxp\/"},"modified":"2007-10-18T15:44:30","modified_gmt":"2007-10-18T13:44:30","slug":"d5-debugging-dll-on-winxp","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/d5-debugging-dll-on-winxp\/","title":{"rendered":"D5: Debugging DLL on WinXP?"},"content":{"rendered":"<p><em>Q: cannot debug DLLs with Delphi5 and WindowsXP<br \/>\n<\/em><\/p>\n<p>A:<br \/>\nSeveral threads address this issue, and here is the solution.  The<br \/>\nproblem is restated here and three workarounds are given.  Please keep<br \/>\nin mind that these solutions are from my experience on one Windows XP<br \/>\nmachine.  You may have different experiences in your environments.<\/p>\n<p>-Sam<br \/>\n<!--more--><br \/>\n<b>PROBLEM<br \/>\n<\/b><br \/>\nWhen debugging a DLL in Delphi 5 on Windows XP, you are unable to set<br \/>\nbreakpoints in the code.  Delphi will stop execution when exceptions<br \/>\nare thrown, but it is unable to find the line of source that matches<br \/>\nup with the exception.<\/p>\n<p>This is problem is not specific to an isapi DLL.  It can happen with a<br \/>\nregular DLL too.  It is caused when the DLL is built to a directory<br \/>\ndifferent than the one the DPR file is in, which happens to be the<br \/>\ncase more often with an isapi DLL because you want to build to your<br \/>\nwebserver&#8217;s scripts or isapi directory.<\/p>\n<p>When Delphi attempts to load the symbol table for the DLL, it fails so<br \/>\nit can&#8217;t set any breakpoints.  You can see this if you open the View |<br \/>\nDebug Windows | Modules dialog.  Find the entry for your DLL.  It will<br \/>\nnot have a Path specified.  If you right click on your DLL and choose<br \/>\n&#8220;Reload Symbol Table&#8230;&#8221; you will be prompted to specify a path to the<br \/>\nDLL.  It will default in the name of you DLL and if you click OK<br \/>\nwithout specifying the path you will get an error indicating that<br \/>\nDelphi was unable to find your DLL.  This is exactly the problem.<\/p>\n<p>This problem is not specific to the webservers OmniHttpd or IIS.<\/p>\n<p>It does not help to add the DLL&#8217;s directory to the system path or to<br \/>\nDelphi&#8217;s search path, or to the project&#8217;s search path.  It also does<br \/>\nnot help to run Delphi or your DLL&#8217;s host application under XP&#8217;s<br \/>\ncompatibility modes for other version&#8217;s of Windows.<\/p>\n<p><b>SOLUTION A<br \/>\n<\/b><br \/>\nBuild your DLL to the same directory as the DPR file.  If you just set<br \/>\nthe &#8220;Output Directory&#8221; entry to be empty on the<br \/>\nDirectories\/Conditionals tab of the project options, then this will<br \/>\nautomatically happen.<\/p>\n<p>Either use this directory as your webserver&#8217;s scripts or isapi<br \/>\ndirectory, or move the DPR\/DOF\/CFG\/RES files to your webserver&#8217;s<br \/>\nscripts or isapi directory.  If you do the later through the Delphi<br \/>\nmenu option File | Save Project As, the Delphi will fix up the<br \/>\ndirectories of your source files in the uses section of the DPR for<br \/>\nyou.  It is not necessary to move the PAS files.<\/p>\n<p>That should be it.  Build and debug happily ever after.  The only<br \/>\ndownside to this is that you have to either change your webserver<br \/>\nsetup or move your project file to your scripts or isapi directory<br \/>\nwhich is a annoying if you are using a source control system and you<br \/>\nare the only one with this setup.<\/p>\n<p><b>SOLUTION B<br \/>\n<\/b><br \/>\nBefore compiling, change the linking options of your project to<br \/>\ninclude Remote Debugging Symbols.<\/p>\n<p>Before debugging, open a file (an empty text file will do) from the<br \/>\ndirectory your DLL is in.  That directory will become the current<br \/>\ndirectory for Delphi.  When you start debugging, Delphi will correctly<br \/>\nfind your DLL and load its Symbol Table because it is in this<br \/>\ndirectory.<\/p>\n<p>I don&#8217;t like this solution because you have to always make sure that<br \/>\nthe directory your DLL is in always the current directory for Delphi<br \/>\nbefore debugging.<\/p>\n<p><b>SOLUTION C<br \/>\n<\/b><br \/>\nBefore compiling, change the linking options of your project to<br \/>\ninclude Remote Debugging Symbols.<\/p>\n<p>After you have started to debug, open the View | Debug Windows |<br \/>\nModules dialog.  Find the entry for your DLL.  If this is an isapi<br \/>\nDLL, make sure you have made a request to the webserver so your DLL<br \/>\nwill already be loaded, otherwise you won&#8217;t find it in this list.<br \/>\nRight click on your DLL and choose &#8220;Reload Symbol Table&#8230;&#8221; and enter<br \/>\nin the full path and filename for your DLL and click OK.  This will<br \/>\nthen properly load the Symbol Table.<\/p>\n<p>A downside to this solution (other than you have to do it every time)<br \/>\nis that you can&#8217;t debug any code the executes when your DLL is first<br \/>\nloaded.<\/p>\n<p><b>Solution D<br \/>\n<\/b><br \/>\nI can&#8217;t get any of the solutions to work, the only thing that works is when<br \/>\nI manually define the dll path in View\\DebugWindows\\Modules.<\/p>\n<p>->Just wanted to tell you I got it working. I checked Remote Debug info in the<br \/>\nlinker tab, and now it works!<\/p>\n<p>Cheers,<br \/>\nThomsen<\/p>\n<p><strong>In German \/ Auf Deutsch:<br \/>\n<\/strong><br \/>\nHier noch eine Zusammenfassung die ich <a target=\"_blank\"  href=\"http:\/\/entwickler-forum.de\/archive\/index.php\/t-24727.html\">im Internet<\/a> gefunden habe:<\/p>\n<blockquote><p>Da Delphi 6 <em>(Anmerkung: es betrifft Delphi5 genau so)<\/em> an vielen Stellen nicht mehr Up-to-date ist, was Windows XP angeht, muss man zu Kompromissen greifen. Es stehen gleich 4 Workarounds zur Auswahl: <br \/>\n1. Host-Anwendung liegt im gleichen Verzeichnis wie die zu debuggende DLL <br \/>\n2. Men\u00fcpunkt Ansicht | Debug-Fenster | Module | Symbol-Tabelle neu laden | Durchsuchen -> Pfad der DLL angeben<br \/>\n3. Alle Sourcecode-Dateien in das DLL-Verzeichnis kopieren und das Projekt in diesem Verzeichnis \u00f6ffnen (so dass Delphi alle Dateien finden kann).<br \/>\n4. ImageBase-Adresse der DLL auf der Linker-Seite auf einen Wert setzen, der im Host-Prozess garantiert frei ist, so dass Win32 die RVAs der DLL nicht neu setzen muss.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Q: cannot debug DLLs with Delphi5 and WindowsXP A: Several threads address this issue, and here is the solution. The problem is restated&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[105,75,97,104],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-2H","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/167"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=167"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/167\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}