07 February, 2007

Debugging DLL in Delphi

Yesterday I spend about an hour to figure out how to debug DLL in Delphi. It is really long time considering that I was doing this before. Google didn't help me a lot because all I have found wasn't really helpful.

I have found this solution in the Internet:

Until up to Win2k, you had to set the HostApplication on Start=>Parameter to debug a DLL. This will not work on Windows XP. That Delphi will know the DLL if you run the program, you have to do the following:
The program must load the DLL. After this, press Ctrl-Alt-M in Delphi, to list all modules. Sometimes there will be the DLL with path.
Solution:
Right click on the DLL, select "Reload symbols" and set the full path to the DLL. Now the breakpoints should be active.
When the DLL will be compiled in the system path (directory in PATH) this problem don't occur.

Not bad! But I have discovered for myself more easy and fast way. Next steps need to be done:

  1. In the Project Manager make your DLL project active and press Ctrl+Shift+F11;
  2. In the Project Options window which just appeared select Debugger node and on the right side of the window in the Host Application field specify the host application (press Browse button and select the application which use your library) and then close the dialog by pressing the Ok button;
  3. Then simply press F9 and be happy!

BTW, it is also good to set up dependencies of your main application which use the DLL you want to debug. You can read about this here.

14 comments:

Steve said...

Well I tried your method, but it doesn't work for me. Application runs, but I don't have breakpoints available in any of my Delphi DLL code. I think because I move my dll into the applications folder so it can use it. I tried setting the Project Options - Debugger - Working directory to the applications location. Then the Project Options - Directoris/Conditionals - Debug source path to my the directory of my Delphi DLL project. All this and it still didn't work.

iSkomorokh said...

Hello Steve. I'll try to help you when I get back home. Approximately next week.

Yusuf Celik said...

Thanks Igor.

Works for me!

Regards
Yusuf

Adrian said...

If you have done this and breakpoints still do not work, make sure that Delphi is using your DLL and not a pre-compiled version in Windows/System32. So, delete your DLL from this folder.

DeBuG said...

Perfect. I was able to debug a DLL called inside a component, which is inside another project. Got everything I need.

Btw, I was doing that on C++ Builder 6, not Delphi. Since both are similar in IDE behavior (thank god Borland :D), it worked very well (with a little modification on where I should set the host application).

Thx!

madhu said...

can you please help me out how to debug a dll application alone in delphi without using the exe

madhu said...

can you please help me out how to debug just a dll application in delphi without any exe.

Millan said...

I got this info about Delphi that i am searching.

KKO said...

Hi Steve,

I am trying to debug C++ Dll using Delphi 7 Professional. Since I am new in Delphi, I couldn't manage to find the right way for debugging unmanaged C++ dll.

I am looking forward to hearign from you soon.


Best regards

akki said...

I am also trying to debug C++ Dll using Delphi 7.
so can you please how can i debug C++ dll using Delphi...

Walter said...

Hello everyone, well, following this method (thanks iSkomorokh!!) I figured out how to make it work for me.
Here is a tip for those "delphi geeks" who use Hydra (from rembojects, I recommend them, they simplifies you life)and delphi 7.
In the proyect manager make your Hydra module active then go to Proyect options by pressing SHIFT+CTRL+F11, then select tabsheet "Compiler" and tick the option "Use debug DCU" there. Press OK. Afterwards go to "tools menu" and then "Debugger options..." When you are there, go to "debug DCU path" and press the button that is just to the right frm the combobox, to add the folder where your hydra module is in. Press ok to accept changes and that's all, now you're are able to debug your dll module.
Make sure that DCU and the DLL generated is in the same folder. You can change this settings in the project options in "directory/conditionals" tabsheet.
Hope it is helpfully for you.

Anonymous said...

Well, in my Delphi project, I have set "Include remote debug symbols" in Linker project options, and it worked for me as well.

Chris said...

Thanks Anonymous that worked on my COM Object DLL.

Anonymous said...

Thanks alot! works perfecly!!!! iiiuuupppppiiii


Not bad! But I have discovered for myself more easy and fast way. Next steps need to be done:

In the Project Manager make your DLL project active and press Ctrl+Shift+F11;
In the Project Options window which just appeared select Debugger node and on the right side of the window in the Host Application field specify the host application (press Browse button and select the application which use your library) and then close the dialog by pressing the Ok button;
Then simply press F9 and be happy!