Add common util to set thread name
[lttng-tools.git] / src / common / filter.c
CommitLineData
71a559f8 1/*
ab5be9fa 2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
71a559f8 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
71a559f8 5 *
71a559f8
JG
6 */
7
8#include "filter.h"
9#include <stddef.h>
10
11struct bytecode_symbol_iterator {
12 /* No ownership of bytecode is taken. */
13 char *bytecode;
14 size_t offset, len;
15};
16
4af1498e 17LTTNG_HIDDEN
71a559f8
JG
18struct bytecode_symbol_iterator *bytecode_symbol_iterator_create(
19 struct lttng_filter_bytecode *bytecode)
20{
21 struct bytecode_symbol_iterator *it = NULL;
22
23 if (!bytecode) {
24 goto end;
25 }
26
27 it = zmalloc(sizeof(*it));
28 if (!it) {
29 goto end;
30 }
31
32 it->bytecode = bytecode->data;
33 it->offset = bytecode->reloc_table_offset;
34 it->len = bytecode->len;
35end:
36 return it;
37}
38
4af1498e 39LTTNG_HIDDEN
71a559f8
JG
40int bytecode_symbol_iterator_next(struct bytecode_symbol_iterator *it)
41{
42 int ret;
43 size_t len;
44
45 if (!it || it->offset >= it->len) {
46 ret = -1;
47 goto end;
48 }
49
50 len = strlen(it->bytecode + it->offset + sizeof(uint16_t)) + 1;
51 it->offset += len + sizeof(uint16_t);
52 ret = it->offset >= it->len ? -1 : 0;
53end:
54 return ret;
55}
56
4af1498e 57LTTNG_HIDDEN
71a559f8
JG
58int bytecode_symbol_iterator_get_type(struct bytecode_symbol_iterator *it)
59{
60 int ret;
61
62 if (!it) {
63 ret = -1;
64 goto end;
65 }
66
67 ret = *((uint16_t *) (it->bytecode + it->offset));
68end:
69 return ret;
70 }
71
4af1498e 72LTTNG_HIDDEN
71a559f8
JG
73const char *bytecode_symbol_iterator_get_name(
74 struct bytecode_symbol_iterator *it)
75{
76 const char *ret = NULL;
77
78 if (!it) {
79 goto end;
80 }
81
82 ret = it->bytecode + it->offset + sizeof(uint16_t);
83end:
84 return ret;
85}
86
4af1498e 87LTTNG_HIDDEN
71a559f8
JG
88void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it)
89{
90 free(it);
91}
This page took 0.041105 seconds and 4 git commands to generate.