Remove old commented out code

2006-08-27  Soren Sandmann <sandmann@redhat.com>

	* binparser.c: Remove old commented out code

2006-08-27  Soren Sandmann  <sandmann@redhat.com>

	* module/Makefile ($(MODULE).o): Add dependency on sysprof-module.h

	* elfparser.c (elf_parser_get_eh_frame): Add this function.
	Remove some commented out code.
This commit is contained in:
Soren Sandmann
2006-09-23 00:54:01 +00:00
committed by Søren Sandmann Pedersen
parent 2c04f6e200
commit b7cf5d34b8
10 changed files with 141 additions and 246 deletions

View File

@ -173,6 +173,9 @@ convert_uint (const guchar *data,
guint16 r16;
guint32 r32;
guint64 r64;
if (width == 4)
g_print ("converting at %p %d %d %d %d\n", data, data[0], data[1], data[2], data[3]);
switch (width)
{
@ -378,12 +381,18 @@ bin_record_get_uint (BinRecord *record,
field = get_field (record->format, name);
pos = record->parser->data + record->offset + field->offset;
g_print (" record offset: %d\n", record->offset);
g_print (" record index: %d\n", record->index);
g_print (" field offset %d\n", field->offset);
if (record->offset + field->offset + field->width > record->parser->length)
{
/* FIXME: generate error */
return 0;
}
g_print (" uint %d at %p => %d\n", field->width, pos, convert_uint (pos, record->format->big_endian, field->width));
return convert_uint (pos, record->format->big_endian, field->width);
}
@ -415,210 +424,3 @@ bin_field_new_fixed_array (int n_elements,
field->align = element_size;
return field;
}
#if 0
#include <elf.h>
static gboolean
find_elf_type (const guchar *data, gsize length,
gboolean *is_64, gboolean *is_be)
{
/* FIXME: this function should be able to return an error */
if (length < EI_NIDENT)
return FALSE;
/* 32 or 64? */
switch (data[EI_CLASS])
{
case ELFCLASS32:
*is_64 = FALSE;
break;
case ELFCLASS64:
*is_64 = TRUE;
break;
default:
/* return ERROR */
return FALSE;
break;
}
/* big or little endian? */
switch (data[EI_DATA])
{
case ELFDATA2LSB:
*is_be = FALSE;
break;
case ELFDATA2MSB:
*is_be = TRUE;
break;
default:
/* return Error */
return FALSE;
break;
}
g_print ("This elf file is %s %s\n",
*is_64? "64 bit" : "32 bit",
*is_be? "big endiann" : "little endian");
return TRUE;
}
void
parse_elf (const guchar *data,
gsize length)
{
gboolean is_64, is_big_endian;
BinFormat *elf_header;
BinFormat *shn_entry;
const guchar *section_header;
BinParser *parser;
BinParser *sh_parser;
BinFormat *sym;
int i;
find_elf_type (data, length, &is_64, &is_big_endian);
elf_header = bin_format_new (
is_big_endian,
"e_ident", bin_field_new_fixed_array (EI_NIDENT, 1),
"e_type", bin_field_new_uint16 (),
"e_machine", bin_field_new_uint16 (),
"e_version", bin_field_new_uint32 (),
"e_entry", make_word (is_64),
"e_phoff", make_word (is_64),
"e_shoff", make_word (is_64),
"e_flags", make_uint32 (),
"e_ehsize", make_uint16(),
"e_phentsize", make_uint16 (),
"e_phnum", make_uint16 (),
"e_shentsize", make_uint16 (),
"e_shnum", make_uint16 (),
"e_shstrndx", make_uint16 (),
NULL);
shn_entry = bin_format_new (
is_big_endian,
"sh_name", make_uint32(),
"sh_type", make_uint32(),
"sh_flags", make_word (is_64),
"sh_addr", make_word (is_64),
"sh_offset", make_word (is_64),
"sh_size", make_word (is_64),
"sh_link", make_uint32(),
"sh_info", make_uint32(),
"sh_addralign", make_word (is_64),
"sh_entsize", make_word (is_64),
NULL);
if (is_64)
{
sym = bin_format_new (
is_big_endian,
"st_name", make_uint32(),
"st_info", make_uint8 (),
"st_other", make_uint8 (),
"st_shndx", make_uint16 (),
"st_value", make_uint64 (),
"st_size", make_uint64 (),
NULL);
}
else
{
sym = bin_format_new (
is_big_endian,
"st_name", make_uint32 (),
"st_value", make_uint32 (),
"st_size", make_uint32 (),
"st_info", make_uint8 (),
"st_other", make_uint8 (),
"st_shndx", make_uint16 ());
}
parser = bin_parser_new (elf_header, data, length);
section_header = data + bin_parser_get_uint (parser, "e_shoff");
#if 0
g_print ("section header offset: %u\n",
section_header - data);
g_print ("There are %llu sections\n",
bin_parser_get_uint (parser, "e_shnum"));
#endif
/* should think through how to deal with offsets, and whether parsers
* are always considered parsers of an array. If yes, then it
* may be reasonable to just pass the length of the array.
*
* Hmm, although the parser still needs to know the end of the data.
* Maybe create yet another structure, a subparser, that also contains
* an offset in addition to the beginning and length.
*
* Ie., bin_sub_parser_new (parser, section_header, shn_entry, n_headers);
*
* In that case, it might be interesting to merge format and parser,
* and just call it 'file' or something, then call the subparser "parser"
*
* Also, how do we deal with strings?
*
* "asdf", make_string()?
*
*/
sh_parser = bin_parser_new (shn_entry, section_header, (guint)-1);
for (i = 0; i < bin_parser_get_uint (parser, "e_shnum"); ++i)
{
#if 0
bin_parser_set_index (sh_parser, i);
#endif
#if 0
bin_parser_get_uint
parser, data + i * bin_format_length (shn_entry));
section_header =
data + bin_parser_get_uint (parser, "e_shoff");
parser = bin_parser_new (
#endif
}
#if 0
bin_format_array_get_string (shn_table, data, "sh_name");
bin_format_array_get_uint (shn_table, data, "sh_addr");
#endif
}
static void
disaster (const char *str)
{
g_printerr ("%s\n", str);
exit (-1);
}
int
main ()
{
GMappedFile *libgtk;
libgtk = g_mapped_file_new ("/usr/lib/libgtk-x11-2.0.so", FALSE, NULL);
if (!libgtk)
disaster ("Could not map the file\n");
parse_elf ((const guchar *)g_mapped_file_get_contents (libgtk),
g_mapped_file_get_length (libgtk));
return 0 ;
}
#endif