www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What is D's "__debugbreak()" equivalent?

reply Simon <simon.vanbernem yahoo.de> writes:
Microsofts C++ compiler provides the __debugbreak function, which 
on x86 emits interrupt 3, which will cause the debugger to halt. 
What is the equivalent in D? I tried using raise(SIGINT) from 
core.stdc.signal, but that just closes the debugger (I thought 
that was the same, seems like I was wrong).
Oct 27 2021
next sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Oct 27, 2021 at 04:54:49PM +0000, Simon via Digitalmars-d-learn wrote:
 Microsofts C++ compiler provides the __debugbreak function, which on
 x86 emits interrupt 3, which will cause the debugger to halt. What is
 the equivalent in D? I tried using raise(SIGINT) from
 core.stdc.signal, but that just closes the debugger (I thought that
 was the same, seems like I was wrong).
Why not just: asm { int 3; } ? Just tested in gdb, it worked. T -- MASM = Mana Ada Sistem, Man!
Oct 27 2021
parent Adam D Ruppe <destructionator gmail.com> writes:
On Wednesday, 27 October 2021 at 17:07:31 UTC, H. S. Teoh wrote:
 	asm { int 3; }
yeah that's how i do it in dmd too
Oct 27 2021
prev sibling next sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 10/27/21 12:54 PM, Simon wrote:
 Microsofts C++ compiler provides the __debugbreak function, which on x86 
 emits interrupt 3, which will cause the debugger to halt. What is the 
 equivalent in D? I tried using raise(SIGINT) from core.stdc.signal, but 
 that just closes the debugger (I thought that was the same, seems like I 
 was wrong).
SIGINT is not an interrupt, it's a POSIX signal. Inline asm maybe? https://dlang.org/spec/iasm.html -Steve
Oct 27 2021
prev sibling parent reply Dennis <dkorpel gmail.com> writes:
On Wednesday, 27 October 2021 at 16:54:49 UTC, Simon wrote:
 What is the equivalent in D?
With LDC, you have: ```D import ldc.intrinsics: llvm_debugtrap; ``` Combining that with previous answers, you can make something like this: ```D void debugbreak() nothrow nogc trusted { version(D_InlineAsm_X86_64) { asm nothrow nogc { int 3; } } else version(LDC) { import ldc.intrinsics: llvm_debugtrap; llvm_debugtrap(); } else { assert(0); // No `breakPoint` for this compiler configuration } } ```
Oct 28 2021
parent reply bauss <jj_1337 live.dk> writes:
On Thursday, 28 October 2021 at 09:54:44 UTC, Dennis wrote:
 On Wednesday, 27 October 2021 at 16:54:49 UTC, Simon wrote:
 What is the equivalent in D?
With LDC, you have: ```D import ldc.intrinsics: llvm_debugtrap; ``` Combining that with previous answers, you can make something like this: ```D void debugbreak() nothrow nogc trusted { version(D_InlineAsm_X86_64) { asm nothrow nogc { int 3; } } else version(LDC) { import ldc.intrinsics: llvm_debugtrap; llvm_debugtrap(); } else { assert(0); // No `breakPoint` for this compiler configuration } } ```
Shouldn't it be this instead, unless D_InlineAsm_X86_64 isn't available for ldc? There's also D_InlineAsm_X86 btw. ```D void debugbreak() nothrow nogc trusted { version(LDC) { import ldc.intrinsics: llvm_debugtrap; llvm_debugtrap(); } else version(D_InlineAsm_X86_64) { asm nothrow nogc { int 3; } } else { assert(0); // No `breakPoint` for this compiler configuration } } ```
Oct 29 2021
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Friday, 29 October 2021 at 09:32:07 UTC, bauss wrote:
 	} else version(D_InlineAsm_X86_64) {
just fyi but `int 3;` works just as well in 32 bit as 64
Oct 29 2021
parent bauss <jj_1337 live.dk> writes:
On Friday, 29 October 2021 at 11:36:13 UTC, Adam D Ruppe wrote:
 On Friday, 29 October 2021 at 09:32:07 UTC, bauss wrote:
 	} else version(D_InlineAsm_X86_64) {
just fyi but `int 3;` works just as well in 32 bit as 64
Yeah, that's why I noted that there's also D_InlineAsm_X86 but I just didn't bother adding it.
Oct 29 2021