From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [ltt-dev] [BABELTRACE PATCH] Extract int and char arrays from fields
Date: Mon, 26 Sep 2011 21:04:35 -0400 [thread overview]
Message-ID: <20110927010435.GC15747@Krystal> (raw)
In-Reply-To: <1317055700-6521-1-git-send-email-julien.desfossez@polymtl.ca>
* Julien Desfossez (julien.desfossez at polymtl.ca) wrote:
> Three helper functions to ease the extraction of basic types from event
> fields. For now we support signed and unsigned integers and strings.
> Other functions could be added following the same principle for other
> types.
FYI, I already started cleaning up ctf.c using these functions.
Thanks!
Mathieu
>
> Signed-off-by: Julien Desfossez <julien.desfossez at polymtl.ca>
> ---
> include/babeltrace/types.h | 3 +++
> types/array.c | 27 +++++++++++++++++++++++++++
> types/integer.c | 30 ++++++++++++++++++++++++++++++
> 3 files changed, 60 insertions(+), 0 deletions(-)
>
> diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h
> index a9fb5fe..62a0d4f 100644
> --- a/include/babeltrace/types.h
> +++ b/include/babeltrace/types.h
> @@ -383,6 +383,8 @@ void definition_unref(struct definition *definition);
> struct declaration_integer *integer_declaration_new(size_t len, int byte_order,
> int signedness, size_t alignment,
> int base, enum ctf_string_encoding encoding);
> +uint64_t get_unsigned_int(struct definition *field);
> +int64_t get_signed_int(struct definition *field);
>
> /*
> * mantissa_len is the length of the number of bytes represented by the mantissa
> @@ -493,6 +495,7 @@ struct declaration_array *
> uint64_t array_len(struct definition_array *array);
> struct definition *array_index(struct definition_array *array, uint64_t i);
> int array_rw(struct stream_pos *pos, struct definition *definition);
> +GString *get_char_array(struct definition *field);
>
> /*
> * int_declaration and elem_declaration passed as parameter now belong
> diff --git a/types/array.c b/types/array.c
> index db6853f..87b2083 100644
> --- a/types/array.c
> +++ b/types/array.c
> @@ -205,3 +205,30 @@ struct definition *array_index(struct definition_array *array, uint64_t i)
> return NULL;
> return g_ptr_array_index(array->elems, i);
> }
> +
> +GString *get_char_array(struct definition *field)
> +{
> + struct definition_array *array_definition;
> + struct declaration_array *array_declaration;
> + struct declaration *elem;
> +
> + array_definition = container_of(field, struct definition_array, p);
> + array_declaration = array_definition->declaration;
> + elem = array_declaration->elem;
> + if (elem->id == CTF_TYPE_INTEGER) {
> + struct declaration_integer *integer_declaration =
> + container_of(elem, struct declaration_integer, p);
> +
> + if (integer_declaration->encoding == CTF_STRING_UTF8
> + || integer_declaration->encoding == CTF_STRING_ASCII) {
> +
> + if (integer_declaration->len == CHAR_BIT
> + && integer_declaration->p.alignment == CHAR_BIT) {
> +
> + return array_definition->string;
> + }
> + }
> + }
> + fprintf(stderr, "[warning] Extracting string\n");
> + return NULL;
> +}
> diff --git a/types/integer.c b/types/integer.c
> index e55c03e..9e6df58 100644
> --- a/types/integer.c
> +++ b/types/integer.c
> @@ -103,3 +103,33 @@ void _integer_definition_free(struct definition *definition)
> declaration_unref(integer->p.declaration);
> g_free(integer);
> }
> +
> +uint64_t get_unsigned_int(struct definition *field)
> +{
> + struct definition_integer *integer_definition;
> + const struct declaration_integer *integer_declaration;
> +
> + integer_definition = container_of(field, struct definition_integer, p);
> + integer_declaration = integer_definition->declaration;
> +
> + if (!integer_declaration->signedness) {
> + return integer_definition->value._unsigned;
> + }
> + fprintf(stderr, "[warning] Extracting unsigned value in a signed int\n");
> + return (uint64_t)integer_definition->value._signed;
> +}
> +
> +int64_t get_signed_int(struct definition *field)
> +{
> + struct definition_integer *integer_definition;
> + const struct declaration_integer *integer_declaration;
> +
> + integer_definition = container_of(field, struct definition_integer, p);
> + integer_declaration = integer_definition->declaration;
> +
> + if (integer_declaration->signedness) {
> + return integer_definition->value._signed;
> + }
> + fprintf(stderr, "[warning] Extracting signed value in an unsigned int\n");
> + return (int64_t)integer_definition->value._unsigned;
> +}
> --
> 1.7.5.4
>
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
prev parent reply other threads:[~2011-09-27 1:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-26 16:48 Julien Desfossez
2011-09-27 0:57 ` Mathieu Desnoyers
2011-09-27 1:04 ` Mathieu Desnoyers [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110927010435.GC15747@Krystal \
--to=mathieu.desnoyers@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox