panic: print stack trace when panicking
This commit is contained in:
parent
385af1b7ef
commit
7f92690f84
5 changed files with 30 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
target_sources(gay_arch PRIVATE
|
target_sources(gay_arch PRIVATE
|
||||||
idt.S
|
idt.S
|
||||||
irq.S
|
irq.S
|
||||||
|
ktrace.c
|
||||||
switch.S
|
switch.S
|
||||||
systm.c
|
systm.c
|
||||||
trap.S
|
trap.S
|
||||||
|
|
18
arch/x86/sys/amd64/ktrace.c
Normal file
18
arch/x86/sys/amd64/ktrace.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* Copyright (C) 2021 fef <owo@fef.moe>. All rights reserved. */
|
||||||
|
|
||||||
|
#include <arch/vmparam.h>
|
||||||
|
|
||||||
|
#include <gay/kprintf.h>
|
||||||
|
#include <gay/ktrace.h>
|
||||||
|
|
||||||
|
void ktrace_print(void)
|
||||||
|
{
|
||||||
|
void **rbp;
|
||||||
|
__asm__ volatile("movq (%%rbp), %0" : "=r"(rbp));
|
||||||
|
|
||||||
|
kprintf("Stack trace:\n");
|
||||||
|
while (rbp >= (void **)KERNBASE) {
|
||||||
|
kprintf(" %p\n", rbp[1]);
|
||||||
|
rbp = *rbp;
|
||||||
|
}
|
||||||
|
}
|
6
include/gay/ktrace.h
Normal file
6
include/gay/ktrace.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
/* Copyright (C) 2021 fef <owo@fef.moe>. All rights reserved. */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/** @brief Print a full stack trace to the kernel log, starting from the caller. */
|
||||||
|
void ktrace_print(void);
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <arch/cpufunc.h>
|
||||||
#include <arch/trap.h>
|
#include <arch/trap.h>
|
||||||
|
|
||||||
#include <gay/cdefs.h>
|
#include <gay/cdefs.h>
|
||||||
|
@ -72,7 +73,7 @@ static inline void critical_leave(void)
|
||||||
|
|
||||||
static inline bool in_critical(void)
|
static inline bool in_critical(void)
|
||||||
{
|
{
|
||||||
if (in_irq())
|
if (in_irq() || !intr_enabled())
|
||||||
return true;
|
return true;
|
||||||
return current->critnest > 0;
|
return current->critnest > 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <gay/cdefs.h>
|
#include <gay/cdefs.h>
|
||||||
#include <gay/config.h>
|
#include <gay/config.h>
|
||||||
#include <gay/kprintf.h>
|
#include <gay/kprintf.h>
|
||||||
|
#include <gay/ktrace.h>
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
@ -22,6 +23,8 @@ void panic(const char *fmt, ...)
|
||||||
else
|
else
|
||||||
kvprintf(fmt, args);
|
kvprintf(fmt, args);
|
||||||
|
|
||||||
|
ktrace_print();
|
||||||
|
|
||||||
kprintf("\nKernel version: %s\nSystem halted", GAY_VERSION_STR);
|
kprintf("\nKernel version: %s\nSystem halted", GAY_VERSION_STR);
|
||||||
|
|
||||||
/* no need for va_end() here i guess */
|
/* no need for va_end() here i guess */
|
||||||
|
|
Loading…
Reference in a new issue