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 | ||
c9e313bc | 8 | #include "filter.hpp" |
28ab034a | 9 | |
71a559f8 JG |
10 | #include <stddef.h> |
11 | ||
12 | struct bytecode_symbol_iterator { | |
13 | /* No ownership of bytecode is taken. */ | |
14 | char *bytecode; | |
15 | size_t offset, len; | |
16 | }; | |
17 | ||
28ab034a | 18 | struct bytecode_symbol_iterator *bytecode_symbol_iterator_create(struct lttng_bytecode *bytecode) |
71a559f8 | 19 | { |
cd9adb8b | 20 | struct bytecode_symbol_iterator *it = nullptr; |
71a559f8 JG |
21 | |
22 | if (!bytecode) { | |
23 | goto end; | |
24 | } | |
25 | ||
64803277 | 26 | it = zmalloc<bytecode_symbol_iterator>(); |
71a559f8 JG |
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; | |
34 | end: | |
35 | return it; | |
36 | } | |
37 | ||
38 | int 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; | |
51 | end: | |
52 | return ret; | |
53 | } | |
54 | ||
55 | int 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)); | |
65 | end: | |
66 | return ret; | |
28ab034a | 67 | } |
71a559f8 | 68 | |
28ab034a | 69 | const char *bytecode_symbol_iterator_get_name(struct bytecode_symbol_iterator *it) |
71a559f8 | 70 | { |
cd9adb8b | 71 | const char *ret = nullptr; |
71a559f8 JG |
72 | |
73 | if (!it) { | |
74 | goto end; | |
75 | } | |
76 | ||
77 | ret = it->bytecode + it->offset + sizeof(uint16_t); | |
78 | end: | |
79 | return ret; | |
80 | } | |
81 | ||
82 | void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it) | |
83 | { | |
84 | free(it); | |
85 | } |