Commit Graph

186 Commits

Author SHA1 Message Date
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
Arnaldo Carvalho de Melo 4848eef743 core: Rename {cus,dwarf,ctf}__load to {cus,dwarf,ctf}__load_file
Because we already use ctf__load in libctf.c, rename the others to
disambiguate, and also as there are the __load_dir and __load_files
it looks more consistent.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 16:48:41 -03:00
Arnaldo Carvalho de Melo d6d845f0d7 core: Handle GCC support for vector instructions
So after the next patch, when dwarf_loader will use this new core
functionality, it recognizes:

908 typedef int __m64 __attribute__ ((__vector_size__ (8))); size: 8
909 int         array __attribute__ ((__vector_size__ (8))); size: 8
910 int         array __attribute__ ((__vector_size__ (4))); size: 4
911 short int   array __attribute__ ((__vector_size__ (2))); size: 2
912 char        array __attribute__ ((__vector_size__ (1))); size: 1

The above output was obtained using pdwtags.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-23 16:56:57 -03:00
Arnaldo Carvalho de Melo 09edf84b74 tag: tag__follow_typedef doesn't change self, make it const
That will allow it to be used in other places were we forward self and it is
const.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-23 16:30:20 -03:00
Arnaldo Carvalho de Melo ac7778099a pahole: Introduce --fixup_silly_bitfields
$ pahole -C acpi_device_perf_flags ac.o
struct acpi_device_perf_flags {
	u8          reserved:8;           /*     0: 0  1 */

	/* size: 1, cachelines: 1, members: 1 */
	/* last cacheline: 1 bytes */
};
$ pahole --fixup_silly_bitfields -C acpi_device_perf_flags ac.o
struct acpi_device_perf_flags {
	u8          reserved;             /*     0     1 */

	/* size: 1, cachelines: 1, members: 1 */
	/* last cacheline: 1 bytes */
};
$

Used in ctfdwdiff as in CTF land we can't express such sillyness.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 13:54:04 -03:00
Arnaldo Carvalho de Melo 6454e1dc8b enumeration: Allow sharing the enumerators
Nasty trick, but works and should be properly documented in the sources
and here:

If struct namespace.shared_tags is 1, we actually are reusing the list
of enumerators in another namespace, so we shouldn't delete them, for
that list_for_each_tag now means more for each _unshared_ tag, so that
cu__delete doesn't visits it, double freeing enumerator tags.

type__for_each_enumerator knows that and only for enums we'll set this
->shared_tags bit to 1, so we should be safe...

Disgusting? send me a patch, but without increasing memory or processing
footprints, please ;-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 12:53:43 -03:00
Arnaldo Carvalho de Melo 57127d45fc pahole: Introduce --flat_array
CTF doesn't have support for multiple array dimensions, so it flattens
the arrays.

This caused a large number of false positives in ctfdwdiff, so introduce
this conf_fprintf option, use it in pahole and ctfdwdiff.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 10:29:50 -03:00
Arnaldo Carvalho de Melo 45255ec6b6 pahole: Add --format_path/-F to specify a list of formats to try
For a file with just DWARF info:

$ pahole -F ctf build/pahole
$

But if we ask that it also try dwarf:

$ pahole -F ctf,dwarf build/pahole | head -2
struct _IO_FILE {
	int          _flags;    /*     0     4 */
$

Useful when testing the new CTF support in these tools, as we'll be able to,
from the DWARF info in objects, generate the CTF equivalent and add to the same
object, then run pahole -A -F ctf, pahole -A -F dwarf and compare the outputs.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:19:37 -03:00
Arnaldo Carvalho de Melo 347e70f4d8 cus: Allow passing a debugging format path to cus__load
So that the user can specify what is the order it wants for decodind, as
we can have several debugging formats encoded in different ELF sections.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:13:00 -03:00
Arnaldo Carvalho de Melo da37c56c26 cu: Add a filename member
Will later be used when generating the CTF info, be it in a separate
file, be it on a new ELF section inserted into this filename.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-18 22:35:54 -03:00
Arnaldo Carvalho de Melo 140712f06a cu: Rename cu__find_{type,tag}_by_id to cu__{type,tag}
To shorten the name and to reflect the fact that we're no longer
"finding" a type, but merely accessing an array with a bounds check in
this function.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-18 12:17:07 -03:00
Arnaldo Carvalho de Melo a56a9a6cfe class_member: Reencode DWARF bitfield types
We now create a new integral type (enum or base_types), creating typedef
chains if needed, while caching the bit_size and bit_offset, so that we
can easily reencode the whole file into CTF.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-18 11:58:32 -03:00