Commit Graph

948 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo
86e083e47b [CTRACER]: No need to use MODULE_{AUTHOR,LICENSE}
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 18:28:03 -02:00
Arnaldo Carvalho de Melo
64bf0272da [CTRACER]: Use expanded forms of __init and __exit
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 18:24:25 -02:00
Arnaldo Carvalho de Melo
2e2cd691da [CTRACER]: Don't emit 'NULL', just (void *)0
Again for not having to emit any "#include" in the ctracer generated module
source file.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 18:14:37 -02:00
Arnaldo Carvalho de Melo
c883f688cc [CTRACER]: Use expanded form of JPROBE_ENTRY() macro
So that we don't need to include any header in the ctracer generated
module source file.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 18:12:41 -02:00
Arnaldo Carvalho de Melo
66ef6a39ba [CLASSES]: Add optional prefix and suffix parameters to class__print
That will be used when typedefs are being emitted, etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 18:09:47 -02:00
Arnaldo Carvalho de Melo
79206c3a22 [CMAKE]: Move the debug setting to the right place
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 13:16:30 -02:00
Arnaldo Carvalho de Melo
3288e28168 [CTRACER]: Use parameter__names and add a little hack for enums
Now ctracer manages vmlinux at least for struct sk_buff, more to come as tests
are made with other classes (structs).

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 20:41:46 -02:00
Arnaldo Carvalho de Melo
27af1f615b [CLASSES]: Introduce parameter__names
Some rework is needed to make class_member__names and parameter__names to share
more code, but there are things like bitfields that are exclusive to
class_member entries, etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 20:40:13 -02:00
Arnaldo Carvalho de Melo
f793f83a6d [CTRACER]: struct function has a list of struct parameter
Not struct class_member, that was not much of a problem, as the
initial layout is the same (struct tag).

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 20:09:49 -02:00
Arnaldo Carvalho de Melo
b3dab6396c [CTRACER]: Emit forward declarations for the return and parameter types
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 14:27:28 -02:00
Arnaldo Carvalho de Melo
973d243189 [CLASSES]: Introduce tag__fwd_decl
To emit forward declarations for types, used in ctracer.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 14:10:07 -02:00
Arnaldo Carvalho de Melo
c372555a6c [CLASSES]: Return NULL in cu__find_class_by_id if tag.type == 0
I.e. if the type is void, avoiding looking the whole list for something
that is not there.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 14:02:05 -02:00
Arnaldo Carvalho de Melo
e15d528941 [CLASSES]: Add a 'visited' flag to struct class
So that tools can mark it as being processed already, such as when ctracer
needs to emit forward declarations for types in function parameters or return
types.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 13:49:51 -02:00
Arnaldo Carvalho de Melo
4d98e6f80b [CTRACER]: Fix handling of multi-object files
In cu_emit_kprobes_table_iterator we were defining the jprobes[] table for each
object file, do it surrounding the cu__for_each_cu call.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 13:24:32 -02:00
Arnaldo Carvalho de Melo
5d1d846e62 [CTRACER]: Return 0 on the cu iterators
This way we process not just the first object file in a multi-object
file such as vmlinux.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 13:18:29 -02:00
Arnaldo Carvalho de Melo
a5147a7785 [CTRACER]: function->name couldn't possibly be NULL
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 13:10:31 -02:00
Arnaldo Carvalho de Melo
3e7e387ddb [CLASSES]: Move passing the object file name from cus__new to cus__load
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>
2006-12-20 12:35:45 -02:00
Arnaldo Carvalho de Melo
a4f099385b [CTRACER]: New tool
A class tracer, it looks for non-inline functions that receive as one of its
parameters a pointer to the specified "class" (a struct) and will generate a
kprobes kernel module, see the whole sequence in the README.ctracer file.

Next steps involve supporting kretprobes, inserting kprobes at each inline
"method" expansion, using relayfs, and eventually uprobes to make this useful
for userspace as well.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 12:16:16 -02:00
Arnaldo Carvalho de Melo
4a015cf738 [CLASSES]: Add list nodes to struct cu and function to be used by tools
Any tool can use it, first one will be ctracer, the class tracer.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 12:07:09 -02:00
Arnaldo Carvalho de Melo
5cb0779231 [CLASSES]: Pass the cookie to the filter in cu__for_each_function
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 12:05:29 -02:00
Arnaldo Carvalho de Melo
5484abff49 [CLASSES]: Move function__has_parameter_of_type from pfunct to libclasses
Will be used by a new tool, ctracer.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 12:03:12 -02:00
Arnaldo Carvalho de Melo
770dbc59ee [README]: Add information about packages required to build
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 10:28:44 -02:00
KOVACS Krisztian
9276e7d7f4 [CMAKE]: Fix build on debian unstable
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 10:16:45 -02:00
KOVACS Krisztian
f35522a09f [PAHOLE]: Fix copy'n'paste error on usage()
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-20 09:41:25 -02:00
Arnaldo Carvalho de Melo
a9d464021d [CLASSES]: Make class__name return "void" when passed a NULL class
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-19 09:20:52 -02:00
Arnaldo Carvalho de Melo
0dd2519bff [CLASSES]: Export class__name
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-19 09:11:17 -02:00
Arnaldo Carvalho de Melo
b7fc53acb1 [PFUNCT]: Move usage() and the long options table to just before main
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-19 06:03:31 -02:00
Arnaldo Carvalho de Melo
a7f819ccb2 [CLASSES]: Remove some now unused functions
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-18 17:14:31 -02:00
Arnaldo Carvalho de Melo
9b12f89fa9 [PAHOLE]: Ditch the opt enum, use a formatter pointer
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-18 16:27:14 -02:00
Arnaldo Carvalho de Melo
366f05e5de [PFUNCT]: Change options processing to match recent changes to pahole
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-18 15:43:17 -02:00
Arnaldo Carvalho de Melo
67621fcea8 [CLASSES]: Codiff and prefcnt doesn't use the filter in cu__for_each_function
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-18 15:42:03 -02:00
Arnaldo Carvalho de Melo
bd4dfbccb9 [CLASSES]: Add a filter to cu__for_each_function
Same purpose as in the one in cu__for_each_class.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-18 15:35:31 -02:00
Arnaldo Carvalho de Melo
e87d958939 [PAHOLE]: Check structure definitions in multi-object files
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>
2006-12-18 11:05:07 -02:00
Arnaldo Carvalho de Melo
afb41b16f9 [PAHOLE]: Improve multi-CU processing
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>
2006-12-18 10:47:39 -02:00
Arnaldo Carvalho de Melo
6d02afd548 [CLASSES]: Remove newlines at the end of class__print
Let the callers decide if they want to do it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-18 10:20:57 -02:00
Arnaldo Carvalho de Melo
e70860fe11 [CLASSES]: Constify print routines class parameter
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-18 09:29:41 -02:00
Arnaldo Carvalho de Melo
8330d47a1a [CLASSES]: Handle bitfields combined with one or two byte members
See the comment in the code.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-14 16:49:06 -02:00
Arnaldo Carvalho de Melo
1578e231f9 [CLASSES]: Tidy up the holes comments
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-14 16:00:28 -02:00
Arnaldo Carvalho de Melo
bb980f7fed [CLASSES]: Whitespace fixups
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-14 13:18:07 -02:00
Arnaldo Carvalho de Melo
a779f9a7c9 [CLASSES]: Fix the bit hole finding logic
We should check if we're in a new byte offset, i.e. the previous bitfield is
gone, now it works well when two bitfields are found one after the other, like
in struct sk_buff.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-14 13:13:14 -02:00
Helio Chissini de Castro
75a3425a9a [MAKEFILE]: Use cmake in the build process
Signed-off-by: Helio Chissini de Castro <helio@mandriva.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-12 00:37:23 -02:00
Arnaldo Carvalho de Melo
b515ca2386 [CLASSES]: Support multidimensional arrays
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-08 12:58:46 -02:00
Arnaldo Carvalho de Melo
b45b9f6a95 [CLASSES]: Add a ->declaration member to struct class
For cases where the compiler doesn't emits the whole struct definition for
things like base classes that don't have any of its members acessed, just the
ones in its descendants.

Will be used to avoid emiting hole anottations, since we don't have the
size of these classes we can't say if its smaller than the space allocated
by the compiler.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-07 20:54:45 -02:00
Arnaldo Carvalho de Melo
9d21d3d72d [CLASSES]: Add support for DW_TAG_inheritance
So that languages such as C++ can have its inheritance concepts
covered, example:

[acme@newtoy examples]$ pahole qsettings.o QSettingsPrivate
/* io/qsettings_p.h:159 */
class QSettingsPrivate {
        class QObjectPrivate;        /* ancestor class */  /*  0 0 */

        /* XXX 56 bytes hole, try to pack */

        /* --- cacheline 1 boundary (32 bytes) was 24 bytes ago --- */
        class QStack<QSettingsGroup> groupStack;           /* 56 4 */
        class QString                groupPrefix;          /* 60 4 */
        /* --- cacheline 2 boundary (64 bytes) --- */
        int                          spec;                 /* 64 4 */
        bool                         fallbacks;            /* 68 1 */
        bool                         pendingChanges;       /* 69 1 */

        /* XXX 2 bytes hole, try to pack */

        enum Status                  status;               /* 72 4 */
}; /* size: 76, cachelines: 3 */
   /* sum members: 18, holes: 2, sum holes: 58 */
   /* last cacheline: 12 bytes */

Nevermind about the "/* XXX 56 bytes hole, try to pack */" and sizeof(class
QObjectPrivate) being zero, its just gcc compressing the DWARF tags avoiding
including definitions that are not used in this specific object file, i.e.
there are not accesses to 'class QObjectPrivate' members.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-07 20:00:45 -02:00
Arnaldo Carvalho de Melo
fd1b4cadc2 [CLASSES]: Print cacheline boundary at the end of a struct too
Useful for structs where cacheline crossings happens on the last
member:

[acme@newtoy net-2.6]$ pahole --cacheline 32 net/ipv4/route.o hh_cache
/* /pub/scm/linux/kernel/git/acme/net-2.6/include/linux/netdevice.h:193 */
struct hh_cache {
        struct hh_cache *  hh_next;          /*  0   4 */
        atomic_t           hh_refcnt;        /*  4   4 */
        __be16             hh_type;          /*  8   2 */
        u16                hh_len;           /* 10   2 */
        int                (*hh_output)();   /* 12   4 */
        rwlock_t           hh_lock;          /* 16   0 */
        long unsigned int  hh_data[24];      /* 16  96 */
        /* --- cacheline 3 boundary (96 bytes) was 16 bytes ago --- */
}; /* size: 112, cachelines: 4 */
   /* last cacheline: 16 bytes */

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-07 19:20:46 -02:00
Arnaldo Carvalho de Melo
d479b9c8e5 [CLASSES]: Disambiguate the cu__find_class_by_name
We want just DW_TAG_structure_type classes, but for now there are
enums, C++ inline classes, etc, have to fix this later.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-07 18:40:00 -02:00
Arnaldo Carvalho de Melo
41f58c52ca [CLASSES]: Make tag_name return "class" if object file is C++
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-07 17:21:52 -02:00
Arnaldo Carvalho de Melo
cb883f6a8f [PAHOLE]: First stab at implementing --packable
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>
2006-12-07 16:14:15 -02:00
Arnaldo Carvalho de Melo
82892cd9dd [CLASSES]: First stab at implementing class__find_bit_hole
This new function searches the first member before the one being traversed that
has a bit hole (or byte_hole, I've just normalised it on bits to make it
generic) that can be used to combine with the class_member at hand to possibly
kill a hole, possibly because for now it doesn't guarantees that moving the
member being traversed to just after the hole after the member returned by
class__find_bit_hole will indeed reduce the struct size, but its a good first
stab, next csets should provide a member to start from so that we can try to
find other holes after the one that proved not enough to reduce the struct
size.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-07 16:11:47 -02:00
Arnaldo Carvalho de Melo
ff0dc936d7 [CLASSES]: Tidy up holes printing, plural form
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-07 13:24:18 -02:00