Commit Graph

389 Commits

Author SHA1 Message Date
Davi Arnaut a7b22b8f2c [LIB]: Show the sum of paddings in structs within a struct
Commiter note:

Idea and initial patch by Davi Arnaut, I fixed it to do the right thing,
to understand why this is useful, nothing better than an example:

/* <bd92a0> /home/acme/git/linux-2.6/include/net/xfrm.h:242 */
struct xfrm_tmpl {
        struct xfrm_id             id;                   /*     0    24 */
        xfrm_address_t             saddr;                /*    24    16 */
        short unsigned int         encap_family;         /*    40     2 */

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

        __u32                      reqid;                /*    44     4 */
        __u8                       mode;                 /*    48     1 */
        __u8                       share;                /*    49     1 */
        __u8                       optional;             /*    50     1 */

        /* XXX 1 byte hole, try to pack */

        __u32                      aalgos;               /*    52     4 */
        __u32                      ealgos;               /*    56     4 */
        __u32                      calgos;               /*    60     4 */
        /* --- cacheline 1 boundary (64 bytes) --- */
}; /* size: 64, cachelines: 1 */
   /* sum members: 61, holes: 2, sum holes: 3 */
   /* sum padding: 3 */
   /* definitions: 22 */

"sum padding" here means there is some member that is a struct and this struct
has paddings: struct xfrm_id:

/* <bd78b6> /home/acme/git/linux-2.6/include/linux/xfrm.h:24 */
struct xfrm_id {
	xfrm_address_t             daddr;                /*     0    16 */
	__be32                     spi;                  /*    16     4 */
	__u8                       proto;                /*    20     1 */
}; /* size: 24, cachelines: 1 */
   /* padding: 3 */
   /* last cacheline: 24 bytes */
   /* definitions: 22 */

Signed-off-by: Davi Arnaut <davi@haxent.com.br>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-29 00:16:33 -02:00
Davi Arnaut c9bd654d3b [PAHOLE]: Handle anonymous structs
Some are just typedefs, others are inside structs and in some cases its
useful to see the statistics for them, so add two new cmd line options:

-a, --anon_include        include anonymous classes\
-A, --nested_anon_include include nested (inside other structs) anonymous classes

Commiter note: I've reworked several aspects of the patch, but mostly to
give better names for the new find_first_typedef_of_type function, adding
a clarifying comment and introducing --nested_anon_include so that we
can select just the typedef'ed anonymous structs.

Damn, I had commited just dwarves.c, here is the dwarves.h and pahole.c bits.

Signed-off-by: Davi Arnaut <davi@haxent.com.br>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-28 11:07:22 -02:00
Davi Arnaut 9241301511 [PAHOLE]: Handle anonymous structs
Some are just typedefs, others are inside structs and in some cases its
useful to see the statistics for them, so add two new cmd line options:

-a, --anon_include        include anonymous classes\
-A, --nested_anon_include include nested (inside other structs) anonymous classes

Commiter note: I've reworked several aspects of the patch, but mostly to
give better names for the new find_first_typedef_of_type function, adding
a clarifying comment and introducing --nested_anon_include so that we
can select just the typedef'ed anonymous structs.

Signed-off-by: Davi Arnaut <davi@haxent.com.br>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-28 02:18:34 -02:00
Arnaldo Carvalho de Melo 2705bba815 [PAHOLE]: Fix the usage info, its a class name not a function name
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-27 19:46:35 -02:00
Arnaldo Carvalho de Melo 9555603666 [RPM]: 9th release
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-27 19:42:54 -02:00
Arnaldo Carvalho de Melo 6bf2d2d770 [CTRACER]: Move the jprobes init code to lib/ctracer_jprobes.c
So that we don't have to do all the code emission inside ctracer.c, add
a Makefile too that uses the kernel rpm files shipped by your distro to
easily build a module for your workstation, see README.ctracer, that was
updated to describe the steps needed to have ctracer running in your
machine.

Now to polish the relay code.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-27 18:38:07 -02:00
Arnaldo Carvalho de Melo ddbf5f0013 [CTRACER]: Cosmetic, add a missing newline
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-27 09:10:30 -02:00
Arnaldo Carvalho de Melo 4a7a4f256a [CTRACER]: At module exit check if we missed any probe
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-27 09:09:04 -02:00
Arnaldo Carvalho de Melo 7465f3c2f0 [CTRACER]: Check if the specified class exists
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-27 09:03:40 -02:00
Arnaldo Carvalho de Melo 8b8166f0a8 [RPM]: 8th release
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-27 08:57:52 -02:00
Arnaldo Carvalho de Melo c49f2c9634 [LIB]: Add orphan DW_TAG_formal_parameter tags to the lexblock where it appears
Previously it was being added to the CU tag list.

This also fixes a problem in cu__find_parameter_by_id where the second test in
the loop was actually outside the loop due to lack of {}.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-26 00:29:53 -02:00
Arnaldo Carvalho de Melo 2aa6ef9a0f [LIB]: Use dwarf_dieoffset where we were using dwarf_cuoffset
Better, to match the readelf (binutils) and eu-readelf (elfutils) tools,
that on multi CU blobs is the way to go.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-25 16:24:09 -02:00
Davi Arnaut 4e93019433 [LIB]: Add missing { in typedef__print
That was preventing the correct printing of anonymous struct typedefs.

Signed-off-by: Davi Arnaut <davi@haxent.com.br>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-25 10:31:36 -02:00
Arnaldo Carvalho de Melo a4856181a7 [LIB]: Emit typedefs of typedef arrays
Such as this one, when using ctracer to trace struct task_struct methods:

  --- ctracer_methods.c.before	2007-01-24 09:20:30.000000000 -0200
  +++ ctracer_methods.c	2007-01-24 09:38:35.000000000 -0200
  @@ -759,7 +759,8 @@
   	.entry = (kprobe_opcode_t *)jprobe_entry__release_thread,
   };

  -typedef elf_greg_t elf_gregset_t;
  +typedef long unsigned int elf_greg_t;
  +typedef elf_greg_t elf_gregset_t[17];

   static int jprobe_entry__dump_task_regs(struct task_struct * tsk, elf_gregset_t * regs)
   {

Code impact:

[acme@filo pahole]$ codiff build/libdwarves.so.before build/libdwarves.so
/home/acme/git/pahole/dwarves.c:
  typedef__print                | +154
    cus__emit_typedef_definitions |  +27
     2 functions changed, 181 bytes added
     [acme@filo pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-24 09:41:46 -02:00
Arnaldo Carvalho de Melo 68d64b2930 [LIB]: Detect typedef loops
Recheck if the typedef was emitted as part of the emission of its target, as
there are cases, like wait_queue_t in the Linux kernel, that is against struct
__wait_queue, that has a wait_queue_func_t member, a function typedef that has
as one of its parameters a... wait_queue_t, that will thus be emitted before
the function typedef, making a no go to redefine the typedef after struct
__wait_queue.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-24 09:10:26 -02:00
Arnaldo Carvalho de Melo 4c2ef6007f [LIB]: Fix emission of arrays of structs, unions, etc
And it even shrinks the lib a bit :-)

[acme@filo pahole]$ codiff build/libdwarves.so.before build/libdwarves.so
/home/acme/git/pahole/dwarves.c:
  cus__emit_tag_definitions |  -68
   1 function changed, 68 bytes removed
   [acme@filo pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-24 08:58:50 -02:00
Arnaldo Carvalho de Melo 30165f5c63 [LIB]: Don't return struct declarations in cu__find_struct_by_name
Find the real thing instead.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-23 16:25:24 -02:00
Arnaldo Carvalho de Melo 4038bf3c4c [CTRACER]: Comment the code
I should have done this since day one, but was lazy, now somebody complained
on my blog and I thought it was time to bite this bullet, hopefully will be
helpful for people interested in helping improve these tools, as the comments
are useful for understanding the other dwarves too.

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-01-20 11:25:50 -02:00
Arnaldo Carvalho de Melo 812406d9fb [LIB]: Use sysconf to get the L1 cacheline size
As suggested by Ulrich Drepper.

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-01-18 21:41:25 -02:00
Arnaldo Carvalho de Melo 46884e3d4f [LIB]: Make the default cacheline be 64
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-01-18 21:18:44 -02:00
Arnaldo Carvalho de Melo 4138db6ebe [RPM]: New release with pdwtags
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-01-18 21:15:54 -02:00
Arnaldo Carvalho de Melo fab0db03ea [PDWTAGS]: New tool
Pretty prints all of the tags, still needs a bit more work.

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-01-18 21:13:56 -02:00
Arnaldo Carvalho de Melo feb2e08c36 [RPM]: First fedora native build
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-01-18 17:28:35 -02:00
Arnaldo Carvalho de Melo e3786105c0 [LIB]: Handle void typedefs
Oh the horror, found in a proprietary kernel module:

typedef void * PVOID;

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-16 12:19:06 -02:00
Arnaldo Carvalho de Melo 1750958111 [LIB]: Separate emission of definitions in a type from the emission of the type itself
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-16 12:11:35 -02:00
Arnaldo Carvalho de Melo 14863f943e [LIB]: Remove the prefix tag for enum functions
Now the functions that call cus__emit_enumeration_definitions should call
tag__print_decl_info, so that if it is a typedef we can just print "typedef ",
then call the enum printing routines.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-15 12:15:59 -02:00
Arnaldo Carvalho de Melo 36c4c5a386 [LIB]: Handle union typedefs
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-15 11:21:39 -02:00
Arnaldo Carvalho de Melo 8f8a691a6a [LIB]: Handle enum typedefs
Using 'ctracer vmlinux pci_dev' without and with this cset:

  --- ctracer.c.old 2007-01-15 10:45:45.000000000 -0200
  +++ ctracer.c	  2007-01-15 10:45:57.000000000 -0200
  @@ -2175,7 +2175,28 @@
   struct hwgroup_s;
   struct proc_dir_entry;
   typedef int (ide_ack_intr_t)(struct hwif_s *);
  -typedef enum  hwif_chipset_t;
  +/* <a710> /pub/scm/linux/kernel/git/acme/linux-2.6/include/linux/ide.h:199 */
  +typedef enum {
  +	ide_unknown = 0,
  +	ide_generic = 1,
  +	ide_pci = 2,
  +	ide_cmd640 = 3,
  +	ide_dtc2278 = 4,
  +	ide_ali14xx = 5,
  +	ide_qd65xx = 6,
  +	ide_umc8672 = 7,
  +	ide_ht6560b = 8,
  +	ide_rz1000 = 9,
  +	ide_trm290 = 10,
  +	ide_cmd646 = 11,
  +	ide_cy82c693 = 12,
  +	ide_4drives = 13,
  +	ide_pmac = 14,
  +	ide_etrax100 = 15,
  +	ide_acorn = 16,
  +	ide_au1xxx = 17,
  +	ide_forced = 18,
  +} hwif_chipset_t;
   struct device;

 /* <a796> /pub/scm/linux/kernel/git/acme/linux-2.6/include/linux/ide.h:211 */

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-15 10:51:07 -02:00
Arnaldo Carvalho de Melo 37d19a9320 [LIB]: Emit definitions for structs in typedefs
I.e. things like

typedef struct foo bar;

will emit the definition for struct foo before emitting the above line.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-15 10:39:23 -02:00
Arnaldo Carvalho de Melo 348fdc8d1a [LIB]: Avoid emitting top level unnamed unions and structs
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-15 10:34:13 -02:00
Arnaldo Carvalho de Melo 9a413e60a3 [LIB]: Fix stupid if + switch case
Where the 'if' should be just one of of the cases in the 'switch', and guess
what:

This:

  diff --git a/dwarves.c b/dwarves.c
  index c0ae7c8..34f29a1 100644
  --- a/dwarves.c
  +++ b/dwarves.c
  @@ -2580,10 +2580,10 @@ static int cus__emit_typedef_definitions
   	}
   	type = cu__find_tag_by_id(cu, tdef->type);

  -	if (type->tag == DW_TAG_typedef)
  -		cus__emit_typedef_definitions(self, cu, type);
  -
   	switch (type->tag) {
  +	case DW_TAG_typedef:
  +		cus__emit_typedef_definitions(self, cu, type);
  +		break;
   	case DW_TAG_pointer_type:
   		ptr_type = cu__find_tag_by_id(cu, type->type);
   		if (ptr_type->tag != DW_TAG_subroutine_type)

Results in this:

[acme@newtoy pahole]$ codiff -V build/libdwarves.so.orig build/libdwarves.so
/home/acme/pahole/dwarves.c:
  cus__emit_typedef_definitions |  -18 # 466 -> 448
 1 function changed, 18 bytes removed
[acme@newtoy pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 16:22:53 -02:00
Arnaldo Carvalho de Melo 9b0f2584fe [LIB]: Minor class_member__snprintf cleanup
Size of generated code doesn't changes.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 16:14:45 -02:00
Arnaldo Carvalho de Melo 45f5c5f8e3 [LIB]: switches are cheaper, step 2
[acme@newtoy pahole]$ codiff -V build/libdwarves.so.orig build/libdwarves.so
/home/acme/pahole/dwarves.c:
  class_member__snprintf |  -45 # 1126 -> 1081
 1 function changed, 45 bytes removed
[acme@newtoy pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 16:12:41 -02:00
Arnaldo Carvalho de Melo 59bddf5928 [LIB]: switches are cheaper
[acme@newtoy pahole]$ codiff -V build/libdwarves.so.orig build/libdwarves.so
/home/acme/pahole/dwarves.c:
  tag__name |  -63 # 982 -> 919
 1 function changed, 63 bytes removed
[acme@newtoy pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 16:04:21 -02:00
Arnaldo Carvalho de Melo 003a38d2b0 [LIB]: Emit a ';' after unions in cus__emit_type_definitions
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 15:56:27 -02:00
Arnaldo Carvalho de Melo dc22745064 [CTRACER]: yield the processor while registering the probes
To avoid soft lockups.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 15:53:51 -02:00
Arnaldo Carvalho de Melo b7fcbac565 [CTRACER]: Dont emit duplicate probes for functions with the same name
This is more like a bandaid, namespace clashes should be handled properly in
the future, but for now, well behaved projects will get the profits ;)

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 14:56:16 -02:00
Arnaldo Carvalho de Melo 0bf740a74c [LIB]: Make cus__emit_fwd_decl handle unions
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 14:27:08 -02:00
Arnaldo Carvalho de Melo 3a9ceb41ee [LIB]: Rename cus__emit_struct_definitions to cus__emit_type_definitions
To make it handle unions too.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 14:19:34 -02:00
Arnaldo Carvalho de Melo 03530985c1 [PAHOLE]: Introduce --nr_methods
To show how many non inline functions receive as a parameter each of the structs
in a project, example:

[acme@newtoy ctracer_example]$ pahole --nr_methods vmlinux | sort -k2 -nr | head -5
file: 526
inode: 479
sk_buff: 386
sock: 383
dentry: 295
[acme@newtoy ctracer_example]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 13:59:32 -02:00
Arnaldo Carvalho de Melo 7e57db18d7 [LIB]: Add support for DW_AT_specification in DW_TAG_subprogram
C++ feature, we have to look for the id, then abstract_origin and then
specification.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 11:37:41 -02:00
Arnaldo Carvalho de Melo 5dcd02daa3 [LIB]: Print the cu offset in tag__print_decl_info
To locate the entry in the readelf output when looking for problems.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 10:58:58 -02:00
Arnaldo Carvalho de Melo f6718f5721 [LIB]: Export lexblock__print
tag__print on a DW_TAG_subprogram tag prints just the function prototype,
without the ending ";\", so if a user wants to print the whole function its
just a matter of calling tag__print + lexblock__(tag__function(tag), cu,
indent).

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 10:57:19 -02:00
Arnaldo Carvalho de Melo 777a21fad0 [LIB]: Replace ntabs with indent, for consistency
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-13 10:40:33 -02:00
Arnaldo Carvalho de Melo aa961db9b9 [LIB]: Reintroduce union__print, this time being called by tag__print
And will be used by a new dwarf, that is about to be merged.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-12 18:00:32 -02:00
Arnaldo Carvalho de Melo de345d7d29 [LIB]: Leave to the callers of enumeration__print to add or not the ; and newline
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-12 17:40:12 -02:00
Arnaldo Carvalho de Melo ef329ecd49 [LIB]: Leave to callers of typedef__print to add or not the ; and newline
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-12 17:23:14 -02:00
Arnaldo Carvalho de Melo 49ca9c8a0b [LIB]: Make ftype__snprintf check for types not found
Again, due to some tags not being collected in the C++ case.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-12 16:34:53 -02:00
Arnaldo Carvalho de Melo ed2d124a0e [LIB]: Make typedef__print check if the type was not found
This should not happen, but right now happens as we don't support all the C++
tags, so some types are not being collected when inside DW_TAG_namespace dies.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-12 16:29:53 -02:00
Arnaldo Carvalho de Melo 16c0586602 [LIB]: Make all callers of function__print use tag__print instead
And since there are no external users now, just unexport it, ditto
for tag__print_decl_info.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-12 16:25:20 -02:00