ATLAS Offline Software
Loading...
Searching...
No Matches
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$ */
60
61#ifndef HEPHAESTUS_STACKSTASH_H
62#define HEPHAESTUS_STACKSTASH_H
63
64
65#include <stddef.h>
66
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72
74typedef void* StackElement;
75
76
87
88
94{
96 unsigned short nelts;
97 unsigned short nkids;
99 /* First elt is always 0. */
100 void* p[1];
101};
102typedef struct StackNode_ StackNode;
103
104
115
116
127 int n_addresses);
128
129
138
139
142
145
148
150void hhh_Cursor_child(StackCursor* cursor, int n);
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
void hhh_Cursor_child(StackCursor *cursor, int n)
Move to the cursor to the nth child.
void * StackElement
One element of a stack trace.
Definition stackstash.h:74
struct StackCursor_ StackCursor
Definition stackstash.h:114
int hhh_Cursor_nchildren(StackCursor *cursor)
Return the number of children.
struct StackHandle_ StackHandle
Definition stackstash.h:86
void hhh_Cursor_next(StackCursor *cursor)
Visit next element in depth-first order.
void hhh_Cursor_initRoot(StackCursor *cursor)
Initialize a cursor to point at the root of the tree.
struct StackNode_ StackNode
Definition stackstash.h:102
void hhh_Cursor_parent(StackCursor *cursor)
Move to the cursor to the parent node.
void hhh_Cursor_initHandle(StackCursor *cursor, StackHandle *handle)
Initialize a cursor from a handle.
StackHandle * hhh_stackstash_store(const StackElement *addresses, int n_addresses)
Return the handle for a stack trace.
StackElement * hhh_stack_element_parent(StackElement *elt)
Function interface to iterate over a trace.
Cursor object used to move between nodes of the tree.
Definition stackstash.h:110
StackNode * node
Definition stackstash.h:111
StackElement * elt
Definition stackstash.h:112
Unique reference for a stack trace.
Definition stackstash.h:82
StackElement * element
Definition stackstash.h:83
struct StackHandle_ * next
Definition stackstash.h:84
Node used to store trace data.
Definition stackstash.h:94
unsigned short nkids
Definition stackstash.h:97
void * p[1]
Definition stackstash.h:100
StackHandle * handles
Definition stackstash.h:98
unsigned short nelts
Definition stackstash.h:96
struct StackNode_ * parent
Definition stackstash.h:95