eliben/pyelftools — pull request #13 by dnozay (2013-10-12 01:11:40+00:00)
Title: first stab at a pahole equivalent.

first stab at a pahole equivalent.
it's not too pretty, but it's not too shabby either.

testing done:

(pypy-elf)# damien@localhost ~/Work/github/pyelftools [17:57:51]> gcc -g -o examples/sample_structs.elf examples/sample_structs.c
(pypy-elf)# damien@localhost ~/Work/github/pyelftools [17:58:05]> time python examples/pahole.py examples/sample_structs.elf
Processing file: examples/sample_structs.elf
Compile unit examples/sample_structs.c
45[45]: type long unsigned int;
52[52]: type unsigned char;
59[59]: type short unsigned int;
66[66]: type unsigned int;
73[73]: type signed char;
80[80]: type short int;
87[87]: type int;
94[94]: type long int;
109[109]: type char;
union __unknown_116 {
long int * pointer_to_long;
char * pointer_to_string;
void * * * triple_void_indirection;
}
struct namedFoo {
int some_int;
char some_character;
volatile long unsigned int [12] some_volatile_unsigned_long_array;
union __unknown_116 some_union;
int seven_bits;
int remaining_bit;
const struct namedFoo * self;
}
315[315]: typedef namedFoo struct namedFoo;
struct __unknown_326 {
int member;
}
347[347]: typedef anonymousStruct struct __unknown_326;

real 0m0.500s
user 0m0.235s
sys 0m0.262s