Better debugging with aspect generated code

When you have an assembly aspect that changes the code of a method, and this code fails (or shows a failed assert), the debugger shows the aspect as current code line.

Example source code:

[assembly: MyAspect]

method MyMethod;
begin
    //some code
end;

The aspect MyAspect changes the code of MyMethod to:

method MyMethod;
begin
    System.Diagnostics.Debug.Assert(false, 'the error'); //inserted by the aspect, not in the source code
    //some code
end;

When MyMethod is executed, the assert is shown, but the debugger breaks on the line:

[assembly: MyAspect]

instead of (what should be more logical for debugging) on the line

method MyMethod;

Is it possible to change this behavior?

Wouldn’t that be even more confusing though?

No, less - it should stop in the code is executed, not where the code generation is executed

Right, but the line its stopping at doesn’t exist in that code…

So then better stop in a complete other unit?
Instead of as close as possible to the real problem line?

im just putting the thought out.

if I had

method MyMethod;
begin
    writeLn("Hello").
end;

and it would break on the writeLn with “the error”, I’d be confused AF.

But it confuses me when the code breaks on the [assembly:MyAspect] line in assembly.pas, while the call stack window says that the code is in mycode.pas, and when I doubleclick on the line in the call stack window, it goes to assembly.pas instead of mycode.pas - while it is stating that the error occurred in mycode.pas, method myMethod.

There are four possibilities:

  1. I added code before the original body -> this should stop on the begin statement of the body
  2. I added code after the original body -> this should stop on the end statement of the body
  3. I replaced the complete body -> this should stop on the begin statement of the body
  4. I added a complete new method -> this can stop on the aspect line as there is no method in the source

But not important enough to waste your time on today.
Have a nice evening tonight and a good flight tomorrow!

We talk about this later :smile:

In the end int comes down to what Carlo thinks about this; I don’t feel strongly. I just wanted to make the point that it’s not clear-cut :wink:

thanx! see you when I get back!