babeltrace 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b20aa5d5700fbd87542d7f18e28694331d8c40d829b9e0ad21467a324ed967e8
4
+ data.tar.gz: 277e12efb46a72d3ee5fb7b9f3f334dfff68afdd90d31140a5269c16a07d977d
5
+ SHA512:
6
+ metadata.gz: 7f554331ae52beb5450495f46280dfdde55b8ebf9d8edc3a079d35e08fcf770aa082c14657731faeaaee5e051e3a5c46c8fabb36a58950d703aaec1679238035
7
+ data.tar.gz: 032d750e4ffff78b92489234ef4de4600aefbf97bdab2c1e54ab7ca52cad2cfe764f6f29b4a5606ea6a46bf096e46dd35b7625d5f2fb148e8090f37c536e5061
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Brice Videau <bvideau@anl.gov>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'babeltrace'
3
+ s.version = "0.1.0"
4
+ s.author = "Brice Videau"
5
+ s.email = "bvideau@anl.gov"
6
+ s.homepage = "https://github.com/alcf-perfengr/babeltrace-ruby"
7
+ s.summary = "Ruby libbabeltrace bindings"
8
+ s.description = "Ruby libbabeltrace ffi bindings"
9
+ s.files = Dir[ 'babeltrace.gemspec', 'LICENSE', 'lib/**/**/*.rb', 'ext/**/*.rb', 'ext/**/*.c', 'ext/**/**/*.h' ]
10
+ s.extensions << 'ext/babeltrace_c/extconf.rb'
11
+ s.has_rdoc = false
12
+ s.license = 'MIT'
13
+ s.required_ruby_version = '>= 2.3.0'
14
+ s.add_dependency 'ffi', '~> 1.9', '>=1.9.3'
15
+ end
@@ -0,0 +1,77 @@
1
+ #include "ruby.h"
2
+ #include "babeltrace/babeltrace.h"
3
+ #include "babeltrace/ctf/events.h"
4
+ #include "./babeltrace/types.h"
5
+
6
+
7
+ static VALUE m_babeltrace;
8
+ static VALUE m_ctf;
9
+ static VALUE m_internal;
10
+ static VALUE c_internal_declaration;
11
+ static VALUE c_internal_definition;
12
+ static VALUE c_ctf_declaration;
13
+ static VALUE c_ctf_array_declaration;
14
+ static VALUE c_ctf_sequence_declaration;
15
+
16
+ static VALUE m_ffi;
17
+ static VALUE c_ffi_pointer;
18
+ static VALUE c_ffi_struct;
19
+
20
+ static VALUE babeltrace_ctf_array_decl_elem(VALUE self) {
21
+
22
+ VALUE decl = rb_ivar_get(self, rb_intern("@declaration"));
23
+ VALUE p = rb_funcall(decl, rb_intern("pointer"), 0);
24
+ VALUE address = rb_funcall(p, rb_intern("address"), 0);
25
+
26
+ const struct declaration_array *ptr = sizeof(ptr) == 4 ? (const struct declaration_array *) NUM2ULONG(address) : (const struct declaration_array *) NUM2ULL(address);
27
+ struct bt_declaration *elem = ptr->elem;
28
+
29
+ VALUE ffi_ptr = rb_funcall(c_ffi_pointer, rb_intern("new"), 1, ULL2NUM( sizeof(ptr) == 4 ? (unsigned long long int) (unsigned long int) elem : (unsigned long long int) elem ));
30
+
31
+ VALUE idecl = rb_funcall(c_internal_declaration, rb_intern("new"), 1, ffi_ptr);
32
+ VALUE arr_decl = rb_funcall(c_ctf_array_declaration, rb_intern("create"), 1, idecl);
33
+ return arr_decl;
34
+ }
35
+
36
+ static VALUE babeltrace_ctf_sequence_decl_elem(VALUE self) {
37
+
38
+ VALUE decl = rb_ivar_get(self, rb_intern("@declaration"));
39
+ VALUE p = rb_funcall(decl, rb_intern("pointer"), 0);
40
+ VALUE address = rb_funcall(p, rb_intern("address"), 0);
41
+
42
+ const struct declaration_sequence *ptr = sizeof(ptr) == 4 ? (const struct declaration_sequence *) NUM2ULONG(address) : (const struct declaration_sequence *) NUM2ULL(address);
43
+ struct bt_declaration *elem = ptr->elem;
44
+
45
+ VALUE ffi_ptr = rb_funcall(c_ffi_pointer, rb_intern("new"), 1, ULL2NUM( sizeof(ptr) == 4 ? (unsigned long long int) (unsigned long int) elem : (unsigned long long int) elem ));
46
+
47
+ VALUE idecl = rb_funcall(c_internal_declaration, rb_intern("new"), 1, ffi_ptr);
48
+ VALUE seq_decl = rb_funcall(c_ctf_sequence_declaration, rb_intern("create"), 1, idecl);
49
+ return seq_decl;
50
+ }
51
+
52
+ static VALUE babeltrace_ctf_internal_definition_get_char_sequence(VALUE self) {
53
+ VALUE p = rb_funcall(self, rb_intern("pointer"), 0);
54
+ VALUE address = rb_funcall(p, rb_intern("address"), 0);
55
+ const struct definition_sequence *ptr = sizeof(ptr) == 4 ? (const struct definition_sequence *) NUM2ULONG(address) : (const struct definition_sequence *) NUM2ULL(address);
56
+
57
+ char *str = ptr->string->str;
58
+ VALUE ffi_ptr = rb_funcall(c_ffi_pointer, rb_intern("new"), 1, ULL2NUM( sizeof(ptr) == 4 ? (unsigned long long int) (unsigned long int) str : (unsigned long long int) str ));
59
+ return ffi_ptr;
60
+ }
61
+
62
+ void Init_babeltrace_c() {
63
+ m_babeltrace = rb_define_module("Babeltrace");
64
+ m_ctf = rb_define_module_under(m_babeltrace, "CTF");
65
+ m_internal = rb_define_module_under(m_ctf, "Internal");
66
+ m_ffi = rb_const_get(rb_cObject, rb_intern("FFI"));
67
+ c_ffi_pointer = rb_const_get(m_ffi, rb_intern("Pointer"));
68
+ c_ffi_struct = rb_const_get(m_ffi, rb_intern("Struct"));
69
+ c_internal_declaration = rb_define_class_under(m_internal, "Declaration", c_ffi_struct);
70
+ c_internal_definition = rb_define_class_under(m_internal, "Definition", c_ffi_struct);
71
+ c_ctf_declaration = rb_define_class_under(m_ctf, "Declaration", rb_cObject);
72
+ c_ctf_array_declaration = rb_define_class_under(m_ctf, "ArrayDecl", c_ctf_declaration);
73
+ c_ctf_sequence_declaration = rb_define_class_under(m_ctf, "SequenceDecl", c_ctf_declaration);
74
+ rb_define_method(c_ctf_array_declaration, "elem", babeltrace_ctf_array_decl_elem, 0);
75
+ rb_define_method(c_ctf_sequence_declaration, "elem", babeltrace_ctf_sequence_decl_elem, 0);
76
+ rb_define_method(c_internal_definition, "get_char_sequence", babeltrace_ctf_internal_definition_get_char_sequence, 0);
77
+ }
@@ -0,0 +1,82 @@
1
+ #ifndef _BABELTRACE_ALIGN_H
2
+ #define _BABELTRACE_ALIGN_H
3
+
4
+ /*
5
+ * BabelTrace align.h - alignment header
6
+ *
7
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in
17
+ * all copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ #include <babeltrace/compiler.h>
29
+ #include <unistd.h>
30
+ #include <limits.h>
31
+
32
+ #ifndef PAGE_SIZE /* Cygwin limits.h defines its own PAGE_SIZE */
33
+ #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
34
+ #endif
35
+
36
+ #define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
37
+ #define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
38
+ #define PTR_ALIGN(p, a) ((typeof(p)) ALIGN((unsigned long) (p), a))
39
+ #define ALIGN_FLOOR(x, a) __ALIGN_FLOOR_MASK(x, (typeof(x)) (a) - 1)
40
+ #define __ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask))
41
+ #define PTR_ALIGN_FLOOR(p, a) \
42
+ ((typeof(p)) ALIGN_FLOOR((unsigned long) (p), a))
43
+ #define IS_ALIGNED(x, a) (((x) & ((typeof(x)) (a) - 1)) == 0)
44
+
45
+ /*
46
+ * Align pointer on natural object alignment.
47
+ */
48
+ #define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj)))
49
+ #define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj)))
50
+
51
+ /**
52
+ * offset_align - Calculate the offset needed to align an object on its natural
53
+ * alignment towards higher addresses.
54
+ * @align_drift: object offset from an "alignment"-aligned address.
55
+ * @alignment: natural object alignment. Must be non-zero, power of 2.
56
+ *
57
+ * Returns the offset that must be added to align towards higher
58
+ * addresses.
59
+ */
60
+ #define offset_align(align_drift, alignment) \
61
+ ({ \
62
+ MAYBE_BUILD_BUG_ON((alignment) == 0 \
63
+ || ((alignment) & ((alignment) - 1))); \
64
+ (((alignment) - (align_drift)) & ((alignment) - 1)); \
65
+ })
66
+
67
+ /**
68
+ * offset_align_floor - Calculate the offset needed to align an object
69
+ * on its natural alignment towards lower addresses.
70
+ * @align_drift: object offset from an "alignment"-aligned address.
71
+ * @alignment: natural object alignment. Must be non-zero, power of 2.
72
+ *
73
+ * Returns the offset that must be substracted to align towards lower addresses.
74
+ */
75
+ #define offset_align_floor(align_drift, alignment) \
76
+ ({ \
77
+ MAYBE_BUILD_BUG_ON((alignment) == 0 \
78
+ || ((alignment) & ((alignment) - 1))); \
79
+ (((align_drift) - (alignment)) & ((alignment) - 1)); \
80
+ })
81
+
82
+ #endif /* _BABELTRACE_ALIGN_H */
@@ -0,0 +1,40 @@
1
+ #ifndef _BABELTRACE_COMPILER_H
2
+ #define _BABELTRACE_COMPILER_H
3
+
4
+ /*
5
+ * compiler.h
6
+ *
7
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in
17
+ * all copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ #include <stddef.h> /* for offsetof */
29
+
30
+ #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
31
+
32
+ #ifndef container_of
33
+ #define container_of(ptr, type, member) \
34
+ ({ \
35
+ const typeof(((type *)NULL)->member) * __ptr = (ptr); \
36
+ (type *)((char *)__ptr - offsetof(type, member)); \
37
+ })
38
+ #endif
39
+
40
+ #endif /* _BABELTRACE_COMPILER_H */
@@ -0,0 +1,565 @@
1
+ #ifndef _BABELTRACE_TYPES_H
2
+ #define _BABELTRACE_TYPES_H
3
+
4
+ /*
5
+ * BabelTrace
6
+ *
7
+ * Type Header
8
+ *
9
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
10
+ *
11
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in
21
+ * all copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ #include <babeltrace/align.h>
33
+ #include <babeltrace/list.h>
34
+ #include <babeltrace/ctf/events.h>
35
+ #include <stdbool.h>
36
+ #include <stdint.h>
37
+ #include <limits.h>
38
+ #include <string.h>
39
+ #include <glib.h>
40
+ #include <assert.h>
41
+
42
+ /* Preallocate this many fields for structures */
43
+ #define DEFAULT_NR_STRUCT_FIELDS 8
44
+
45
+ struct ctf_stream_definition;
46
+ struct bt_stream_pos;
47
+ struct bt_format;
48
+ struct bt_definition;
49
+ struct ctf_clock;
50
+
51
+ /* type scope */
52
+ struct declaration_scope {
53
+ /* Hash table mapping type name GQuark to "struct declaration" */
54
+ /* Used for both typedef and typealias. */
55
+ GHashTable *typedef_declarations;
56
+ /* Hash table mapping struct name GQuark to "struct declaration_struct" */
57
+ GHashTable *struct_declarations;
58
+ /* Hash table mapping variant name GQuark to "struct declaration_variant" */
59
+ GHashTable *variant_declarations;
60
+ /* Hash table mapping enum name GQuark to "struct type_enum" */
61
+ GHashTable *enum_declarations;
62
+ struct declaration_scope *parent_scope;
63
+ };
64
+
65
+ /* definition scope */
66
+ struct definition_scope {
67
+ /* Hash table mapping field name GQuark to "struct definition" */
68
+ GHashTable *definitions;
69
+ struct definition_scope *parent_scope;
70
+ /*
71
+ * Complete "path" leading to this definition scope.
72
+ * Includes dynamic scope name '.' field name '.' field name '.' ....
73
+ * Array of GQuark elements (which are each separated by dots).
74
+ * The dynamic scope name can contain dots, and is encoded into
75
+ * a single GQuark. Thus, scope_path[0] returns the GQuark
76
+ * identifying the dynamic scope.
77
+ */
78
+ GArray *scope_path; /* array of GQuark */
79
+ };
80
+
81
+ struct bt_declaration {
82
+ enum ctf_type_id id;
83
+ size_t alignment; /* type alignment, in bits */
84
+ int ref; /* number of references to the type */
85
+ /*
86
+ * declaration_free called with declaration ref is decremented to 0.
87
+ */
88
+ void (*declaration_free)(struct bt_declaration *declaration);
89
+ struct bt_definition *
90
+ (*definition_new)(struct bt_declaration *declaration,
91
+ struct definition_scope *parent_scope,
92
+ GQuark field_name, int index,
93
+ const char *root_name);
94
+ /*
95
+ * definition_free called with definition ref is decremented to 0.
96
+ */
97
+ void (*definition_free)(struct bt_definition *definition);
98
+ };
99
+
100
+ struct bt_definition {
101
+ struct bt_declaration *declaration;
102
+ int index; /* Position of the definition in its container */
103
+ GQuark name; /* Field name in its container (or 0 if unset) */
104
+ int ref; /* number of references to the definition */
105
+ GQuark path;
106
+ struct definition_scope *scope;
107
+ };
108
+
109
+ typedef int (*rw_dispatch)(struct bt_stream_pos *pos,
110
+ struct bt_definition *definition);
111
+
112
+ /* Parent of per-plugin positions */
113
+ struct bt_stream_pos {
114
+ /* read/write dispatch table. Specific to plugin used for stream. */
115
+ rw_dispatch *rw_table; /* rw dispatch table */
116
+ int (*event_cb)(struct bt_stream_pos *pos,
117
+ struct ctf_stream_definition *stream);
118
+ int (*pre_trace_cb)(struct bt_stream_pos *pos,
119
+ struct bt_trace_descriptor *trace);
120
+ int (*post_trace_cb)(struct bt_stream_pos *pos,
121
+ struct bt_trace_descriptor *trace);
122
+ struct bt_trace_descriptor *trace;
123
+ };
124
+
125
+ static inline
126
+ int generic_rw(struct bt_stream_pos *pos, struct bt_definition *definition)
127
+ {
128
+ enum ctf_type_id dispatch_id = definition->declaration->id;
129
+ rw_dispatch call;
130
+
131
+ assert(pos->rw_table[dispatch_id] != NULL);
132
+ call = pos->rw_table[dispatch_id];
133
+ return call(pos, definition);
134
+ }
135
+
136
+ /*
137
+ * Because we address in bits, bitfields end up being exactly the same as
138
+ * integers, except that their read/write functions must be able to deal with
139
+ * read/write non aligned on CHAR_BIT.
140
+ */
141
+ struct declaration_integer {
142
+ struct bt_declaration p;
143
+ size_t len; /* length, in bits. */
144
+ int byte_order; /* byte order */
145
+ int signedness;
146
+ int base; /* Base for pretty-printing: 2, 8, 10, 16 */
147
+ enum ctf_string_encoding encoding;
148
+ struct ctf_clock *clock;
149
+ };
150
+
151
+ #ifdef ENABLE_DEBUG_INFO
152
+ struct debug_info_source;
153
+ #endif
154
+
155
+ struct definition_integer {
156
+ struct bt_definition p;
157
+ struct declaration_integer *declaration;
158
+ /* Last values read */
159
+ union {
160
+ uint64_t _unsigned;
161
+ int64_t _signed;
162
+ } value;
163
+
164
+ #ifdef ENABLE_DEBUG_INFO
165
+ /*
166
+ * Debug infos (NULL if not set).
167
+ *
168
+ * This is extended debug informations set by the CTF input plugin
169
+ * itself when available. If it's set, then this integer definition
170
+ * is the "_ip" field of the stream event context.
171
+ */
172
+ struct debug_info_source *debug_info_src;
173
+ #endif
174
+ };
175
+
176
+ struct declaration_float {
177
+ struct bt_declaration p;
178
+ struct declaration_integer *sign;
179
+ struct declaration_integer *mantissa;
180
+ struct declaration_integer *exp;
181
+ int byte_order;
182
+ /* TODO: we might want to express more info about NaN, +inf and -inf */
183
+ };
184
+
185
+ struct definition_float {
186
+ struct bt_definition p;
187
+ struct declaration_float *declaration;
188
+ struct definition_integer *sign;
189
+ struct definition_integer *mantissa;
190
+ struct definition_integer *exp;
191
+ /* Last values read */
192
+ double value;
193
+ };
194
+
195
+ /*
196
+ * enum_val_equal assumes that signed and unsigned memory layout overlap.
197
+ */
198
+ struct enum_range {
199
+ union {
200
+ int64_t _signed;
201
+ uint64_t _unsigned;
202
+ } start; /* lowest range value */
203
+ union {
204
+ int64_t _signed;
205
+ uint64_t _unsigned;
206
+ } end; /* highest range value */
207
+ };
208
+
209
+ struct enum_range_to_quark {
210
+ struct bt_list_head node;
211
+ struct enum_range range;
212
+ GQuark quark;
213
+ };
214
+
215
+ /*
216
+ * We optimize the common case (range of size 1: single value) by creating a
217
+ * hash table mapping values to quark sets. We then lookup the ranges to
218
+ * complete the quark set.
219
+ *
220
+ * TODO: The proper structure to hold the range to quark set mapping would be an
221
+ * interval tree, with O(n) size, O(n*log(n)) build time and O(log(n)) query
222
+ * time. Using a simple O(n) list search for now for implementation speed and
223
+ * given that we can expect to have a _relatively_ small number of enumeration
224
+ * ranges. This might become untrue if we are fed with symbol tables often
225
+ * required to lookup function names from instruction pointer value.
226
+ */
227
+ struct enum_table {
228
+ GHashTable *value_to_quark_set; /* (value, GQuark GArray) */
229
+ struct bt_list_head range_to_quark; /* (range, GQuark) */
230
+ GHashTable *quark_to_range_set; /* (GQuark, range GArray) */
231
+ };
232
+
233
+ struct declaration_enum {
234
+ struct bt_declaration p;
235
+ struct declaration_integer *integer_declaration;
236
+ struct enum_table table;
237
+ };
238
+
239
+ struct definition_enum {
240
+ struct bt_definition p;
241
+ struct definition_integer *integer;
242
+ struct declaration_enum *declaration;
243
+ /* Last GQuark values read. Keeping a reference on the GQuark array. */
244
+ GArray *value;
245
+ };
246
+
247
+ struct declaration_string {
248
+ struct bt_declaration p;
249
+ enum ctf_string_encoding encoding;
250
+ };
251
+
252
+ struct definition_string {
253
+ struct bt_definition p;
254
+ struct declaration_string *declaration;
255
+ char *value; /* freed at definition_string teardown */
256
+ size_t len, alloc_len;
257
+ };
258
+
259
+ struct declaration_field {
260
+ GQuark name;
261
+ struct bt_declaration *declaration;
262
+ };
263
+
264
+ struct declaration_struct {
265
+ struct bt_declaration p;
266
+ GHashTable *fields_by_name; /* Tuples (field name, field index) */
267
+ struct declaration_scope *scope;
268
+ GArray *fields; /* Array of declaration_field */
269
+ };
270
+
271
+ struct definition_struct {
272
+ struct bt_definition p;
273
+ struct declaration_struct *declaration;
274
+ GPtrArray *fields; /* Array of pointers to struct bt_definition */
275
+ };
276
+
277
+ struct declaration_untagged_variant {
278
+ struct bt_declaration p;
279
+ GHashTable *fields_by_tag; /* Tuples (field tag, field index) */
280
+ struct declaration_scope *scope;
281
+ GArray *fields; /* Array of declaration_field */
282
+ };
283
+
284
+ struct declaration_variant {
285
+ struct bt_declaration p;
286
+ struct declaration_untagged_variant *untagged_variant;
287
+ GArray *tag_name; /* Array of GQuark */
288
+ };
289
+
290
+ /* A variant needs to be tagged to be defined. */
291
+ struct definition_variant {
292
+ struct bt_definition p;
293
+ struct declaration_variant *declaration;
294
+ struct bt_definition *enum_tag;
295
+ GPtrArray *fields; /* Array of pointers to struct bt_definition */
296
+ struct bt_definition *current_field; /* Last field read */
297
+ };
298
+
299
+ struct declaration_array {
300
+ struct bt_declaration p;
301
+ size_t len;
302
+ struct bt_declaration *elem;
303
+ struct declaration_scope *scope;
304
+ };
305
+
306
+ struct definition_array {
307
+ struct bt_definition p;
308
+ struct declaration_array *declaration;
309
+ GPtrArray *elems; /* Array of pointers to struct bt_definition */
310
+ GString *string; /* String for encoded integer children */
311
+ };
312
+
313
+ struct declaration_sequence {
314
+ struct bt_declaration p;
315
+ GArray *length_name; /* Array of GQuark */
316
+ struct bt_declaration *elem;
317
+ struct declaration_scope *scope;
318
+ };
319
+
320
+ struct definition_sequence {
321
+ struct bt_definition p;
322
+ struct declaration_sequence *declaration;
323
+ struct definition_integer *length;
324
+ GPtrArray *elems; /* Array of pointers to struct bt_definition */
325
+ GString *string; /* String for encoded integer children */
326
+ };
327
+
328
+ int bt_register_declaration(GQuark declaration_name,
329
+ struct bt_declaration *declaration,
330
+ struct declaration_scope *scope);
331
+ struct bt_declaration *bt_lookup_declaration(GQuark declaration_name,
332
+ struct declaration_scope *scope);
333
+
334
+ /*
335
+ * Type scopes also contain a separate registry for struct, variant and
336
+ * enum types. Those register types rather than type definitions, so
337
+ * that a named variant can be declared without specifying its target
338
+ * "choice" tag field immediately.
339
+ */
340
+ int bt_register_struct_declaration(GQuark struct_name,
341
+ struct declaration_struct *struct_declaration,
342
+ struct declaration_scope *scope);
343
+ struct declaration_struct *
344
+ bt_lookup_struct_declaration(GQuark struct_name,
345
+ struct declaration_scope *scope);
346
+ int bt_register_variant_declaration(GQuark variant_name,
347
+ struct declaration_untagged_variant *untagged_variant_declaration,
348
+ struct declaration_scope *scope);
349
+ struct declaration_untagged_variant *bt_lookup_variant_declaration(GQuark variant_name,
350
+ struct declaration_scope *scope);
351
+ int bt_register_enum_declaration(GQuark enum_name,
352
+ struct declaration_enum *enum_declaration,
353
+ struct declaration_scope *scope);
354
+ struct declaration_enum *
355
+ bt_lookup_enum_declaration(GQuark enum_name,
356
+ struct declaration_scope *scope);
357
+
358
+ struct declaration_scope *
359
+ bt_new_declaration_scope(struct declaration_scope *parent_scope);
360
+ void bt_free_declaration_scope(struct declaration_scope *scope);
361
+
362
+ /*
363
+ * field_definition is for field definitions. They are registered into
364
+ * definition scopes.
365
+ */
366
+ struct bt_definition *
367
+ bt_lookup_path_definition(GArray *cur_path, /* array of GQuark */
368
+ GArray *lookup_path, /* array of GQuark */
369
+ struct definition_scope *scope);
370
+ int bt_register_field_definition(GQuark field_name,
371
+ struct bt_definition *definition,
372
+ struct definition_scope *scope);
373
+ struct definition_scope *
374
+ bt_new_definition_scope(struct definition_scope *parent_scope,
375
+ GQuark field_name, const char *root_name);
376
+ void bt_free_definition_scope(struct definition_scope *scope);
377
+
378
+ GQuark bt_new_definition_path(struct definition_scope *parent_scope,
379
+ GQuark field_name, const char *root_name);
380
+
381
+ static inline
382
+ int compare_definition_path(struct bt_definition *definition, GQuark path)
383
+ {
384
+ return definition->path == path;
385
+ }
386
+
387
+ void bt_declaration_ref(struct bt_declaration *declaration);
388
+ void bt_declaration_unref(struct bt_declaration *declaration);
389
+
390
+ void bt_definition_ref(struct bt_definition *definition);
391
+ void bt_definition_unref(struct bt_definition *definition);
392
+
393
+ struct declaration_integer *bt_integer_declaration_new(size_t len, int byte_order,
394
+ int signedness, size_t alignment,
395
+ int base, enum ctf_string_encoding encoding,
396
+ struct ctf_clock *clock);
397
+ uint64_t bt_get_unsigned_int(const struct bt_definition *field);
398
+ int64_t bt_get_signed_int(const struct bt_definition *field);
399
+ int bt_get_int_signedness(const struct bt_definition *field);
400
+ int bt_get_int_byte_order(const struct bt_definition *field);
401
+ int bt_get_int_base(const struct bt_definition *field);
402
+ size_t bt_get_int_len(const struct bt_definition *field); /* in bits */
403
+ enum ctf_string_encoding bt_get_int_encoding(const struct bt_definition *field);
404
+
405
+ /*
406
+ * mantissa_len is the length of the number of bytes represented by the mantissa
407
+ * (e.g. result of DBL_MANT_DIG). It includes the leading 1.
408
+ */
409
+ struct declaration_float *bt_float_declaration_new(size_t mantissa_len,
410
+ size_t exp_len, int byte_order,
411
+ size_t alignment);
412
+
413
+ /*
414
+ * A GQuark can be translated to/from strings with g_quark_from_string() and
415
+ * g_quark_to_string().
416
+ */
417
+
418
+ /*
419
+ * Returns a GArray of GQuark or NULL.
420
+ * Caller must release the GArray with g_array_unref().
421
+ */
422
+ GArray *bt_enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
423
+ uint64_t v);
424
+
425
+ /*
426
+ * Returns a GArray of GQuark or NULL.
427
+ * Caller must release the GArray with g_array_unref().
428
+ */
429
+ GArray *bt_enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
430
+ int64_t v);
431
+
432
+ /*
433
+ * Returns a GArray of struct enum_range or NULL.
434
+ * Callers do _not_ own the returned GArray (and therefore _don't_ need to
435
+ * release it).
436
+ */
437
+ GArray *bt_enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
438
+ GQuark q);
439
+ void bt_enum_signed_insert(struct declaration_enum *enum_declaration,
440
+ int64_t start, int64_t end, GQuark q);
441
+ void bt_enum_unsigned_insert(struct declaration_enum *enum_declaration,
442
+ uint64_t start, uint64_t end, GQuark q);
443
+ size_t bt_enum_get_nr_enumerators(struct declaration_enum *enum_declaration);
444
+
445
+ struct declaration_enum *
446
+ bt_enum_declaration_new(struct declaration_integer *integer_declaration);
447
+
448
+ struct declaration_string *
449
+ bt_string_declaration_new(enum ctf_string_encoding encoding);
450
+ char *bt_get_string(const struct bt_definition *field);
451
+ enum ctf_string_encoding bt_get_string_encoding(const struct bt_definition *field);
452
+
453
+ double bt_get_float(const struct bt_definition *field);
454
+
455
+ const struct bt_definition *bt_get_variant_field(struct bt_definition *definition);
456
+
457
+ struct declaration_struct *
458
+ bt_struct_declaration_new(struct declaration_scope *parent_scope,
459
+ uint64_t min_align);
460
+ void bt_struct_declaration_add_field(struct declaration_struct *struct_declaration,
461
+ const char *field_name,
462
+ struct bt_declaration *field_declaration);
463
+ /*
464
+ * Returns the index of a field within a structure.
465
+ */
466
+ int bt_struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
467
+ GQuark field_name);
468
+ /*
469
+ * field returned only valid as long as the field structure is not appended to.
470
+ */
471
+ struct declaration_field *
472
+ bt_struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
473
+ int index);
474
+ struct bt_definition *
475
+ bt_struct_definition_get_field_from_index(const struct definition_struct *struct_definition,
476
+ int index);
477
+ int bt_struct_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
478
+ uint64_t bt_struct_declaration_len(const struct declaration_struct *struct_declaration);
479
+
480
+ /*
481
+ * The tag enumeration is validated to ensure that it contains only mappings
482
+ * from numeric values to a single tag. Overlapping tag value ranges are
483
+ * therefore forbidden.
484
+ */
485
+ struct declaration_untagged_variant *bt_untagged_bt_variant_declaration_new(
486
+ struct declaration_scope *parent_scope);
487
+ struct declaration_variant *bt_variant_declaration_new(struct declaration_untagged_variant *untagged_variant,
488
+ const char *tag);
489
+
490
+ void bt_untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration,
491
+ const char *field_name,
492
+ struct bt_declaration *field_declaration);
493
+ struct declaration_field *
494
+ bt_untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration,
495
+ GQuark tag);
496
+ /*
497
+ * Returns 0 on success, -EPERM on error.
498
+ */
499
+ int variant_definition_set_tag(struct definition_variant *variant,
500
+ struct bt_definition *enum_tag);
501
+ /*
502
+ * Returns the field selected by the current tag value.
503
+ * field returned only valid as long as the variant structure is not appended
504
+ * to.
505
+ */
506
+ struct bt_definition *bt_variant_get_current_field(struct definition_variant *variant);
507
+ int bt_variant_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
508
+
509
+ /*
510
+ * elem_declaration passed as parameter now belongs to the array. No
511
+ * need to free it explicitly. "len" is the number of elements in the
512
+ * array.
513
+ */
514
+ struct declaration_array *
515
+ bt_array_declaration_new(size_t len, struct bt_declaration *elem_declaration,
516
+ struct declaration_scope *parent_scope);
517
+ uint64_t bt_array_len(struct definition_array *array);
518
+ struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
519
+ int bt_array_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
520
+ GString *bt_get_char_array(const struct bt_definition *field);
521
+ int bt_get_array_len(const struct bt_definition *field);
522
+
523
+ /*
524
+ * int_declaration and elem_declaration passed as parameter now belong
525
+ * to the sequence. No need to free them explicitly.
526
+ */
527
+ struct declaration_sequence *
528
+ bt_sequence_declaration_new(const char *length_name,
529
+ struct bt_declaration *elem_declaration,
530
+ struct declaration_scope *parent_scope);
531
+ uint64_t bt_sequence_len(struct definition_sequence *sequence);
532
+ struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
533
+ int bt_sequence_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
534
+
535
+ /*
536
+ * in: path (dot separated), out: q (GArray of GQuark)
537
+ */
538
+ void bt_append_scope_path(const char *path, GArray *q);
539
+
540
+ /*
541
+ * Lookup helpers.
542
+ */
543
+ struct bt_definition *bt_lookup_definition(const struct bt_definition *definition,
544
+ const char *field_name);
545
+ struct bt_definition *bt_lookup_definition_by_quark(const struct bt_definition *definition,
546
+ GQuark quark);
547
+ struct definition_integer *bt_lookup_integer(const struct bt_definition *definition,
548
+ const char *field_name,
549
+ int signedness);
550
+ struct definition_enum *bt_lookup_enum(const struct bt_definition *definition,
551
+ const char *field_name,
552
+ int signedness);
553
+ struct bt_definition *bt_lookup_variant(const struct bt_definition *definition,
554
+ const char *field_name);
555
+
556
+ static inline
557
+ const char *rem_(const char *str)
558
+ {
559
+ if (str[0] == '_')
560
+ return &str[1];
561
+ else
562
+ return str;
563
+ }
564
+
565
+ #endif /* _BABELTRACE_TYPES_H */