Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Debugging DLLs

Posted on 2003-11-18
Medium Priority
Last Modified: 2010-04-05
D7Pro... wrote a DLL myself and attempting to use the DLL in another program which I'm also writing, so I have full source for both. The problem is something falls over in the DLL and I cannot use the debugger to find out exactly where and why. I've followed the Delphi help which goes as follows:

"The following topics cover issues when debugging DLLs.

Specifying the host executable

When debugging a DLL, you don’t need to add the host executable file to a project to debug it. You can specify a path name to the executable by selecting Run|Parameters and entering the path to the executable in the Host application edit box. Press the Load button to load the executable in the debugger.

Using Module load breakpoints when debugging DLLs

Use Module load breakpoints to halt an application when it loads a specified DLL. To set a Module load breakpoint either:

Select either Run|Add Breakpoint|Module Load Breakpoint
      Choose View|Debug Windows|Modules to display the Modules window and right-click anywhere in the upper-left pane and select Add Module

Then in the Add Module dialog box, enter the module name of the DLL or click Browse to find the DLL. Click OK. When the application loads the specified DLL, the application will halt.

Setting a debug source path

The debug source path is specified under Project|Options|Directories\Conditionals. Debug source paths for modules in the current project, or project group, are automatically set. If you are debugging modules (executables, DLL) in different projects or projects groups, you need to add the debug source path for each module that is not part of the current project group.

Locating symbol files

All dcp files must be located in the Debug Symbols Search Path (set on General page of the Tools|Debugger Options)."

I can set a breakpoint in Delphi on a line with a blue dot. As soon as I choose Run or Load Module, that blue dot disappears and the line is never stopped at (although I know damn well it is using it). The program itself runs fine (apart from the error inside the DLL).

I've set the debug search paths to everywhere possible (source of the exe, source of the DLL). All the debugging options are on for both the DLL and the EXE.

Any ideas?

Geoff M.
Question by:gmayo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
LVL 12

Expert Comment

ID: 9770335
DLL debugging always seems to be a little hit-and-miss in Delphi...

Make sure you compiled the DLL with full debug enabled.

Make sure you compile your client application with full debug enabled.

Tyhpically, I DON'T debug the DLL with a host appplication - I debug the client application, and it seems to be able to walk into a DLL.

Breakpoint in the client on a line that calls a DLL function. Step into the call (F7). It might ask you to find the source file - Do it. Then usually it works....

I think there's a little black magic involved, somewhere.

If you lose breakpoint dots, delete all the .dcu and .tds files, and do a full rebuild of both projects. That sometimes helps...

Author Comment

ID: 9770360
Sorry, this question is awaiting deletion. I found the solution: even though Delphi built and compiled one DLL, it actually ran with another DLL in another directory. Why, I don't know. Deleting the other DLL worked.

Thanks anyway.

Geoff M.
LVL 12

Expert Comment

ID: 9770386
You can delete them yourself if there haven't been any comments added!

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 17

Expert Comment

by:Wim ten Brink
ID: 9777841
Suggestion: how about PAQ'ing this question and refund the points to gmayo? This is a very typical error when people decide to debug a DLL and I have seen a very frustrated collegue dealing with a similar error in the past.
Btw... That other directory, is that part of your 'PATH' environment variable? Is it e.g. in your C:\WinNT or C:\WinNT\System32 folder? :-) My collegue had this problem. He expected the DLL in his project folder to be used but instead he ran the one in the C:\WinNT\System32 folder.

Oh, a reminder from thw Windows platform SDK:

When no path is specified, the function searches for -> loaded modules <- whose base name matches the base name of the module to be loaded. If the name matches, the load succeeds. Otherwise, the function searches for the file in the following sequence:

1) The directory from which the application loaded.
2) The current directory.
3) The system directory. Use the GetSystemDirectory function to get the path of this directory.
    Windows NT/2000/XP:  The name of this directory is System32.
    Windows NT/2000/XP: The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
4) The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
5) The directories that are listed in the PATH environment variable.

Windows XP:  If HKLM\System\CurrentControlSet\Control\SessionManager\SafeDllSearchMode is 1, the current directory is searched after the system and Windows directories, but before the directories in the PATH environment variable. The default value is 0 (current directory is searched before the system and Windows directories).

This was just a little advise, free of charge. :-)
LVL 17

Expert Comment

by:Wim ten Brink
ID: 9777848
Of course, deletion of this question is also still possible... :-)

Author Comment

ID: 9778207
The app was in one directory, C:\TMS, and the DLL was in another directory, C:\TRESISDLL. The DLL had been copied to the C:\TMS directory to enable that to run. But when compiling the DLL, the version it compiled was put into the C:\TRESISDLL directory but run from the C:\TMS directory. Probably like (1) and (2) you mention above.

To be honest, I think Borland have fallen down in this respect. There is no mention in their help files of such a thing possibly happening.

If everyone would prefer this question to be awarded points and PAQd, then that's fine by me (I've got unlimited points anyway!).

Geoff M.

Author Comment

ID: 9781219
Okay, that's fine by me. Thanks.

Geoff M.

Accepted Solution

Lunchy earned 0 total points
ID: 9799778
PAQed, with points refunded (250)

Friendly Neighbourhood Community Support Admin

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question