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