Commit Graph

1064 Commits

Author SHA1 Message Date
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
Arnaldo Carvalho de Melo fc0827327b pahole: Remove a not needed "the" article in the man page.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-23 16:53:54 -03:00
Arnaldo Carvalho de Melo 7bd3c2d828 core: Handle GCC support for vector instructions
So now 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:31:21 -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 7d643b7d32 pdwtags: Use conf_load.stealer
Just like pahole we want to trow away compile units as we process them.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-23 14:22:23 -03:00
Arnaldo Carvalho de Melo 23df52c620 ctf_loader: One more attempt at handling packed enums
With this a "make allyesconfig" on a 2.6.29-rc8 Linux kernel build left 16
cases flagged by ctfdwdiff, 8 unique ones, out of 6209 single-cu (compile unit)
.o files.

But what this clearly shows is that we really need to detect if a struct is
packed, and wether it is naturally packed or if __attribute__ packed was used,
that way we will have more clues as to if a enum is packed or if the whole
struct where it is used as a type for a/several member(s) is packed.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-22 15:02:33 -03:00
Arnaldo Carvalho de Melo c1d567f047 ctfdwdiff: allow specifying just one file again
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-22 13:06:41 -03:00
Arnaldo Carvalho de Melo 17b83fcbf1 ctfdwdiff: Handle files without DWARF info too
Such as some built-in.o files in the Linux kernel build process.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 23:44:12 -03:00
Arnaldo Carvalho de Melo 9a3f5b2c9e ctfdwdiff: Make it work in directories
Looking for all the single-compile unit .o files and acting on those.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 14:34:30 -03:00
Arnaldo Carvalho de Melo 938690a7e4 pahole: don't print private members inside types when using show_private_classes
As we will show them on the first level. This is yet another thing
required to properly compare te result of "pahole -F ctf foo" with the
output of "pahole -F dwarf foo", as there is no support, that I know of,
for namespacing in ctf.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 14:13:40 -03:00
Arnaldo Carvalho de Melo 790019678d dwarves: Fixup the flat_arrays code
To deal with cases such as this:

$ pahole -C tun_filter drivers/net/tun.o
struct tun_filter {
	__u16           flags;         /*   0  2 */
	__u16           count;         /*   2  2 */
	__u8            addr[0][6];    /*   4  0 */

	/* size: 4, cachelines: 1, members: 3 */
	/* last cacheline: 4 bytes */
};
$ pahole --flat_arrays -C tun_filter drivers/net/tun.o
struct tun_filter {
	__u16           flags;         /*   0  2 */
	__u16           count;         /*   2  2 */
	__u8            addr[0];       /*   4  0 */

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

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 14:05:01 -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 aff24d3517 base_type: floats are 32 bits
Gee, I guess I was nuts when thinking int was dependent on the arch
word-size.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 13:38:03 -03:00
Arnaldo Carvalho de Melo da177f87a3 ctf_encoder: Check if something was encoded before saving the info
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 13:20:24 -03:00
Arnaldo Carvalho de Melo 9775df792d dwarf: share the enumerators when recoding an enum bitfield
And this now allows us to properly encode enum bitfields with pahole -Z.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 13:01:25 -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 ce97ac9a26 ctf_encoder: Allow encoding a bit_size in enumeration types
As we have to support enum bitfields, so remember the bit_size.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 12:51:30 -03:00
Arnaldo Carvalho de Melo a3cd3c4a09 ctf_loader: enums can have a bit_size less than 8 * size(int)
At least in our encoder, as we support enum bitfields, so if it comes
zeroed, as in the other implementation, we assume 8 * sizeof(int), if
not, its the bitsize.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 12:48:25 -03:00
Arnaldo Carvalho de Melo 56f4fc831a pahole: Introduce --show_private_classes
By default pahole doesn't prints structs/classes that are only defined
inside functions, so add a knob to aks for that.

This is for the benefit of ctfdwdiff, as in CTF we don't have
expressiveness to tell that a struct is only defined inside a function,
its all in the global table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 11:37:22 -03:00
Arnaldo Carvalho de Melo 659c1eae69 strings: Allow calling strings__delete with a NULL pointer
Just like free, and as this is the common exit path of the tools, we
better do that not to segfault when not asking for something. ;-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 10:35:57 -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 01c4fa3114 ctfdwdiff: Make it more bulk test friendly
So that I can run it with:

find . -type d | while read dir ; do cd $dir ; ls *.o 2> /dev/null |
while read file ; do ctfdwdiff $file ; done ; cd - ; done

for instance.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 10:11:47 -03:00
Arnaldo Carvalho de Melo 6564699144 base_type: Add "float" to base_type_name_to_size_table
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 21:52:01 -03:00
Arnaldo Carvalho de Melo fedbfb60ff libctf: Encode VARARGS an extra 0 short at the end of the parm list
We'll see if this is how things should be, but its good enough for me 8)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 20:10:33 -03:00
Arnaldo Carvalho de Melo 82d5dbe637 ctfdwdiff: Simple shell script for testing the CTF encoder/decoder
First it gets a file with DWARF info, converts that to CTF and adds
a ".SUNW_ctf" ELF section to the file with DWARF info. Double debugging
foo! Pay for one, take two!

For tcp_input.o for instance, the result is:

[acme@doppio pahole]$ cat /tmp/tcp_input.o.diff
--- /tmp/tcp_input.o.ctf.c	2009-03-19 19:48:23.000000000 -0300
+++ /tmp/tcp_input.o.dwarf.c	2009-03-19 19:48:23.000000000 -0300
@@ -1811,7 +1811,7 @@

 	/* XXX 6 bytes hole, try to pack */

-	void (*call)(const struct marker *, void *);	  /* 24  8 */
+	void (*call)(const struct marker *, void *, ...); /* 24  8 */
 	struct marker_probe_closure single;		  /* 32 16 */
 	struct marker_probe_closure * multi;		  /* 48  8 */
 	const char  *               tp_name;		  /* 56  8 */
[acme@doppio pahole]$

Now back to figuring out how to encode a VARARGS marker in CTF...

Ah, to use the script just do:

./ctfdwdiff foo.o

Some will crash, but we're working hard for fuller customer
satisfaction.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 19:50:09 -03:00
Arnaldo Carvalho de Melo dcef613288 libctf: give up "for now" on using libelf to add a section to an existing file
And use what worked so far, that is: if the section is already there,
replacing its contents works, because probably all the relocation was
done... If not, be a chicken and call system("objcopy..."), but...
I'llll be bahck!

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 19:41:14 -03:00
Arnaldo Carvalho de Melo f2495cd1a6 libctf: comment out some debug messages
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 19:17:41 -03:00
Arnaldo Carvalho de Melo d9d63574a3 ctf: Give some more info about UNKNOWN types
And make the output go to stderr.

I guess the best we can do about these is to completely ignore them,
well see...

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:25:13 -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 feab8aa5e3 ctf: Include the initial implementation of a ctf encoder
"pahole -Z foo" will create foo.SUNW_ctf, that if objcopy
--add-section'ed to the right word-sized object will work, sans VARARGS,
that will get fixed soon (as in, probably, tomorrow).

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:16:07 -03:00
Arnaldo Carvalho de Melo b27463f995 ctf: class__fixup_ctf_bitfields has to handle enums
As they can be the "integral type" of bitfields.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:14:39 -03:00
Arnaldo Carvalho de Melo fbaab74297 ctf: Stop returning "(anonymous)" in ctf_string
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:14:23 -03:00
Arnaldo Carvalho de Melo f7a428ef24 ctf: Add a filename member to struct ctf
That will be later used when encoding the CTF info.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:14:01 -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