Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: How to debug run until you get back to your source file?

If I run a program and an exception is raised I am asked if I want to continue or break.

If I choose break I can see where the exception is coming from but if the break is in a library or system file not one of my source files (Say the exception is in System.pas or Controls.pas) I need to manually step the execution forward using F8 until it returns to one of my files, so I can see what part of my code caused the exception.

This can take a long time.

I know I should be catching lower level exceptions in my code but in this instance it's not hitting one of my exception handlers.

Is there a way to say

  • run forward with execution until you get to file X or
  • until you get back into a project specific file.

I'm also interested out of general curiosity on how other compilers / IDEs handle this.

Apologies if I haven't made this as clear as a I should.

like image 746
SamH Avatar asked Apr 20 '09 10:04

SamH


3 Answers

You can resolve this by using the Stack View window.

  1. Open the Stack View window (CTRL+ALT+S).
  2. Double click on the method in the stack view where you wish to insert a breakpoint.
  3. The unit, containing the caller method opens and the cursor is positioned on the caller method.
  4. Set your breakpoint.
like image 101
Lieven Keersmaekers Avatar answered Oct 20 '22 14:10

Lieven Keersmaekers


There's an even simpler way than Lieven's suggestion. Follow the first 3 steps as he laid them out, but don't place a breakpoint.

The problem with placing a breakpoint is that you have to clear it afterwards or you'll end up getting dropped into the debugger every time you pass that line. If you only want to run to a certain line and then drop to the debugger once, put the cursor on that line (the insertion point, not the mouse cursor) and press F4 (Run to Cursor). It's like a one-time breakpoint.

like image 5
Mason Wheeler Avatar answered Oct 20 '22 14:10

Mason Wheeler


There are several ways:

  1. Use the "Next source line" function (Shift+F7)
  2. Use the call stack and double-click on the function you need, add a breakpoint there and hit "Run" (F9).
  3. Use the "Step out" (Shift+F8) function until you are back into your own code.
like image 3
Daniel Rikowski Avatar answered Oct 20 '22 13:10

Daniel Rikowski