Add sequence and string support
[lttng-modules.git] / probes / lttng-types.h
CommitLineData
40652b65
MD
1/*
2 * Protect against multiple inclusion of structure declarations, but run the
3 * stages below each time.
4 */
5#ifndef _LTTNG_PROBES_LTTNG_TYPES_H
6#define _LTTNG_PROBES_LTTNG_TYPES_H
7
8#include <lttng.h>
9
1d12cebd
MD
10#ifdef __KERNEL__
11# include <asm/byteorder.h>
12# ifdef __BIG_ENDIAN
13# define __BYTE_ORDER __BIG_ENDIAN
14# elif defined(__LITTLE_ENDIAN)
15# define __BYTE_ORDER __LITTLE_ENDIAN
16# else
17# error "unknown endianness"
18# endif
19#ifndef __BIG_ENDIAN
20# define __BIG_ENDIAN 4321
21#endif
22#ifndef __LITTLE_ENDIAN
23# define __LITTLE_ENDIAN 1234
24#endif
25#else
26# include <endian.h>
27#endif
28
29/* Update the astract_types name table in lttng-types.c along with this enum */
40652b65
MD
30enum abstract_types {
31 atype_integer,
32 atype_enum,
33 atype_array,
1d12cebd
MD
34 atype_sequence,
35 atype_string,
40652b65
MD
36 NR_ABSTRACT_TYPES,
37};
38
1d12cebd
MD
39/* Update the string_encodings name table in lttng-types.c along with this enum */
40enum lttng_string_encodings {
41 lttng_encode_UTF8 = 0,
42 lttng_encode_ASCII = 1,
43 NR_STRING_ENCODINGS,
44};
45
40652b65
MD
46struct lttng_enum_entry {
47 unsigned long long start, end; /* start and end are inclusive */
48 const char *string;
49};
50
51struct lttng_enum {
52 const struct lttng_enum_entry *entries;
53 unsigned int len;
54};
55
56struct lttng_type {
57 enum abstract_types atype;
58 const char *name;
59 union {
60 struct {
61 unsigned int size; /* in bits */
62 unsigned short alignment; /* in bits */
63 unsigned int signedness:1;
1d12cebd 64 unsigned int reverse_byte_order:1;
40652b65
MD
65 } integer;
66 struct {
67 const char *parent_type;
68 const struct lttng_enum def;
69 } enumeration;
70 struct {
71 const char *elem_type;
72 unsigned int length; /* num. elems. */
73 } array;
1d12cebd
MD
74 struct {
75 const char *elem_type;
76 const char *length_type;
77 } sequence;
78 struct {
79 enum lttng_string_encodings encoding;
80 } string;
40652b65
MD
81 } u;
82} __attribute__((packed));
83
84#endif /* _LTTNG_PROBES_LTTNG_TYPES_H */
85
86
87/* Export enumerations */
88
89#ifdef STAGE_EXPORT_ENUMS
90
91#undef TRACE_EVENT_TYPE
92#define TRACE_EVENT_TYPE(_name, _abstract_type, args...)
93
94#undef TRACE_EVENT_ENUM
95#define TRACE_EVENT_ENUM(_name, _entries...) \
96 const struct lttng_enum_entry __trace_event_enum_##_name[] = { \
97 PARAMS(_entries) \
98 };
99
100/* Enumeration entry (single value) */
101#undef V
102#define V(_string) { _string, _string, #_string}
103
104/* Enumeration entry (range) */
105#undef R
106#define R(_string, _range_start, _range_end) \
107 { _range_start, _range_end, #_string }
108
109#endif /* STAGE_EXPORT_ENUMS */
110
111
112/* Export named types */
113
114#ifdef STAGE_EXPORT_TYPES
115
1d12cebd
MD
116#undef TRACE_EVENT_TYPE___integer_ext
117#define TRACE_EVENT_TYPE___integer_ext(_name, _byte_order) \
40652b65
MD
118 { \
119 .atype = atype_integer, \
120 .name = #_name, \
121 .u.integer.size = sizeof(_name) * 8, \
122 .u.integer.alignment = __alignof__(_name) * 8,\
123 .u.integer.signedness = is_signed_type(_name),\
1d12cebd 124 .u.integer.reverse_byte_order = ((_byte_order) != __BYTE_ORDER),\
40652b65
MD
125 },
126
1d12cebd
MD
127#undef TRACE_EVENT_TYPE___integer
128#define TRACE_EVENT_TYPE___integer(_name, _unused) \
129 TRACE_EVENT_TYPE___integer_ext(_name, __BYTE_ORDER)
130
40652b65
MD
131#undef TRACE_EVENT_TYPE___enum
132#define TRACE_EVENT_TYPE___enum(_name, _parent_type) \
133 { \
134 .atype = atype_enum, \
135 .name = #_name, \
136 .u.enumeration.parent_type = #_parent_type, \
137 .u.enumeration.def.entries = __trace_event_enum_##_name, \
138 .u.enumeration.def.len = ARRAY_SIZE(__trace_event_enum_##_name), \
139 },
140
141#undef TRACE_EVENT_TYPE___array
142#define TRACE_EVENT_TYPE___array(_name, _elem_type, _length) \
143 { \
144 .atype = atype_array, \
145 .name = #_name, \
146 .u.array.elem_type = #_elem_type, \
147 .u.array.length = _length, \
148 },
149
1d12cebd
MD
150#undef TRACE_EVENT_TYPE___sequence
151#define TRACE_EVENT_TYPE___sequence(_name, _elem_type, _length_type) \
152 { \
153 .atype = atype_sequence, \
154 .name = #_name, \
155 .u.sequence.elem_type = #_elem_type, \
156 .u.sequence.length_type = #_length_type, \
157 },
158
159#undef TRACE_EVENT_TYPE___string
160#define TRACE_EVENT_TYPE___string(_name, _encoding) \
161 { \
162 .atype = atype_string, \
163 .name = #_name, \
164 .u.string.encoding = lttng_encode_##_encoding,\
165 },
166
167
40652b65
MD
168/* Local declaration */
169#undef TRACE_EVENT_TYPE
170#define TRACE_EVENT_TYPE(_name, _abstract_type, args...) \
171 TRACE_EVENT_TYPE___##_abstract_type(_name, args)
172
173#undef TRACE_EVENT_ENUM
174#define TRACE_EVENT_ENUM(_name, _entries...)
175
176#endif /* STAGE_EXPORT_TYPES */
This page took 0.029422 seconds and 4 git commands to generate.