Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate a Delphi breakpoint in code?

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!

like image 220
Jim McKeeth Avatar asked Oct 02 '08 04:10

Jim McKeeth


People also ask

How do you breakpoint in code?

To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

How do you breakpoint in Delphi?

Using of Breakpoints We can put break point by pressing the F5 button or clicking on the left bar in your code editor, it will put a red point to your source code line. When running the program, the execution will stop when it passes the source line.

How do I debug Delphi code?

Debugging delphi source files You need to go to "project->options->compiler" on this tab you need to check the "use debug DCUs". After that you need to build your project again and you can run your application. From now on breakpoints also stop in Delphi source files.

How do you set a breakpoint to a program?

You can set a breakpoint at a line number, using the stop at command, where n is a source code line number and filename is an optional program file name qualifier. If the line specified is not an executable line of source code, dbx sets the breakpoint at the next executable line.


2 Answers

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

like image 181
Joeri Sebrechts Avatar answered Sep 26 '22 00:09

Joeri Sebrechts


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

like image 24
gabr Avatar answered Sep 23 '22 00:09

gabr