Commit 085857a9 authored by Mathieu Maret's avatar Mathieu Maret

Add backtrace function

parent 50fa9b7d
......@@ -2,9 +2,11 @@
CPPFLAGS = -MMD
AS=nasm
ASFLAGS += -f elf32
#LDFLAGS += -m32 -nostdlib -mkernel -fno-stack-protector
LDFLAGS += -m32 -nostdlib -static -fno-common -fno-use-cxa-atexit -fno-exceptions -fno-non-call-exceptions -fno-weak -fno-rtti -fno-stack-protector
CFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-pie -fno-stack-protector
CXXFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-rtti -fno-pie
DEBUG_FLAGS += -g -Og -DDEBUG -fno-omit-frame-pointer
SUBDIRS := core drivers tests
......@@ -44,8 +46,8 @@ self_test: clean kernel
test:kernel
qemu-system-x86_64 -kernel $<
debug: CFLAGS += -g -Og
debug: CXXFLAGS += -g -Og
debug: CFLAGS += $(DEBUG_FLAGS)
debug: CXXFLAGS += $(DEBUG_FLAGS)
debug:kernel kernel.sym
qemu-system-x86_64 -s -S -kernel kernel&
gdb -s kernel.sym -ex "target remote localhost:1234"
......
#include "stack.h"
#include "vga.h"
void printStackTrace(unsigned int maxFrames){
#ifdef DEBUG
// Now on Stack:
// ( potential second function argument )
// first function argument (maxFrames)
// return address from caller
// EBP (Extended Base Pointer) of calling function
unsigned int * ebp = &maxFrames - 2;
for (unsigned int frame = 0 ; frame < maxFrames; frame ++){
unsigned int eip = ebp [1];
if (eip == 0){
// No caller on stack
break;
}
ebp = (unsigned int *)(ebp[0]);
//unsigned int * arguments = &ebp[2];
printf(" 0x%x\n", eip);
}
#else
printf("Must be compiled with -fno-omit-frame-pointer for full stack\n");
unsigned int * ebp = &maxFrames - 2;
unsigned int eip = ebp [1];
printf("Caller: 0x%x\n", eip);
#endif
}
#pragma once
void printStackTrace(unsigned int maxFrame);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment