My first question is how I would go about implementing assert?
My second question is how I would get the value of EFLAGS? If I can get it, then I can just do
Code: Select all
assert(EFLAGS & (1 << 8))
Code: Select all
assert(EFLAGS & (1 << 8))
Code: Select all
GetEFlags:
pushf
pop eax
ret
Code: Select all
#ifndef _ASSERT_H_
#define _ASSERT_H_
#include "screen.h"
#include "defs.h"
#define ASSERT(cond) \
do { \
if (!cond) { \
set_text_color(RED, BLACK); \
puts("Assertion '" #cond "' failed at line "); \
puti(__LINE__); \
puts(" of file " __FILE__); \
asm("hlt"); \
} \
} while (0);
#endif
How would I stop execution without halting, so I could attach a debugger?I don't like the way when assertion failure leads to unconditional system halt. It's better, for example, to wait for debugger connection (so we can at least try to retrieve more information about the error), in some situations it's even possible to recover (e.g., missed packet from PS/2 device).
I know how to set up remote debugging with GDB, but what I was looking for was something like magic breakpoints (so I can break instead of halt and then attach a debugger). But I use QEMU, and I can't find any similar functionality for it.Nable wrote:Did you try to search before asking this question?
I can suggest you this: http://wiki.osdev.org/GDB
And here is an extremely good alternative for beginners: http://wiki.osdev.org/Bochs#Magic_Breakpoint