X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Ffilter.c;fp=src%2Fcommon%2Ffilter.c;h=f103d240f7fe6d9c14fd904d119ca934d6fde1ca;hb=71a559f8ebee6ba681dfba864d6dace2efcf0440;hp=0000000000000000000000000000000000000000;hpb=54fb33cfaf7d29a831d32f4f81323119ca0499e7;p=lttng-tools.git diff --git a/src/common/filter.c b/src/common/filter.c new file mode 100644 index 000000000..f103d240f --- /dev/null +++ b/src/common/filter.c @@ -0,0 +1,100 @@ +/* + * filter.c + * + * LTTng filter bytecode utilities. + * + * Copyright 2016 - Jérémie Galarneau + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License, version 2.1 only, + * as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#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_filter_bytecode *bytecode) +{ + struct bytecode_symbol_iterator *it = NULL; + + if (!bytecode) { + goto end; + } + + it = 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); +}