ATLAS Offline Software
Classes | Macros | Typedefs | Functions
stackstash.h File Reference
#include <stddef.h>
Include dependency graph for stackstash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  StackHandle_
 Unique reference for a stack trace. More...
 
struct  StackNode_
 Node used to store trace data. More...
 
struct  StackCursor_
 Cursor object used to move between nodes of the tree. More...
 

Macros

#define STACK_ELEMENT_BEGIN_P(element)   (*((element)-1) == 0)
 Is the element pointed to by ELEMENT the first one in its node? More...
 
#define STACK_ELEMENT_NODE(element)   ((StackNode*)((char*)((element)-1) - offsetof(StackNode, p)))
 ELEMENT should be a pointer to the first element in a node. More...
 
#define STACK_ELEMENT_NODEPARENT(element)   (STACK_ELEMENT_NODE(element)->parent)
 ELEMENT should be a pointer to the first element in a node. More...
 
#define STACK_NODE_NTH_ELEMENT(node, n)   ((node)->p[n+1])
 Return the Nth element stored in a node. More...
 
#define STACK_NODE_NTH_CHILD(node, n)   (*(StackNode**)&((node)->p[n+1+(node)->nelts]))
 Return a pointer to the Nth child stored in a node. More...
 
#define STACK_ELEMENT_NONNULL(elt)   ((elt) ? (elt) : (StackElement)1)
 We can't store a null element in a trace; fold them to 1. More...
 
#define STACK_NODE_SET_ELEMENT(node, n, elt)   do{ (node)->p[n+1] = STACK_ELEMENT_NONNULL(elt); } while(0)
 Set the Nth element stored in a node. More...
 
#define STACK_HANDLE_ELEMENT(handle)   ((handle)->element)
 Return a pointer to the first element in the handle's trace. More...
 
#define STACK_HANDLE_ADDR(handle)   STACK_ELEMENT_ADDR(STACK_HANDLE_ELEMENT(handle))
 Return the first element in the handle's trace. More...
 
#define STACK_HANDLE_PARENT(handle)   STACK_ELEMENT_PARENT(STACK_HANDLE_ELEMENT(handle))
 Return a pointer to the second in the handle's trace. More...
 
#define STACK_HANDLE_IS_ROOT(handle)   STACK_ELEMENT_IS_ROOT(STACK_HANDLE_ELEMENT(handle))
 Test to see if a handle represents the root of the call tree. More...
 
#define STACK_ELEMENT_ADDR(element)   (*(element))
 Given a pointer to an element, return the element. More...
 
#define STACK_ELEMENT_PARENT(element)   hhh_stack_element_parent(element)
 Given a pointer to an element, return a pointer to the element's parent. More...
 
#define STACK_ELEMENT_IS_ROOT(element)   (*(element) == 0)
 Test if an element is the root of trace. More...
 
#define STACK_CURSOR_ELEMENT(cursor)   ((cursor).elt)
 Return the address of the element referenced by the cursor. More...
 
#define STACK_CURSOR_ELEMENT_ADDR(cursor)   STACK_ELEMENT_ADDR(STACK_CURSOR_ELEMENT(cursor))
 Return the element referenced by the cursor. More...
 
#define STACK_CURSOR_INIT_ROOT(cursor)   hhh_Cursor_initRoot(&cursor)
 Initialize a cursor to point at the root of the tree. More...
 
#define STACK_CURSOR_INIT_HANDLE(cursor, handle)   hhh_Cursor_initHandle(&cursor, handle)
 Initialize a cursor from a handle. More...
 
#define STACK_CURSOR_IS_ROOT(cursor)   STACK_ELEMENT_IS_ROOT(STACK_CURSOR_ELEMENT(cursor))
 Does the cursor reference the root of the tree? More...
 
#define STACK_CURSOR_PARENT(cursor)   hhh_Cursor_parent(&cursor)
 Move to the cursor to the parent node. More...
 
#define STACK_CURSOR_NCHILDREN(cursor)   hhh_Cursor_nchildren(&cursor)
 Return the number of children. More...
 
#define STACK_CURSOR_CHILD(cursor, n)   hhh_Cursor_child(&cursor, n)
 Move to the cursor to the nth child. More...
 
#define STACK_CURSOR_NEXT(cursor)   hhh_Cursor_next(&cursor)
 Visit next element in depth-first order. More...
 

Typedefs

typedef void * StackElement
 One element of a stack trace. More...
 
typedef struct StackHandle_ StackHandle
 
typedef struct StackNode_ StackNode
 
typedef struct StackCursor_ StackCursor
 

Functions

StackHandlehhh_stackstash_store (const StackElement *addresses, int n_addresses)
 Return the handle for a stack trace. More...
 
StackElementhhh_stack_element_parent (StackElement *elt)
 Function interface to iterate over a trace. More...
 
void hhh_Cursor_initRoot (StackCursor *cursor)
 Initialize a cursor to point at the root of the tree. More...
 
void hhh_Cursor_initHandle (StackCursor *cursor, StackHandle *handle)
 Initialize a cursor from a handle. More...
 
void hhh_Cursor_parent (StackCursor *cursor)
 Move to the cursor to the parent node. More...
 
void hhh_Cursor_child (StackCursor *cursor, int n)
 Move to the cursor to the nth child. More...
 
int hhh_Cursor_nchildren (StackCursor *cursor)
 Return the number of children. More...
 
void hhh_Cursor_next (StackCursor *cursor)
 Visit next element in depth-first order. More...
 

Macro Definition Documentation

◆ STACK_CURSOR_CHILD

#define STACK_CURSOR_CHILD (   cursor,
 
)    hhh_Cursor_child(&cursor, n)

Move to the cursor to the nth child.

Definition at line 253 of file stackstash.h.

◆ STACK_CURSOR_ELEMENT

#define STACK_CURSOR_ELEMENT (   cursor)    ((cursor).elt)

Return the address of the element referenced by the cursor.

Definition at line 232 of file stackstash.h.

◆ STACK_CURSOR_ELEMENT_ADDR

#define STACK_CURSOR_ELEMENT_ADDR (   cursor)    STACK_ELEMENT_ADDR(STACK_CURSOR_ELEMENT(cursor))

Return the element referenced by the cursor.

Definition at line 235 of file stackstash.h.

◆ STACK_CURSOR_INIT_HANDLE

#define STACK_CURSOR_INIT_HANDLE (   cursor,
  handle 
)    hhh_Cursor_initHandle(&cursor, handle)

Initialize a cursor from a handle.

Definition at line 241 of file stackstash.h.

◆ STACK_CURSOR_INIT_ROOT

#define STACK_CURSOR_INIT_ROOT (   cursor)    hhh_Cursor_initRoot(&cursor)

Initialize a cursor to point at the root of the tree.

Definition at line 238 of file stackstash.h.

◆ STACK_CURSOR_IS_ROOT

#define STACK_CURSOR_IS_ROOT (   cursor)    STACK_ELEMENT_IS_ROOT(STACK_CURSOR_ELEMENT(cursor))

Does the cursor reference the root of the tree?

Definition at line 244 of file stackstash.h.

◆ STACK_CURSOR_NCHILDREN

#define STACK_CURSOR_NCHILDREN (   cursor)    hhh_Cursor_nchildren(&cursor)

Return the number of children.

Definition at line 250 of file stackstash.h.

◆ STACK_CURSOR_NEXT

#define STACK_CURSOR_NEXT (   cursor)    hhh_Cursor_next(&cursor)

Visit next element in depth-first order.

Definition at line 256 of file stackstash.h.

◆ STACK_CURSOR_PARENT

#define STACK_CURSOR_PARENT (   cursor)    hhh_Cursor_parent(&cursor)

Move to the cursor to the parent node.

Definition at line 247 of file stackstash.h.

◆ STACK_ELEMENT_ADDR

#define STACK_ELEMENT_ADDR (   element)    (*(element))

Given a pointer to an element, return the element.

Definition at line 218 of file stackstash.h.

◆ STACK_ELEMENT_BEGIN_P

#define STACK_ELEMENT_BEGIN_P (   element)    (*((element)-1) == 0)

Is the element pointed to by ELEMENT the first one in its node?

Definition at line 165 of file stackstash.h.

◆ STACK_ELEMENT_IS_ROOT

#define STACK_ELEMENT_IS_ROOT (   element)    (*(element) == 0)

Test if an element is the root of trace.

Definition at line 225 of file stackstash.h.

◆ STACK_ELEMENT_NODE

#define STACK_ELEMENT_NODE (   element)    ((StackNode*)((char*)((element)-1) - offsetof(StackNode, p)))

ELEMENT should be a pointer to the first element in a node.

Returns a pointer to the node itself.

Definition at line 169 of file stackstash.h.

◆ STACK_ELEMENT_NODEPARENT

#define STACK_ELEMENT_NODEPARENT (   element)    (STACK_ELEMENT_NODE(element)->parent)

ELEMENT should be a pointer to the first element in a node.

Returns a pointer to the parent of this node.

Definition at line 174 of file stackstash.h.

◆ STACK_ELEMENT_NONNULL

#define STACK_ELEMENT_NONNULL (   elt)    ((elt) ? (elt) : (StackElement)1)

We can't store a null element in a trace; fold them to 1.

Definition at line 184 of file stackstash.h.

◆ STACK_ELEMENT_PARENT

#define STACK_ELEMENT_PARENT (   element)    hhh_stack_element_parent(element)

Given a pointer to an element, return a pointer to the element's parent.

Gives 0 if element referred to the root.

Definition at line 222 of file stackstash.h.

◆ STACK_HANDLE_ADDR

#define STACK_HANDLE_ADDR (   handle)    STACK_ELEMENT_ADDR(STACK_HANDLE_ELEMENT(handle))

Return the first element in the handle's trace.

Definition at line 202 of file stackstash.h.

◆ STACK_HANDLE_ELEMENT

#define STACK_HANDLE_ELEMENT (   handle)    ((handle)->element)

Return a pointer to the first element in the handle's trace.

Definition at line 199 of file stackstash.h.

◆ STACK_HANDLE_IS_ROOT

#define STACK_HANDLE_IS_ROOT (   handle)    STACK_ELEMENT_IS_ROOT(STACK_HANDLE_ELEMENT(handle))

Test to see if a handle represents the root of the call tree.

Definition at line 210 of file stackstash.h.

◆ STACK_HANDLE_PARENT

#define STACK_HANDLE_PARENT (   handle)    STACK_ELEMENT_PARENT(STACK_HANDLE_ELEMENT(handle))

Return a pointer to the second in the handle's trace.

Definition at line 206 of file stackstash.h.

◆ STACK_NODE_NTH_CHILD

#define STACK_NODE_NTH_CHILD (   node,
 
)    (*(StackNode**)&((node)->p[n+1+(node)->nelts]))

Return a pointer to the Nth child stored in a node.

Definition at line 180 of file stackstash.h.

◆ STACK_NODE_NTH_ELEMENT

#define STACK_NODE_NTH_ELEMENT (   node,
 
)    ((node)->p[n+1])

Return the Nth element stored in a node.

Definition at line 177 of file stackstash.h.

◆ STACK_NODE_SET_ELEMENT

#define STACK_NODE_SET_ELEMENT (   node,
  n,
  elt 
)    do{ (node)->p[n+1] = STACK_ELEMENT_NONNULL(elt); } while(0)

Set the Nth element stored in a node.

Definition at line 187 of file stackstash.h.

Typedef Documentation

◆ StackCursor

typedef struct StackCursor_ StackCursor

Definition at line 74 of file stackstash.h.

◆ StackElement

typedef void* StackElement

One element of a stack trace.

Definition at line 74 of file stackstash.h.

◆ StackHandle

typedef struct StackHandle_ StackHandle

Definition at line 74 of file stackstash.h.

◆ StackNode

typedef struct StackNode_ StackNode

Definition at line 74 of file stackstash.h.

Function Documentation

◆ hhh_Cursor_child()

void hhh_Cursor_child ( StackCursor cursor,
int  n 
)

Move to the cursor to the nth child.

◆ hhh_Cursor_initHandle()

void hhh_Cursor_initHandle ( StackCursor cursor,
StackHandle handle 
)

Initialize a cursor from a handle.

◆ hhh_Cursor_initRoot()

void hhh_Cursor_initRoot ( StackCursor cursor)

Initialize a cursor to point at the root of the tree.

◆ hhh_Cursor_nchildren()

int hhh_Cursor_nchildren ( StackCursor cursor)

Return the number of children.

◆ hhh_Cursor_next()

void hhh_Cursor_next ( StackCursor cursor)

Visit next element in depth-first order.

◆ hhh_Cursor_parent()

void hhh_Cursor_parent ( StackCursor cursor)

Move to the cursor to the parent node.

◆ hhh_stack_element_parent()

StackElement* hhh_stack_element_parent ( StackElement elt)

Function interface to iterate over a trace.

Parameters
eltPointer to an element of a trace.

Returns a pointer to the previous element of the trace (the caller). Returns 0 if we're at the root of the trace.

◆ hhh_stackstash_store()

StackHandle* hhh_stackstash_store ( const StackElement addresses,
int  n_addresses 
)

Return the handle for a stack trace.

Parameters
addressesStack trace to store.
n_addressesLength of the trace.

Returns the unique Handle object representing this trace. If this trace has been seen before, the existing Handle object will be returned; otherwise, a new Handle object will be made and returned.