How to debug Delphi IDE?

别等时光非礼了梦想. 提交于 2019-12-05 01:46:09
Cosmin Prund

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.

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.

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.

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

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