SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
Functions
stdlib.h File Reference

Go to the source code of this file.

Functions

int backtrace (char *PC, long *SP, char *LR)
 Perform a backtrace to find the call stack.
 
int dump_stack (void)
 Dumps the current stack state and performs a backtrace.
 

Function Documentation

◆ backtrace()

int backtrace ( char *  PC,
long *  SP,
char *  LR 
)

Perform a backtrace to find the call stack.

This function attempts to walk the call stack by analyzing the program counter (PC), stack pointer (SP), and link register (LR) to determine the sequence of function calls leading to the current execution point.

The backtrace process works by using the stack and link register to trace the call hierarchy, logging each level of the backtrace, and attempting recovery from any errors. If the backtrace from the stack fails, it will attempt to trace using the link register (LR).

Parameters
PCThe current program counter (PC), typically pointing to the instruction where the backtrace starts.
SPThe current stack pointer (SP), pointing to the top of the stack.
LRThe link register (LR), used to store return addresses for function calls.
Returns
The number of backtrace levels successfully traversed. Returns 0 if no valid backtrace could be performed.

Perform a backtrace to find the call stack.

This function tries to traverse the stack to generate a backtrace, logging the current PC at each level. If the stack backtrace fails, it attempts to trace using the LR as a fallback.

Parameters
PCPointer to the program counter.
SPPointer to the stack pointer.
LRPointer to the link register (return address).
Returns
The number of backtrace levels found, or 0 if the backtrace failed.

◆ dump_stack()

int dump_stack ( void  )

Dumps the current stack state and performs a backtrace.

This function captures the current program counter (PC), stack pointer (SP), link register (LR), and current processor status register (CPSR). It uses inline assembly to obtain these values, then performs a backtrace to provide insight into the function call stack.

The function also checks if the processor is in THUMB mode based on the CPSR state and adjusts the program counter (PC) accordingly. If the program counter or stack pointer is invalid, the function will return early with a status of 0.

Returns
The result of the backtrace function, representing the number of successfully traced backtrace levels, or 0 if the stack pointer (SP) or program counter (PC) is invalid.

Dumps the current stack state and performs a backtrace.

This function retrieves the current values of the stack pointer, program counter, and link register, then uses these to generate a backtrace. If either the stack pointer or program counter is invalid, it returns 0.

Returns
The backtrace level, or 0 if SP or PC is invalid.