Commit | Line | Data |
---|---|---|
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 | ||
11 | struct bytecode_symbol_iterator { | |
12 | /* No ownership of bytecode is taken. */ | |
13 | char *bytecode; | |
14 | size_t offset, len; | |
15 | }; | |
16 | ||
4af1498e | 17 | LTTNG_HIDDEN |
71a559f8 | 18 | struct bytecode_symbol_iterator *bytecode_symbol_iterator_create( |
2b00d462 | 19 | struct lttng_bytecode *bytecode) |
71a559f8 JG |
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; | |
35 | end: | |
36 | return it; | |
37 | } | |
38 | ||
4af1498e | 39 | LTTNG_HIDDEN |
71a559f8 JG |
40 | int 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; | |
53 | end: | |
54 | return ret; | |
55 | } | |
56 | ||
4af1498e | 57 | LTTNG_HIDDEN |
71a559f8 JG |
58 | int 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)); | |
68 | end: | |
69 | return ret; | |
70 | } | |
71 | ||
4af1498e | 72 | LTTNG_HIDDEN |
71a559f8 JG |
73 | const 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); | |
83 | end: | |
84 | return ret; | |
85 | } | |
86 | ||
4af1498e | 87 | LTTNG_HIDDEN |
71a559f8 JG |
88 | void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it) |
89 | { | |
90 | free(it); | |
91 | } |