Commit Graph

210 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo 8cecc52959 [CLASSES]: Look for nameless classes in cus__find_definition
structs typedef'ed...

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 22:35:38 -02:00
Arnaldo Carvalho de Melo 297d7b3f8f [CLASSES]: Handle cases where fwd decls and definitions can happen
If a definition is being emitted and there was already a forward declaration,
remove the class from the fwd_decl list before adding it to the declarations
list, in the reverse case just don't add it to the fwd_decl list.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 22:28:40 -02:00
Arnaldo Carvalho de Melo 2d7ec7cd35 [CLASSES]: Set ->{fwd_decl_emitted,visited} to speed up lookups
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 21:44:55 -02:00
Arnaldo Carvalho de Melo bbac253ab0 [CLASSES]: Just move class__subroutine_ptr_mask before class_member__names
So that we can use it there.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 20:39:24 -02:00
Arnaldo Carvalho de Melo 6276810a8a [CTRACER]: Group open coded function definition in a helper function
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 20:37:23 -02:00
Arnaldo Carvalho de Melo d1a6c173b9 [CTRACER]: Print the number of registered probes at module load time
vmlinux sk_buff example:

[ 1933.122713] ctracer: registered 331 probes

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 20:22:40 -02:00
Arnaldo Carvalho de Melo 4c08435f55 [CTRACER]: Introduce emit_module_license
Its needed after all, if we want to use EXPORT_SYMBOL_GPL'ed symbols such as
register_jprobe, etc :-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 20:09:02 -02:00
Arnaldo Carvalho de Melo a9d9241e48 [CLASSES]: Emit module_{exit,init} directly
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 19:58:00 -02:00
Arnaldo Carvalho de Melo 149f4f81ed [CLASSES]: Introduce functions to rebuild structs, typedefs, etc
So that we can build a module that doesn't uses #includes to get these
definitions.

More work to be done for enums, etc, but this already is enough for
ctracer to handle tracing the sk_buff methods in vmlinux.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 19:29:27 -02:00
Arnaldo Carvalho de Melo f7a934cf0a [CLASSES]: Add _add and _find functions for definitions and fwd decls
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 18:53:25 -02:00
Arnaldo Carvalho de Melo af9adf0b9a [CLASSES]: Introduce cus__find_function_by_name
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 18:46:05 -02:00
Arnaldo Carvalho de Melo 7d581ce17c [CLASSES]: Introduce list heads for definitions and forward declarations
In struct cus, that will be used when rebuilding class definitions for
enums, struct pointers, struct definitions, etc, in ctracer for a start.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-23 18:30:48 -02:00
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