Implement filter bytecode support in lttng-session, and parse filter string
[lttng-tools.git] / src / lib / lttng-ctl / filter-bytecode.h
CommitLineData
953192ba
MD
1#ifndef _FILTER_BYTECODE_H
2#define _FILTER_BYTECODE_H
3
4/*
5 * filter-bytecode.h
6 *
7 * LTTng filter bytecode
8 *
9 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License, version 2.1 only,
13 * as published by the Free Software Foundation.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#include "filter-ast.h"
53a80697 26#include "../../common/sessiond-comm/sessiond-comm.h"
953192ba
MD
27
28/*
29 * offsets are absolute from start of bytecode.
30 */
31
32enum filter_register {
33 REG_R0 = 0,
34 REG_R1 = 1,
35 REG_ERROR,
36};
37
38enum field_ref_type {
39 FIELD_REF_UNKNOWN = 0,
40 FIELD_REF_STRING,
41 FIELD_REF_SEQUENCE,
42 FIELD_REF_S64,
43};
44
45struct field_ref {
46 /* Initially, symbol offset. After link, field offset. */
47 uint16_t offset;
48 uint8_t type; /* enum field_ref_type */
49} __attribute__((packed));
50
51struct literal_numeric {
52 int64_t v;
53} __attribute__((packed));
54
55struct literal_string {
56 char string[0];
57} __attribute__((packed));
58
59enum filter_op {
60 FILTER_OP_UNKNOWN = 0,
61
62 FILTER_OP_RETURN,
63
64 /* binary */
65 FILTER_OP_MUL,
66 FILTER_OP_DIV,
67 FILTER_OP_MOD,
68 FILTER_OP_PLUS,
69 FILTER_OP_MINUS,
70 FILTER_OP_RSHIFT,
71 FILTER_OP_LSHIFT,
72 FILTER_OP_BIN_AND,
73 FILTER_OP_BIN_OR,
74 FILTER_OP_BIN_XOR,
75 FILTER_OP_EQ,
76 FILTER_OP_NE,
77 FILTER_OP_GT,
78 FILTER_OP_LT,
79 FILTER_OP_GE,
80 FILTER_OP_LE,
81
82 /* unary */
83 FILTER_OP_UNARY_PLUS,
84 FILTER_OP_UNARY_MINUS,
85 FILTER_OP_UNARY_NOT,
86
87 /* logical */
88 FILTER_OP_AND,
89 FILTER_OP_OR,
90
91 /* load */
92 FILTER_OP_LOAD_FIELD_REF,
93 FILTER_OP_LOAD_STRING,
94 FILTER_OP_LOAD_S64,
95
96 NR_FILTER_OPS,
97};
98
99typedef uint8_t filter_opcode_t;
100
101struct load_op {
102 filter_opcode_t op;
103 uint8_t reg; /* enum filter_register */
104 char data[0];
105 /* data to load. Size known by enum filter_opcode and null-term char. */
106} __attribute__((packed));
107
108struct binary_op {
109 filter_opcode_t op;
110} __attribute__((packed));
111
112struct unary_op {
113 filter_opcode_t op;
114 uint8_t reg; /* enum filter_register */
115} __attribute__((packed));
116
117/* skip_offset is absolute from start of bytecode */
118struct logical_op {
119 filter_opcode_t op;
120 uint16_t skip_offset; /* bytecode insn, if skip second test */
121} __attribute__((packed));
122
123struct return_op {
124 filter_opcode_t op;
125} __attribute__((packed));
126
53a80697 127struct lttng_filter_bytecode_alloc {
953192ba 128 uint16_t alloc_len;
53a80697 129 struct lttng_filter_bytecode b;
953192ba
MD
130};
131
132static inline
53a80697 133unsigned int bytecode_get_len(struct lttng_filter_bytecode *bytecode)
953192ba
MD
134{
135 return bytecode->len;
136}
137
138#endif /* _FILTER_BYTECODE_H */
This page took 0.039786 seconds and 4 git commands to generate.