13

Sometimes when debugging, specifically when catching an exception and following through destructors called, Delphi steps through a lot of assembly code. Hit Shift+F8 appears to cause mayhem.

Can I tell the debugger to skip assembly code automatically?

3 Answers 3

9

In my experience, the vast majority of such assembly code is in VCL or RTL units.

If you compile with "Debug .dcu's" disabled then the debugger will not step through this code. However, it will also not step through any other VCL/RTL code either - assembler or Pascal. It will still step through any code that is not part of the VCL/RTL, assuming you have the Debug information option enabled for the project.

Compiler options dialog

Whether turning off VCL/RTL debug units makes debugging any particular issue you may have easier or harder will of course depend on your particular circumstances, but usually what is going on inside the VCL/RTL code is of little consequence unless and until you have eliminated the possibility of some error in your own code and then need to investigate a potential bug in the VCL/RTL itself.

For myself, I have "Debug .dcus" turned OFF unless I need them ON.

Your mileage may vary.

Sign up to request clarification or add additional context in comments.

2 Comments

Winner winner chicken dinner. Exactly what I was after. Thanks.
Also, an extra thank you for the screen shot. Very much demystified "turn off Debug .dcus" for a new guy like myself.
3

If you see assembler code, you probably are in the Alt-F2 CPU view. Just close the CPU view (escape key on old Delphi, or close its tabs), and you'll continue stepping within pascal source code (e.g. press F7 or F8).

If you see assembler code in the middle of a .pas file (in an asm ... end block), then you can try going to the end of it (at end level) and press F4 (shift F8 is buggy). But be aware that it may quit not at the end but in an internal ret assembler op code. So my personal advice is, if you do not know about assembler, to display the Call Stack (this window displays the function calls that brought you to your current program location and the arguments passed to each function call) and double-click on the parent caller. This will be always safe.

For additional info about debugging, this e.g. this article.

3 Comments

I could be wrong but - as reflected in my answer - I really don't think the OP means the "CPU Window" as he specifically talks about stepping through destructors. The debugger may open in the CPU Window but I don't think you will often find yourself stepping from source code into the CPU Window. Far more likely it refers to those routines in the VCL/RTL which are coded as inline assembler and invoked by "compiler magic" during procedure epilogue, such as FinalizeRecord etc.
@Deltics By default, you do not see this RTL source code lines. Only the CPU view will show you these asm lines. This is my 1st paragraph. Inside asm..end blocks (like the one you described), I gave in my 2nd paragraph a safe way to retrieve the caller.
if you have "Use debug DCU's" and are stepping through destructors then you will very often see RTL source code, especially if you are using reference types such as strings, dynamic arrays or interfaces as even your custom destructors (or other procedures) will have epilogue code injected by the compiler to call various RTL routines, many of which are coded as inline assembler. In any event, it appears from the OP's profuse thanks that my psychic socks were working well on this occasion. :)
0

You can use the {$D-} directive to switch off debugging for a block of code. I think this will allow you to achieve what you want.

Also - dont use shift F8 in assembly code, I believe it causes all sorts of trouble - better to place your cursor after the block and F4 down to that.

3 Comments

-1 {$D-} scope is global to the unit, so it won't work with a block of code.
This won't help if the code in question is in a VCL/RTL unit as these are precompiled and are not included in the build/compilation process. This is precisely why the "Use debug .dcu's" option is provided - it allows you to switch between $D+ and $D- versions of the VCL/RTL dcu's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.