Commit ff436052 authored by Cedric Roux's avatar Cedric Roux

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4233 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent b4dca574
This diff is collapsed.
This diff is collapsed.
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir)/libparser \
-I$(top_srcdir)/libresolver \
-I$(top_srcdir)/libbuffers \
-I$(top_srcdir)/libui
SUBDIRS = libparser libresolver libbuffers libui .
itti_analyzer_LDADD = \
$(top_builddir)/libui/libui.la \
$(top_builddir)/libparser/libparser.la \
$(top_builddir)/libresolver/libresolver.la \
$(top_builddir)/libbuffers/libbuffers.la
bin_PROGRAMS = itti_analyzer
#! /bin/sh
aclocal \
&& autoheader \
&& automake --add-missing \
&& autoconf
\ No newline at end of file
AC_PREREQ([2.68])
define([svnversion], esyscmd([sh -c "svnversion ..|tr -d '\n'"]))
AC_DEFINE(SVN_REVISION, "svnversion", [SVN Revision])
AC_INIT([itti_debugger], [0.1.svnversion], [openair_admin@eurecom.fr])
AC_CANONICAL_BUILD
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([1.11 silent-rules])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AM_MAINTAINER_MODE
AM_SILENT_RULES([yes])
AM_PROG_LIBTOOL
AC_PROG_RANLIB
AC_PROG_CXX
AC_FUNC_ALLOCA
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_INT8_T
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_CHECK_FUNCS([memset])
AC_CHECK_FUNCS([socket])
AC_CHECK_FUNCS([strdup])
AC_CHECK_FUNCS([strerror])
AC_CHECK_HEADERS([arpa/inet.h])
AC_CHECK_HEADERS([fcntl.h])
AC_CHECK_HEADERS([libintl.h])
AC_CHECK_HEADERS([malloc.h])
AC_CHECK_HEADERS([stddef.h])
AC_CHECK_HEADERS([netinet/in.h])
PKG_CHECK_MODULES(XML2, [libxml-2.0 >= 2.7.8], [HAVE_XML2=true], [AC_MSG_ERROR(lixml-2.0 not installed)])
CFLAGS="$CFLAGS $XML2_CFLAGS"
LIBS="$LIBS $XML2_LIBS"
AM_PATH_GTK_3_0(3.0.0, [], AC_MSG_ERROR(Requirement not met: gtk >= 3.0.0))
CFLAGS="$CFLAGS $GTK_CFLAGS"
LIBS="$LIBS $GTK_LIBS"
dnl Add these flags
CFLAGS="$CFLAGS -Wall"
CFLAGS="$CFLAGS -Wshadow"
CFLAGS="$CFLAGS -Wcast-align"
CFLAGS="$CFLAGS -Wchar-subscripts"
CFLAGS="$CFLAGS -Wmissing-prototypes"
CFLAGS="$CFLAGS -Wmissing-declarations"
CFLAGS="$CFLAGS -Werror=implicit-function-declaration"
AC_SUBST([AM_CFLAGS])
AC_SUBST(ADD_CFLAGS)
dnl *** Autoconf support ***
AC_ARG_ENABLE(autoconf,
[ --disable-autoconf disable automatic generation of configure script ],
enable_autoconf=$enableval, enable_autoconf=yes
)
AC_PATH_PROG(AUTOCONF, autoconf, @echo autoconf not available)
AC_PATH_PROG(AUTOHEADER, autoheader, @echo autoheader not available)
if test -z "$AUTOCONF"; then enable_autoconf=no ; fi
if test -z "$AUTOHEADER"; then enable_autoconf=no ; fi
if test x$enable_autoconf = xyes; then
CONFIGURE_DEPENDS="configure.in aclocal.m4"
fi
AC_SUBST(CONFIGURE_DEPENDS)
AC_CONFIG_FILES(
libbuffers/Makefile \
libparser/Makefile \
libresolver/Makefile \
libui/Makefile \
Makefile \
)
AC_OUTPUT
\ No newline at end of file
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <gtk/gtk.h>
#include "xml_parse.h"
#include "resolvers.h"
#include "locate_root.h"
#include "file.h"
#include "ui_main_screen.h"
#include "rc.h"
int debug_buffers = 1;
int debug_parser = 0;
int main(int argc, char *argv[])
{
int ret = 0;
CHECK_FCT(ui_gtk_initialize(argc, argv));
return ret;
}
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir) \
-I$(top_srcdir)/libparser \
-I$(top_srcdir)/libui
noinst_LTLIBRARIES = libbuffers.la
libbuffers_la_LDFLAGS = -all-static
libbuffers_la_SOURCES = \
buffers.c buffers.h \
file.c file.h \
socket.c socket.h
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../rc.h"
#include "buffers.h"
extern int debug_buffers;
buffer_list_t list = {
.head = NULL,
.tail = NULL,
.count = 0,
};
pthread_mutex_t buffer_list_mutex = PTHREAD_MUTEX_INITIALIZER;
static
int buffer_fetch(buffer_t *buffer, uint32_t offset, int size, void *value);
/* Try to fetch 8 bits unsigned from the buffer */
uint8_t buffer_get_uint8_t(buffer_t *buffer, uint32_t offset)
{
uint8_t value;
buffer_fetch(buffer, offset, 1, &value);
return value;
}
/* Try to fetch 16 bits unsigned from the buffer */
uint16_t buffer_get_uint16_t(buffer_t *buffer, uint32_t offset)
{
uint16_t value;
buffer_fetch(buffer, offset, 2, &value);
return value;
}
/* Try to fetch 32 bits unsigned from the buffer */
uint32_t buffer_get_uint32_t(buffer_t *buffer, uint32_t offset)
{
uint32_t value;
buffer_fetch(buffer, offset, 4, &value);
return value;
}
static
int buffer_fetch(buffer_t *buffer, uint32_t offset, int size, void *value)
{
if (buffer == NULL || value == NULL)
return -1;
if (size <= 0)
return -1;
if (buffer->size_bytes < ((offset >> 3) + size)) {
printf("Not enough data to fetch\n");
return -1;
}
memcpy(value, &buffer->data[offset >> 3], size);
buffer->buffer_current = &buffer->data[(offset >> 3) + size];
return 0;
}
int buffer_fetch_bits(buffer_t *buffer, uint32_t offset, int nbits, uint32_t *value)
{
uint32_t temp = 0;
int i;
if (buffer == NULL || value == NULL)
return RC_BAD_PARAM;
/* We cannot fetch more than 32 bits */
if (nbits > 32)
return RC_BAD_PARAM;
for (i = 0; i < nbits; i++)
{
temp |= ((buffer->data[(offset + i) / 8] >> ((offset + i) % 8)) & 1) << i;
}
*value = temp;
return RC_OK;
}
/**
* @brief Create a new buffer from data
* @param buffer caller reference where created buffer will be stored
* @param data Data to attach to the new buffer
* @param length Length of data buffer
* @param data_static flag that indicates if data pointer has been statically (= 0) or not (!= 0)
*/
int buffer_new_from_data(buffer_t **buffer, uint8_t *data, const uint32_t length,
int data_static)
{
buffer_t *new;
if (!buffer)
return RC_BAD_PARAM;
new = malloc(sizeof(buffer_t));
new->size_bytes = length;
if (data && length > 0) {
if (data_static == 0) {
new->data = malloc(sizeof(uint8_t) * new->size_bytes);
memcpy(new->data, data, new->size_bytes);
} else {
new->data = data;
}
new->buffer_current = &new->data[0];
} else {
new->buffer_current = NULL;
}
new->next = NULL;
*buffer = new;
return 0;
}
#define INDENTED(fILE, x, y) \
do { \
int indentation = x; \
while(indentation--) fprintf(fILE, " "); \
y; \
} while(0)
#define INDENT_BREAK 20
void buffer_dump(buffer_t *buffer, FILE *to)
{
FILE *file = to;
uint32_t i;
if (!buffer)
return;
if (!to)
to = stdout;
fprintf(file, "<Buffer>\n");
INDENTED(file, 4, fprintf(file, "<Length>%u<Length>\n", buffer->size_bytes));
INDENTED(file, 4, fprintf(file, "<Bytes>\n"));
for (i = 0; i < buffer->size_bytes; i++)
{
if ((i % INDENT_BREAK) == 0)
fprintf(file, " ");
fprintf(file, "0x%02x ", buffer->data[i]);
if ((i % INDENT_BREAK) == (INDENT_BREAK - 1))
fprintf(file, "\n");
}
if ((i % INDENT_BREAK) != (INDENT_BREAK - 1))
fprintf(file, "\n");
INDENTED(file, 4, fprintf(file, "</Bytes>\n"));
fprintf(file, "</Buffer>\n");
}
int buffer_append_data(buffer_t *buffer, const uint8_t *data, const uint32_t length)
{
if (!buffer)
return -1;
if (data && length > 0) {
if (!buffer->data) {
buffer->size_bytes = length;
buffer->data = malloc(sizeof(uint8_t) * buffer->size_bytes);
memcpy(buffer->data, data, buffer->size_bytes);
} else {
buffer->data = realloc(buffer->data, sizeof(uint8_t) * (buffer->size_bytes + length));
memcpy(&buffer->data[buffer->size_bytes], data, length);
buffer->size_bytes += length;
}
buffer->buffer_current = &buffer->data[0];
}
return 0;
}
int buffer_has_enouch_data(buffer_t *buffer, uint32_t offset, uint32_t to_get)
{
int underflow;
if (!buffer)
return -1;
underflow = (buffer->size_bytes >= ((offset + to_get) / 8)) ? 0 : -1;
if (underflow && debug_buffers)
printf("Detected Underflow offset %u, to_get %u, buffer size %u\n",
offset, to_get, buffer->size_bytes);
return underflow;
}
int buffer_get_from_mn(const uint32_t message_number, buffer_t **buffer)
{
buffer_t *temp_buf;
if (!buffer)
return RC_BAD_PARAM;
for (temp_buf = list.head; temp_buf; temp_buf = temp_buf->next) {
if (temp_buf->message_number == message_number) {
break;
}
}
*buffer = temp_buf;
return RC_OK;
}
int buffer_add_to_list(buffer_t *new_buf)
{
if (!new_buf)
return RC_BAD_PARAM;
pthread_mutex_lock(&buffer_list_mutex);
/* No element at tail */
if (list.tail == NULL) {
if (list.head == NULL) {
list.head = new_buf;
list.tail = list.head;
} else {
return RC_FAIL;
}
} else {
list.tail->next = new_buf;
new_buf->previous = list.tail;
list.tail = new_buf;
}
list.count++;
pthread_mutex_unlock(&buffer_list_mutex);
return RC_OK;
}
#include <stdint.h>
#ifndef BUFFERS_H_
#define BUFFERS_H_
typedef struct buffer_s {
/* The size in bytes as read from socket */
uint32_t size_bytes;
/* Current position */
uint8_t *buffer_current;
/* The complete data */
uint8_t *data;
/* The message number as read from socket */
uint32_t message_number;
uint32_t message_id;
struct buffer_s *previous;
struct buffer_s *next;
} buffer_t;
typedef struct {
buffer_t *head;
buffer_t *tail;
uint32_t count;
} buffer_list_t;
uint8_t buffer_get_uint8_t(buffer_t *buffer, uint32_t offset);
uint16_t buffer_get_uint16_t(buffer_t *buffer, uint32_t offset);
uint32_t buffer_get_uint32_t(buffer_t *buffer, uint32_t offset);
int buffer_fetch_bits(buffer_t *buffer, uint32_t offset, int nbits, uint32_t *value);
void buffer_dump(buffer_t *buffer, FILE *to);
int buffer_append_data(buffer_t *buffer, const uint8_t *data, const uint32_t length);
int buffer_new_from_data(buffer_t **buffer, uint8_t *data, const uint32_t length,
int data_static);
int buffer_has_enouch_data(buffer_t *buffer, uint32_t offset, uint32_t to_get);
int buffer_add_to_list(buffer_t *new_buf);
int buffer_get_from_mn(const uint32_t message_number, buffer_t **buffer);
#endif /* BUFFERS_H_ */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "../rc.h"
#include "buffers.h"
#include "file.h"
#define READ_BUFFER_SIZE 1024
int file_read_dump(buffer_t **buffer, const char *filename)
{
int fd = -1;
buffer_t *new_buf = NULL;
uint8_t data[READ_BUFFER_SIZE];
ssize_t current_read;
if (!filename)
return RC_BAD_PARAM;
if ((fd = open(filename, O_RDONLY)) == -1) {
fprintf(stderr, "Cannot open %s for reading, returned %d:%s\n",
filename, errno, strerror(errno));
return RC_FAIL;
}
CHECK_FCT(buffer_new_from_data(&new_buf, NULL, 0, 0));
do {
current_read = read(fd, data, READ_BUFFER_SIZE);
if (current_read == -1)
{
fprintf(stderr, "Failed to read data from file, returned %d:%s\n",
errno, strerror(errno));
return RC_FAIL;
}
CHECK_FCT(buffer_append_data(new_buf, data, current_read));
} while(current_read == READ_BUFFER_SIZE);
*buffer = new_buf;
buffer_dump(new_buf, stdout);
close(fd);
return RC_OK;
}
#ifndef FILE_H_
#define FILE_H_
int file_read_dump(buffer_t **buffer, const char *filename);
#endif /* FILE_H_ */
This diff is collapsed.
#include <arpa/inet.h>
#include <netinet/in.h>
#ifndef SOCKET_H_
#define SOCKET_H_
typedef struct {
pthread_t thread;
uint16_t port;
char *remote_ip;
int sd;
struct sockaddr_in si_me;
} socket_data_t;
int socket_connect_to_remote_host(const char *remote_ip, const uint16_t port);
int socket_disconnect_from_remote_host(void);
#endif /* SOCKET_H_ */
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir) \
-I$(top_srcdir)/libbuffers \
-I$(top_srcdir)/libui
noinst_LTLIBRARIES = libparser.la
libparser_la_LDFLAGS = -all-static
libparser_la_SOURCES = \
xml_parse.c \
array_type.c array_type.h \
enum_type.c enum_type.h \
enum_value_type.c enum_value_type.h \
file_type.c file_type.h \
field_type.c field_type.h \
fundamental_type.c fundamental_type.h \
pointer_type.h pointer_type.c \
reference_type.c reference_type.h \
struct_type.c struct_type.h \
typedef_type.c typedef_type.h \
types.h types.c \
union_type.c union_type.h
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "array_type.h"
#include "fundamental_type.h"
#include "ui_interface.h"
int array_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
struct types_s *type_child;
DISPLAY_PARSE_INFO("array", type->name, offset, parent_offset);
/* Ignore TYPEDEF children */
for (type_child = type->child; type_child != NULL && type_child->type == TYPE_TYPEDEF;
type_child = type_child->child) {
}
if (type->name) {
INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
}
if (type->child != NULL) {
int items = type->size / type_child->size;
int i;
int zero_counter = 0;
/* Factorizes trailing 0 */
if ((items > 1) && (type_child->type == TYPE_FUNDAMENTAL))
{
for (i = items - 1; i >= 0; i--)
{
if (fundamental_read_from_buffer(type_child, buffer, parent_offset, offset + i * type_child->size) == 0)
{
zero_counter ++;
}
else
{
break;
}
}
/* Do not factorize if there is only one item */
if (zero_counter <= 1)
{
zero_counter = 0;
}
}
for (i = 0; i < (items - zero_counter); i++)
type->child->type_dissect_from_buffer (type->child, buffer, parent_offset, offset + i * type_child->size,
type->name == NULL ? indent : indent + 4);
if (zero_counter > 0)
{
int length = 0;
char cbuf[50];
char *cpy = NULL;
INDENTED_STRING(cbuf, type->name == NULL ? indent : indent + 4,);
length = sprintf(cbuf, "[%d .. %d] ", i, items -1);
cpy = malloc(sizeof(char) * length);
memcpy(cpy, cbuf, length);
ui_interface.ui_signal_set_text(cpy, length);
if (cpy)
free(cpy);
type->child->type_dissect_from_buffer (type->child, buffer, parent_offset, offset + i * type_child->size, 0);
}
}
if (type->name) {
INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
}
return 0;
}
int array_type_file_print(struct types_s *type, int indent, FILE *file) {
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Array>\n"));
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
INDENTED(file, indent+4, fprintf(file, "Min ........: %d\n", type->min));
INDENTED(file, indent+4, fprintf(file, "Max ........: %d\n", type->max));
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
if (type->file_ref != NULL)
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
if (type->child != NULL)
type->child->type_file_print (type->child, indent + 4, file);
INDENTED(file, indent, fprintf(file, "</Array>\n"));
return 0;
}
int array_type_hr_display(struct types_s *type, int indent) {
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Array>\n"));
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
INDENTED(stdout, indent+4, printf("Min ........: %d\n", type->min));
INDENTED(stdout, indent+4, printf("Max ........: %d\n", type->max));
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
if (type->file_ref != NULL)
type->file_ref->type_hr_display (type->file_ref, indent + 4);
if (type->child != NULL)
type->child->type_hr_display (type->child, indent + 4);
INDENTED(stdout, indent, printf("</Array>\n"));
return 0;
}
#include "types.h"
#ifndef ARRAY_TYPE_H_
#define ARRAY_TYPE_H_
int array_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int array_type_hr_display(struct types_s *type, int indent);
int array_type_file_print(struct types_s *type, int indent, FILE *file);
#endif /* ARRAY_TYPE_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "enum_type.h"
#include "ui_interface.h"
int enum_type_dissect_from_buffer(
struct types_s *type, buffer_t *buffer, uint32_t offset,
uint32_t parent_offset, int indent)
{
uint32_t value = 0;
types_t *values;
DISPLAY_PARSE_INFO("enum", type->name, offset, parent_offset);
value = buffer_get_uint32_t(buffer, parent_offset + offset);
// if (type->name) {
// INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
// }
for (values = type->child; values; values = values->next) {
if (value == values->init_value) {
values->type_dissect_from_buffer(
values, buffer, offset, parent_offset,
type->name == NULL ? indent: indent+4);
break;
}
}
if (values == NULL) {
// INDENTED(stdout, indent+4, fprintf(stdout, "<UNKNOWN/>\n"));
int length = 0;
char cbuf[50];
char *cpy = NULL;
length = sprintf(cbuf, "(0x%08x) UNKNOWN;\n", value);
cpy = malloc(sizeof(char) * length);
memcpy(cpy, cbuf, length);
ui_interface.ui_signal_set_text(cpy, length);
if (cpy)
free(cpy);
}
// if (type->name) {
// INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
// }
return 0;
}
int enum_type_file_print(struct types_s *type, int indent, FILE *file)
{
types_t *values;
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Enumeration>\n"));
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial));
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
if (type->file_ref != NULL)
type->file_ref->type_file_print(type->file_ref, indent+4, file);
/* Call enum values display */
for (values = type->child; values; values = values->next) {
values->type_file_print(values, indent + 4, file);
}
INDENTED(file, indent, fprintf(file, "</Enumeration>\n"));
return 0;
}
int enum_type_hr_display(struct types_s *type, int indent)
{
types_t *values;
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Enumeration>\n"));
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial));
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
if (type->file_ref != NULL)
type->file_ref->type_hr_display(type->file_ref, indent+4);
/* Call enum values display */
for (values = type->child; values; values = values->next) {
values->type_hr_display(values, indent + 4);
}
INDENTED(stdout, indent, printf("</Enumeration>\n"));
return 0;
}
#include "types.h"
#ifndef ENUM_TYPE_H_
#define ENUM_TYPE_H_
int enum_type_dissect_from_buffer(
struct types_s *type, buffer_t *buffer, uint32_t offset,
uint32_t parent_offset, int indent);
int enum_type_file_print(struct types_s *type, int indent, FILE *file);
int enum_type_hr_display(struct types_s *type, int indent);
#endif /* ENUM_TYPE_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "enum_value_type.h"
#include "ui_interface.h"
int enum_value_dissect_from_buffer(
struct types_s *type, buffer_t *buffer, uint32_t offset,
uint32_t parent_offset, int indent)
{
uint32_t value = 0;
DISPLAY_PARSE_INFO("enum_value", type->name, offset, parent_offset);
value = buffer_get_uint32_t(buffer, parent_offset + offset);
if (type->name) {
int length = 0;
char cbuf[50 + strlen(type->name)];
char *cpy = NULL;
sprintf(cbuf, "(0x%08x) %s;\n", value, type->name);
length = strlen(cbuf);
cpy = malloc(sizeof(char) * length);
memcpy(cpy, cbuf, length);
ui_interface.ui_signal_set_text(cpy, length);
if (cpy)
free(cpy);
}
return 0;
}
int enum_value_file_print(struct types_s *type, int indent, FILE *file)
{
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Value>\n"));
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
INDENTED(file, indent+4, fprintf(file, "Value ......: %d\n", type->init_value));
if (type->file_ref != NULL)
type->file_ref->type_file_print(type->file_ref, indent+4, file);
INDENTED(file, indent, fprintf(file, "</Value>\n"));
return 0;
}
int enum_value_type_hr_display(struct types_s *type, int indent)
{
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Value>\n"));
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
INDENTED(stdout, indent+4, printf("Value ......: %d\n", type->init_value));
if (type->file_ref != NULL)
type->file_ref->type_hr_display(type->file_ref, indent+4);
INDENTED(stdout, indent, printf("</Value>\n"));
return 0;
}
#include "types.h"
#ifndef ENUM_VALUE_TYPE_H_
#define ENUM_VALUE_TYPE_H_
int enum_value_dissect_from_buffer(
struct types_s *type, buffer_t *buffer, uint32_t offset,
uint32_t parent_offset, int indent);
int enum_value_file_print(struct types_s *type, int indent, FILE *file);
int enum_value_type_hr_display(struct types_s *type, int indent);
#endif /* ENUM_VALUE_TYPE_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "../rc.h"
#include "field_type.h"
#include "buffers.h"
#include "ui_interface.h"
int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int length = 0;
char cbuf[50];
char *cpy = NULL;
struct types_s *type_child;
char array_info[50];
int indent_child;
DISPLAY_PARSE_INFO("field", type->name, offset, parent_offset);
CHECK_FCT(buffer_has_enouch_data(buffer, parent_offset + offset, type->size / 8));
if (type->bits == -1) {
if (type->child != NULL) {
/* Ignore TYPEDEF children */
for (type_child = type->child; type_child != NULL && type_child->type == TYPE_TYPEDEF; type_child =
type_child->child) {
}
if (type_child->type == TYPE_ARRAY) {
struct types_s *type_array_child;
/* Ignore TYPEDEF children */
for (type_array_child = type_child->child;
type_array_child != NULL && type_array_child->type == TYPE_TYPEDEF; type_array_child =
type_array_child->child) {
}
sprintf (array_info, "[%d]", type_child->size / type_array_child->size);
}
else {
array_info[0] = '\0';
}
DISPLAY_TYPE("Fld");
INDENTED_STRING(cbuf, indent, sprintf(cbuf, ".%s%s = ", type->name ? type->name : "Field", array_info));
length = strlen (cbuf);
cpy = malloc (sizeof(char) * length);
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
indent_child = indent;
if (type_child->type == TYPE_ARRAY || type_child->type == TYPE_STRUCT || type_child->type == TYPE_UNION) {
DISPLAY_BRACE(ui_interface.ui_signal_set_text ("{", 1);)
ui_interface.ui_signal_set_text ("\n", 1);
indent_child += 4;
}
if (type_child->type == TYPE_FUNDAMENTAL || type_child->type == TYPE_POINTER) {
indent_child = 0;
}
CHECK_FCT(
type->child->type_dissect_from_buffer( type->child, buffer, parent_offset, offset + type->offset, indent_child));
DISPLAY_BRACE(
if (type_child->type == TYPE_ARRAY || type_child->type == TYPE_STRUCT || type_child->type == TYPE_UNION) {
DISPLAY_TYPE("Fld");
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n"));
length = strlen (cbuf);
cpy = malloc (sizeof(char) * length); memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
});
}
}
else {
/* The field is only composed of bits */
uint32_t value = 0;
CHECK_FCT(buffer_fetch_bits(buffer, offset + type->offset + parent_offset, type->bits, &value));
DISPLAY_TYPE("Fld");
INDENTED_STRING(
cbuf,
indent,
sprintf(cbuf, ".%s:%d = (0x%0*x) %d;\n", type->name ? type->name : "Field", type->bits, (type->bits + 3) / 4, value, value));
length = strlen (cbuf);
cpy = malloc (sizeof(char) * length);
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
}
return 0;
}
int field_type_file_print(struct types_s *type, int indent, FILE *file) {
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Field>\n"));
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
INDENTED(file, indent+4, fprintf(file, "Bits .......: %d\n", type->bits));
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
INDENTED(file, indent+4, fprintf(file, "Offset .....: %d\n", type->offset));
INDENTED(file, indent+4, fprintf(file, "Context ....: %d\n", type->context));
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
if (type->file_ref != NULL)
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
if (type->child != NULL)
type->child->type_file_print (type->child, indent + 4, file);
INDENTED(file, indent, fprintf(file, "</Field>\n"));
return 0;
}
int field_type_hr_display(struct types_s *type, int indent) {
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Field>\n"));
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
INDENTED(stdout, indent+4, printf("Bits .......: %d\n", type->bits));
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
INDENTED(stdout, indent+4, printf("Offset .....: %d\n", type->offset));
INDENTED(stdout, indent+4, printf("Context ....: %d\n", type->context));
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
if (type->file_ref != NULL)
type->file_ref->type_hr_display (type->file_ref, indent + 4);
if (type->child != NULL)
type->child->type_hr_display (type->child, indent + 4);
INDENTED(stdout, indent, printf("</Field>\n"));
return 0;
}
#include "types.h"
#ifndef FIELD_TYPE_H_
#define FIELD_TYPE_H_
int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int field_type_file_print(struct types_s *type, int indent, FILE *file);
int field_type_hr_display(struct types_s *type, int indent);
#endif /* FIELD_TYPE_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "file_type.h"
int file_type_file_print(struct types_s *type, int indent, FILE *file)
{
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<File>\n"));
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
INDENTED(file, indent, fprintf(file, "</File>\n"));
return 0;
}
int file_type_hr_display(struct types_s *type, int indent)
{
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<File>\n"));
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
INDENTED(stdout, indent, printf("</File>\n"));
return 0;
}
#include "types.h"
#ifndef FILE_TYPE_H_
#define FILE_TYPE_H_
int file_type_file_print(struct types_s *type, int indent, FILE *file);
int file_type_hr_display(struct types_s *type, int indent);
#endif /* FILE_TYPE_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "fundamental_type.h"
#include "ui_interface.h"
uint32_t fundamental_read_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset) {
uint32_t value;
switch (type->size) {
case 8: {
value = buffer_get_uint8_t (buffer, offset + parent_offset);
}
break;
case 16: {
value = buffer_get_uint16_t (buffer, offset + parent_offset);
}
break;
case 32: {
value = buffer_get_uint32_t (buffer, offset + parent_offset);
}
break;
default:
/* ??? */
value = 0;
break;
}
return value;
}
int fundamental_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int length = 0;
char cbuf[200];
char *cpy = NULL;
int type_unsigned;
uint32_t value;
DISPLAY_PARSE_INFO("fundamental", type->name, offset, parent_offset);
memset (cbuf, 0, 200);
type_unsigned = strstr (type->name, "unsigned") == NULL ? 0 : 1;
value = fundamental_read_from_buffer(type, buffer, offset, parent_offset);
if (indent > 0)
{
DISPLAY_TYPE("Fun");
}
switch (type->size) {
case 8: {
INDENTED_STRING(cbuf, indent,
sprintf(cbuf, type_unsigned ? "(0x%02x) %3u '%c';\n" : "(0x%02x) %4d '%c';\n", value, value, isprint(value) ? value : '.'));
}
break;
case 16: {
INDENTED_STRING(cbuf, indent,
sprintf(cbuf, type_unsigned ? "(0x%04x) %5u;\n" : "(0x%04x) %6d;\n", value, value));
}
break;
case 32: {
INDENTED_STRING(cbuf, indent,
sprintf(cbuf, type_unsigned ? "(0x%08x) %9u;\n" : "(0x%08x) %10d;\n", value, value));
}
break;
default:
/* ??? */
break;
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
return 0;
}
int fundamental_type_file_print(struct types_s *type, int indent, FILE *file) {
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Fundamental>\n"));
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
if (type->file_ref != NULL)
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
INDENTED(file, indent, fprintf(file, "</Fundamental>\n"));
return 0;
}
int fundamental_type_hr_display(struct types_s *type, int indent) {
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Fundamental>\n"));
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
if (type->file_ref != NULL)
type->file_ref->type_hr_display (type->file_ref, indent + 4);
INDENTED(stdout, indent, printf("</Fundamental>\n"));
return 0;
}
#include "types.h"
#ifndef FUNDAMENTAL_TYPE_H_
#define FUNDAMENTAL_TYPE_H_
uint32_t fundamental_read_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset);
int fundamental_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent);
int fundamental_type_file_print(struct types_s *type, int indent, FILE *file);
int fundamental_type_hr_display(struct types_s *type, int indent);
#endif /* FUNDAMENTAL_TYPE_H_ */
#include "fundamental_type.h"
#include "struct_type.h"
#ifndef INTERTASK_CONTEXTS_H_
#define INTERTASK_CONTEXTS_H_
typedef struct {
/* List of fundamental types that can contruct any other type */
fundamental_type_t *ft_list;
struct_type_t *struct_list;
} intertask_context_t;
#endif /* INTERTASK_CONTEXTS_H_ */
/* For development only : */
%debug
%error-verbose
/* Keep track of location */
%locations
%defines
%pure-parser
%{
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "parser.h"
int
yyerror(const char *msg);
extern int yywrap();
extern int yylex();
extern int yylineno;
/* The Lex parser prototype */
int fddlex(YYSTYPE *lvalp, YYLTYPE *llocp);
%}
/* Values returned by lex for token */
%union {
char *string; /* The string is allocated by strdup in lex.*/
int integer; /* Store integer values */
}
%token LEX_ERROR
%token <string> QSTRING
%token <string> STRING
%token <integer> INTEGER
%token Y_TYPEDEF
%token Y_STRUCT
%token Y_UNION
%token Y_CHARTYPE
%token Y_SHORTTYPE
%token Y_INTTYPE
%token Y_LONGTYPE
%token Y_ENUM
%token Y_UNSIGNED
%token Y_SIGNED
%token Y_EXTENSION
%token Y_ATTRIBUTE
%token Y_ATTRIBUTE_MODE
%token Y_ATTRIBUTE_HI
%token Y_ATTRIBUTE_SI
%token Y_VOIDTYPE
%token Y_POINTER
%token Y_SIZEOF
%%
messages:
| messages definition
| messages errors
{
yyerror("An error occurred while parsing the configuration file");
return EINVAL;
}
;
definition:
| Y_EXTENSION definition
| Y_TYPEDEF enumerate
| Y_TYPEDEF structure
| structure
| enumerate
| Y_STRUCT STRING ';'
| Y_TYPEDEF singletype attribute ';'
;
enumerate:
| Y_ENUM '{' enumlist '}' STRING ';'
| Y_ENUM STRING '{' enumlist '}' ';'
| Y_ENUM STRING '{' enumlist '}' STRING ';'
;
enumlist:
| enumitem ',' enumlist
| enumitem
;
enumitem: STRING '=' INTEGER
| STRING '=' STRING
| STRING
;
structure: Y_STRUCT STRING '{' paramlist '}' STRING ';'
| Y_STRUCT '{' paramlist '}' STRING ';'
| Y_STRUCT STRING '{' paramlist '}' ';'
| Y_STRUCT STRING ';'
| Y_STRUCT STRING STRING attribute ';'
| Y_STRUCT singletype ';'
;
paramlist:
| paramlist singletype ';'
| paramlist union
| paramlist structure
;
union: Y_UNION STRING '{' paramlist '}' STRING ';'
| Y_UNION '{' paramlist '}' STRING ';'
| Y_UNION STRING '{' paramlist '}' ';'
;
singletype:
| Y_SIGNED singletype
| Y_UNSIGNED singletype
| STRING STRING
| Y_CHARTYPE STRING
| Y_SHORTTYPE STRING
| Y_INTTYPE STRING
| Y_SHORTTYPE Y_INTTYPE STRING
| Y_LONGTYPE STRING
| Y_LONGTYPE Y_INTTYPE STRING
| Y_LONGTYPE Y_LONGTYPE Y_INTTYPE STRING
| Y_VOIDTYPE Y_POINTER STRING
| Y_VOIDTYPE STRING
| STRING Y_POINTER STRING
| basictype Y_POINTER STRING
| singletype '[' arraydef ']'
| structure
;
arraydef:
| INTEGER arraydef
| '*' arraydef
| Y_POINTER arraydef
| Y_SIZEOF arraydef
| '(' arraydef
| ')' arraydef
| basictype arraydef
| '-' arraydef
| STRING arraydef
;
attribute:
| Y_ATTRIBUTE '(' attributevalue ')'
;
attributevalue:
| '(' Y_ATTRIBUTE_MODE attributeparam ')'
| Y_ATTRIBUTE_MODE attributeparam
;
attributeparam:
| '(' Y_ATTRIBUTE_HI ')'
| '(' Y_ATTRIBUTE_SI ')'
;
basictype:
| Y_CHARTYPE
| Y_SHORTTYPE
| Y_INTTYPE
| Y_LONGTYPE
| Y_VOIDTYPE
;
/* Lexical or syntax error */
errors: LEX_ERROR
| error
;
%%
int
yyerror(const char *msg) {
extern char *yytext;
fprintf(stderr,
"Parse error near line %d (token \"%s\"): %s\n",
yylineno, yytext, msg);
return -1;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "pointer_type.h"
#include "ui_interface.h"
int pointer_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int length = 0;
char cbuf[200];
char *cpy = NULL;
DISPLAY_PARSE_INFO("pointer", type->name, offset, parent_offset);
memset (cbuf, 0, 200);
// int i;
// CHECK_FCT(buffer_has_enouch_data(buffer, offset, type->size / 8));
uint32_t value;
value = buffer_get_uint32_t (buffer, parent_offset + offset);
DISPLAY_TYPE("Ptr");
if (type->child->name) {
/*
INDENTED(stdout, indent, fprintf(stdout, "<%s>0x%08x</%s>\n",
type->child->name, value, type->child->name));
*/
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "(%s *) 0x%08x;\n", type->child->name, value));
}
else {
/*
INDENTED(stdout, indent, fprintf(stdout, "<Pointer>0x%08x</Pointer>\n",
value));
*/
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "(void *) 0x%08x;\n", value));
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
return 0;
}
int pointer_type_file_print(struct types_s *type, int indent, FILE *file) {
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Pointer>\n"));
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
if (type->child != NULL)
type->child->type_file_print (type->child, indent + 4, file);
if (type->file_ref != NULL)
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
INDENTED(file, indent, fprintf(file, "</Pointer>\n"));
return 0;
}
int pointer_type_hr_display(struct types_s *type, int indent) {
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Pointer>\n"));
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
if (type->child != NULL)
type->child->type_hr_display (type->child, indent + 4);
if (type->file_ref != NULL)
type->file_ref->type_hr_display (type->file_ref, indent + 4);
INDENTED(stdout, indent, printf("</Pointer>\n"));
return 0;
}
#include "types.h"
#ifndef POINTER_TYPE_H_
#define POINTER_TYPE_H_
int pointer_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int pointer_type_file_print(struct types_s *type, int indent, FILE *file);
int pointer_type_hr_display(struct types_s *type, int indent);
#endif /* POINTER_TYPE_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "reference_type.h"
#include "ui_interface.h"
int reference_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent)
{
DISPLAY_PARSE_INFO("reference", type->name, offset, parent_offset);
if (type->name) {
INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
}
if (type->child != NULL)
type->child->type_dissect_from_buffer(type->child, buffer, offset, parent_offset,
type->name == NULL ? indent: indent+4);
if (type->name) {
INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
}
return 0;
}
int reference_type_file_print(struct types_s *type, int indent, FILE *file)
{
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Reference>\n"));
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
INDENTED(file, indent+4, fprintf(file, "Context ....: %d\n", type->context));
INDENTED(file, indent+4, fprintf(file, "Offset .....: %d\n", type->offset));
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
if (type->child != NULL)
type->child->type_file_print(type->child, indent+4, file);
if (type->file_ref != NULL)
type->file_ref->type_file_print(type->file_ref, indent+4, file);
INDENTED(file, indent, fprintf(file, "</Reference>\n"));
return 0;
}
int reference_type_hr_display(struct types_s *type, int indent)
{
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Reference>\n"));
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
INDENTED(stdout, indent+4, printf("Context ....: %d\n", type->context));
INDENTED(stdout, indent+4, printf("Offset .....: %d\n", type->offset));
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
if (type->child != NULL)
type->child->type_hr_display(type->child, indent+4);
if (type->file_ref != NULL)
type->file_ref->type_hr_display(type->file_ref, indent+4);
INDENTED(stdout, indent, printf("</Reference>\n"));
return 0;
}
#include "types.h"
#ifndef REFERENCE_TYPE_H_
#define REFERENCE_TYPE_H_
int reference_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int reference_type_file_print(struct types_s *type, int indent, FILE *file);
int reference_type_hr_display(struct types_s *type, int indent);
#endif /* REFERENCE_TYPE_H_ */
/* Lex configuration parser.
*
* This file defines the token for parsing the configuration file
*
* Note : This module is NOT thread-safe. All processing must be done from one thread only.
*/
%{
#include <stdio.h>
/* Include yacc tokens definitions */
#include "parser.h"
/* Update the column information */
#ifdef DEBUG_LEX
#define YY_USER_ACTION { \
yylloc->first_column = yylloc->last_column + 1; \
yylloc->last_column = yylloc->first_column + yyleng - 1; \
TRACE_DEBUG(FULL, \
"(%d:%d-%d:%d) matched rule %d, length=%d, txt='%s'\n", \
yylloc->first_line, yylloc->first_column, \
yylloc->last_line, yylloc->last_column, \
yy_act, yyleng, yytext); \
}
#else /* DEBUG_LEX */
#define YY_USER_ACTION { \
yylloc->first_column = yylloc->last_column + 1; \
yylloc->last_column = yylloc->first_column + yyleng - 1; \
}
#endif
#define YY_NO_INPUT
%}
%option bison-bridge bison-locations
%option noyywrap
%option nounput
%option yylineno
/* Quoted string. Multilines do not match. */
qstring \"[^\"\n]*\"
%%
/* List of patterns and actions */
<*>\n {
/* Update the line count */
yylloc->first_line++;
yylloc->last_line++;
yylloc->last_column=0;
}
<*>([[:space:]]{-}[\n])+ ; /* Eat all spaces, not new lines */
<*>#.*$ ; /* Eat all comments */
/* Full words tokens (keywords) */
(?i:"typedef") { return Y_TYPEDEF; }
(?i:"struct") { return Y_STRUCT; }
(?i:"union") { return Y_UNION; }
(?i:"enum") { return Y_ENUM; }
(?i:"signed") { return Y_SIGNED; }
(?i:"unsigned") { return Y_UNSIGNED; }
(?i:"short") { return Y_SHORTTYPE; }
(?i:"char") { return Y_CHARTYPE; }
(?i:"int") { return Y_INTTYPE; }
(?i:"long") { return Y_LONGTYPE; }
(?i:"void") { return Y_VOIDTYPE; }
(?i:"__extension__") { return Y_EXTENSION; }
(?i:"__attribute__") { return Y_ATTRIBUTE; }
(?i:"__mode__") { return Y_ATTRIBUTE_MODE; }
(?i:"__HI__") { return Y_ATTRIBUTE_HI; }
(?i:"__SI__") { return Y_ATTRIBUTE_SI; }
(?i:"sizeof") { return Y_SIZEOF; }
[A-Za-z_][A-Za-z0-9_]* {
/* First copy the string without the quotes for use in the yacc parser */
if ((yylval->string = strdup(yytext+1)) == NULL) { /* This allocates one useless tail char but... it's easier :D */
return LEX_ERROR;/* on error, trig an error in yacc parser */
}
yylval->string[yyleng-2] = '\0';
/* the yacc parser will check the string is valid */
return STRING;
}
{qstring} {
/* First copy the string without the quotes for use in the yacc parser */
if ((yylval->string = strdup(yytext+1)) == NULL) { /* This allocates one useless tail char but... it's easier :D */
return LEX_ERROR;/* on error, trig an error in yacc parser */
}
yylval->string[yyleng-2] = '\0';
/* the yacc parser will check the string is valid */
return QSTRING;
}
[[:digit:]]+ {
/* Convert this to an integer value */
int ret = sscanf(yytext, "%i", &yylval->integer);
if (ret != 1) {
/* No matching: an error occurred */
fprintf(stderr, "Unable to convert the value '%s' to a valid number: %s\n",
yytext, strerror(errno));
return LEX_ERROR; /* trig an error in yacc parser */
/* Maybe we could REJECT instead of failing here? */
}
return INTEGER;
}
/* Valid single characters for yyparse */
<*>[\-+=,:;{}\[\]\(\)] { return yytext[0]; }
<*>[*]* { return Y_POINTER; }
<*>[[:alnum:]]+ | /* This rule is only useful to print a complete token in error messages */
/* Unrecognized character */
<*>. {
fprintf(stderr, "Unrecognized text on line %d col %d: '%s'.\n",
yylloc->first_line, yylloc->first_column, yytext);
return LEX_ERROR;
}
%%
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "rc.h"
#include "struct_type.h"
#include "buffers.h"
#include "ui_interface.h"
int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int i;
int length = 0;
char cbuf[200];
char *cpy = NULL;
DISPLAY_PARSE_INFO("structure", type->name, offset, parent_offset);
memset (cbuf, 0, 200);
if (type->name) {
DISPLAY_TYPE("Str");
INDENTED_STRING(cbuf, indent, sprintf (cbuf, "%s =%s\n", type->name, "" DISPLAY_BRACE(" {")));
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
for (i = 0; i < type->nb_members; i++) {
if (type->members_child[i] != NULL)
type->members_child[i]->type_dissect_from_buffer (type->members_child[i], buffer, offset, parent_offset,
type->name == NULL ? indent : indent + 4);
}
DISPLAY_BRACE(
if (type->name) {
DISPLAY_TYPE("Str");
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n"));
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);)
return 0;
}
int struct_type_file_print(struct types_s *type, int indent, FILE *file) {
int i;
if (type == NULL)
return -1;
if (file == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Struct>\n"));
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial));
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members));
INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled));
INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled));
if (type->file_ref != NULL)
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
for (i = 0; i < type->nb_members; i++) {
if (type->members_child[i] != NULL)
type->members_child[i]->type_file_print (type->members_child[i], indent + 4, file);
}
INDENTED(file, indent, fprintf(file, "</Struct>\n"));
return 0;
}
int struct_type_hr_display(struct types_s *type, int indent) {
int i;
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Struct>\n"));
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial));
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members));
INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled));
INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled));
if (type->file_ref != NULL)
type->file_ref->type_hr_display (type->file_ref, indent + 4);
for (i = 0; i < type->nb_members; i++) {
if (type->members_child[i] != NULL)
type->members_child[i]->type_hr_display (type->members_child[i], indent + 4);
}
INDENTED(stdout, indent, printf("</Struct>\n"));
return 0;
}
#include "types.h"
#ifndef STRUCT_TYPE_H_
#define STRUCT_TYPE_H_
int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int struct_type_hr_display(struct types_s *type, int indent);
int struct_type_file_print(struct types_s *type, int indent, FILE *file);
#endif /* STRUCT_TYPE_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "typedef_type.h"
#include "ui_interface.h"
int typedef_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent)
{
DISPLAY_PARSE_INFO("typedef", type->name, offset, parent_offset);
/* Simply call next_type */
if (type->child != NULL) {
type->child->type_dissect_from_buffer(
type->child, buffer, offset, parent_offset, indent);
}
return 0;
}
int typedef_type_file_print(struct types_s *type, int indent, FILE *file)
{
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Typedef>\n"));
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
INDENTED(file, indent+4, fprintf(file, "Type .......: %d\n", type->type_xml));
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial));
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members));
INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled));
INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled));
if (type->file_ref != NULL)
type->file_ref->type_file_print(type->file_ref, indent+4, file);
if (type->child != NULL)
type->child->type_file_print(type->child, indent+4, file);
INDENTED(file, indent, fprintf(file, "</Typedef>\n"));
return 0;
}
int typedef_type_hr_display(struct types_s *type, int indent)
{
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Typedef>\n"));
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
INDENTED(stdout, indent+4, printf("Type .......: %d\n", type->type_xml));
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial));
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members));
INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled));
INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled));
if (type->file_ref != NULL)
type->file_ref->type_hr_display(type->file_ref, indent+4);
if (type->child != NULL)
type->child->type_hr_display(type->child, indent+4);
INDENTED(stdout, indent, printf("</Typedef>\n"));
return 0;
}
#include "types.h"
#ifndef TYPEDEF_TYPE_H_
#define TYPEDEF_TYPE_H_
int typedef_type_file_print(struct types_s *type, int indent, FILE *file);
int typedef_type_hr_display(struct types_s *type, int indent);
int typedef_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
#endif /* TYPEDEF_TYPE_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "types.h"
#include "array_type.h"
#include "enum_type.h"
#include "fundamental_type.h"
#include "struct_type.h"
#include "union_type.h"
#include "typedef_type.h"
#include "enum_value_type.h"
#include "file_type.h"
#include "field_type.h"
#include "reference_type.h"
#include "pointer_type.h"
types_t *type_new(enum type_e type)
{
types_t *new_p;
new_p = malloc(sizeof(types_t));
memset(new_p, 0, sizeof(types_t));
new_p->type = type;
switch(type) {
case TYPE_ENUMERATION:
new_p->type_hr_display = enum_type_hr_display;
new_p->type_file_print = enum_type_file_print;
new_p->type_dissect_from_buffer = enum_type_dissect_from_buffer;
break;
case TYPE_FUNDAMENTAL:
new_p->type_hr_display = fundamental_type_hr_display;
new_p->type_file_print = fundamental_type_file_print;
new_p->type_dissect_from_buffer = fundamental_dissect_from_buffer;
break;
case TYPE_STRUCT:
new_p->type_hr_display = struct_type_hr_display;
new_p->type_file_print = struct_type_file_print;
new_p->type_dissect_from_buffer = struct_dissect_from_buffer;
break;
case TYPE_UNION:
new_p->type_hr_display = union_type_hr_display;
new_p->type_file_print = union_type_file_print;
new_p->type_dissect_from_buffer = union_dissect_from_buffer;
break;
case TYPE_TYPEDEF:
new_p->type_hr_display = typedef_type_hr_display;
new_p->type_file_print = typedef_type_file_print;
new_p->type_dissect_from_buffer = typedef_dissect_from_buffer;
break;
case TYPE_ENUMERATION_VALUE:
new_p->type_hr_display = enum_value_type_hr_display;
new_p->type_file_print = enum_value_file_print;
new_p->type_dissect_from_buffer = enum_value_dissect_from_buffer;
break;
case TYPE_FILE:
new_p->type_hr_display = file_type_hr_display;
new_p->type_file_print = file_type_file_print;
// new_p->type_dissect_from_buffer = file_dissect_from_buffer;
break;
case TYPE_FIELD:
new_p->type_hr_display = field_type_hr_display;
new_p->type_file_print = field_type_file_print;
new_p->type_dissect_from_buffer = field_dissect_from_buffer;
break;
case TYPE_REFERENCE:
new_p->type_hr_display = reference_type_hr_display;
new_p->type_file_print = reference_type_file_print;
new_p->type_dissect_from_buffer = reference_dissect_from_buffer;
break;
case TYPE_ARRAY:
new_p->type_hr_display = array_type_hr_display;
new_p->type_file_print = array_type_file_print;
new_p->type_dissect_from_buffer = array_dissect_from_buffer;
break;
case TYPE_POINTER:
new_p->type_hr_display = pointer_type_hr_display;
new_p->type_file_print = pointer_type_file_print;
new_p->type_dissect_from_buffer = pointer_dissect_from_buffer;
break;
default:
break;
}
return new_p;
}
int types_insert_tail(types_t **head, types_t *to_insert)
{
if (to_insert == NULL || head == NULL)
return -1;
if (*head == NULL) {
*head = to_insert;
} else {
types_t *last = *head;
while(last->next != NULL) {
last = last->next;
}
last->next = to_insert;
to_insert->previous = last;
}
to_insert->head = *head;
return 0;
}
void types_hr_display(types_t *head)
{
types_t *current = head;
if (head == NULL) {
printf("Empty list\n");
/* Empty list */
return;
}
while((current = current->next) != NULL)
{
current->type_hr_display(current, 0);
}
}
#include <stdio.h>
#include "buffers.h"
#ifndef TYPES_H_
#define TYPES_H_
/* Activate to display the type at the beginning of the line (debug option) */
#define ENABLE_DISPLAY_TYPE 0
/* Activate to display the parse information before processing each item (debug option) */
#define ENABLE_DISPLAY_PARSE_INFO 0
/* Activate to show braces, in increase the number of displayed lines (formating option)*/
#define ENABLE_DISPLAY_BRACE 0
#if (ENABLE_DISPLAY_TYPE != 0)
# define DISPLAY_TYPE(tYPE) ui_interface.ui_signal_set_text(tYPE, strlen(tYPE));
#else
# define DISPLAY_TYPE(tYPE)
#endif
#if (ENABLE_DISPLAY_PARSE_INFO != 0)
# define DISPLAY_PARSE_INFO(tYPE, nAME, oFFSET, pARENToFFSET) \
{ \
char buf[200]; \
sprintf(buf, "/* %s \"%s\" %d %d */\n", tYPE, nAME, oFFSET, pARENToFFSET); \
ui_interface.ui_signal_set_text(buf, strlen(buf)); \
}
#else
# define DISPLAY_PARSE_INFO(tYPE, nAME, oFFSET, pARENToFFSET)
#endif
#if (ENABLE_DISPLAY_BRACE != 0)
# define DISPLAY_BRACE(cODE) cODE
#else
# define DISPLAY_BRACE(cODE)
#endif
enum type_e {
TYPE_ENUMERATION,
TYPE_ENUMERATION_VALUE,
TYPE_STRUCT,
TYPE_UNION,
TYPE_FUNDAMENTAL,
TYPE_TYPEDEF,
TYPE_ARRAY,
TYPE_REFERENCE,
TYPE_FIELD,
TYPE_FUNCTION,
TYPE_ARGUMENT,
TYPE_POINTER,
TYPE_FILE,
};
/* Forward declarations */
struct types_s;
typedef int (*type_hr_display_t)(struct types_s *type, int indent);
typedef int (*type_ui_display_t)(struct types_s *type, int indent);
typedef int (*type_file_print_t)(struct types_s *type, int indent, FILE *file);
/**
* type_dissect_from_buffer_t
* @param type The current type
* @param buffer The buffer containing data to dissect
* @param offset offset of field from the beginning of the parent
* @param parent_offset offset of the parent from begining
**/
typedef int (*type_dissect_from_buffer_t)(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
typedef struct types_s {
/* The type of the current description */
enum type_e type;
/* Printable name for the current type */
char *name;
int type_xml;
int size;
int align;
int bits;
/* Used only for arrays */
int min;
int max;
int context;
/* Init value for enumerations */
int init_value;
int incomplete;
/* Id of the type as defined in XML file */
int id;
int artificial;
char *mangled;
char *demangled;
/* List of members in constructed types */
char *members;
/* The file containing the definition */
char *file;
/* Line number of the current definition */
int line;
/* offset of the field in the parent type
* -1 means no parent
*/
int offset;
struct types_s *previous;
struct types_s *next;
struct types_s *parent;
struct types_s *child;
struct types_s *file_ref;
/* Reference to the head */
struct types_s *head;
/* For structures or union */
int nb_members;
struct types_s **members_child;
/* Some procedures to display the type on terminal */
type_hr_display_t type_hr_display;
/* Some procedures to display the type on UI */
type_ui_display_t type_ui_display;
/* Procedure to display the type to a file */
type_file_print_t type_file_print;
/* Dissect the type */
type_dissect_from_buffer_t type_dissect_from_buffer;
} types_t;
types_t *type_new(enum type_e type);
int types_insert_tail(types_t **head, types_t *to_insert);
void types_hr_display(types_t *head);
#define INDENTED(fILE, x, y) \
do { \
int indentation = x; \
while(indentation--) fprintf(fILE, " "); \
y; \
} while(0)
#define INDENTED_STRING(sTR, x, y) \
do { \
int indentation = x; \
while(indentation--) ui_interface.ui_signal_set_text(" ", 1); \
y; \
} while(0)
#endif /* TYPES_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "rc.h"
#include "union_type.h"
#include "../libresolver/locate_root.h"
#include "ui_interface.h"
/* There is only one special case of union which is associated to an index: the message id */
int union_msg_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
uint32_t message_id;
DISPLAY_PARSE_INFO("union_msg", type->name, offset, parent_offset);
CHECK_FCT(get_message_id(type->head, buffer, &message_id));
if (type->members_child[message_id] != NULL)
type->members_child[message_id]->type_dissect_from_buffer (type->members_child[message_id], buffer, offset,
parent_offset, indent);
return RC_OK;
}
int union_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int length = 0;
char cbuf[200];
char *cpy = NULL;
DISPLAY_PARSE_INFO("union", type->name, offset, parent_offset);
memset (cbuf, 0, 200);
// CHECK_FCT(buffer_has_enouch_data(buffer, offset + parent_offset, type->size / 8));
if (type->name) {
// INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
DISPLAY_TYPE("Uni");
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "%s {\n", type->name));
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
/* Only dissect the first field present in unions */
if (type->members_child[0] != NULL)
type->members_child[0]->type_dissect_from_buffer (type->members_child[0], buffer, offset, parent_offset,
type->name == NULL ? indent : indent + 4);
if (type->name) {
// INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
DISPLAY_TYPE("Uni");
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n"));
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
return 0;
}
int union_type_file_print(struct types_s *type, int indent, FILE *file) {
int i;
if (type == NULL)
return -1;
INDENTED(file, indent, fprintf(file, "<Union>\n"));
INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial));
INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members));
INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled));
INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled));
if (type->file_ref != NULL)
type->file_ref->type_file_print (type->file_ref, indent + 4, file);
for (i = 0; i < type->nb_members; i++) {
if (type->members_child[i] != NULL)
type->members_child[i]->type_file_print (type->members_child[i], indent + 4, file);
}
INDENTED(file, indent, fprintf(file, "</Union>\n"));
return 0;
}
int union_type_hr_display(struct types_s *type, int indent) {
int i;
if (type == NULL)
return -1;
INDENTED(stdout, indent, printf("<Union>\n"));
INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial));
INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members));
INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled));
INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled));
if (type->file_ref != NULL)
type->file_ref->type_hr_display (type->file_ref, indent + 4);
for (i = 0; i < type->nb_members; i++) {
if (type->members_child[i] != NULL)
type->members_child[i]->type_hr_display (type->members_child[i], indent + 4);
}
INDENTED(stdout, indent, printf("</Union>\n"));
return 0;
}
#include "types.h"
#ifndef UNION_TYPE_H_
#define UNION_TYPE_H_
int union_msg_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int union_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int union_type_file_print(struct types_s *type, int indent, FILE *file);
int union_type_hr_display(struct types_s *type, int indent);
#endif /* UNION_TYPE_H_ */
This diff is collapsed.
#include "../rc.h"
#include "types.h"
#ifndef XML_PARSE_H_
#define XML_PARSE_H_
int xml_parse_file(const char *filename);
int xml_parse_buffer(const char *xml_buffer, const int size);
int dissect_signal(const uint32_t message_number);
#endif /* XML_PARSE_H_ */
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir) \
-I$(top_srcdir)/libparser \
-I$(top_srcdir)/libbuffers
noinst_LTLIBRARIES = libresolver.la
libresolver_la_LDFLAGS = -all-static
libresolver_la_SOURCES = \
locate_root.c locate_root.h \
resolvers.c resolvers.h
#include <stdio.h>
#include <string.h>
#include "../rc.h"
#include "types.h"
#include "locate_root.h"
int locate_root(const char *root_name, types_t *head, types_t **root) {
types_t *next_type;
/* The root element is for example : MessageDef.
* This element is the entry for other sub-types.
*/
if (!root_name || (strlen (root_name) == 0)) {
printf ("FATAL: no root element name provided\n");
return -1;
}
if (!head) {
printf ("Empty list detected\n");
return -1;
}
if (!root) {
printf ("NULL root reference\n");
return -1;
}
for (next_type = head; next_type; next_type = next_type->next) {
if (next_type->name == NULL)
continue;
if (strcmp (root_name, next_type->name) == 0) {
/* Matching reference */
break;
}
}
*root = next_type;
return (next_type == NULL) ? -2 : 0;
}
int locate_type(const char *type_name, types_t *head, types_t **type) {
types_t *next_type;
/* The root element is for example : MessageDef.
* This element is the entry for other sub-types.
*/
if (!type_name) {
printf ("FATAL: no root element name provided\n");
return RC_BAD_PARAM;
}
if (!head) {
printf ("Empty list detected\n");
return RC_BAD_PARAM;
}
for (next_type = head; next_type; next_type = next_type->next) {
if (next_type->name == NULL)
continue;
if (strcmp (type_name, next_type->name) == 0) {
/* Matching reference */
break;
}
}
if (type)
*type = next_type;
return (next_type == NULL) ? RC_FAIL : RC_OK;
}
int get_message_id(types_t *head, buffer_t *buffer, uint32_t *message_id) {
uint32_t value;
types_t *type_message_id;
if (!head || !message_id || !buffer)
return RC_BAD_PARAM;
CHECK_FCT(locate_type("messageId", head, &type_message_id));
/* MessageId is an offset from start of buffer */
value = buffer_get_uint32_t (buffer, type_message_id->offset);
*message_id = value;
return RC_OK;
}
#ifndef LOCATE_ROOT_H_
#define LOCATE_ROOT_H_
int locate_root(const char *root_name, types_t *head, types_t **root);
int locate_type(const char *type_name, types_t *head, types_t **type);
int get_message_id(types_t *head, buffer_t *buffer, uint32_t *message_id);
#endif /* LOCATE_ROOT_H_ */
#include <stdio.h>
#include <string.h>
#include "types.h"
int resolve_typedefs(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return -1;
}
for (next_type = head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_TYPEDEF)
continue;
printf("Trying to resolve typedef %s\n", next_type->name);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "types.h"
#include "resolvers.h"
typedef enum {
RESOLV_OK = 0,
RESOLV_ERROR = -1,
RESOLV_LIST_EMPTY = -2,
RESOLV_NOT_FOUND = -3,
} resolv_rc_e;
int search_id(types_t *head, types_t **found, int id)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = head; next_type; next_type = next_type->next)
{
if (next_type->id == id && next_type->type != TYPE_FILE)
break;
}
if (found)
*found = next_type;
return next_type == NULL ? RESOLV_NOT_FOUND : RESOLV_OK;
}
int search_file(types_t *head, types_t **found, int file_id)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = head; next_type; next_type = next_type->next)
{
if (next_type->type != TYPE_FILE)
continue;
if (file_id == next_type->id)
break;
}
if (found)
*found = next_type;
return next_type == NULL ? RESOLV_NOT_FOUND : RESOLV_OK;
}
int resolve_typedefs(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_TYPEDEF)
continue;
// printf("Trying to resolve typedef %s with type %d\n", next_type->name, next_type->id);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}/* else {
next_type->type_hr_display(next_type, 0);
}*/
}
return 0;
}
int resolve_struct(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
char *member;
char *members;
/* Only resolve typedef */
if (next_type->type != TYPE_STRUCT)
continue;
// printf("Trying to resolve struct members %s with type %d\n", next_type->name, next_type->id);
/* Struct may have no member */
if (next_type->members == NULL)
continue;
/* We have to copy the string as strtok will split the string in argument */
members = strdup(next_type->members);
/* Split the string on spaces and _ */
member = strtok(members, " _");
while(member != NULL)
{
if (next_type->nb_members == 0) {
next_type->members_child = malloc(sizeof(struct types_s *));
} else {
next_type->members_child = realloc(next_type->members_child,
(next_type->nb_members + 1) * sizeof(struct types_s *));
}
if (search_id(*head, &next_type->members_child[next_type->nb_members], atoi(member)) != RESOLV_OK) {
/* We have to remove this reference */
}
if ((next_type->members_child[next_type->nb_members] != NULL)
&& (next_type->members_child[next_type->nb_members]->type != TYPE_FIELD))
{
/* Only keep field child for structure, other member can be present
* for defining types (union or struct) used by fields but should not be considered. */
next_type->members_child[next_type->nb_members] = NULL;
/* We have to remove this reference */
}
next_type->nb_members++;
/* Pick up the next string available */
member = strtok(NULL, " _");
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_union(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
char *member;
char *members;
/* Only resolve typedef */
if (next_type->type != TYPE_UNION)
continue;
// printf("Trying to resolve struct members %s with type %d\n", next_type->name, next_type->id);
/* Struct may have no member */
if (next_type->members == NULL)
continue;
/* We have to copy the string as strtok will modify the string in argument */
members = strdup(next_type->members);
/* Split the string on spaces and _ */
member = strtok(members, " _");
while(member != NULL)
{
if (next_type->nb_members == 0) {
next_type->members_child = malloc(sizeof(struct types_s *));
} else {
next_type->members_child = realloc(next_type->members_child,
(next_type->nb_members + 1) * sizeof(struct types_s *));
}
if (search_id(*head, &next_type->members_child[next_type->nb_members], atoi(member)) != RESOLV_OK) {
/* We have to remove this reference */
}
next_type->nb_members++;
/* Pick up the next string available */
member = strtok(NULL, " _");
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_pointer_type(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_POINTER)
continue;
// printf("Trying to resolve pointer id %d with type %d\n",
// next_type->id, next_type->type_xml);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_reference(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_REFERENCE)
continue;
// printf("Trying to resolve reference id %d with type %d\n",
// next_type->id, next_type->type_xml);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_field(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_FIELD)
continue;
// printf("Trying to resolve pointer id %d with type %d\n",
// next_type->id, next_type->type_xml);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_array(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_ARRAY)
continue;
// printf("Trying to resolve array id %d with type %d\n",
// next_type->id, next_type->type_xml);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_file(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type == TYPE_FILE)
continue;
/* No reference to a file */
if (next_type->file == NULL) {
continue;
}
// printf("Trying to resolve file %s\n", next_type->file);
if (search_file(*head, &next_type->file_ref, atoi(&next_type->file[1])) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
#ifndef RESOLVERS_H_
#define RESOLVERS_H_
int resolve_typedefs(types_t **head);
int resolve_struct(types_t **head);
int resolve_pointer_type(types_t **head);
int resolve_field(types_t **head);
int resolve_array(types_t **head);
int resolve_reference(types_t **head);
int resolve_union(types_t **head);
int resolve_file(types_t **head);
int search_file(types_t *head, types_t **found, int id);
#endif /* RESOLVERS_H_ */
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir)/libbuffers \
-I$(top_srcdir)/libparser
noinst_LTLIBRARIES = libui.la
libui_la_LDFLAGS = -all-static
libui_la_SOURCES = \
ui_main_screen.c ui_main_screen.h \
ui_menu_bar.c ui_menu_bar.h \
ui_callbacks.c ui_callbacks.h \
ui_tree_view.c ui_tree_view.h \
ui_signal_dissect_view.c ui_signal_dissect_view.h \
ui_notifications.c ui_notifications.h \
ui_interface.c ui_interface.h \
ui_notebook.c ui_notebook.h
This diff is collapsed.
#ifndef UI_CALLBACKS_H_
#define UI_CALLBACKS_H_
gboolean ui_callback_on_open(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_about(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_connect(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_disconnect(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_tree_view_select(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean
ui_callback_on_select_signal(GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer userdata);
#endif /* UI_CALLBACKS_H_ */
#include <pthread.h>
#include <stdint.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include "ui_interface.h"
#include "ui_tree_view.h"
#include "ui_notifications.h"
#include "ui_signal_dissect_view.h"
#include "socket.h"
#include "xml_parse.h"
ui_interface_t ui_interface = {
.dissector_ready = 0,
/** core program -> UI **/
.ui_notification_dialog = ui_notification_dialog,
.ui_disable_connect_button = ui_disable_connect_button,
.ui_enable_connect_button = ui_enable_connect_button,
.ui_progress_bar_set_fraction = ui_progress_bar_set_fraction,
.ui_progress_bar_terminate = ui_progress_bar_terminate,
.ui_tree_view_new_signal_ind = ui_tree_view_new_signal_ind,
.ui_signal_set_text = ui_signal_set_text,
/** UI -> core program **/
.socket_connect = socket_connect_to_remote_host,
.socket_disconnect = socket_disconnect_from_remote_host,
.parse_signal_file = xml_parse_file,
.dissect_signal = dissect_signal,
};
This diff is collapsed.
This diff is collapsed.
#ifndef UI_MAIN_SCREEN_H_
#define UI_MAIN_SCREEN_H_
typedef struct {
GtkWidget *window;
GtkWidget *ipentry;
GtkWidget *portentry;
GtkWidget *progressbar;
GtkWidget *signalslist;
GtkWidget *textview;
/* Buttons */
GtkToolItem *connect;
GtkToolItem *disconnect;
} ui_main_data_t;
extern ui_main_data_t ui_main_data;
int ui_gtk_initialize(int argc, char *argv[]);
#endif /* UI_MAIN_SCREEN_H_ */
This diff is collapsed.
#ifndef UI_MENU_BAR_H_
#define UI_MENU_BAR_H_
int ui_menu_bar_create(GtkWidget *vbox);
int ui_toolbar_create(GtkWidget *vbox);
#endif /* UI_MENU_BAR_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment