12
votes

What are the detailed steps on how to debug the Delphi IDE?

I understand, from other posts, that one needs to create a project and, in the project's debugger settings, set the project's "host application" to Delphi (C:\Program Files\Borland\BDS\3.0\Bin\bds.exe). Then, when the project is run in the debugger (by pressing the F9 key), a second instance of the Delphi IDE should appear.

I have managed to do the above step. However, when I run the project in debugger mode, I don't see any second instance of the Delphi IDE opening.

Motivation

There is a VCL component, for which I do have the source code, that builds, compiles and installs fine. But, when it is placed on a form in a project, Delphi hangs when you close the form. So, I want to find out why Delphi is freezing on exit with this component on a form. (It hangs at design-time, when closing the project).

4
What do you mean by debug: seeing the other process (the second IDE) running under the debugger (the first IDE), or do you actually want to find and remove a certain bug? Asking because the question and title make it look like you want to debug the IDE itself! You can surely see it running under your debugger, but finding and removing bugs is an other story: you need source code for that, and you don't have source code for the IDE!Cosmin Prund
Sorry for not being clearer. There is a VCL component, for which I do have the source code, that builds, compiles and installs fine. But, when it is placed on a form in a project, Delphi hangs when you close the form. So, I want to find out why Delphi is freezing on exit with this component on a form.user1202134
I added your clarifications as an edit to the question itself, because that's where everyone will look for clarifications. Asking for more clarifications: Are you saying you've got a DPK as the only active project, you set it's host application to the Delphi IDE, hit Run and it doesn't launch the IDE? Does it do anything else? Example: does it give you an error message?Cosmin Prund
Take a look at something like CodeSite from Raize. Add Codesite.Send lines for all the parameters and ins and outs of your component's operation. There is an IDE utility to help do this for all functions. This will help you learn what is happening, and why. And it doesn't interfere with the operation like popping up messageboxes etc.mj2008

4 Answers

10
votes

Your project is most likely an EXE-type. EXE type projects don't need host applications so the setting is ignored, no other IDE is started. At a minimum, you should make your project a DLL-type: that will start the second IDE, but it will not be very helpful.

The technique you mentioned is usually used to debug your design time package projects. Create a design-time package project, install it into the IDE, set the project's host application to be the IDE, set some breakpoints, hit F9 and a second copy of Delphi will start.

You can also "debug" the Delphi IDE by manually starting a second copy yourself and then using the "Attach to process" command from the "Run" menu, but that's not going to be very useful since you can't easily find your code to set a breakpoint.

2
votes

I would first check if the hang occurs at run-time as well as at design-time. Instantiate the component dynamically in your run-time code. If the hang sstill occurs, then you can step through the component's source code normally using a single debugger instance. You do not need to debug into a running IDE instance unless the behavior only occurs within the IDE process.

1
votes

First find and open the component packages, turn both the runtime and designtime package build options from Release to Debug, if they aren't already, and rebuild.

Then save a project group containing both the package projects (one designtime and one runtime, in some exceptional cases, people only have one package, which is designtime+runtime in one).

Then follow the steps to set BDS.exe as the Host Application.

I would be tempted to add some OutputDebugString messages to the component that you know is broken:

Constructor:

constructor TMyComponent.Create(AOwner:TComponent);
begin
    inherited;
    // other stuff.
    OutputDebugString('Created TMyComponent');
end;

Destructor:

destructor TMyComponent.Destroy(AOwner:TComponent);
begin
    OutputDebugString('Destructor TMyComponent starts');
    inherited;
    // other stuff.
    OutputDebugString('Destructor TMyComponent finish');
end;

Finalization section of the unit that TMyComponent is in:

 finalization
      OutputDebugString('Finalization section for Unit MyComponentUnit');
 end.

Looking at the output Events page in the delphi debugger, you can figure out how far the code got, and even if you don't get an exception breakpoint that you can use to locate the flaw fairly accurately, you can use either OutputDebugString messages like the above, or you can even just set Non Breaking Breakpoints in delphi, and turn off the breakpoint property "Break on exception" and instead set up a "log message". These messages (breakpoint messages) have the benefit of not requiring any damage to your component in order to add some simple "print-statement-debug" like capabilities to your debugging toolkit.

1
votes

If the second instance of Delphi is not launching then you have the path to bds.exe incorrect.