Fix: add missing semicolons after MSG, DBG, ERR print macros
[lttng-tools.git] / src / common / filter.c
CommitLineData
71a559f8
JG
1/*
2 * filter.c
3 *
4 * LTTng filter bytecode utilities.
5 *
6 * Copyright 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "filter.h"
23#include <stddef.h>
24
25struct bytecode_symbol_iterator {
26 /* No ownership of bytecode is taken. */
27 char *bytecode;
28 size_t offset, len;
29};
30
4af1498e 31LTTNG_HIDDEN
71a559f8
JG
32struct bytecode_symbol_iterator *bytecode_symbol_iterator_create(
33 struct lttng_filter_bytecode *bytecode)
34{
35 struct bytecode_symbol_iterator *it = NULL;
36
37 if (!bytecode) {
38 goto end;
39 }
40
41 it = zmalloc(sizeof(*it));
42 if (!it) {
43 goto end;
44 }
45
46 it->bytecode = bytecode->data;
47 it->offset = bytecode->reloc_table_offset;
48 it->len = bytecode->len;
49end:
50 return it;
51}
52
4af1498e 53LTTNG_HIDDEN
71a559f8
JG
54int bytecode_symbol_iterator_next(struct bytecode_symbol_iterator *it)
55{
56 int ret;
57 size_t len;
58
59 if (!it || it->offset >= it->len) {
60 ret = -1;
61 goto end;
62 }
63
64 len = strlen(it->bytecode + it->offset + sizeof(uint16_t)) + 1;
65 it->offset += len + sizeof(uint16_t);
66 ret = it->offset >= it->len ? -1 : 0;
67end:
68 return ret;
69}
70
4af1498e 71LTTNG_HIDDEN
71a559f8
JG
72int bytecode_symbol_iterator_get_type(struct bytecode_symbol_iterator *it)
73{
74 int ret;
75
76 if (!it) {
77 ret = -1;
78 goto end;
79 }
80
81 ret = *((uint16_t *) (it->bytecode + it->offset));
82end:
83 return ret;
84 }
85
4af1498e 86LTTNG_HIDDEN
71a559f8
JG
87const char *bytecode_symbol_iterator_get_name(
88 struct bytecode_symbol_iterator *it)
89{
90 const char *ret = NULL;
91
92 if (!it) {
93 goto end;
94 }
95
96 ret = it->bytecode + it->offset + sizeof(uint16_t);
97end:
98 return ret;
99}
100
4af1498e 101LTTNG_HIDDEN
71a559f8
JG
102void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it)
103{
104 free(it);
105}
This page took 0.0273409999999999 seconds and 4 git commands to generate.