How to simulate a Delphi breakpoint in code?

2020-02-08 04:02发布

I am pretty sure I have seen this before, but I haven't found out / remembered how to do it. I want to have a line of code that when executed from the Delphi debugger I want the debugger to pop-up like there was a break point on that line.

Something like:

FooBar := Foo(Bar);
SimulateBreakPoint; // Cause break point to occur in Delphi IDE if attached
WriteLn('Value: ' + FooBar);

Hopefully that makes sense. I know I could use an exception, but that would be a lot more overhead then I want. It is for some demonstration code.

Thanks in advance!

2条回答
Root(大扎)
2楼-- · 2020-02-08 04:21

To trigger the debugger from code (supposedly, I don't have a copy of delphi handy to try):

asm int 3 end;

See this page:

http://17slon.com/blogs/gabr/2008/03/debugging-with-lazy-breakpoints.html

查看更多
家丑人穷心不美
3楼-- · 2020-02-08 04:43

As Andreas Hausladen stated in comments to that artice, Win32 API DebugBreak() function is less DOS-ish and works equally well.

查看更多
登录 后发表回答