KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Stack Traces

API for managing stack backtracing More...

Files

file  stack.h
 Stack functions.
 

Macros

#define THD_STACK_ALIGNMENT   8
 Required alignment for stack.
 
#define THD_STACK_SIZE   32768
 Default thread stack size.
 
#define THD_KERNEL_STACK_SIZE   (64 * 1024)
 Main/kernel thread's stack size.
 

Functions

static __always_inline uintptr_t arch_get_ret_addr (void)
 DC specific "function" to get the return address from the current function.
 
static __always_inline uintptr_t arch_get_fptr (void)
 DC specific "function" to get the frame pointer from the current function.
 
static uintptr_t arch_fptr_ret_addr (uintptr_t fptr)
 Pass in a frame pointer value to get the return address for the given frame.
 
static uintptr_t arch_fptr_next (uintptr_t fptr)
 Pass in a frame pointer value to get the previous frame pointer for the given frame.
 
bool arch_stk_unwind_step (uintptr_t sp, uintptr_t *ret_addr_out, uintptr_t *next_sp_out)
 Find the next return address by scanning the stack.
 
void arch_stk_setup (kthread_t *nt)
 Set up new stack before running.
 
void arch_stk_trace (int n)
 Do a stack trace from the current function.
 
void arch_stk_trace_at (uintptr_t sp, size_t n)
 Do a stack trace from the given stack pointer.
 

Detailed Description

API for managing stack backtracing

Macro Definition Documentation

◆ THD_KERNEL_STACK_SIZE

#define THD_KERNEL_STACK_SIZE   (64 * 1024)

Main/kernel thread's stack size.

◆ THD_STACK_ALIGNMENT

#define THD_STACK_ALIGNMENT   8

Required alignment for stack.

◆ THD_STACK_SIZE

#define THD_STACK_SIZE   32768

Default thread stack size.

Function Documentation

◆ arch_fptr_next()

static uintptr_t arch_fptr_next ( uintptr_t fptr)
inlinestatic

Pass in a frame pointer value to get the previous frame pointer for the given frame.

Parameters
fptrThe frame pointer to look at.
Returns
The previous frame pointer.

References arch_fptr_ret_addr().

◆ arch_fptr_ret_addr()

static uintptr_t arch_fptr_ret_addr ( uintptr_t fptr)
inlinestatic

Pass in a frame pointer value to get the return address for the given frame.

Parameters
fptrThe frame pointer to look at.
Returns
The return address of the pointer.

Referenced by arch_fptr_next().

◆ arch_get_fptr()

static __always_inline uintptr_t arch_get_fptr ( void )
static

DC specific "function" to get the frame pointer from the current function.

Returns
The frame pointer from the current function.
Note
This only works if you don't disable frame pointers.

◆ arch_get_ret_addr()

static __always_inline uintptr_t arch_get_ret_addr ( void )
static

DC specific "function" to get the return address from the current function.

Returns
The return address of the current function.

Referenced by __stack_chk_fail().

◆ arch_stk_setup()

void arch_stk_setup ( kthread_t * nt)

Set up new stack before running.

This function does nothing as it is unnecessary on Dreamcast.

Parameters
ntA pointer to the new thread for which a stack is to be set up.

◆ arch_stk_trace()

void arch_stk_trace ( int n)

Do a stack trace from the current function.

This function does a stack trace from the current function, printing the results to stdout. This is used, for instance, when an assertion fails in assert().

Parameters
nThe number of frames to leave off. Each frame is a jump to subroutine or branch to subroutine. assert() leaves off 2 frames, for reference.
See also
arch_stk_trace_at

Referenced by depth_recurse(), do_work(), and main().

◆ arch_stk_trace_at()

void arch_stk_trace_at ( uintptr_t sp,
size_t n )

Do a stack trace from the given stack pointer.

This function does a stack trace from the specified stack pointer, printing the results to stdout. This could be used for doing something like stack tracing a main thread from inside an IRQ handler.

Parameters
spThe stack pointer to start scanning from.
nThe number of frames to leave off.

◆ arch_stk_unwind_step()

bool arch_stk_unwind_step ( uintptr_t sp,
uintptr_t * ret_addr_out,
uintptr_t * next_sp_out )

Find the next return address by scanning the stack.

Scans upward from the given stack pointer for saved PR values validated as return addresses from call instructions.

Parameters
spStack pointer to start scanning from.
ret_addr_outOn success, receives the found return address.
next_sp_outOn success, receives the stack position to continue scanning from.
Returns
true if a return address was found.