So that we can load many object files, that is what the next csets will
do, to recursively look for files with debug info in a build tree, such
as the kernel one.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
An example to illustrate the kind of checks done:
[acme@newtoy multi-cu]$ cat a.c
struct foo {
int a;
char b;
};
void a_foo_print(struct foo *f)
{
printf("f.a=%d\n", f->a);
}
[acme@newtoy multi-cu]$ cat main.c
struct foo {
int a;
char b;
char c;
};
extern void a_foo_print(struct foo *f);
int main(void)
{
struct foo f = { .a = 10, };
a_foo_print(&f);
return 0;
}
[acme@newtoy multi-cu]$ cc -g -c a.c -o a.o
[acme@newtoy multi-cu]$ cc -g -c main.c -o main.o
[acme@newtoy multi-cu]$ cc a.o main.o -o m
[acme@newtoy multi-cu]$ pahole m
class: foo
first: a.c
current: main.c
nr_members: 2 != 3
padding: 3 != 2
[acme@newtoy multi-cu]$
Gotcha? In the above case this inconsistency wouldn't cause problems, as the
'c' member doesn't makes the struct bigger, it uses the padding, but what if we
inverted the members 'a' and 'b'?
Upcoming csets will check if the type and order of the members are the same,
should help in some complex projects where people insist on using #ifdefs in
struct definitions.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Simplifying options processing by using just pair of cu and class iterators and
using the list we were building just for --total_structure_stats for all
options, this way we don't print multiple times structures that are defined in
more than one object file when processing a multi-object file.
With this in place all the options will check if a struct definition in one
object file somehow doesn't matches the same struct definition in some other
object file, more checks will be put in place in the upcoming csets.
And, to show that this besides simplifying reduces the code size, lets use
codiff:
[acme@newtoy pahole]$ codiff build/pahole.before build/pahole
/home/acme/pahole/pahole.c:
structures__add | -143
class__filter | +147
main | -263
3 functions changed, 147 bytes added, 406 bytes removed
[acme@newtoy pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
That is to find structs that have combinable holes, trying to pack the struct
by suggesting a move, for now it just prints structs that have holes that can
be combined, but these hints are not guaranteed to generate struct size
reductions, more has to be done and that involves understanding the alignment
rules that depend on the arch being 32 or 64 bits, but it at least reduces the
number of packing candidates.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
So that we can see only the structs that have more than the specified number of
bit holes.
Can be combined with --holes to see structs that have bit and byte holes.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
These are currently only used by pahole and would live in classes otherwise.
Signed-off-by: Bernhard Fischer <rep.nop@aon.at>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
The minimum number of holes that a struct must have for it to be
reported, to help in combining holes.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
pahole -D /pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/ \
../OUTPUT/qemu/net-2.6.20/net/ipv4/tcp.o
Will exclude all the classes that were defined in files in the
/pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/ directory, note that its
a prefix, not a directory, so one could as well pass
/pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/tcp_ to exclude just the
files in the include/net directory and that start with 'tcp_'.
Now I think I implemented what Bernard wanted, and that is useful for me
as well, of course :-)
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
To simplify the callsites and make implementing the same thing on the other
dwarves (prefcnt, pfunct, etc) easy.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Doesn't make that much sense for structs, because of the usual includes hell in
most projects, but makes sense for pfunct, so implement it now and later move
it to classes.c.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
That checks for constraints, the first one being a exclude prefix, and is used
by all the iterators.
Additional constraints can be things like specifying prefixes for compilation
unit names, i.e. "show me only the object files which name starts with
net/ipv4/", etc.
Initial patch provided by Bernhard Fischer, who also had the --exclude idea.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Correct short option for nr_members in help text.
Signed-off-by: Bernhard Fischer <rep.nop@aon.at>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
This should have been done from the start: all DW_TAG_s will be represented by
structs that has as its first member a struct tag, so that we can fully
represent the DWARF information, following csets will take continue the
restructuring.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
[acme@newtoy guinea_pig-2.6]$ pahole -t ../../acme/OUTPUT/qemu/net-2.6/vmlinux | sort -k2 -nr | head -5
list_head 468
__wait_queue_head 466
timespec 466
rw_semaphore 466
plist_head 466
[acme@newtoy guinea_pig-2.6]$
Which leads to another, more non-trivia question, what if a struct
definition is included but there are no references to this function?
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
With some of the options in pfunct, such as:
[acme@newtoy guinea_pig-2.6]$ pahole --sizes kernel/sched.o | sort -k2 -nr | head -5
pglist_data: 3456
task_struct: 2704
rq: 2480
mmu_gather: 2040
zone: 1664
[acme@newtoy guinea_pig-2.6]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
So that we can find all the cus for some specific class
(cus__find_class_by_name), or traverse all the CUs (cus__for_each_cu),
etc.
Now we don't look at just the first CU in multi-CU files (vmlinux, etc).
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
types for each CU, for now when working on multi-CU files (vmlinux, any binary
with more than one object file linked) we look only at the first CU when
looking for a specific class or function name, this will be fixed in the
upcoming csets, but doesn't affect the case when we don't specify a class or
function name, where all the CU's are traversed.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
print just the structs with holes, that indeed is what we do now if no class
name is passed.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
call it if the class ->tag is DW_TAG_structure_type, and do a basic
print for the other tags.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Dwarf_Attribute to work on, as we just return a integer and it handles more
than just unsigned ints.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
much cleaner and now uses what seems to be a better maintained DWARF library
that hopefully works well on 64bit platforms, well see.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
struct foo {
char c:1;
int b:1;
short a:1;
};
the first byte_size for the first member (c) will be 1, as the "type"
is char, but the compiler combines all of them into a single 4 byte
bitfield, and the '4' only appear when the bit field has type int, in
the above case on the second member.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
found is equal to the sizeof of the structure and emit a "BRAIN FART ALERT!" if
this assertion fails, good news is that no such brain farts ocurred so far :-)
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
class instance for the DW_TAG_subroutine_type tag and class->members for the
list of DW_TAG_formal_parameter, if any.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>