Visual D return BP
Rainer Schuetze
r.sagitario at gmx.de
Thu Aug 15 18:23:25 UTC 2019
On 11/08/2019 11:47, Bert wrote:
> if (x)
> return
>
> do()
>
> putting a BP on return will cause the BP to hit jump to do on execution
> no matter the value of x. This is very annoying ;/
>
> I know this has been brought up before and supposedly it is an issue
> with D itself.
>
> Can anything be done about it? It is not sane. No programming language I
> have ever used works this way.
>
> 00007FF6BEC8FC6C cmp rcx,rax
> 00007FF6BEC8FC6F je foo+48h (07FF6BEC8FC78h)
> 00007FF6BEC8FC71 pop rsi
> 00007FF6BEC8FC72 pop rbx
> 00007FF6BEC8FC73 mov rsp,rbp
> 00007FF6BEC8FC76 pop rbp
> 00007FF6BEC8FC77 ret
> return;
>
> Do();
> 00007FF6BEC8FC78 mov rcx,qword ptr [this]
> 00007FF6BEC8FC7C sub rsp,20h
> 00007FF6BEC8FC80 mov rax,qword ptr [rcx]
> 00007FF6BEC8FC83 call qword ptr [rax+78h]
> 00007FF6BEC8FC87 add rsp,20h
>
>
> There is definitely assembly code that should be able to have a BP put
> at it to make it all work. The way it works, one is forced to add junk
> code simply to get a BP to work correctly in to a very common
> programming semantic.
In this example it could work, but the code after the jump is not
associated with the return statement, but it is a duplication of the
epilog of the function that is considered to have the location of the
closing brace. In debug builds the compiler should avoid these kind of
optimizations and insert/keep a jump to the end of the function.
>
> It seems more like a bug to me, like somehow the BP gets added after the
> return rather than before it.
>
> I'm not sure how it couldn't work, you mentioned something about the D
> language, optimizations, and Walter refusing to allow it to work. Surely
> there is some way to get this to function correctly?
>
> Thanks
>
It's not a problem of the language, but the compiler implementation. I
recently filed a bug for this issue when Walter asked for reports:
https://issues.dlang.org/show_bug.cgi?id=19985.
Somewhat related:
https://issues.dlang.org/show_bug.cgi?id=19989
https://issues.dlang.org/show_bug.cgi?id=19991
More information about the Digitalmars-d-ide
mailing list