How to debug Delphi IDE?

北战南征 提交于 2019-12-06 20:21:01

问题


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).


回答1:


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:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/9644052/how-to-debug-delphi-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!