Commit Graph

1064 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo d5d45ab5af core: cu__find_function_by_name must use function__name()
And not compare by string_t, as now it may not be on the global strings table,
so we have to give a chance to the underlying debug format to translate that to
a string for us.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 12:07:53 -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 b911a0aa7a ctf_encoder: Add void (void) signature for functions not found on DWARF
Temporary hack till I figure out how to do more filtering on the functions on
the symtab that aren't in the DWARF info.

Problem is that if we don't put something on the table at encode time, we won't
find it at decode time, when we don't have DWARF to notice that its not there
because its not in DWARF.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 14:11:51 -03:00
Arnaldo Carvalho de Melo deb509cf6c libctf: Ignore hidden symbols
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 14:03:04 -03:00
Arnaldo Carvalho de Melo e104ae6b69 codiff: Support -F/--format_path
So that we can ask for a CTF on a file with both CTF and DWARF.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 14:02:21 -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 583ba1c645 codiff: Stop using cu__for_each_tag
Just use cu__for_each_struct and cu__for_each_function, newer functions that
are more appropriate and make the code more easy to follow.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 13:47:48 -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 6025d4ce38 pfunct: Stop using cu__for_each_tag
All it really needs its the recently introduced cu__for_each_function.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 11:55:49 -03:00
Arnaldo Carvalho de Melo f77930c4f8 prefcnt: Stop using cu__for_each_tag
The new iterators cu__for_each_function and cu__for_all_tags are better suited.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 11:43:58 -03:00
Arnaldo Carvalho de Melo 0048711e43 pglobal: Stop using cu__for_each_tag
It really needs the recently introduced cu__for_each_variable and
cu__for_each_function.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 11:39:43 -03:00
Arnaldo Carvalho de Melo 2584df6335 ctf_loader: Fill in the binding information for variables and functions
Using elf_sym__bind, i.e. Elf_Sym->st_info bind subfield.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 11:38:37 -03:00
Arnaldo Carvalho de Melo c73972591b syscse: Stop using cu__for_each_tag
What it really needs is cu__for_each_function.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 11:11:20 -03:00
Arnaldo Carvalho de Melo 494d32fba0 dtagnames: Stop using cu__for_each_tag
It really wants to do cu__for_all_tags

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 11:01:16 -03:00
Arnaldo Carvalho de Melo 75687b4719 pahole: Stop using cu__for_each_tag
All it needs in this last case is really cu__for_each_type.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 10:58:25 -03:00
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