Mastodon
Programmierung

D5: Debugging DLL on WinXP?

Q: cannot debug DLLs with Delphi5 and WindowsXP

A:
Several threads address this issue, and here is the solution. The
problem is restated here and three workarounds are given. Please keep
in mind that these solutions are from my experience on one Windows XP
machine. You may have different experiences in your environments.

-Sam

PROBLEM

When debugging a DLL in Delphi 5 on Windows XP, you are unable to set
breakpoints in the code. Delphi will stop execution when exceptions
are thrown, but it is unable to find the line of source that matches
up with the exception.

This is problem is not specific to an isapi DLL. It can happen with a
regular DLL too. It is caused when the DLL is built to a directory
different than the one the DPR file is in, which happens to be the
case more often with an isapi DLL because you want to build to your
webserver’s scripts or isapi directory.

When Delphi attempts to load the symbol table for the DLL, it fails so
it can’t set any breakpoints. You can see this if you open the View |
Debug Windows | Modules dialog. Find the entry for your DLL. It will
not have a Path specified. If you right click on your DLL and choose
“Reload Symbol Table…” you will be prompted to specify a path to the
DLL. It will default in the name of you DLL and if you click OK
without specifying the path you will get an error indicating that
Delphi was unable to find your DLL. This is exactly the problem.

This problem is not specific to the webservers OmniHttpd or IIS.

It does not help to add the DLL’s directory to the system path or to
Delphi’s search path, or to the project’s search path. It also does
not help to run Delphi or your DLL’s host application under XP’s
compatibility modes for other version’s of Windows.

SOLUTION A

Build your DLL to the same directory as the DPR file. If you just set
the “Output Directory” entry to be empty on the
Directories/Conditionals tab of the project options, then this will
automatically happen.

Either use this directory as your webserver’s scripts or isapi
directory, or move the DPR/DOF/CFG/RES files to your webserver’s
scripts or isapi directory. If you do the later through the Delphi
menu option File | Save Project As, the Delphi will fix up the
directories of your source files in the uses section of the DPR for
you. It is not necessary to move the PAS files.

That should be it. Build and debug happily ever after. The only
downside to this is that you have to either change your webserver
setup or move your project file to your scripts or isapi directory
which is a annoying if you are using a source control system and you
are the only one with this setup.

SOLUTION B

Before compiling, change the linking options of your project to
include Remote Debugging Symbols.

Before debugging, open a file (an empty text file will do) from the
directory your DLL is in. That directory will become the current
directory for Delphi. When you start debugging, Delphi will correctly
find your DLL and load its Symbol Table because it is in this
directory.

I don’t like this solution because you have to always make sure that
the directory your DLL is in always the current directory for Delphi
before debugging.

SOLUTION C

Before compiling, change the linking options of your project to
include Remote Debugging Symbols.

After you have started to debug, open the View | Debug Windows |
Modules dialog. Find the entry for your DLL. If this is an isapi
DLL, make sure you have made a request to the webserver so your DLL
will already be loaded, otherwise you won’t find it in this list.
Right click on your DLL and choose “Reload Symbol Table…” and enter
in the full path and filename for your DLL and click OK. This will
then properly load the Symbol Table.

A downside to this solution (other than you have to do it every time)
is that you can’t debug any code the executes when your DLL is first
loaded.

Solution D

I can’t get any of the solutions to work, the only thing that works is when
I manually define the dll path in View\DebugWindows\Modules.

->Just wanted to tell you I got it working. I checked Remote Debug info in the
linker tab, and now it works!

Cheers,
Thomsen

In German / Auf Deutsch:

Hier noch eine Zusammenfassung die ich im Internet gefunden habe:

Da Delphi 6 (Anmerkung: es betrifft Delphi5 genau so) 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:
1. Host-Anwendung liegt im gleichen Verzeichnis wie die zu debuggende DLL
2. Menüpunkt Ansicht | Debug-Fenster | Module | Symbol-Tabelle neu laden | Durchsuchen -> Pfad der DLL angeben
3. Alle Sourcecode-Dateien in das DLL-Verzeichnis kopieren und das Projekt in diesem Verzeichnis öffnen (so dass Delphi alle Dateien finden kann).
4. 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.

0 Kommentare zu “D5: Debugging DLL on WinXP?

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.