20 #include "pedigree/kernel/debugger/Backtrace.h" 21 #include "pedigree/kernel/Log.h" 22 #include "pedigree/kernel/debugger/DwarfUnwinder.h" 23 #include "pedigree/kernel/linker/KernelElf.h" 24 #include "pedigree/kernel/processor/Processor.h" 25 #include "pedigree/kernel/processor/ProcessorInformation.h" 26 #include "pedigree/kernel/processor/StackFrame.h" 27 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 29 extern uintptr_t start;
35 Backtrace::~Backtrace()
50 WARNING_NOLOCK(
"Backtracer built without DWARF enabled.");
55 WARNING_NOLOCK(
"Dwarf backtracing not available.");
56 #if defined(X86_COMMON) || defined(HOSTED) 58 #elif defined(ARM_COMMON) 59 performArmBacktrace(state.getBasePointer(), state.getInstructionPointer());
61 ERROR_NOLOCK(
"Backtrace: No backtracing method available!");
67 ProcessorState initial(state);
75 while (i < MAX_STACK_FRAMES)
77 if (!du.
unwind(initial, next, frameBase))
106 while (i < MAX_STACK_FRAMES)
110 reinterpret_cast<void *>(base)) &&
112 reinterpret_cast<void *>(base +
sizeof(uintptr_t))))
114 uintptr_t nextAddress = *
reinterpret_cast<uintptr_t *
>(base);
117 *
reinterpret_cast<uintptr_t *
>(base +
sizeof(uintptr_t));
127 if (nextAddress == 0)
140 void Backtrace::performArmBacktrace(uintptr_t base, uintptr_t instruction)
144 if (instruction == 0)
153 while (i < MAX_STACK_FRAMES)
155 uintptr_t *nextFramePointer =
156 reinterpret_cast<uintptr_t *
>(base - (3 *
sizeof(uintptr_t)));
157 uintptr_t *returnAddressPointer =
158 reinterpret_cast<uintptr_t *
>(base -
sizeof(uintptr_t));
161 if (va.
isMapped(nextFramePointer) &&
162 (i && va.
isMapped(returnAddressPointer)))
168 uintptr_t nextFrame = *nextFramePointer;
193 void Backtrace::prettyPrint(
201 for (
size_t i = nFromFrame; i < nFrames + nFromFrame; i++)
203 uintptr_t symStart = 0;
bool unwind(const ProcessorState &inState, ProcessorState &outState, uintptr_t &frameBase)
uintptr_t m_pBasePointers[MAX_STACK_FRAMES]
virtual bool isMapped(void *virtualAddress)=0
static ProcessorInformation & information()
static KernelElf & instance()
uintptr_t getBasePointer(size_t n)
uintptr_t m_pReturnAddresses[MAX_STACK_FRAMES]
void performDwarfBacktrace(InterruptState &state)
void performBacktrace(InterruptState &state)
uintptr_t globalLookupSymbol(const char *pName)
void performBpBacktrace(uintptr_t base, uintptr_t instruction)
static uintptr_t getInstructionPointer()
ProcessorState m_pStates[MAX_STACK_FRAMES]
uintptr_t getReturnAddress(size_t n)
static uintptr_t getBasePointer()