Skip to content

Commit

Permalink
Userland: Trap debugger when assertion fails
Browse files Browse the repository at this point in the history
  • Loading branch information
asynts committed Apr 18, 2021
1 parent ba3c447 commit 2c46af7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 2 additions & 5 deletions Userland/LibC/assert.c
@@ -1,9 +1,6 @@
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>

void assert_failed(const char *condition, const char *filename, size_t line)
void breakpoint(const char *filename, size_t line)
{
printf("assert(%s) failed\n%s:%zu\n", condition, filename, line);
abort();
asm volatile("bkpt #0");
}
7 changes: 5 additions & 2 deletions Userland/LibC/assert.h
@@ -1,5 +1,8 @@
#pragma once

#include <stdlib.h>
#include <sys/types.h>

#define assert(...) ((__VA_ARGS__) ? (void)0 : abort())
__attribute__((noinline))
void breakpoint(const char *filename, size_t line);

#define assert(condition) ((condition) ? (void)0 : breakpoint(__FILE__, __LINE__))

0 comments on commit 2c46af7

Please sign in to comment.