# Better debugging with aspect generated code

**URL:** https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565
**Category:** Oxygene
**Tags:** aspects
**Created:** [October 18, 2019, 2:37pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565 "2019-10-18T14:37:00Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Theo69](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@Theo69](https://talk.remobjects.com/u/Theo69)
#### Post date: [October 18, 2019, 2:37pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/1 "2019-10-18T14:37:00Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [October 18, 2019, 4:02pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/2 "2019-10-18T16:02:34Z")

</div>

> [@Theo69](#):
>
> instead of (what should be more logical for debugging) on the line
> 
> ```auto
> method MyMethod;
> 
> ```

Wouldn’t that be even more confusing though?

---

<div class="post-metadata">

### Author: ![Theo69](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@Theo69](https://talk.remobjects.com/u/Theo69)
#### Post date: [October 18, 2019, 4:04pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/3 "2019-10-18T16:04:53Z")

</div>

No, less - it should stop in _the code is executed,_ not where the _code generation_ is executed

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [October 18, 2019, 4:09pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/4 "2019-10-18T16:09:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Theo69](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@Theo69](https://talk.remobjects.com/u/Theo69)
#### Post date: [October 18, 2019, 5:15pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/5 "2019-10-18T17:15:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [October 18, 2019, 6:33pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/6 "2019-10-18T18:33:40Z")

</div>

im just putting the thought out.

if I had

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

```

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

---

<div class="post-metadata">

### Author: ![Theo69](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@Theo69](https://talk.remobjects.com/u/Theo69)
#### Post date: [October 18, 2019, 7:19pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/7 "2019-10-18T19:19:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Theo69](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@Theo69](https://talk.remobjects.com/u/Theo69)
#### Post date: [October 18, 2019, 7:23pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/8 "2019-10-18T19:23:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Theo69](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@Theo69](https://talk.remobjects.com/u/Theo69)
#### Post date: [October 18, 2019, 7:28pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/9 "2019-10-18T19:28:45Z")

</div>

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 😄

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [October 19, 2019, 12:37pm UTC](https://talk.remobjects.com/t/better-debugging-with-aspect-generated-code/20565/10 "2019-10-19T12:37:05Z")

</div>

> [@Theo69](#):
>
> But not important enough to waste your time on _today_ .

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 😉

> [@Theo69](#):
>
> Have a nice evening tonight and a good flight tomorrow!
> 
> We talk about this later 😄

thanx! see you when I get back!
