From: Soren Sandmann Date: Sat, 24 Feb 2007 08:49:51 +0000 (+0000) Subject: Updates X-Git-Tag: 1.1.2~133 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf70d3a7ed2090c09e4e7baec18a5bfb745842f9;p=platform%2Fupstream%2Fsysprof.git Updates 2007-02-24 Soren Sandmann * TODO: Updates * binparser.[ch]: Get rid of BIN_UINTn types; replace with single BIN_UINT, where the user must provide the width * elfparser.c: Update to new binparser API svn path=/trunk/; revision=354 --- diff --git a/ChangeLog b/ChangeLog index f58bbbf..a9a6388 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-02-24 Soren Sandmann + + * TODO: Updates + + * binparser.[ch]: Get rid of BIN_UINTn types; replace with single + BIN_UINT, where the user must provide the width + + * elfparser.c: Update to new binparser API + 2007-02-24 Soren Sandman * binparser.[ch]: Switch to a simpler conceptual model. diff --git a/TODO b/TODO index 9776bd3..719b132 100644 --- a/TODO +++ b/TODO @@ -110,9 +110,6 @@ Before 1.2: - the bin_parser_seek_record (..., 1); idiom is a little dubious - - maybe convert BIN_UINT32 => { BIN_UINT, 4 } - we already have the width in the struct. - - Add error checking Also need to add error checking. @@ -675,6 +672,10 @@ Later: -=-=-=-=-=-=-=-=-=-=-=-=-=-=- ALREADY DONE -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +* Missing things in binparser.[ch] + + - maybe convert BIN_UINT32 => { BIN_UINT, 4 } + we already have the width in the struct. * Rethink binparser. Maybe the default mode should be: - there is a current offset diff --git a/binparser.c b/binparser.c index ce063ee..6b6c95a 100644 --- a/binparser.c +++ b/binparser.c @@ -108,33 +108,12 @@ align (guint64 offset, int alignment) } static int -get_field_width (const BinField *field) -{ - switch (field->type) - { - case BIN_UINT8: - return 1; - case BIN_UINT16: - return 2; - case BIN_UINT32: - return 4; - case BIN_UINT64: - return 8; - case BIN_UNINTERPRETED: - return field->n_bytes; - } - - g_assert_not_reached (); - return -1; -} - -static int get_align (const BinField *field) { if (field->type == BIN_UNINTERPRETED) return 1; else - return get_field_width (field); + return field->n_bytes; } BinRecord * @@ -169,12 +148,8 @@ bin_parser_create_record (BinParser *parser, strncpy (field->name, bin_field->name, BIN_MAX_NAME - 1); field->offset = offset; field->type = bin_field->type; - field->width = get_field_width (bin_field); + field->width = bin_field->n_bytes; -#if 0 - g_print ("created field %s with type %d\n", field->name, field->type); -#endif - offset += record->fields[i].width; } @@ -268,7 +243,7 @@ bin_parser_restore (BinParser *parser) static guint64 convert_uint (const guchar *data, BinEndian endian, - BinType type) + int width) { guint8 r8; guint16 r16; @@ -282,13 +257,13 @@ convert_uint (const guchar *data, /* FIXME: check that we are within the file */ - switch (type) + switch (width) { - case BIN_UINT8: + case 1: r8 = *(guint8 *)data; return r8; - case BIN_UINT16: + case 2: r16 = *(guint16 *)data; if (endian == BIN_BIG_ENDIAN) @@ -298,7 +273,7 @@ convert_uint (const guchar *data, return r16; - case BIN_UINT32: + case 4: r32 = *(guint32 *)data; if (endian == BIN_BIG_ENDIAN) @@ -308,7 +283,7 @@ convert_uint (const guchar *data, return r32; - case BIN_UINT64: + case 8: r64 = *(guint64 *)data; if (endian == BIN_BIG_ENDIAN) @@ -324,31 +299,13 @@ convert_uint (const guchar *data, } } -static int -get_uint_width (BinType type) -{ - switch (type) - { - case BIN_UINT8: - return 1; - case BIN_UINT16: - return 2; - case BIN_UINT32: - return 4; - case BIN_UINT64: - return 8; - default: - return -1; - } -} - guint64 bin_parser_get_uint (BinParser *parser, - BinType type) + int width) { - guint64 r = convert_uint (parser->data + parser->offset, parser->endian, type); + guint64 r = convert_uint (parser->data + parser->offset, parser->endian, width); - parser->offset += get_uint_width (type); + parser->offset += width; return r; } @@ -422,5 +379,5 @@ bin_parser_get_uint_field (BinParser *parser, g_print (" uint %d at %p => %d\n", field->width, pos, convert_uint (pos, record->format->big_endian, field->width)); #endif - return convert_uint (pos, parser->endian, field->type); + return convert_uint (pos, parser->endian, field->width); } diff --git a/binparser.h b/binparser.h index a0b423c..d576161 100644 --- a/binparser.h +++ b/binparser.h @@ -65,10 +65,7 @@ typedef enum typedef enum { /* More types can (and probably will) be added in the future */ - BIN_UINT8, - BIN_UINT16, - BIN_UINT32, - BIN_UINT64, + BIN_UINT, BIN_UNINTERPRETED } BinType; @@ -107,7 +104,7 @@ void bin_parser_restore (BinParser *parser); /* retrieve data */ guint64 bin_parser_get_uint (BinParser *parser, - BinType type); + int width); const char * bin_parser_get_string (BinParser *parser); guint64 bin_parser_get_uint_field (BinParser *parser, BinRecord *record, diff --git a/elfparser.c b/elfparser.c index d0e6273..332ea10 100644 --- a/elfparser.c +++ b/elfparser.c @@ -584,7 +584,7 @@ elf_parser_get_debug_link (ElfParser *parser, guint32 *crc32) bin_parser_align (parser->parser, 4); if (crc32) - *crc32 = bin_parser_get_uint (parser->parser, BIN_UINT32); + *crc32 = bin_parser_get_uint (parser->parser, 4); return result; } @@ -669,85 +669,85 @@ get_formats (gboolean is_64, { static const BinField elf64_header[] = { { "e_ident", BIN_UNINTERPRETED, EI_NIDENT }, - { "e_type", BIN_UINT16 }, - { "e_machine", BIN_UINT16 }, - { "e_version", BIN_UINT32 }, - { "e_entry", BIN_UINT64 }, - { "e_phoff", BIN_UINT64 }, - { "e_shoff", BIN_UINT64 }, - { "e_flags", BIN_UINT32 }, - { "e_ehsize", BIN_UINT16 }, - { "e_phentsize", BIN_UINT16 }, - { "e_phnum", BIN_UINT16 }, - { "e_shentsize", BIN_UINT16 }, - { "e_shnum", BIN_UINT16 }, - { "e_shstrndx", BIN_UINT16 }, + { "e_type", BIN_UINT, 2 }, + { "e_machine", BIN_UINT, 2 }, + { "e_version", BIN_UINT, 4 }, + { "e_entry", BIN_UINT, 8 }, + { "e_phoff", BIN_UINT, 8 }, + { "e_shoff", BIN_UINT, 8 }, + { "e_flags", BIN_UINT, 4 }, + { "e_ehsize", BIN_UINT, 2 }, + { "e_phentsize", BIN_UINT, 2 }, + { "e_phnum", BIN_UINT, 2 }, + { "e_shentsize", BIN_UINT, 2 }, + { "e_shnum", BIN_UINT, 2 }, + { "e_shstrndx", BIN_UINT, 2 }, { "" }, }; static const BinField elf32_header[] = { { "e_ident", BIN_UNINTERPRETED, EI_NIDENT }, - { "e_type", BIN_UINT16 }, - { "e_machine", BIN_UINT16 }, - { "e_version", BIN_UINT32 }, - { "e_entry", BIN_UINT32 }, - { "e_phoff", BIN_UINT32 }, - { "e_shoff", BIN_UINT32 }, - { "e_flags", BIN_UINT32 }, - { "e_ehsize", BIN_UINT16 }, - { "e_phentsize", BIN_UINT16 }, - { "e_phnum", BIN_UINT16 }, - { "e_shentsize", BIN_UINT16 }, - { "e_shnum", BIN_UINT16 }, - { "e_shstrndx", BIN_UINT16 }, + { "e_type", BIN_UINT, 2 }, + { "e_machine", BIN_UINT, 2 }, + { "e_version", BIN_UINT, 4 }, + { "e_entry", BIN_UINT, 4 }, + { "e_phoff", BIN_UINT, 4 }, + { "e_shoff", BIN_UINT, 4 }, + { "e_flags", BIN_UINT, 4 }, + { "e_ehsize", BIN_UINT, 2 }, + { "e_phentsize", BIN_UINT, 2 }, + { "e_phnum", BIN_UINT, 2 }, + { "e_shentsize", BIN_UINT, 2 }, + { "e_shnum", BIN_UINT, 2 }, + { "e_shstrndx", BIN_UINT, 2 }, { "" }, }; static const BinField shn64_entry[] = { - { "sh_name", BIN_UINT32 }, - { "sh_type", BIN_UINT32 }, - { "sh_flags", BIN_UINT64 }, - { "sh_addr", BIN_UINT64 }, - { "sh_offset", BIN_UINT64 }, - { "sh_size", BIN_UINT64 }, - { "sh_link", BIN_UINT32 }, - { "sh_info", BIN_UINT32 }, - { "sh_addralign", BIN_UINT64 }, - { "sh_entsize", BIN_UINT64 }, + { "sh_name", BIN_UINT, 4 }, + { "sh_type", BIN_UINT, 4 }, + { "sh_flags", BIN_UINT, 8 }, + { "sh_addr", BIN_UINT, 8 }, + { "sh_offset", BIN_UINT, 8 }, + { "sh_size", BIN_UINT, 8 }, + { "sh_link", BIN_UINT, 4 }, + { "sh_info", BIN_UINT, 4 }, + { "sh_addralign", BIN_UINT, 8 }, + { "sh_entsize", BIN_UINT, 8 }, { "" } }; static const BinField shn32_entry[] = { - { "sh_name", BIN_UINT32 }, - { "sh_type", BIN_UINT32 }, - { "sh_flags", BIN_UINT32 }, - { "sh_addr", BIN_UINT32 }, - { "sh_offset", BIN_UINT32 }, - { "sh_size", BIN_UINT32 }, - { "sh_link", BIN_UINT32 }, - { "sh_info", BIN_UINT32 }, - { "sh_addralign", BIN_UINT32 }, - { "sh_entsize", BIN_UINT32 }, + { "sh_name", BIN_UINT, 4 }, + { "sh_type", BIN_UINT, 4 }, + { "sh_flags", BIN_UINT, 4 }, + { "sh_addr", BIN_UINT, 4 }, + { "sh_offset", BIN_UINT, 4 }, + { "sh_size", BIN_UINT, 4 }, + { "sh_link", BIN_UINT, 4 }, + { "sh_info", BIN_UINT, 4 }, + { "sh_addralign", BIN_UINT, 4 }, + { "sh_entsize", BIN_UINT, 4 }, { "" } }; static const BinField sym64_format[] = { - { "st_name", BIN_UINT32 }, - { "st_info", BIN_UINT8 }, - { "st_other", BIN_UINT8 }, - { "st_shndx", BIN_UINT16 }, - { "st_value", BIN_UINT64 }, - { "st_size", BIN_UINT64 }, + { "st_name", BIN_UINT, 4 }, + { "st_info", BIN_UINT, 1 }, + { "st_other", BIN_UINT, 1 }, + { "st_shndx", BIN_UINT, 2 }, + { "st_value", BIN_UINT, 8 }, + { "st_size", BIN_UINT, 8 }, { "" } }; static const BinField sym32_format[] = { - { "st_name", BIN_UINT32 }, - { "st_value", BIN_UINT32 }, - { "st_size", BIN_UINT32 }, - { "st_info", BIN_UINT8 }, - { "st_other", BIN_UINT8 }, - { "st_shndx", BIN_UINT16 }, + { "st_name", BIN_UINT, 4 }, + { "st_value", BIN_UINT, 4 }, + { "st_size", BIN_UINT, 4 }, + { "st_info", BIN_UINT, 1 }, + { "st_other", BIN_UINT, 1 }, + { "st_shndx", BIN_UINT, 2 }, { "" }, };