Commit Graph

170 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo 5deeded578 [CLASSES]: Introduce struct type
Out of struct typedef_tag, that now becomes the superclass of struct class, and
that also will be for struct enumeration, struct union_type and then finally
for struct struct_type, when struct class finally dies.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-07 12:30:58 -02:00
Arnaldo Carvalho de Melo 3368862360 [CLASSES]: Call cus__add_definition in cus__emit_enumeration_definitions
To avoid emitting the same enumeration when it appears in more than one object
file (CU).

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-07 11:40:10 -02:00
Arnaldo Carvalho de Melo 6165ac5ba6 [CLASSES]: Reduce the space needed to represent a DW_TAG_typedef
By having its own class, struct typedef_tag.

As it, as structs, unions and enums have a common part, the node and visited
fields, required when emitting its definitions there is an opportunity for
consolidation, that will be explored when adding the specific classes for
DW_TAG_enumeration & DW_TAG_union.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-06 15:17:58 -02:00
Arnaldo Carvalho de Melo 276ba078f2 [CLASSES]: Remove the last bits of recursion in dealing with dies
And don't create a struct case as default, instead emit a warning that the tag
is not being handled.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-06 14:07:28 -02:00
Arnaldo Carvalho de Melo 0b930b1ce8 [CLASSES]: Move cu__create_new_enumeration to before cu__process_function
Will be used by cu__process_function, no code changed.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-06 14:01:09 -02:00
Arnaldo Carvalho de Melo 9f9f2896b2 [CLASSES]: attr_string doesn't need a Dwarf_Attributte passed to it
Just use one in the stack.

[acme@newtoy pahole]$ codiff build/libclasses.so.orig build/libclasses.so
/home/acme/pahole/classes.c:
  base_type__new        |   -7
  enumerator__new       |   -7
  variable__new         |   -7
  class_member__new     |  -11
  parameter__new        |   -7
  inline_expansion__new |   -7
  label__new            |   -7
  class__new            |   -7
  function__new         |   -7
  cus__load             |   -7
 10 functions changed, 74 bytes removed
[acme@newtoy pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-04 17:27:24 -02:00
Arnaldo Carvalho de Melo 47b4f029fb [CLASSES]: Handle DW_TAG_unspecified_parameters in function pointers
My favourite guinea pig (linux's vmlinux) has not one pointer to a function
that has unspecified parameters (...), but a new guinea pig, also a kernel,
has, openbsd's kernel, example:

/* /usr/home/leonardo/openbsd/src/sys/sys/protosw.h:63 */
struct protosw {
        short int pr_type;              /*     0     2 */
<SNIP>
        void      (*pr_input)(struct mbuf *, ...); /*    12     4 */
        int       (*pr_output)(struct mbuf *, ...); /*    16     4 */
<SNIP>

So fix it!

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-04 13:28:45 -02:00
Arnaldo Carvalho de Melo 9f3a65c7fa [CLASSES]: Introduce lexblock__find_tag_by_id
Right now used only by cu__find_variable_by_id, so that we can ditch the
cu_node node in struct variable and keep variables only in the lexblock tags
list.

[acme@newtoy pahole]$ codiff build/libclasses.so.orig build/libclasses.so
/home/acme/pahole/classes.c:
  struct cu               |   -8
  struct variable         |   -8
 2 structs changed
  cu__new                 |  -18
  cu__add_variable        |  -32
  cu__find_variable_by_id |  +66
  variable__name          |  -31
  cu__create_new_variable |  -18
 5 functions changed, 66 bytes added, 99 bytes removed

/home/acme/pahole/classes.c:
  lexblock__find_tag_by_id | +174
 1 function changed, 174 bytes added

build/libclasses.so:
 6 functions changed, 240 bytes added, 99 bytes removed

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-04 13:13:21 -02:00
Arnaldo Carvalho de Melo 78ae95c02d [CLASSES]: Handle DW_TAG_subroutine_type in tag__name
This has to be reworked as it doesn't do the right thing, it has to be a mask
as function pointers needs, but variables are not something so heavily used in
the more interesting tools, so leave this for later.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-04 13:06:29 -02:00
Arnaldo Carvalho de Melo b11c508509 [CLASSES]: Remove cu field from struct class
Same reason as for the previous structs were the same change was made.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-04 01:41:11 -02:00
Arnaldo Carvalho de Melo 251e3973ef [CLASSES]: Ditch struct function->cu
Since we have it available where we need:

[acme@newtoy pahole]$ codiff build/libclasses.so.orig build/libclasses.so
/home/acme/pahole/classes.c:
  struct function                     |   -4
 1 struct changed
  cu__add_function                    |   -9
  cus__find_class_by_name             |  +14
  cus__find_function_by_name          |  +14
  lexblock__account_inline_expansions |   -6
  function__print                     |  -10
 5 functions changed, 28 bytes added, 25 bytes removed
[acme@newtoy pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 21:57:35 -02:00
Arnaldo Carvalho de Melo bed9378b42 [CLASSES]: Use just one list for classes (structs, unions, etc) and functions
Almost mirroring the DWARF on-disk linkage on memory, more to come before
getting over these simplification refactorings.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 21:29:24 -02:00
Arnaldo Carvalho de Melo f93f16b51a [CLASSES]: Pass the die to the tag type constructors
For now we're just supporting DWARF, so no need to keep the DWARF
knowledge outside of the core type constructors, with this we greatly
simplify the code, shrinking the resulting binaries:

[acme@newtoy pahole]$ codiff build/libclasses.so.orig build/libclasses.so
/home/acme/pahole/classes.c:
  tag__init                       |  +38
  tag__new                        |  -74
  base_type__new                  |  -26
  enumerator__new                 |  -26
  variable__new                   |  -43
  class_member__new               | -164
  parameter__new                  |  -44
  inline_expansion__new           | +295
  label__new                      |  -29
  array_type__new                 |  -67
  class__new                      |  -24
  lexblock__init                  |  +46
  lexblock__new                   | -102
  ftype__init                     |  -61
  ftype__new                      |  -74
  function__new                   |  -56
  cu__create_new_tag              |  -62
  cu__create_new_class            | -203
  cu__create_new_base_type        |  -95
  cu__create_new_array            |  -59
  cu__create_new_parameter        | -135
  cu__create_new_label            | -209
  cu__create_new_variable         | -180
  cu__new_subroutine_type         | -308
  cu__process_class               | -258
  cu__create_new_lexblock         | -180
  cu__create_new_inline_expansion | -437
  cu__process_function            |   -8
  cu__create_new_function         | -251
  cu__create_new_enumeration      | -309
  cu__process_die                 | -376
 31 functions changed, 379 bytes added, 3860 bytes removed

/home/acme/pahole/classes.c:
  cu__create_new_subroutine_type | +241
 1 function changed, 241 bytes added

build/libclasses.so:
 32 functions changed, 620 bytes added, 3860 bytes removed
[acme@newtoy pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 20:22:51 -02:00
Arnaldo Carvalho de Melo 44575d7b08 [CLASSES]: Normalize the rest of the cu__create_new_ functions
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 11:59:31 -02:00
Arnaldo Carvalho de Melo 918d3d16b8 [CLASSES]: Normalize cu__create_new_function
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 11:28:28 -02:00
Arnaldo Carvalho de Melo 3ca3d94f1b [CLASSES]: Simplify cu__create_new_class
[acme@newtoy pahole]$ codiff build/libclasses.so.orig build/libclasses.so
/home/acme/pahole/classes.c:
  cu__create_new_class |  +75
  cu__process_class    |  -49
  cu__process_function | -165
  cu__process_die      |  -52
 4 functions changed, 75 bytes added, 266 bytes removed
[acme@newtoy pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 11:09:52 -02:00
Arnaldo Carvalho de Melo 850ad9262d [CLASSES]: Simplify cu__create_new_lexblock
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 10:58:28 -02:00
Arnaldo Carvalho de Melo 56c2d99953 [CLASSES]: Remove most c'n'pasted, useless dwarf parameter
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 10:16:42 -02:00
Arnaldo Carvalho de Melo 03a83c7faf [CLASSES]: Simplify cu__create_new_inline_expansion
All the cu__create_new_foo functions are now being normalised, will provide
opportunies for further consolidation/cleaning up, lets do this now before
moving on to libelf work.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 10:01:37 -02:00
Arnaldo Carvalho de Melo a3871a073e [CLASSES]: Create cu__create_new_label out of cu__process__function
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 09:54:06 -02:00
Arnaldo Carvalho de Melo 8d850effe1 [CLASSES]: Create cu__create_new_variable out of cu__process_function
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-03 09:49:20 -02:00
Arnaldo Carvalho de Melo 3c36b7488f [CLASSES]: Emit definitions for DW_TAG_subroutine_type
Now that we have its parameter list we must call cus__emit_ftype_definitions in
cus__emit_typedef_definitions when we find DW_TAG_subroutine tags.

This fixes this problem with ctracer:

[acme@newtoy ctracer_example]$ make
<SNIP>
  CC [M]  /home/acme/pahole/ctracer_example/ctracer.o
/home/acme/pahole/ctracer_example/ctracer.c:21: warning: 'struct pt_regs' declared inside parameter list
/home/acme/pahole/ctracer_example/ctracer.c:21: warning: its scope is only this definition or declaration, which is probably not what you want
/home/acme/pahole/ctracer_example/ctracer.c:21: warning: 'struct kprobe' declared inside parameter list
<SNIP>

I.e. the struct pt_regs and kprobe forward declarations are done earlier.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 22:49:19 -02:00
Arnaldo Carvalho de Melo 214a115dc6 [CLASSES]: Use just one tags list in struct lexblock
To preserve ordering, even with DW_tag_label tags not being kept in order by
gcc its better to have just one list, uses less space and keeps what is in the
dwarf sections.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 22:26:01 -02:00
Arnaldo Carvalho de Melo 5b17097b2e [CLASSES]: Add missing lexblock__init initialization of {high,low}_pc
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 18:36:03 -02:00
Arnaldo Carvalho de Melo c6d68d705c [CLASSES]: Consolidate DW_TAG_formal_parameter handling
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 18:21:59 -02:00
Arnaldo Carvalho de Melo 6705960010 [CLASSES]: Fix oom message prefix
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 18:02:08 -02:00
Arnaldo Carvalho de Melo 9618245851 [CLASSES]: Create cu__create_new_inline_expansion out of cu__process_function
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 16:26:11 -02:00
Arnaldo Carvalho de Melo ce281d1341 [CLASSES]: Improve lexblock handling
Creating nested lexblocks, that improves a bit the function body printing.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 13:25:56 -02:00
Arnaldo Carvalho de Melo 28c09d1f77 [CLASSES]: Introduce cu__create_new_function
And make cu__process_function use a real loop for the siblings, not calling
itself again like in the code pahole was initially based of.

This causes tags below DW_TAG_lexical_block tags to be discarded, will be fixed
in the next csets, with proper lex block support.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 12:20:32 -02:00
Arnaldo Carvalho de Melo e173712c04 [CLASSES]: Use ftype__snprintf in class_member__print
To fix these cases:

--- /tmp/pahole.before  2006-12-29 14:47:59.000000000 -0200
+++ /tmp/pahole.after   2007-01-02 03:16:43.000000000 -0200
@@ -52,8 +52,8 @@

 /* /pub/scm/linux/kernel/git/acme/linux-2.6/net/xfrm/xfrm_user.c:1649 */
 struct xfrm_link {
-        int (*doit)(void /* FIXME: add parm list */); /* 0  4 */
-        int (*dump)(void /* FIXME: add parm list */); /* 4  4 */
+        int (*doit)(struct sk_buff *, struct nlmsghdr *, void * *); /* 0  4 */
+        int (*dump)(struct sk_buff *, struct netlink_callback *); /* 4  4 */
 }; /* size: 8, cachelines: 1 */
    /* last cacheline: 8 bytes */
    /* definitions: 1 */

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 03:18:33 -02:00
Arnaldo Carvalho de Melo 8a4df0e070 [CLASSES]: Introduce DW_TAG_subroutine_type specific parser
So that we handle DW_TAG_formal_parameters in this tag, fixing
these cases:

--- /tmp/ctracer.c.before   2006-12-29 13:27:24.000000000 -0200
+++ /tmp/ctracer.c       2007-01-02 02:34:18.000000000 -0200
<SNIP>
@@ -62,7 +62,7 @@
 }; /* size: 68, cachelines: 3 */
    /* last cacheline: 4 bytes */

-typedef int (*kretprobe_handler_t)(void /* FIXME: add parm list */);
+typedef int (*kretprobe_handler_t)(struct kretprobe_instance *, struct pt_regs *);
 /* /pub/scm/linux/kernel/git/acme/linux-2.6/include/linux/list.h:607 */
 struct hlist_head {
         struct hlist_node *        first;                /*     0     4 */
[acme@newtoy ctracer_example]$

--- /tmp/pfunct.before  2006-12-30 16:18:25.000000000 -0200
+++ /tmp/pfunct.after   2007-01-02 02:08:50.000000000 -0200
@@ -249,7 +249,7 @@
 /* definitions: 1 */

 /* /pub/scm/linux/kernel/git/acme/linux-2.6/lib/klist.c:57 */
-void klist_init(struct klist * k,  * get,  * put);
+void klist_init(struct klist * k, void (*get)(struct klist_node *), void (*put)(struct klist_node *));
 /* size: 12, inline expansions: 1 (5 bytes) */
 /* definitions: 1 */

The struct/union case still needs fixing, but we're getting there...

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 02:42:33 -02:00
Arnaldo Carvalho de Melo 2d08b4d00f [CLASSES]: Don't pass the function pointer to the childs in cu__process_function
This is very hackish, see the previous cset comment, without this hack
unrelated, deeper DW_TAG_formal_parameter tags were being attributed to the
function being processed, proper fix is described in previous comment, for now
this is enough as a bandaid.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 02:21:59 -02:00
Arnaldo Carvalho de Melo 1e985b42eb [CLASSES]: Process DW_TAG_{union,structure}_type tags in cu__process_function
There are cases where just a declaration is emitted, such as in
blk_rq_map_user_iov's iov parameter:

 <2><dc04>: Abbrev Number: 29 (DW_TAG_structure_type)
     DW_AT_name        : (indirect string, offset: 0x3be8): sg_iovec
     DW_AT_declaration : 1
 <2><dc0a>: Abbrev Number: 88 (DW_TAG_formal_parameter)
     DW_AT_name        : iov
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 2472
     DW_AT_type        : <dc60>
     DW_AT_location    : 0x4288 (location list)

I.e. the DW_TAG_structure_type tag is emitted at the same level as the
DW_TAG_formal_parameter tags, so handled inside the cu__process_function
method.

This and the next cset only shows that a normalization in the parsing routines
is in real demand and will be done, normalization because what needs to be done
is similar to what is already done in places like cu__create_new_array, i.e.
process all the siblings in a level in tag specific cu methods.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2007-01-02 02:17:37 -02:00
Arnaldo Carvalho de Melo 29fc67353c [CLASSES]: Pave the way to reuse DW_TAG_subprogram prototype code
Will be reused when handling DW_TAG_subprogram_type more comprehensively, in
the upcoming csets.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-30 16:34:20 -02:00
Arnaldo Carvalho de Melo e78718148d [CLASSES]: Introduce struct base_type
To use less memory to represent DW_TAG_base_type tags.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-29 20:58:03 -02:00
Arnaldo Carvalho de Melo c83a88bd77 [CLASSES]: Use only a struct tag to represent DW_TAG_{pointer,const}_type tags
This reduces by 8MB the dtagnames memory footprint when processing a qemu
vmlinux, that now uses ~79MB.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-29 16:34:11 -02:00
Arnaldo Carvalho de Melo bbf3f8d95e [CLASSES]: Become struct tag centric
So far struct class was being used as the main data structure, switch to struct
tag, that already was the top of the tag hierarchy, being a struct class
ancestor, so reflect that and stop using struct class as the catch all class,
as a started DW_TAG_array_type tags are now represented by a new class, struct
array_type, reducing the size of struct class and reducing DW__TAG_array_type
instance memory usage.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-29 15:28:58 -02:00
Arnaldo Carvalho de Melo 3e177d577a [CLASSES]: Discard DW_TAG_formal_parameter when processing classes
Only needed, so far, when processing functions, have to reenable this in the
future when we got to handle it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-28 14:35:44 -02:00
Arnaldo Carvalho de Melo 594463f756 [CLASSES]: Save 12 bytes on struct class
With some tradeoff for the code size...

[acme@newtoy pahole]$ codiff build/libclasses.so.orig build/libclasses.so
/home/acme/pahole/classes.c:
  struct class            |  -12
 1 struct changed
  class__array_nr_entries |   +3
  class_member__names     |   +3
  parameter__names        |   +3
  class__find_holes       |   -8
  class__print_struct     |   -1
  cu__create_new_array    |  +48
 6 functions changed, 57 bytes added, 9 bytes removed
[acme@newtoy pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-28 12:00:21 -02:00
Arnaldo Carvalho de Melo 43de2d269f [CLASSES]: Use ISO C99 integer types more comprehensively
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-28 11:18:43 -02:00
Arnaldo Carvalho de Melo a6d3a1c5e3 [CLASSES]: Be a bit paranoid on class_member__new
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-28 10:10:07 -02:00
Arnaldo Carvalho de Melo 95578b7694 [CLASSES]: Shrink struct class_member
[acme@newtoy pahole]$ codiff build/libclasses.so.orig build/libclasses.so
/home/acme/pahole/classes.c:
  struct class_member |  -16
 1 struct changed
  class_member__new   |   +6
  class_member__names |   +5
  class_member__print |   -9
  class__find_holes   |  -37
  class__print_struct |  -22
  cu__process_class   |   +1
 6 functions changed, 12 bytes added, 68 bytes removed
[acme@newtoy pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-28 10:09:18 -02:00
Arnaldo Carvalho de Melo 849eda4a71 [CLASSES]: Fix abstract_origin type, its a Dwarf_Off
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-28 09:38:40 -02:00
Arnaldo Carvalho de Melo e838c259e0 [CLASSES]: low_pc and high_pc attributes are Dwarf_Addr
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-28 09:36:39 -02:00
Arnaldo Carvalho de Melo 3ac4b868aa [CLASSES]: Introduce cus__load_dir()
To load directory trees, looking for files with a specified glob mask, calling
cus__load() on the ones that match and optionally recursively searching for
more matches in subdirectories.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-27 14:57:19 -02:00
Arnaldo Carvalho de Melo b0e2c51ec8 [CLASSES]: Allow struct cus instances to share a list of defs and fwd_decls
So that we can extract bits from one and combine it bits from other instances,
like we'll do in ctracer, where we want to have a cus instance just to get the
kprobes definitions and forward declarations but not handle the methods in it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-27 14:39:37 -02:00
Arnaldo Carvalho de Melo 5f2af297df [CLASSES]: Emit definitions for DW_TAG_subroutine_type in cus__emit_tag_definitions
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-27 10:21:40 -02:00
Arnaldo Carvalho de Melo 6be23f3d82 [CLASSES]: Support unions
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-26 20:44:03 -02:00
Arnaldo Carvalho de Melo bc5728f294 [CLASSES]: Store the high and low pc addresses in inline_expansion
For the ranges cases we store the lowest low_pc (in the first range) and the
highest high_pc (in the last range).

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-26 11:44:05 -02:00
Arnaldo Carvalho de Melo 3e60a747e6 [CLASSES]: Use size_t for size variables
uint64_t is a bit excessive.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-12-24 22:27:22 -02:00