ATLAS Offline Software
stackstash.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /* $Id$ */
61 #ifndef HEPHAESTUS_STACKSTASH_H
62 #define HEPHAESTUS_STACKSTASH_H
63 
64 
65 #include <stddef.h>
66 
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 
74 typedef void* StackElement;
75 
76 
82 {
84  struct StackHandle_* next;
85 };
86 typedef struct StackHandle_ StackHandle;
87 
88 
93 struct StackNode_
94 {
95  struct StackNode_* parent;
96  unsigned short nelts;
97  unsigned short nkids;
99  /* First elt is always 0. */
100  void* p[1];
101 };
102 typedef struct StackNode_ StackNode;
103 
104 
110 {
113 };
114 typedef struct StackCursor_ StackCursor;
115 
116 
127  int n_addresses);
128 
129 
138 
139 
142 
145 
148 
151 
154 
157 
158 
159 /***********************************************************************
160  * For internal use.
161  */
162 
164 #define STACK_ELEMENT_BEGIN_P(element) (*((element)-1) == 0)
165 
168 #define STACK_ELEMENT_NODE(element) \
169  ((StackNode*)((char*)((element)-1) - offsetof(StackNode, p)))
170 
173 #define STACK_ELEMENT_NODEPARENT(element) (STACK_ELEMENT_NODE(element)->parent)
174 
176 #define STACK_NODE_NTH_ELEMENT(node, n) ((node)->p[n+1])
177 
179 #define STACK_NODE_NTH_CHILD(node, n) \
180  (*(StackNode**)&((node)->p[n+1+(node)->nelts]))
181 
183 #define STACK_ELEMENT_NONNULL(elt) ((elt) ? (elt) : (StackElement)1)
184 
186 #define STACK_NODE_SET_ELEMENT(node, n, elt) do{ (node)->p[n+1] = STACK_ELEMENT_NONNULL(elt); } while(0)
187 
188 
189 
190 /***********************************************************************
191  * Public interface.
192  */
193 
194 
195 /*** Operations on StackHandle. */
196 
198 #define STACK_HANDLE_ELEMENT(handle) ((handle)->element)
199 
201 #define STACK_HANDLE_ADDR(handle) \
202  STACK_ELEMENT_ADDR(STACK_HANDLE_ELEMENT(handle))
203 
205 #define STACK_HANDLE_PARENT(handle) \
206  STACK_ELEMENT_PARENT(STACK_HANDLE_ELEMENT(handle))
207 
209 #define STACK_HANDLE_IS_ROOT(handle) \
210  STACK_ELEMENT_IS_ROOT(STACK_HANDLE_ELEMENT(handle))
211 
212 
213 
214 /*** Operations on StackElement. */
215 
217 #define STACK_ELEMENT_ADDR(element) (*(element))
218 
221 #define STACK_ELEMENT_PARENT(element) hhh_stack_element_parent(element)
222 
224 #define STACK_ELEMENT_IS_ROOT(element) (*(element) == 0)
225 
226 
227 /*** Operations on StackCursor. */
228 
229 
231 #define STACK_CURSOR_ELEMENT(cursor) ((cursor).elt)
232 
234 #define STACK_CURSOR_ELEMENT_ADDR(cursor) STACK_ELEMENT_ADDR(STACK_CURSOR_ELEMENT(cursor))
235 
237 #define STACK_CURSOR_INIT_ROOT(cursor) hhh_Cursor_initRoot(&cursor)
238 
240 #define STACK_CURSOR_INIT_HANDLE(cursor, handle) hhh_Cursor_initHandle(&cursor, handle)
241 
243 #define STACK_CURSOR_IS_ROOT(cursor) STACK_ELEMENT_IS_ROOT(STACK_CURSOR_ELEMENT(cursor))
244 
246 #define STACK_CURSOR_PARENT(cursor) hhh_Cursor_parent(&cursor)
247 
249 #define STACK_CURSOR_NCHILDREN(cursor) hhh_Cursor_nchildren(&cursor)
250 
252 #define STACK_CURSOR_CHILD(cursor, n) hhh_Cursor_child(&cursor, n)
253 
255 #define STACK_CURSOR_NEXT(cursor) hhh_Cursor_next(&cursor)
256 
257 
258 #ifdef __cplusplus
259 } // extern "C"
260 #endif
261 
262 
263 #endif // not HEPHAESTUS_STACKSTASH_H
hhh_stackstash_store
StackHandle * hhh_stackstash_store(const StackElement *addresses, int n_addresses)
Return the handle for a stack trace.
hhh_Cursor_initRoot
void hhh_Cursor_initRoot(StackCursor *cursor)
Initialize a cursor to point at the root of the tree.
hhh_Cursor_parent
void hhh_Cursor_parent(StackCursor *cursor)
Move to the cursor to the parent node.
StackCursor_::node
StackNode * node
Definition: stackstash.h:111
StackElement
void * StackElement
One element of a stack trace.
Definition: stackstash.h:74
hhh_Cursor_initHandle
void hhh_Cursor_initHandle(StackCursor *cursor, StackHandle *handle)
Initialize a cursor from a handle.
StackNode_::nkids
unsigned short nkids
Definition: stackstash.h:97
StackHandle_
Unique reference for a stack trace.
Definition: stackstash.h:82
StackCursor_::elt
StackElement * elt
Definition: stackstash.h:112
StackNode_::nelts
unsigned short nelts
Definition: stackstash.h:96
hhh_Cursor_next
void hhh_Cursor_next(StackCursor *cursor)
Visit next element in depth-first order.
hhh_Cursor_child
void hhh_Cursor_child(StackCursor *cursor, int n)
Move to the cursor to the nth child.
StackNode_
Node used to store trace data.
Definition: stackstash.h:94
StackCursor_
Cursor object used to move between nodes of the tree.
Definition: stackstash.h:110
StackNode_::handles
StackHandle * handles
Definition: stackstash.h:98
beamspotman.n
n
Definition: beamspotman.py:731
StackNode_::p
void * p[1]
Definition: stackstash.h:100
StackHandle_::element
StackElement * element
Definition: stackstash.h:83
hhh_Cursor_nchildren
int hhh_Cursor_nchildren(StackCursor *cursor)
Return the number of children.
query_example.cursor
cursor
Definition: query_example.py:21
hhh_stack_element_parent
StackElement * hhh_stack_element_parent(StackElement *elt)
Function interface to iterate over a trace.
StackHandle_::next
struct StackHandle_ * next
Definition: stackstash.h:84
StackNode_::parent
struct StackNode_ * parent
Definition: stackstash.h:95