X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Ffilter.cpp;fp=src%2Fcommon%2Ffilter.cpp;h=f74b6374bcea3dcbb4b1405361917a334e23591b;hb=a6bc4ca9d659caf016ef932fcd944029737ac57c;hp=0000000000000000000000000000000000000000;hpb=97535efaa975ca52bf02c2d5e76351bfd2e3defa;p=lttng-tools.git diff --git a/src/common/filter.cpp b/src/common/filter.cpp new file mode 100644 index 000000000..f74b6374b --- /dev/null +++ b/src/common/filter.cpp @@ -0,0 +1,86 @@ +/* + * Copyright 2016 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#include "filter.h" +#include + +struct bytecode_symbol_iterator { + /* No ownership of bytecode is taken. */ + char *bytecode; + size_t offset, len; +}; + +struct bytecode_symbol_iterator *bytecode_symbol_iterator_create( + struct lttng_bytecode *bytecode) +{ + struct bytecode_symbol_iterator *it = NULL; + + if (!bytecode) { + goto end; + } + + it = (bytecode_symbol_iterator *) zmalloc(sizeof(*it)); + if (!it) { + goto end; + } + + it->bytecode = bytecode->data; + it->offset = bytecode->reloc_table_offset; + it->len = bytecode->len; +end: + return it; +} + +int bytecode_symbol_iterator_next(struct bytecode_symbol_iterator *it) +{ + int ret; + size_t len; + + if (!it || it->offset >= it->len) { + ret = -1; + goto end; + } + + len = strlen(it->bytecode + it->offset + sizeof(uint16_t)) + 1; + it->offset += len + sizeof(uint16_t); + ret = it->offset >= it->len ? -1 : 0; +end: + return ret; +} + +int bytecode_symbol_iterator_get_type(struct bytecode_symbol_iterator *it) +{ + int ret; + + if (!it) { + ret = -1; + goto end; + } + + ret = *((uint16_t *) (it->bytecode + it->offset)); +end: + return ret; + } + +const char *bytecode_symbol_iterator_get_name( + struct bytecode_symbol_iterator *it) +{ + const char *ret = NULL; + + if (!it) { + goto end; + } + + ret = it->bytecode + it->offset + sizeof(uint16_t); +end: + return ret; +} + +void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it) +{ + free(it); +}