Skip to content

Commit 34feb11

Browse files
Add debugger breaks in nu_fatal for convenience
1 parent 8352790 commit 34feb11

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

source/numem/core/hooks.d

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ void* nu_memset(return scope void* dst, ubyte value, size_t bytes) @nogc nothrow
162162
This function $(B should) exit the application and if possible,
163163
print an error. But it $(B may) not print an error.
164164
165+
Notes:
166+
This function may trigger a trap to alert a debugger to
167+
create a breakpoint.
168+
165169
Params:
166170
errMsg = A D string containing the error in question.
167171
@@ -171,6 +175,29 @@ void* nu_memset(return scope void* dst, ubyte value, size_t bytes) @nogc nothrow
171175
export
172176
extern(C)
173177
void nu_fatal(const(char)[] errMsg) @nogc nothrow @system pure @weak {
178+
debug {
179+
version(LDC) {
180+
pragma(LDC_intrinsic, "llvm.debugtrap")
181+
extern extern(C) void llvm_debugtrap() @nogc nothrow @system pure;
182+
183+
llvm_debugtrap();
184+
} else version(DigitalMars) {
185+
version(X86) {
186+
asm @nogc pure nothrow {
187+
int 0x03;
188+
}
189+
} else version(X86_64) {
190+
asm @nogc pure nothrow {
191+
int 0x03;
192+
}
193+
} else version(AArch64) {
194+
asm @nogc pure nothrow {
195+
inst 0xd4200000;
196+
}
197+
}
198+
}
199+
}
200+
174201
pragma(mangle, "printf")
175202
extern extern(C) int printf(const(char)*, ...) @nogc nothrow @system pure;
176203
pragma(mangle, "abort")

0 commit comments

Comments
 (0)