blob: bb6da8696b1a3a06931484722d6080857655544c [file] [log] [blame]
#import <Foundation/Foundation.h>
#include <pthread.h>
/** Max number of frames in the stack trace buffer */
#define kLPThreadStackTraceMaxFramesCount 128
typedef struct LPThreadStackTrace {
/** The thread that the stacktrace belongs to. */
pthread_t thread;
/** Array of addresses in the thread stack. */
void *stacktrace[kLPThreadStackTraceMaxFramesCount];
/** Number of valid frames in stacktrace array. */
int frames;
} LPThreadStackTrace;
/**
* Generate the stacktrace of all threads in the current process.
*
* @param buffer Output. Array of stacktraces.
* @param size Size of buffer.
* @return The count of actual threads in the buffer. If the count of threads is more than the size
* of buffer, it returns the size of buffer and cut off rest of threads.
*/
int LPSnapshotAllThreadsStackTrace(LPThreadStackTrace *buffer, int size);
/**
* Generate the stacktrace of the thread.
*
* @param buffer Output. Array of addresses in the stacktrace.
* @param size Size of buffer.
* @param thread The target thread to be snapshotted.
* @return The count of actual stack frames in the buffer. If the count of stack frames is more than
* the size of buffer, it returns the size of buffer and cut off rest of frames.
*
*/
int LPSnapshotThreadStackTrace(void **buffer, int size, pthread_t thread);
/**
* Symbolicates addresses in a stack trace.
* Not guaranteed in release mode.
*
* @param buffer Array of addresses in the stacktrace.
* @param size Size of buffer array.
* @return Array of symbolicated address.
*/
NSArray<NSString *> *LPStackTraceString(void **buffer, int size);
/**
* Symbolicates a list of stack traces.
* The parameters should be the output of LPSnapshotAllThreadsStackTrace().
* Not guaranteed in release mode.
*
* @param buffer Array of LPThreadStackTrace.
* @param size Size of buffer array.
* @return Array of symbolicated address.
*/
NSArray<NSArray<NSString *> *> *LPStackTracesString(LPThreadStackTrace *buffer, int size);