So I want to put a Breakpoint in a specific API or Windows message. I don't find any easy way to do that without writing code in any Delphi version. Is there a way to do that similar as I can put a breakpoint in memory access?
The shortcut key that stops debugging (SHIFT+F5) stops the execution at the current position.
You can press F5 while debugging to jump to next breakpoint and F10 to jump line by line.
# Conditional line-of-code breakpoints Use a conditional line-of-code breakpoint when you know the exact region of code that you need to investigate, but you want to pause only when some other condition is true. To set a conditional line-of-code breakpoint: Click the Sources tab.
Debug | Stop Debugging. Click Stop Debugging on the Debug menu to stop the target's execution and end the target process and all its threads. This action enables you to start to debug a different target application. This command is equivalent to pressing SHIFT+F5 or clicking the Stop debugging (Shift+F5) button () on the toolbar.
You can tell the debugger which exceptions or sets of exceptions to break on, and at which point you want the debugger to break (that is, pause in the debugger). When the debugger breaks, it shows you where the exception was thrown.
If no debugging is available, the debugger statement has no effect. With the debugger turned on, this code will stop executing before it executes the third line. Normally, you activate debugging in your browser with F12, and select "Console" in the debugger menu.
Tell Debugger to Continue on User Unhandled Exceptions 1 In the Exception Settings window, open the shortcut menu by right-clicking a column label, and then select Show Columns... 2 To change this setting for a particular exception, select the exception, right-click to show the shortcut menu, and... See More....
To stop at any call to an API function, find it in the implementation
section of Windows.pas (or wherever the function of interest is declared) and set a breakpoint. That takes care of functions you use with load-time dynamic linking. For run-time dynamic linking (LoadLibrary
and GetProcAddress
), you'll need a different technique. The variable that gets the result of GetProcAddress
will hold the address you want to break at, but I don't know off-hand how to set a breakpoint at that address.
Stopping on a Window message is trickier since messages can be retrieved in many places. You'll have to use conditional breakpoints instead.
To catch most posted messages, you can put a breakpoint in TApplication.HandleMessage
on the first line after the call to PeekMessage
. Set the condition to be Msg.Message = x
. HandleMessage
takes care of messages posted to the main thread's message queue for the main Application.Run
message loop as well as the VCL's modal message loops. Other modal dialogs (such as Windows.MessageBox
) won't use it, though.
Observing sent messages is harder because the OS dispatches them to their target window procedures directly. You'll have to set a breakpoint in the window procedure of every window class you're interested in. You could get most VCL window classes by putting your conditional breakpoint in Classes.StdWndProc
.
Keep in mind that conditional breakpoints can be very slow. They work by the debugger putting an unconditional breakpoint there, and when the OS triggers it, the debugger takes over, checks the condition, and then resumes execution if the conditional fails. That can involve a lot of overhead, switching between the debugger and your application; programs receive lots of messages, so if you can find a way to avoid having the debugger interrupt your program to check every one of them, do it.
If this isn't feasible for whatever it is you're trying to debug, then I recommend posting a new question where you describe the problem you're really trying to solve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With