Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement backtrace() in terms of _Unwind_Backtrace().
Remove get_frame_pointer() entirely as it is now obsolete.
- Loading branch information
Showing
8 changed files
with
28 additions
and
96 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
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,38 +1,14 @@ | ||
#ifndef FLAPJACKOS_KERNEL_INCLUDE_BACKTRACE_HPP | ||
#define FLAPJACKOS_KERNEL_INCLUDE_BACKTRACE_HPP | ||
|
||
#include <common/text_terminal.hpp> | ||
#include <get_frame_pointer.h> | ||
#include <unwind.h> // for _Unwind_* symbols | ||
|
||
template<typename Function> | ||
void enumerate_stack_frames(Function&& function) | ||
{ | ||
constexpr size_t MAXFRAMES = 16; | ||
size_t frame; | ||
uintptr_t* frame_pointer; | ||
class StackWalker { | ||
public: | ||
virtual ~StackWalker() = default; | ||
virtual void trace(void* ip) = 0; | ||
}; | ||
|
||
frame_pointer = get_frame_pointer(); | ||
|
||
for (frame = 0; frame < MAXFRAMES; ++frame) { | ||
uintptr_t return_address; | ||
|
||
if(frame_pointer == nullptr) { | ||
// We set ebp to zero at the root stack frame. | ||
break; | ||
} | ||
|
||
return_address = frame_pointer[1]; | ||
|
||
if(return_address == 0) { | ||
// No return address? | ||
break; | ||
} | ||
|
||
frame_pointer = (uintptr_t *)(frame_pointer[0]); | ||
function(return_address); | ||
} | ||
} | ||
|
||
void backtrace(TextTerminal &term); | ||
void backtrace(StackWalker& stack_walker); | ||
|
||
#endif // FLAPJACKOS_KERNEL_INCLUDE_BACKTRACE_HPP |
This file was deleted.
Oops, something went wrong.
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,14 +1,17 @@ | ||
#include <backtrace.hpp> | ||
#include <common/logger.hpp> | ||
|
||
void backtrace(TextTerminal &term) | ||
static _Unwind_Reason_Code backtrace_trace(struct _Unwind_Context* context, void* param) | ||
{ | ||
TRACE("begin"); | ||
term.printf("Back Trace:\n"); | ||
enumerate_stack_frames([&](uintptr_t instruction_pointer){ | ||
TRACE("[%p]", reinterpret_cast<void*>(instruction_pointer)); | ||
term.printf("[%p]\n", reinterpret_cast<void*>(instruction_pointer)); | ||
}); | ||
TRACE("end"); | ||
term.printf("\n"); | ||
void* ip = reinterpret_cast<void*>(_Unwind_GetIP(context)); | ||
if (ip) { | ||
reinterpret_cast<StackWalker*>(param)->trace(ip); | ||
return _URC_NO_REASON; | ||
} else { | ||
return _URC_END_OF_STACK; | ||
} | ||
} | ||
|
||
void backtrace(StackWalker& stack_walker) | ||
{ | ||
_Unwind_Backtrace(backtrace_trace, reinterpret_cast<void*>(&stack_walker)); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.