Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is any quick way to, while debuging, to stop at a specific Windows Message or API?

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?

like image 985
EMBarbosa Avatar asked Feb 28 '12 01:02

EMBarbosa


People also ask

What is the shortcut to stop debugging?

The shortcut key that stops debugging (SHIFT+F5) stops the execution at the current position.

Which debugging shortcut will you use to go inside a function while debugging using breakpoint in JS?

You can press F5 while debugging to jump to next breakpoint and F10 to jump line by line.

What feature do you use to pause the execution of the code at a specific line number only when something is true?

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

How do I stop debugging in Visual Studio Code?

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.

How do I tell the debugger to break an exception?

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.

What happens if there is no debugger in the browser?

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.

How to enable debugger to continue on user unhandled exceptions?

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


1 Answers

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.

like image 134
Rob Kennedy Avatar answered Oct 06 '22 00:10

Rob Kennedy