Commit Graph

30 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo c87d8d831a [ALL]: Emit better diagnostic messages
[acme@mica pahole]$ pahole lala
pahole: Permission denied
[acme@mica pahole]$ pahole foo
pahole: No such file or directory
[acme@mica pahole]$ pahole ctracer.c
pahole: couldn't load DWARF info from ctracer.c
[acme@mica pahole]$

Thanks to Matthew Wilcox for noticing how lame it was :-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-28 12:54:46 -03:00
Arnaldo Carvalho de Melo 7bd8fb3c43 [LIB]: Fix compiler warnings on 64bits
Mostly related to size_t, Dwarf_Off -> (unsigned long long), etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-28 11:38:32 -03:00
Arnaldo Carvalho de Melo 3005b6b7e1 [LIB]: Reorganize struct tag
Erm, eating my dog food now that I have access to a 64bit machine here at home:

[acme@mica pahole]$ pahole build/libdwarves.so.1.0.0 tag
/* <b7e> /home/acme/git/pahole/dwarves.h:48 */
struct tag {
        struct list_head      node;          /*     0    16 */
        Dwarf_Off             type;          /*    16     8 */
        Dwarf_Off             id;            /*    24     8 */
        uint16_t              tag;           /*    32     2 */
        uint16_t              decl_line;     /*    34     2 */

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

        const char  *         decl_file;     /*    40     8 */
        uint32_t              refcnt;        /*    48     4 */
}; /* size: 56, cachelines: 1 */
   /* sum members: 48, holes: 1, sum holes: 4 */
   /* padding: 4 */
   /* last cacheline: 56 bytes */
[acme@mica pahole]$

[acme@mica pahole]$ pahole --reorganize build/libdwarves.so.1.0.0 tag
/* <b7e> /home/acme/git/pahole/dwarves.h:48 */
struct tag {
        struct list_head      node;          /*     0    16 */
        Dwarf_Off             type;          /*    16     8 */
        Dwarf_Off             id;            /*    24     8 */
        uint16_t              tag;           /*    32     2 */
        uint16_t              decl_line;     /*    34     2 */
        uint32_t              refcnt;        /*    36     4 */
        const char  *         decl_file;     /*    40     8 */
}; /* size: 48, cachelines: 1 */
   /* last cacheline: 48 bytes */
   /* saved 8 bytes! */
[acme@mica pahole]$

[acme@mica pahole]$ codiff build/libdwarves.so.1.0.0.before build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
  struct tag              |   -8
  struct type             |   -8
  struct class            |   -8
  struct base_type        |   -8
  struct array_type       |   -8
  struct class_member     |   -8
  struct lexblock         |   -8
  struct ftype            |   -8
  struct function         |  -16
  struct parameter        |   -8
  struct variable         |   -8
  struct inline_expansion |   -8
  struct label            |   -8
  struct enumerator       |   -8
 14 structs changed
  class_member__clone     |   -8
  class__clone            |   -8
 2 functions changed, 16 bytes removed
[acme@mica pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-07 12:10:56 -03:00
Arnaldo Carvalho de Melo 5a420cc24e [LIB]: Make tag__fprintf return the number of bytes printed
For consistency with all the other __fprintf routines.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-15 12:03:47 -02:00
Arnaldo Carvalho de Melo c3103abfef [LIB]: Rename function__print_stats to function__fprintf_stats, for consistency
Also make it return the number of bytes printed.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-15 12:01:01 -02:00
Arnaldo Carvalho de Melo d5a0c78a4c [LIB]: Rename lexblock__print to lexblock__fprintf, for consistency
Also make it return the number of bytes printed.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-15 11:56:16 -02:00
Arnaldo Carvalho de Melo 70f9135467 [LIB]: Rename tag__print to tag__fprintf, for consistency
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-15 11:40:51 -02:00
Arnaldo Carvalho de Melo f411354f05 [LIB]: Convert the __snprintf routines to __fprintf semantics
So that we get rid of all the buffer limits, if we need to format into strings
we can use string streams, like we're doing now in just one case, tag__name for
DW_TAG_subroutine_type, that is bogus as it is, as we need to have the name of
the type inside the type declaration (void (*type_name)(parameters)) and not
after (void (*)(parameters) type_name)), but leave this for an upcoming cset.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-15 11:36:49 -02:00
Arnaldo Carvalho de Melo d37f41df58 [LIB]: Pass a FILE pointer to the cus__emit routines
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-02 12:52:46 -02:00
Davi Arnaut 4ab3403e3b [LIB]: Add initial support for DW_AT_location, in variables
And use it in a new tool, pglobal, that shows global variables and functions.

Signed-off-by: Davi Arnaut <davi@haxent.com.br>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-02 11:56:53 -02:00
Arnaldo Carvalho de Melo e4ad9bb2e8 [LIB]: Optionally pass a new name for the class in class__clone
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-01 14:09:48 -02:00
Arnaldo Carvalho de Melo aab506fdcc [LIB]: Pass a FILE pointer to the __print routines
So that in tools like ctracer we can print to a file, most of the tools just
pass stdout, keeping the previous behaviour.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-01 13:50:28 -02:00
Arnaldo Carvalho de Melo 67119ea1a3 [LIB]: Move class__reorganize and friends from pahole to libdwarves
Will be used in ctracer to create a struct subset with just the types for which
we have "collectors", i.e. functions that reduce complex types to base types
that will be put in the mini-struct, that will be as tightly packed as it can
be.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-01 13:17:41 -02:00
Arnaldo Carvalho de Melo 5d300c135e [LIB]: Export class__print
Will be used by pahole --show_reorg_steps

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-01 11:51:38 -02:00
Arnaldo Carvalho de Melo ac4fe37f72 [LIB]: Introduce cu__find_base_type_by_name
Will be used by the bitfield reorganizer in pahole.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-30 16:53:01 -02:00
Arnaldo Carvalho de Melo 4a4b75e75a [PAHOLE]: Introduce --reorganize
Reorganizes structs with holes as non disruptively as possible to combine
holes, possibly reducing the struct size.

It doesn't yet combines bit holes, but will.

And will suggest type demotion in the bitfields case i.e. if there is a integer
(4) bytes bitfield that could fit on an short int bitfield or on a char
bitfield, it'll do just that 8)

Examples are available at:

http://oops.ghostprotocols.net:81/acme/dwarves/pahole--reorganize-ide-core-struct-hwif_s.pahole.txt
http://oops.ghostprotocols.net:81/acme/dwarves/pahole--reorganize-sched-struct-task_struct.pahole.txt
http://oops.ghostprotocols.net:81/acme/dwarves/pahole--reorganize-serial-struct-jsm_channel.pahole.txt

Also look at a more detailed description at my blog:

http://oops.ghostprotocols.net:81/blog/?p=49

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-30 13:32:55 -02:00
Arnaldo Carvalho de Melo 2de67fcaf4 [PAHOLE]: Implement type expansion
What is in a struct...

[acme@filo pahole]$ pahole net/ipv6/tcp_ipv6.o delayed_work
/* <2bc9> /home/acme/git/linux-2.6/include/linux/workqueue.h:37 */
struct delayed_work {
        struct work_struct         work;                 /*     0    16 */
        struct timer_list          timer;                /*    16    24 */
}; /* size: 40, cachelines: 1 */
   /* last cacheline: 40 bytes */
[acme@filo pahole]$

Oh, but what if we want to unfold all the structs?

lo pahole]$ pahole --expand_types /home/acme/git/OUTPUT/qemu/linux-2.6/net/ipv6/tcp_ipv6.o delayed_work
/* <2bc9> /home/acme/git/linux-2.6/include/linux/workqueue.h:37 */
struct delayed_work {
        struct work_struct {
                atomic_long_t      data;                 /*   0   4 */
                struct list_head {
                        struct list_head * next;         /*   0   4 */
                        struct list_head * prev;         /*   4   4 */
                } entry;				 /*   4   8 */
                work_func_t        func;                 /*  12   4 */
        } work;						 /*   0  16 */
        struct timer_list {
                struct list_head {
                        struct list_head * next;         /*   0   4 */
                        struct list_head * prev;         /*   4   4 */
                } entry; /*     0     8 */
                long unsigned int  expires;              /*   8   4 */
                void               (*function)(long unsigned int); /*    12     4 */
                long unsigned int  data;                 /*  16   4 */
                struct tvec_t_base_s * base;             /*  20   4 */
        } timer; /*    16    24 */
}; /* size: 40, cachelines: 1 */
   /* last cacheline: 40 bytes */
[acme@filo pahole]$

Quick hack, as we already had all the needed infrastructure due to anonymous struct
printing inside structs/unions, now for the curious, if you have the kernel-debuginfo
package installed in your FC6 machine:

[acme@filo pahole]$ pahole --expand_types /usr/lib/debug/lib/modules/2.6.19-1.2895.fc6/kernel/net/ipv6/ipv6.ko.debug tcp6_sock

Try struct task_struct too 8-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-29 13:12:23 -02:00
Arnaldo Carvalho de Melo b5baabcd16 [ALL]: Fixup warnings
Using export CFLAGS="-Wall -Wfatal-errors -Wformat=2 -Wsequence-point -Wextra
-Wno-parentheses -g", suggested by Davi Arnault, amazing how cruft piles up
when one is not looking ;)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-01-29 10:42:03 -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
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 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 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 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 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 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
Arnaldo Carvalho de Melo df1832ac4f [LIB]: Introduce tag__print_decl_info
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-12 16:11:37 -02:00
Arnaldo Carvalho de Melo 3fe4f09a27 [LIB]: Move the stats printing bits out of function__print
Moving them to a new function, function__print_stats.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-12 16:00:07 -02:00
Arnaldo Carvalho de Melo d385563a53 [LIB]: Make the function methods return and receive a struct tag
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-12 15:47:26 -02:00
Arnaldo Carvalho de Melo 30b6aa2f73 [LIB]: Rename classes.[ch] to dwarves.[ch]
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-11 16:07:05 -02:00