libroot/ppc: Add missing stack_trace

This commit is contained in:
Alexander von Gluck IV 2017-07-04 19:28:13 -05:00
parent 021ffa56b9
commit 144e404b2d
2 changed files with 48 additions and 0 deletions

View File

@ -17,6 +17,7 @@ for architectureObject in [ MultiArchSubDirSetup ppc ] {
byteorder.S
compatibility.c # only here until the places where those functions
# are used are fixed
stack_trace.cpp
stack_frame.c
# systeminfo.c
system_time.c

View File

@ -0,0 +1,47 @@
/*
* Copyright 2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Lotz, mmlr@mlotz.ch
*/
#include <libroot_private.h>
/*! Captures a stack trace (the return addresses) of the current thread.
\param returnAddresses The array the return address shall be written to.
\param maxCount The maximum number of return addresses to be captured.
\param skipFrames The number of stack frames that shall be skipped.
\param stackBase The base address of the thread stack.
\param stackEnd The first address past the thread stack.
\return The number of return addresses written to the given array.
*/
int32
__arch_get_stack_trace(addr_t* returnAddresses, int32 maxCount,
int32 skipFrames, addr_t stackBase, addr_t stackEnd)
{
int32 count = 0;
addr_t basePointer = (addr_t)get_stack_frame();
while (basePointer != 0 && count < maxCount) {
if (basePointer < stackBase || basePointer >= stackEnd)
break;
struct stack_frame {
addr_t previous;
addr_t return_address;
};
stack_frame* frame = (stack_frame*)basePointer;
if (skipFrames <= 0)
returnAddresses[count++] = frame->return_address;
else
skipFrames--;
basePointer = frame->previous;
}
return count;
}