Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Userland: Trap debugger when assertion fails
- Loading branch information
Showing
2 changed files
with
7 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__)) |