Commit Graph

197 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo ca6dc1446c dwarf_loader: Follow const types too in class_member__cache_byte_size
In the same fashion as DW_TAG_volatile_type, as we need to get to the
DW_TAG_base_type at the end of the chain.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-08-20 19:48:14 -03:00
Arnaldo Carvalho de Melo bd361e461e dwarf_loader/dwarves_fprintf: Support "using" pointing to data members
If it is C++ add DW_TAG_member entries to cu->tags_table and at
imported_declaration__fprintf fallback to cu__tag() if cu__function()
fails.

The right thing tho, long term, is to have a class for
"DW_TAG_imported_declaration" to register to what kind of tag this
points, if for DW_TAG_subprogram or to DW_TAG_member, the info is in the
DWARF DW_AT_import attribute, but so far we're not decoding it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-08-20 18:33:52 -03:00
Arnaldo Carvalho de Melo 3de722e9ab dwarves: Delete list entries in reverse order
It doesn't matter when using a traditional malloc/free allocator, but
with obstacks we need to do it in reverse order.

For the usual case where we successfully process an object this doesn't
matter, as when we started using obstacks we don't traverse all the tags
calling their destructors anymore, we just free the whole obstack in one
go.

Noticed when processing object files built from non-supported languages
such as FORTRAN and Pascal, where there are some DWARF tags that are not
supported, which makes the object file load to be prematurely aborted
and that calls destructors for things like classes and functions that in
turn free space for their parameter/member lists, which now have to be
done in reverse order.

We could just stop calling the destructors and then destroying the whole
obstack, but I think that partially processed files are a nice feature,
so keep the interface in a way that both obstacks and traditinal malloc
alocators can be used.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-08-19 10:32:49 -03:00
Arnaldo Carvalho de Melo 19bbecf668 dwarves: Pass the cu to destructors to free memory on the obstack
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-08-18 18:21:20 -03:00
Arnaldo Carvalho de Melo d46525e7ce dwarves: reorganize struct namespace
Oh well, we need to use these tools on these tools from time to time ;-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-07-08 16:53:22 -03:00
Arnaldo Carvalho de Melo 932a884ed9 dwarves: Use an obstack for all the tags
We got it down from:

15.733210256  seconds time elapsed   ( +-   0.197% )

as reported in the previous changeset to:

[acme@doppio pahole]$ perf stat -r 5 pahole object_samples/zweinberg\@mozilla.com/libgklayout.so > /dev/null

 Performance counter stats for 'pahole object_samples/zweinberg@mozilla.com/libgklayout.so' (5 runs):

   12293.726462  task-clock-msecs         #      0.969 CPUs    ( +-   0.189% )
           2663  context-switches         #      0.000 M/sec   ( +-  18.994% )
             40  CPU-migrations           #      0.000 M/sec   ( +-  34.146% )
         127003  page-faults              #      0.010 M/sec   ( +-   0.000% )
    24417854522  cycles                   #   1986.204 M/sec   ( +-   0.174% )
    29007002413  instructions             #      1.188 IPC     ( +-   0.009% )
      297872959  cache-references         #     24.230 M/sec   ( +-   0.529% )
       21440854  cache-misses             #      1.744 M/sec   ( +-   0.321% )

   12.680530119  seconds time elapsed   ( +-   1.042% )

[acme@doppio pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-07-08 16:37:37 -03:00
Arnaldo Carvalho de Melo 9c0cb4939c dwarves: Allow avoiding loading addr information
As, for instance, pahole doesn't need it at all.

Down from:

[acme@doppio pahole]$ perf stat -r 5 pahole object_samples/zweinberg\@mozilla.com/libgklayout.so > /dev/null

 Performance counter stats for 'pahole object_samples/zweinberg@mozilla.com/libgklayout.so' (5 runs):

   17233.989563  task-clock-msecs         #      0.994 CPUs    ( +-   0.076% )
           1880  context-switches         #      0.000 M/sec   ( +-   0.159% )
              0  CPU-migrations           #      0.000 M/sec   ( +-   0.000% )
          26248  page-faults              #      0.002 M/sec   ( +-   0.000% )
    34244461105  cycles                   #   1987.030 M/sec   ( +-   0.078% )
    34510583834  instructions             #      1.008 IPC     ( +-   0.001% )
      445937867  cache-references         #     25.875 M/sec   ( +-   0.160% )
       56898165  cache-misses             #      3.302 M/sec   ( +-   0.074% )

   17.335292038  seconds time elapsed   ( +-   0.076% )

[acme@doppio pahole]$

To:

[acme@doppio pahole]$ perf stat -r 5 pahole object_samples/zweinberg\@mozilla.com/libgklayout.so > /dev/null

 Performance counter stats for 'pahole object_samples/zweinberg@mozilla.com/libgklayout.so' (5 runs):

   16511.627334  task-clock-msecs         #      0.992 CPUs    ( +-   0.208% )
           1922  context-switches         #      0.000 M/sec   ( +-   3.068% )
              0  CPU-migrations           #      0.000 M/sec   ( +-   0.000% )
          25570  page-faults              #      0.002 M/sec   ( +-   0.000% )
    32807624343  cycles                   #   1986.941 M/sec   ( +-   0.208% )
    32711598374  instructions             #      0.997 IPC     ( +-   0.001% )
      436345377  cache-references         #     26.427 M/sec   ( +-   0.178% )
       54044997  cache-misses             #      3.273 M/sec   ( +-   0.685% )

   16.652951166  seconds time elapsed   ( +-   0.304% )

[acme@doppio pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-07-06 13:44:57 -03:00
Arnaldo Carvalho de Melo 5ad2e36d32 dwarves: overhaul cu->language handling
Adding an enum so that CTF doesn't have to include dwarf.h and
setting the language to LANG_C in the CTF loader.

Next csets will handle C++ in a different way, because we may need
to find class sizes in a different CU since ancestors sometimes
are only forward declared...

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-17 15:32:35 -03:00
Arnaldo Carvalho de Melo 063bad0a80 dwarves: Add missing return type to function__addr
dwarves.h:695: warning: return type defaults to ‘int’

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-17 13:09:54 -03:00
Arnaldo Carvalho de Melo 4b796de4aa dwarves: export ftype__fprintf_parms
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-08 14:23:46 -03:00
Arnaldo Carvalho de Melo e39c0b0998 dwarves: Introduce function__addr method
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-08 14:20:44 -03:00
Arnaldo Carvalho de Melo 2791a55e95 dwarves: Add label__name method
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-08 14:19:23 -03:00
Arnaldo Carvalho de Melo 570dd1ea55 dwarves: constify filename parm of cus__load_file
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-08 14:17:23 -03:00
Arnaldo Carvalho de Melo 7c6603189e dwarves: Make all the tags that have an IP to be derived from ip_tag
Next we'll add a new kind of tag, DW_TAG_perf_counter, that will come
from perf.data generated by 'perf report'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-04 17:30:06 -03:00
Arnaldo Carvalho de Melo e429f8efbb dwarves: Add an rbtree for the functions in a cu
That is used by cus__find_function_by_addr & cu__func_function_by_addr.

First user is pfunct --addr, but this is really for pfunct --annotate, that
will process a perf.data file generated by 'perf report', load the debugging
info and regenerate the functions (pfunct -TVi like) that had hits, using
libdisasm to show the assembly code, etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-04 14:56:44 -03:00
Arnaldo Carvalho de Melo dd8c983b40 dwarves: addresses are now uint64_t, no more Dwarf_ types in the core
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-03 15:40:38 -03:00
Arnaldo Carvalho de Melo 0b9d022fb1 dwarf_loader: Move the specification Dwarf_Off from the core
This field is resolved now entirely by the dwarf loader, no sense in having it
in the core.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-03 15:33:57 -03:00
Arnaldo Carvalho de Melo e2b7d1a5f5 dwarves: types are uint16_t now
Remove one more DWARF specific detail.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-03 14:56:53 -03:00
Arnaldo Carvalho de Melo 8cdd311538 dwarf_loader: Load JAVA interfaces as a struct/class
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-25 01:53:59 -03:00
Arnaldo Carvalho de Melo 29e67fce58 dwarf_loader: Add containing_type to dwarf_tag
Sharing the same space with abstract_origin, so that we can remove the last
Dwarf_Off in dwarf_fprintf.c.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-19 14:04:59 -03:00
Arnaldo Carvalho de Melo f84bf73d54 dwarves: Move the fprintf code to a new source file.
$ wc -l dwarves.c dwarves_fprintf.c
 1468 dwarves.c
 1554 dwarves_fprintf.c
 3022 total
$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-19 13:48:51 -03:00
Arnaldo Carvalho de Melo e148f93418 code: Combine the debugging_formats and debug_fmt_ops structs
Paving the way for pluggable debugging formats via dlopen.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-04 14:56:39 -03:00
Arnaldo Carvalho de Melo 4d619ac4cb core: Only DWARF uses the global strings table, so move it there
There is still the problem of handing the strings table to the CTF encoder, but
that will be fixed another day.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 18:46:54 -03:00
Arnaldo Carvalho de Melo 486299a359 ctf: Plug debug_fmt_ops->strings__ptr
So that we can use the strings in ".strtab" directly, without duplicating them
on the global strings table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 17:55:17 -03:00
Arnaldo Carvalho de Melo 870afee9ce core: Stop using strings__ptr(strings, i) directly
Instead pass thru cu__strings(cu, i) so that we can figure out if the
underlying debugging format handler can do that more efficiently, such as by
looking up directly the ELF section ".strtab".

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 17:54:43 -03:00
Arnaldo Carvalho de Melo 9bb29daac4 base_type: Don't combine names with attributes
Such as signed, etc. This is in preparation for using directly ctf_strings.
Instead of duplicating it in the global strings table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 16:12:36 -03:00
Arnaldo Carvalho de Melo 50844b5f25 dwarf_loader: Handle volatile bitfields in class_member__cache_byte_size
Reported-by: Breno Leitão <leitao@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 13:58:46 -03:00
Arnaldo Carvalho de Melo c93fff6743 core: Add variable__name to struct debug_fmt_ops
Same reason as for function__name

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 12:40:33 -03:00
Arnaldo Carvalho de Melo 8f14fd6d53 core: Check if the debug_fmt_ops methods are available
In the paste we ass-umed that if cu->dfops != NULL, all the methods would be
there, this ain't so anymore, so check it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 12:05:50 -03:00
Arnaldo Carvalho de Melo 0837979e09 core: function__name in CTF gets the name from .strtab
That is done by adding some new struct debug_fmt_ops methods:

->function__name()

This one, if specified, will be called by function__name(), giving a chance to
formats such as CTF to get this from some other place than the global strings
table. CTF does this by storing GElf_Sym->st_name in function->name, and by
providing a dfops->function__name() that uses function->name as an index into
the .strtab ELF section.

->cu__delete()

This is needed because we can't anymore call ctf__delete at the end of
ctf__load_file, as we will need at least the .strstab ELF section to be
available till we're done with the cu, i.e. till we call cu__delete(), that now
calls dfops->cu__delete() if it is available.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 11:46:26 -03:00
Arnaldo Carvalho de Melo 6b4aec4a73 core: Rename cu_orig_info to debug_fmt_ops
There are more things that should be handled differently, such as function
names coming from the .strtab ELF section instead of from the global strings_t
table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 11:12:02 -03:00
Arnaldo Carvalho de Melo db741ee3fc core: Hasta la vista cu__for_each_tag
build/libdwarves.so.1.0.0:
 1 function changed, 169 bytes removed, diff: -169

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 13:49:58 -03:00
Arnaldo Carvalho de Melo 3c94ff34ec core: Fix cu__for_each_struct and cu__for_each_type
To cover the case where there aren't structs or even any type at all.

It looks now just like cu__for_each_function, so its more consistent as a bonus
:-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 13:46:11 -03:00
Arnaldo Carvalho de Melo da861ba6ab core: Remove duplicate test for enums in tag__is_tag_type
It already uses tag__is_type(), that checks if it is an enumeration.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 18:02:45 -03:00
Arnaldo Carvalho de Melo 0bc59195d4 core: Fix cu__for_each_variable to cover an empty tags table
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 17:50:19 -03:00
Arnaldo Carvalho de Melo d7d419f6ab ctf_encoder: Create objects section (data/variables)
Encoding all the non UNDEF OBJECT entries in the symtab. Some must be filtered
in upcoming patches, but for at least kernel/sched.o it works just fine.

To test it I used DaveM's ctfdump and also pdwtags on a --strip-debug, pahole
-Z CTF encoded object.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 16:12:00 -03:00
Arnaldo Carvalho de Melo a6ea527aab variable: Add ->addr member
For loaders to fill with the address of global variables.
More work is needed to cover relocation, registers, etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 16:03:23 -03:00
Arnaldo Carvalho de Melo bf233bf162 core: Introduce cu__for_each_variable
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 15:58:07 -03:00
Arnaldo Carvalho de Melo 879f483daf core: Introduce cu__cache_symtab
We need it to be able to call cu__for_each_cached_symtab_entry more
than once in the same function.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 15:15:08 -03:00
Arnaldo Carvalho de Melo e97d952744 ctf_encoder: Convert DWARF functions to CTF
Finally we can use the Elf file already opened in dwarf_load, call
cu__for_each_cached_symtab_entry to iterate over the symtab entries,
this iterator will first call dwfl_module_getsymtab, that will do the
relocation that will allow us to go from the symtab address to the one
in the DWARF DW_TAG_subprogram tag DW_AT_low_pc attribute.

And voila, for a relatively complex single unit Linux kernel object
file, kernel/sched.o, we go from:

Just DWARF (gcc -g):

$ ls -la kernel/sched.o
1979011 kernel/sched.o

Then we run this to encode the CTF section:

$ pahole -Z kernel/sched.o

And get a file with both DWARF and CTF ELF sections:

$ ls -la kernel/sched.o
2019848 kernel/sched.o

We still need to encode the "OBJECTS", i.e. variables, but this
gets us from 1979011 (just DWARF) to:

$ strip--strip-debug kernel/sched.o
$ ls -la kernel/sched.o
-rw-rw-r-- 1 acme acme 507008 2009-03-30 23:01 kernel/sched.o

25% of the original size.

Of course we don't have inline expansion information, parameter names,
goto labels, etc, but should be good enough for most use cases.

See, without DWARF data, if we ask for it to use DWARF, nothing will be
printed, if we don't speficy the format, it will try first DWARF, it
will not find anything, it will try CTF:

$ pahole -F dwarf kernel/sched.o
$ pahole -C seq_operations kernel/sched.o
struct seq_operations {
	void *  (*start)(struct seq_file *, loff_t *);         /*   0  8 */
        void    (*stop)(struct seq_file *, void *);            /*   8  8 */
	void *  (*next)(struct seq_file *, void *, loff_t *);  /*  16  8 */
	int     (*show)(struct seq_file *, void *);            /*  24  8 */

	/* size: 32, cachelines: 1, members: 4 */
	/* last cacheline: 32 bytes */
};
$ $ pfunct -Vi -f schedule kernel/sched.o
void schedule(void);
{ /* low_pc=0xe01 */
}/* size: 83 */
$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:54:29 -03:00
Arnaldo Carvalho de Melo 6457b396aa core: Allow reusing the symtab already loaded and relocated
Via cu__for_each_cached_symtab_entry.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:45:55 -03:00
Arnaldo Carvalho de Melo 60e76245b8 core: Allow cachine an open Elf file handle for reuse
pahole --ctf_encode being the first to put this to good use.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:00:39 -03:00
Arnaldo Carvalho de Melo 2d8700009b pfunct: Introduce --no_parm_names
Because CTF doesn't encodes the names of the parameters and I want to
test the upcoming CTF function section code in ctftwdiff.

$ pfunct -V pahole > /tmp/before
$ pfunct --no_parm_names -V pahole > /tmp/after
$ diff -u /tmp/before /tmp/after | tail -3
-struct structure * structure__new(strings_t name);
+struct structure * structure__new(strings_t);
 /* definitions: 1 */
$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 21:47:59 -03:00
Arnaldo Carvalho de Melo 51ea39717f core: Add destructors for the function and lexblock classes
And also export the namespace destructor.

The tag__delete destructor now also uses these new destructors.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 14:54:02 -03:00
Arnaldo Carvalho de Melo 4024ccee40 tag: Make tag__delete call the right destructors for non-trivial types
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 13:06:29 -03:00
Arnaldo Carvalho de Melo fe27f41973 enumerator: Introduce enumerator__delete
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 12:17:50 -03:00
Arnaldo Carvalho de Melo 6d66c9ae6b type: Introduce type__delete
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 12:00:30 -03:00
Arnaldo Carvalho de Melo 0e29fc9912 ftype: Introduce ftype__delete
To delete all the members added so far in the loaders in case memory is scarce.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 11:40:05 -03:00
Arnaldo Carvalho de Melo 49256cfd84 core: Introduce ftype__for_each_parameter_safe
Will be used by ftype__delete.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 11:39:26 -03:00
Arnaldo Carvalho de Melo 4bdead6876 core: Add a per object file functions_table
CTF will need this distinction in that it handles functions differently, using
data in the ELF symbol table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 20:12:59 -03:00