Commit Graph

227 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo 18f5910f96 dwarves: Add type to tag helper
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-01-10 15:26:53 -03:00
Yonghong Song 1176661409 btf: Fix kind_flag usage in btf_loader
Commit 2a82d593be ("btf: Add kind_flag support for btf_loader") added
kind_flag supported in btf_loader to get correct bitfield_size and
bit_offset for struct/union members.  The commit unnecessarily stored
the bit in the structure type which is not used later.

So let us remove the kind_flag from the struct type and any other
changes whose purpose is to set this bit.

Signed-off-by: Yonghong Song <yhs@fb.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Fixes: 2a82d593be ("btf: Add kind_flag support for btf_loader")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-01-10 15:26:53 -03:00
Arnaldo Carvalho de Melo b24718fe27 dwarves: Fix documentation for class_memer->bitfield_size
Just a cut'n'past thinko.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-01-10 15:26:53 -03:00
Yonghong Song 2a82d593be btf: Add kind_flag support for btf_loader
For struct/union members, the struct/union type info kind_flag is needed
to calculate correct bitfield_size and bit_offset.

  if (kind_flag) {
    bitfield_size = BTF_MEMBER_BITFIELD_SIZE(member->offset);
    bit_offset = BTF_MEMBER_BIT_OFFSET(member->offset);
  } else {
    bitfield_size = 0;
    bit_offset = member->offset;
  }

Note that bitfield_size and bit_offset will not depend on the member
type. The member type will help calculate correct bitfield_offset,
byte_size, byte_offset, bit_size.

For example, with the fix, we will be able to display
bit offset and bitfield size properly.

  -bash-4.4$ cat t.c
  struct t {
    int a:2;
    int b:3;
    int c:2;
  } g;
  -bash-4.4$ gcc -c -O2 -g t.c
  -bash-4.4$ pahole -JV t.o
  File t.o:
  [1] STRUCT t kind_flag=1 size=4 vlen=3
          a type_id=2 bitfield_size=2 bits_offset=0
          b type_id=2 bitfield_size=3 bits_offset=2
          c type_id=2 bitfield_size=2 bits_offset=5
  [2] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED
  -bash-4.4$ pahole -F btf t.o
  struct t {
          int                        a:2;                  /*     0: 0  4 */
          int                        b:3;                  /*     0: 2  4 */
          int                        c:2;                  /*     0: 5  4 */

          /* size: 4, cachelines: 1, members: 3 */
          /* bit_padding: 25 bits */
          /* last cacheline: 4 bytes */
  };

Note that the above offset showing is different from the below dwarf as
BTF bitfield_offset is always the offset from the start of structure,
kindly like big endian encoding. This may need adjustment to be
conforming to the dwarf dump format.

  -bash-4.4$ pahole -F dwarf t.o
  struct t {
          int                        a:2;                  /*     0:30  4 */
          int                        b:3;                  /*     0:27  4 */
          int                        c:2;                  /*     0:25  4 */

          /* size: 4, cachelines: 1, members: 3 */
          /* bit_padding: 25 bits */
          /* last cacheline: 4 bytes */
  };

Signed-off-by: Yonghong Song <yhs@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-12-21 09:51:12 -03:00
Yonghong Song 8630ce4042 btf: fix struct/union/fwd types with kind_flag
This patch fixed two issues with BTF. One is related to struct/union
bitfield encoding and the other is related to forward type.

Issue #1 and solution:
======================

Current btf encoding of bitfield follows what pahole generates.
For each bitfield, pahole will duplicate the type chain and
put the bitfield size at the final int or enum type.
Since the BTF enum type cannot encode bit size,
commit b18354f64c ("btf: Generate correct struct bitfield
member types") workarounds the issue by generating
an int type whenever the enum bit size is not 32.

The above workaround is not ideal as we lost original type
in BTF. Another undesiable fact is the type duplication
as the pahole duplicates the type chain.

To fix this issue, this patch implemented a compatible
change for BTF struct type encoding:
  . the bit 31 of type->info, previously reserved,
    now is used to indicate whether bitfield_size is
    encoded in btf_member or not.
  . if bit 31 of struct_type->info is set,
    btf_member->offset will encode like:
      bit 0 - 23: bit offset
      bit 24 - 31: bitfield size
    if bit 31 is not set, the old behavior is preserved:
      bit 0 - 31: bit offset

So if the struct contains a bit field, the maximum bit offset
will be reduced to (2^24 - 1) instead of MAX_UINT. The maximum
bitfield size will be 255 which is enough for today as maximum
bitfield in compiler can be 128 where int128 type is supported.

A new global, no_bitfield_type_recode, is introduced and which
will be set to true if BTF encoding is enabled. This global
will prevent pahole duplicating the bitfield types to avoid
type duplication in BTF.

Issue #2 and solution:
======================

Current forward type in BTF does not specify whether the original
type is struct or union. This will not work for type pretty print
and BTF-to-header-file conversion as struct/union must be specified.

To fix this issue, similar to issue #1, type->info bit 31
is used. If the bit is set, it is union type. Otherwise, it is
a struct type.

Examples:
=========

  -bash-4.4$ cat t.c
  struct s;
  union u;
  typedef int ___int;
  enum A { A1, A2, A3 };
  struct t {
	  int a[5];
	  ___int b:4;
	  volatile enum A c:4;
	  struct s *p1;
	  union u *p2;
  } g;
  -bash-4.4$ gcc -c -O2 -g t.c

Without this patch:

  $ pahole -JV t.o
  [1] TYPEDEF ___int type_id=2
  [2] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED
  [3] ENUM A size=4 vlen=3
        A1 val=0
        A2 val=1
        A3 val=2
  [4] STRUCT t size=40 vlen=5
        a type_id=5 bits_offset=0
        b type_id=13 bits_offset=160
        c type_id=15 bits_offset=164
        p1 type_id=9 bits_offset=192
        p2 type_id=11 bits_offset=256
  [5] ARRAY (anon) type_id=2 index_type_id=2 nr_elems=5
  [6] INT sizetype size=8 bit_offset=0 nr_bits=64 encoding=(none)
  [7] VOLATILE (anon) type_id=3
  [8] FWD s type_id=0
  [9] PTR (anon) type_id=8
  [10] FWD u type_id=0
  [11] PTR (anon) type_id=10
  [12] INT int size=1 bit_offset=0 nr_bits=4 encoding=(none)
  [13] TYPEDEF ___int type_id=12
  [14] INT (anon) size=1 bit_offset=0 nr_bits=4 encoding=SIGNED
  [15] VOLATILE (anon) type_id=14

With this patch:

  $ pahole -JV t.o
  File t.o:
  [1] TYPEDEF ___int type_id=2
  [2] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED
  [3] ENUM A size=4 vlen=3
        A1 val=0
        A2 val=1
        A3 val=2
  [4] STRUCT t kind_flag=1 size=40 vlen=5
        a type_id=5 bitfield_size=0 bits_offset=0
        b type_id=1 bitfield_size=4 bits_offset=160
        c type_id=7 bitfield_size=4 bits_offset=164
        p1 type_id=9 bitfield_size=0 bits_offset=192
        p2 type_id=11 bitfield_size=0 bits_offset=256
  [5] ARRAY (anon) type_id=2 index_type_id=2 nr_elems=5
  [6] INT sizetype size=8 bit_offset=0 nr_bits=64 encoding=(none)
  [7] VOLATILE (anon) type_id=3
  [8] FWD s struct
  [9] PTR (anon) type_id=8
  [10] FWD u union
  [11] PTR (anon) type_id=10

The fix removed the type duplication, preserved the enum type for the
bitfield, and have correct struct/union information for the forward
type.

Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-12-20 11:27:20 -03:00
Arnaldo Carvalho de Melo da632a3686 dwarves: Introduce {cu,cus}__find_struct_or_union_by_name() methods
Since tools like 'pahole' now shows unions in addition to structs.

Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-12-03 13:13:51 -03:00
Arnaldo Carvalho de Melo 31664d60ad pahole: Show tagged enums as well when no class is specified
The pahole tool initial goal was to show struct holes, which can't
happen with a first level of a tagged union (a union with a name),
so those only were displayed when part of a higher level struct.

Show the first level tagged enums as well, as this is useful when just
wanting to see its members.

E.g.:

  $ pahole ../build/v4.20-rc5/net/core/sock.o | grep ^union
  union fpregs_state {
  union irq_stack_union {
  union sigval {
  union __sifields {
  union thread_union {
  union kernfs_node_id {
  union flowi_uli {
  union ethtool_flow_union {
  union key_payload {
  union bpf_attr {
  union tcp_md5_addr {
  $

Suggested-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-12-03 12:51:30 -03:00
Arnaldo Carvalho de Melo bfdea37668 dwarves_fprintf: Print the scope of variables
E.g.:

$ pfunct -iVT ../build/v4.18.0+/kernel/sched/core.o  -f tg_cfs_schedulable_down
int tg_cfs_schedulable_down(struct task_group * tg, void * data);
{ /* low_pc=0x10340 */
	struct cfs_schedulable_data * d; /* scope: optimized */       //  6681
	struct cfs_bandwidth * cfs_b; /* scope: optimized */          //  6682
	s64 quota; /* scope: optimized */                             //  6683
	s64 parent_quota; /* scope: register */                       //  6683
	{
		struct cfs_bandwidth * parent_b; /* scope: optimized */ //  6688
		{
			bool branch; /* scope: optimized */           //  6698
			arch_static_branch(struct static_key * key,
						bool branch); /* size=30, low_pc=0x103a3 */ //  6698
		} /* lexblock size=0 */
		{
			s64 __UNIQUE_ID___x272; /* scope: optimized *///  6699
			s64 __UNIQUE_ID___y273; /* scope: optimized *///  6699
		} /* lexblock size=0 */
		normalize_cfs_quota(struct task_group * tg,
					struct cfs_schedulable_data * d); /* size=94, low_pc=0x10355 */ //  6690
	} /* lexblock size=0 */
}/* size: 240, variables: 4 */

This is part of an investigation on how to lookup the struct types associated
to registers in instructions with offsets from registers.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-09-26 16:45:25 -03:00
Arnaldo Carvalho de Melo 465110ec99 dwarves: Add the DWARF location to struct variable
This is DWARF specific, we don't have in CTF, AFAIK, info about where a
variable is put, i.e. in a register? in the stack? etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-09-26 16:45:25 -03:00
Arnaldo Carvalho de Melo c65f2cf436 dwarves: Rename variable->location to ->scope
We'll use location in the DWARF sense, i.e. location lists, etc, i.e.
where is this variable? In a register? The stack? etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-09-26 16:45:25 -03:00
Arnaldo Carvalho de Melo 103e89bb25 dwarves_fprintf: Find holes on structs embedded in other structs
Take 'struct task_struct' in the Linux kernel, these fields:

        /* --- cacheline 2 boundary (128 bytes) --- */
        struct sched_entity        se;                   /*   128   448 */

        /* XXX last struct has 24 bytes of padding */

        /* --- cacheline 9 boundary (576 bytes) --- */
        struct sched_rt_entity     rt;                   /*   576    48 */

The sched_entity struct has 24 bytes of padding, and that info would
only appear when printing 'struct task_struct' if class__find_holes()
had previously been run on 'struct sched_entity' which wasn't always the
case, make sure that happens.

This results in this extra stat being printed for 'struct task_struct':

	/* paddings: 4, sum paddings: 38 */

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-06-30 16:18:11 -03:00
Arnaldo Carvalho de Melo ab97c07a7e dwarves_fprintf: Fixup cacheline boundary printing on expanded structs
A diff for 'pahole -EC task_struct vmlinux' should clarify what this fixes:

  [acme@jouet linux]$ diff -u /tmp/before.c /tmp/after.c | head -30
  --- /tmp/before.c	2016-06-29 17:00:38.082647281 -0300
  +++ /tmp/a.c	2016-06-29 17:03:36.913124779 -0300
  @@ -43,8 +43,8 @@
 			struct list_head * prev;                                         /*   176     8 */
 		} group_node; /*   168    16 */
 		unsigned int       on_rq;                                                /*   184     4 */
  +		/* --- cacheline 3 boundary (192 bytes) --- */
 		/* typedef u64 */ long long unsigned int exec_start;                     /*   192     8 */
  -		/* --- cacheline 1 boundary (64 bytes) was 4 bytes ago --- */
 		/* typedef u64 */ long long unsigned int sum_exec_runtime;               /*   200     8 */
 		/* typedef u64 */ long long unsigned int vruntime;                       /*   208     8 */
 		/* typedef u64 */ long long unsigned int prev_sum_exec_runtime;          /*   216     8 */
  @@ -53,40 +53,40 @@
 			/* typedef u64 */ long long unsigned int wait_start;             /*   232     8 */
 			/* typedef u64 */ long long unsigned int wait_max;               /*   240     8 */
 			/* typedef u64 */ long long unsigned int wait_count;             /*   248     8 */
  +			/* --- cacheline 4 boundary (256 bytes) --- */
 			/* typedef u64 */ long long unsigned int wait_sum;               /*   256     8 */
 			/* typedef u64 */ long long unsigned int iowait_count;           /*   264     8 */
 			/* typedef u64 */ long long unsigned int iowait_sum;             /*   272     8 */
 			/* typedef u64 */ long long unsigned int sleep_start;            /*   280     8 */
 			/* typedef u64 */ long long unsigned int sleep_max;              /*   288     8 */
  -			/* --- cacheline 1 boundary (64 bytes) --- */
 			/* typedef s64 */ long long int sum_sleep_runtime;               /*   296     8 */
 			/* typedef u64 */ long long unsigned int block_start;            /*   304     8 */
 			/* typedef u64 */ long long unsigned int block_max;              /*   312     8 */
  +			/* --- cacheline 5 boundary (320 bytes) --- */
 			/* typedef u64 */ long long unsigned int exec_max;               /*   320     8 */
 			/* typedef u64 */ long long unsigned int slice_max;              /*   328     8 */
 			/* typedef u64 */ long long unsigned int nr_migrations_cold;     /*   336     8 */
  [acme@jouet linux]$

I.e. the boundary detection was being reset at each expanded struct, do the math globally,
using the member offset, that was already done globally and correctly.

Reported-and-Tested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-06-29 17:27:51 -03:00
Arnaldo Carvalho de Melo 046ad67af3 dwarves_fprintf: Shorten class__fprintf() sig
That conf_fprintf can be elided as it is always NULL for the root call,
i.e. only when expanding types is that it will be called recursively.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-06-29 16:19:20 -03:00
Arnaldo Carvalho de Melo 45618c7ec1 dwarf_loader: Initial support for DW_TAG_unspecified_type
Still need to check what to fprintf for this, but at least have it in
the type lists so that we can find it.

Reported-by: Christophe Fergeau <cfergeau@redhat.com>
Cc: Dodji Seketeli <dodji@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-17 10:05:34 -03:00
Arnaldo Carvalho de Melo 0fbb39291d dwarf_loader: Add support for DW_TAG_restrict_type
I.e. supporting the 'restrict' keyword, emitted by recent compilers:

  [acme@jouet pahole]$ pfunct -P ~/bin/perf |& grep -w restrict
  inline int vprintf(const char  * restrict  __fmt, struct __va_list_tag * __ap);
  inline size_t fread(void * restrict  __ptr, size_t __size, size_t __n, FILE * restrict  __stream);
  inline int vfprintf(FILE * restrict  __stream, const char  * restrict  __fmt, struct __va_list_tag * __ap);
  inline int vasprintf(char * * restrict  __ptr, const char  * restrict  __fmt, struct __va_list_tag * __ap);
  inline char * realpath(const char  * restrict  __name, char * restrict  __resolved);
  inline ssize_t readlink(const char  * restrict  __path, char * restrict  __buf, size_t __len);
  inline char * strcat(char * restrict  __dest, const char  * restrict  __src);
  inline char * fgets(char * restrict  __s, int __n, FILE * restrict  __stream);
  inline int snprintf(char * restrict  __s, size_t __n, const char  * restrict  __fmt, ...);
  inline int sprintf(char * restrict  __s, const char  * restrict  __fmt, ...);
  inline char * strcpy(char * restrict  __dest, const char  * restrict  __src);
  inline int asprintf(char * * restrict  __ptr, const char  * restrict  __fmt, ...);
  inline char * strncpy(char * restrict  __dest, const char  * restrict  __src, size_t __len);
  inline int fprintf(FILE * restrict  __stream, const char  * restrict  __fmt, ...);
  inline int vsnprintf(char * restrict  __s, size_t __n, const char  * restrict  __fmt, struct __va_list_tag * __ap);
  inline int printf(const char  * restrict  __fmt, ...);
  [acme@jouet pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-06 15:02:17 -03:00
Arnaldo Carvalho de Melo 9df42c6826 dwarves: Initial support for rvalue_reference_type
Need to read more on http://www.artima.com/cppsource/rvalue.html, but
handling it mostly like DW_TAG_typedef so that at least references to it
are resolved, we can get its byte size, etc.

FIXME: look at the vtable parameters, some are resolving to "(null)".

Reported-by: Benjamin Kosnik <bkoz@redhat.com>
Reported-by: Mark Wieelard <mjw@redhat.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=962571
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-03-15 16:37:48 -03:00
Arnaldo Carvalho de Melo 10515a7c4d dwarves: Introduce cus__fprintf_load_files_err()
Out of code in pdwtags and pahole, will be used in the other tools.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-03-15 14:25:58 -03:00
Arnaldo Carvalho de Melo fd3838ae9a dwarves: Stop using 'self'
As Thomas Gleixner wisely pointed out, using 'self' is stoopid, it
doesn't convey useful information, so use sensible names

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2014-01-06 16:46:50 -03:00
Arnaldo Carvalho de Melo 8c6378fd88 dwarves: Support static class data members
Fixes the following BFA:

[acme@sandy pahole]$ pahole brainfart.o
class ios_base {
	enum _Ios_Openmodeconst    in;                   /*     0     4 */
	typedef enum _Ios_Fmtflags fmtflags;

	/* size: 1, cachelines: 1, members: 1 */
	/* padding: 65533 */
	/* last cacheline: 1 bytes */

	/* BRAIN FART ALERT! 1 != 4 + 0(holes), diff = -3 */

};

That now produces:

[acme@sandy pahole]$ build/pahole brainfart.o
class ios_base {
	static enum _Ios_Openmodeconst    in = 8;        /*     0     0 */
	typedef enum _Ios_Fmtflags fmtflags;

	/* size: 1, cachelines: 0, members: 0, static members: 1 */
	/* last cacheline: 1 bytes */
};
[acme@sandy pahole]$

Reported-by: Nicolas <nikos42@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-20 14:42:17 -03:00
Tom Tromey 2938a70e1e Add support for .debug_types sections.
.debug_types is a new DWARF 4 feature that adds some simple
compression to DWARF.  The basic idea is that identical type
definitions are merged by the linker and put into a new .debug_types
section.

This introduces 'dwarf_off_ref', which is like Dwarf_Off, but carries
a flag indicating if the DIE came from .debug_types.  This allows
future uses to find the DIE properly.

Type units are read a little differently from ordinary CUs.  All type
units are read at once, then types are recoded for them.  (I think
something like this is needed more generally, to support inter-CU
references, but I have not tried that.)

The type unit is also kept around longer, because any other CU may
refer to it.  This necessitated a change to load_steal_kind to replace
the notion of a "stolen" CU with a request by the "stealer" for the
caller to delete the CU when appropriate.

I need elfutils patch 581c3f60e2b1fc7ddaf4260bb5a9cb59f8e3f0d0
to make this work properly; without it I see crashes.

You can make test cases by compiling with '-gdwarf-4 -fdebug-types-section'.
2012-03-22 12:51:20 -06:00
Tom Tromey 5ef26a053d Remove unused field from debug_fmt_ops
Nothing seemed to use the 'tag__orig_type' method in debug_fmt_ops.
It was simpler to remove it than to try to fix it for the next patch.
2012-03-22 12:43:59 -06:00
Arnaldo Carvalho de Melo 25cd635806 dwarves: base_type->float_type holds only 12 possible values
So make it a :4 u8 to combine with the previous bitfield. This field is
also seldom used so no expected perf hit.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-12-05 19:07:51 -02:00
Arnaldo Carvalho de Melo c6d27e325c dwarves: Enlarge vtable_entry
Since we have two bytes after it in a hole, use them for vtable_entry,
hell knows if there isn't any crazy code with that many vtable
entries...

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-12-05 18:35:10 -02:00
Arnaldo Carvalho de Melo 800fd44d6b dwarves: Make two bitfield entries be bool
As we had 14 bits hole, so use them as bools, each taking one byte
but generating better/shorter code.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-12-05 18:31:16 -02:00
Arnaldo Carvalho de Melo 6476d24d73 pahole: Introduce --hex to print offsets and sizes in hexadecimal
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-10-20 13:59:12 -02:00
Arnaldo Carvalho de Melo 9720415091 dwarf: Detect type loops
[acme@doppio pahole]$ pahole -F ctf /media/tb/debuginfo/usr/lib/debug/usr/bin/greycstoration4integration.debug > /tmp/bla
<ERROR(tag__size:837): detected type loop: type=572, tag=const_type>
<ERROR(tag__size:837): detected type loop: type=572, tag=const_type>
[acme@doppio pahole]$

These type loops are problems in the CTF encoding, that should be fixed, but
should not cause the core code to segfault on an infinite recursion.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-09-14 17:07:02 -03:00
Arnaldo Carvalho de Melo 406944b404 dwarves: Add more __name() routines and remove s()
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-09-12 18:11:19 -03:00
Arnaldo Carvalho de Melo 7e5b39f944 dwarves_fprintf: Make tag__id_not_found_(f|sn)printf print __LINE__
Helps debugging.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-09-11 15:10:43 -03:00
Arnaldo Carvalho de Melo fc1269af2f pahole: Introduce --classes_as_structs
That asks dwarf_fprintf to always use "struct" in places where it would
use "class", because CTF doesn't have the "class" concept, so for
'regtest diffctf' sake, we use this.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-08-24 17:22:43 -03:00
Arnaldo Carvalho de Melo d9b4badca2 ctf: Handle dwfl_module_getsymtab errors
That can happen, for instance, when the symtabs are NOBITS. When that
happened we ended up in an infinite loop. Call it earlier and check the
result.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-08-23 11:47:03 -03:00
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