Thread overview
What is D's "__debugbreak()" equivalent?
Oct 27, 2021
Simon
Oct 27, 2021
H. S. Teoh
Oct 27, 2021
Adam D Ruppe
Oct 28, 2021
Dennis
Oct 29, 2021
bauss
Oct 29, 2021
Adam D Ruppe
Oct 29, 2021
bauss
October 27, 2021
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).
October 27, 2021
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!
October 27, 2021

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

October 27, 2021
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
October 28, 2021

On Wednesday, 27 October 2021 at 16:54:49 UTC, Simon wrote:

>

What is the equivalent in D?

With LDC, you have:

import ldc.intrinsics: llvm_debugtrap;

Combining that with previous answers, you can make something like this:

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
	}
}
October 29, 2021

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:

import ldc.intrinsics: llvm_debugtrap;

Combining that with previous answers, you can make something like this:

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.

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
	}
}
October 29, 2021
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
October 29, 2021
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.