Commit Graph

897 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo a94b511f6c ctfdwdiff: Don't ask for variables and inline expansions in pfunct
As we won't find them in CTF land... I also have to add a new pfunct cmdline
option to ask for inline functions not to be printed, as they aren't on the
symtab.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 19:21:46 -03:00
Arnaldo Carvalho de Melo 6afe884c16 dwarf_loader: Delay recoding bitfield types
Till all the tags were processed, as in DWARF we can have class_member types
being defined _after_ them, so we don't find it when trying to recode
class_member at constructor time (class_member__new). Do it later after all the
types are hashed, in namespace__recode_dwarf_types.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 19:19:26 -03:00
Arnaldo Carvalho de Melo bc77517911 dwarf_loader: Handle const and volatile bitfields in tag__recode_dwarf_bitfield
We should do just as with typedefs, i.e. find the type these tags point to, and
create a new volatile/const tag pointing to the underlying bitfield tag.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 19:18:50 -03:00
Arnaldo Carvalho de Melo 9f4cedc61d ctf_encoder: ctf__ignore_symtab_object should ignore symbols with dots
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 18:19:19 -03:00
Arnaldo Carvalho de Melo 62c46e4a94 dwarf_loader: Fix thinko class_member__cache_byte_size
How could this be like this for so long? :-\

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 18:10:25 -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 f0aec4a0f4 ctf_encoder: Rename hashaddr__find to hashaddr__find_function
As we will also hash variables by addr.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 16:06:22 -03:00
Arnaldo Carvalho de Melo 1d7bd94e2f elf_symtab: Introduce elf_sym__is_local_object
Will be used when encoding the OBJECT symtab entries in the
objects CTF section (varibles/data).

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 16:04:27 -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 2b5815842f pdwtags: Print functions and variables too
And separate the different kinds of tags with separator
headers.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 15:58:29 -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 83d2438698 gobuffer: Introduce gobuffer__copy
To replace some long open coded sequences.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 15:54:53 -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 3b530f8f14 ctf_loader: Load the function section
Iterating thru the symtab and getting the missing info from
ctf_header->ctf_func_off.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:52:37 -03:00
Arnaldo Carvalho de Melo 0a924bf4eb ctf_encoder: Interface to encode functions
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:49:13 -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 0f97ea0329 libctf: fix ctf__delete
It should free ->filename and only close the file and call
elf_end if it was opened at ctf__new.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:05:54 -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 31fd625644 elf_symtab: Fix bogus elf_symtab__is_local_function
It should look for functions, not OBJECTS (variables).

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-28 19:27:00 -03:00
Arnaldo Carvalho de Melo 640bfd9679 pfunct: Introduce --symtab
With an optional argument, that if not especified defaults to
".symtab": example:

[acme@emilia pahole]$ pfunct --symtab=".dynsym" pahole
54: strings                   0x606480     8
56: _IO_stdin_used            0x403ec0     4
60: stderr                    0x606488     8
68: argp_program_version_hook 0x404038     8
69: stdout                    0x606490     8
[acme@emilia pahole]$

Yes, some filtering is done

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 18:03:28 -03:00
Arnaldo Carvalho de Melo ba47890b18 elf_symtab: Allow passing the name of the symtab to be parsed
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 18:02:48 -03:00
Arnaldo Carvalho de Melo 33cec4c457 elf_symtab: Add accessor for the symbol size
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 17:26:27 -03:00
Arnaldo Carvalho de Melo 717f7ab8b0 elf_symtab: Introduce elf_symtab__for_each_symbol
And ditch the iterate calling a function interface. I'm trying to get rid of
that in the core (cu__for_each+callback+filter, etc) because doit it
explicitely, like in the kernel, where you have a foo__for_each_bar and do the
filtering directly and process the data, if the processing is simple, right in
the body of the loop, instead of having to go back and forth thru functions.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 17:17:25 -03:00
Arnaldo Carvalho de Melo 2696bee553 dwarf_loader: Ditch that fugly oom crap, propagate errors
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 16:19:14 -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 fe88959e80 ctf_loader: Ditch that fugly oom crap, propagate errors
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 12:18:11 -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 ed0c3ae7d1 ctf: Move ctf_format_flt_attrs from the loader to libctf
It is not glue from CTF to the core, it is pure CTF stuff.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 11:29:13 -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 a386913705 core: function__tag_fprintf should check if the alias name is NULL
Only seen in some C++ inline expansion cases. Will appear as "(null)" in the
rendered source code.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 19:05:25 -03:00
Arnaldo Carvalho de Melo e924cacdf6 pahole: Remove --dwarf_offset/-O option
Too DWARF specific and wasn't working since I implemented type recoding and
removed the Dwarf_Off from struct tag.

To achieve the same result one can use --show_decl_info that also shows the
dwarf offset, since it needs to keep the DWARF specific line number and file
and then use a text editor to find the offset.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 18:44:43 -03:00
Arnaldo Carvalho de Melo b9d569e2aa ctf_loader: create_new_subroutine_type should create just a ftype
Full functions will be added later, to another CTF section.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 18:18:57 -03:00
Arnaldo Carvalho de Melo 2fd3936a9d ctf: combine the structs ctf_state and ctf
Moving more CTF only stuff out of the dwarves land and into something that can
be more easily stolen by other projects not interested in funny named stuff
such as pahole.

This also will help with encoding, as we will normally be recoding data from
DWARF, so the ELF file will be available and we will just add a new section to
it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 18:12:11 -03:00
Arnaldo Carvalho de Melo 4d32a800e7 ctf_loader: Remove the elf iteration functions/structs
Already moved to elf_symtab.[ch].

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 17:19:20 -03:00
Arnaldo Carvalho de Melo 49f590e3b9 libctf: Adopt ctf__string from ctf_loader.c
The ctf_loader.c file should be a direct counterpart to dwarf_loader,
that is, it should have just use what is in libctf to decode the CTF
sections and convert it to the core format in dwarves.[ch].

Also introduce a ctf__string32 for the very common idiom:

ctf_string(ctf__get32(sp->ctf, &tp->base.ctf_name), sp);

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 17:13:40 -03:00
Arnaldo Carvalho de Melo 0954d75152 elf_symtab: Introduce elf_symtab
We will need this when encoding the CTF functions section.  Things like lookup
a function by its address when converting from a DW_TAG_subprogram to a CTF
function, for instance.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 16:58:44 -03:00
Arnaldo Carvalho de Melo 8bf5eb9bc8 dutil: Move elf_section_by_name to dutil
Will be used by more than one file.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 16:56:19 -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 25264fdf74 pfunct: Add --format_path/-F as in pahole
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 16:39:14 -03:00
Arnaldo Carvalho de Melo cf985058ba Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/acme/pahole 2009-03-23 17:00:10 -03:00
Arnaldo Carvalho de Melo 726a91bae6 dwarf: Handle DW_AT_GNU_vector attributes in arrays
So that we can properly recognize the GNU extensions to support vector
instructions.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-23 16:57:54 -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